aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GameBench.cpp6
-rw-r--r--bench/VertBench.cpp10
-rw-r--r--fuzz/FuzzCanvas.cpp21
-rw-r--r--gm/gamut.cpp6
-rw-r--r--gm/vertices.cpp45
-rw-r--r--gn/android_framework_defines.gni1
-rw-r--r--include/core/SkCanvas.h2
-rw-r--r--include/core/SkVertices.h46
-rw-r--r--samplecode/SamplePatch.cpp8
-rw-r--r--samplecode/SampleSlides.cpp23
-rw-r--r--samplecode/SampleVertices.cpp24
-rw-r--r--src/core/SkCanvas.cpp8
-rw-r--r--src/core/SkDraw.cpp2
-rw-r--r--src/core/SkDraw.h3
-rw-r--r--src/core/SkPicturePlayback.cpp2
-rw-r--r--src/core/SkVertState.cpp8
-rw-r--r--src/core/SkVertState.h4
-rw-r--r--src/core/SkVertices.cpp20
-rw-r--r--src/gpu/SkGpuDevice.cpp8
-rw-r--r--src/gpu/SkGpuDevice.h2
-rw-r--r--src/gpu/SkGr.h9
-rw-r--r--src/gpu/ops/GrDrawVerticesOp.cpp2
-rw-r--r--src/pipe/SkPipeReader.cpp30
-rw-r--r--src/utils/SkDumpCanvas.cpp2
-rw-r--r--src/utils/SkPatchUtils.cpp2
-rw-r--r--src/utils/SkShadowTessellator.cpp2
-rw-r--r--tests/BlitRowTest.cpp6
-rw-r--r--tests/CanvasTest.cpp6
-rw-r--r--tests/VerticesTest.cpp2
-rw-r--r--tools/viewer/Viewer.cpp11
30 files changed, 170 insertions, 151 deletions
diff --git a/bench/GameBench.cpp b/bench/GameBench.cpp
index 681b823f09..bd7d11465d 100644
--- a/bench/GameBench.cpp
+++ b/bench/GameBench.cpp
@@ -11,6 +11,7 @@
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
+#include "SkVertices.h"
// This bench simulates the calls Skia sees from various HTML5 canvas
// game bench marks
@@ -200,8 +201,9 @@ protected:
{ SkIntToScalar(src.fRight), SkIntToScalar(src.fTop) },
{ SkIntToScalar(src.fRight), SkIntToScalar(src.fBottom) },
};
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
- 4, verts, uvs, nullptr, indices, 6, p2);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode,
+ 4, verts, uvs, nullptr, 6, indices),
+ SkBlendMode::kModulate, p2);
} else {
canvas->drawBitmapRect(fAtlas, src, dst, &p,
SkCanvas::kFast_SrcRectConstraint);
diff --git a/bench/VertBench.cpp b/bench/VertBench.cpp
index 0744f948ba..6e1613b9ff 100644
--- a/bench/VertBench.cpp
+++ b/bench/VertBench.cpp
@@ -11,6 +11,7 @@
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
+#include "SkVertices.h"
enum VertFlags {
kColors_VertFlag,
@@ -76,14 +77,15 @@ public:
}
protected:
- virtual const char* onGetName() { return fName.c_str(); }
- virtual void onDraw(int loops, SkCanvas* canvas) {
+ const char* onGetName() override { return fName.c_str(); }
+ void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
this->setupPaint(&paint);
+ auto verts = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, PTS,
+ fPts, nullptr, fColors, IDX, fIdx);
for (int i = 0; i < loops; i++) {
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, PTS,
- fPts, nullptr, fColors, fIdx, IDX, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
}
}
private:
diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp
index 3b533398a8..ba9f3eda90 100644
--- a/fuzz/FuzzCanvas.cpp
+++ b/fuzz/FuzzCanvas.cpp
@@ -1717,9 +1717,9 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
}
case 53: {
fuzz_paint(fuzz, &paint, depth - 1);
- SkCanvas::VertexMode vertexMode;
+ SkVertices::VertexMode vertexMode;
SkBlendMode blendMode;
- fuzz_enum_range(fuzz, &vertexMode, 0, SkCanvas::kTriangleFan_VertexMode);
+ fuzz_enum_range(fuzz, &vertexMode, 0, SkVertices::kTriangleFan_VertexMode);
fuzz->next(&blendMode);
constexpr int kMaxCount = 100;
int vertexCount;
@@ -1744,18 +1744,11 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
fuzz->nextRange(&indices[i], 0, vertexCount - 1);
}
}
- if (make_fuzz_t<bool>(fuzz)) {
- canvas->drawVertices(vertexMode, vertexCount, vertices,
- useTexs ? texs : nullptr, useColors ? colors : nullptr,
- blendMode, indexCount > 0 ? indices : nullptr, indexCount,
- paint);
- } else {
- canvas->drawVertices(SkVertices::MakeCopy(vertexMode, vertexCount, vertices,
- useTexs ? texs : nullptr,
- useColors ? colors : nullptr,
- indexCount, indices),
- blendMode, paint);
- }
+ canvas->drawVertices(SkVertices::MakeCopy(vertexMode, vertexCount, vertices,
+ useTexs ? texs : nullptr,
+ useColors ? colors : nullptr,
+ indexCount, indices),
+ blendMode, paint);
break;
}
default:
diff --git a/gm/gamut.cpp b/gm/gamut.cpp
index af104c480a..2aaa2b36d3 100644
--- a/gm/gamut.cpp
+++ b/gm/gamut.cpp
@@ -13,6 +13,7 @@
#include "SkImagePriv.h"
#include "SkPM4fPriv.h"
#include "SkSurface.h"
+#include "SkVertices.h"
static const int gRectSize = 50;
static const SkScalar gScalarSize = SkIntToScalar(gRectSize);
@@ -105,8 +106,9 @@ struct VerticesCellRenderer : public CellRenderer {
SkPoint::Make(gScalarSize, gScalarSize),
SkPoint::Make(0, gScalarSize)
};
- canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, vertices, nullptr, fColors,
- SkBlendMode::kModulate, nullptr, 0, paint);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, vertices,
+ nullptr, fColors),
+ SkBlendMode::kModulate, paint);
}
const char* label() override {
return "Vertices";
diff --git a/gm/vertices.cpp b/gm/vertices.cpp
index 4bf9f87f5e..7c7c011d46 100644
--- a/gm/vertices.cpp
+++ b/gm/vertices.cpp
@@ -89,12 +89,10 @@ class VerticesGM : public skiagm::GM {
sk_sp<SkShader> fShader1;
sk_sp<SkShader> fShader2;
sk_sp<SkColorFilter> fColorFilter;
- bool fUseObject;
SkScalar fShaderScale;
public:
- VerticesGM(bool useObject, SkScalar shaderScale = 1)
- : fUseObject(useObject), fShaderScale(shaderScale) {}
+ VerticesGM(SkScalar shaderScale) : fShaderScale(shaderScale) {}
protected:
@@ -107,9 +105,6 @@ protected:
SkString onShortName() override {
SkString name("vertices");
- if (fUseObject) {
- name.append("_object");
- }
if (fShaderScale != 1) {
name.append("_scaled_shader");
}
@@ -173,16 +168,10 @@ protected:
const SkColor* colors = attrs.fHasColors ? fColors : nullptr;
const SkPoint* texs = attrs.fHasTexs ? fTexs : nullptr;
- if (fUseObject) {
- auto v = SkVertices::MakeCopy(SkCanvas::kTriangleFan_VertexMode,
- kMeshVertexCnt, fPts, texs, colors,
- kMeshIndexCnt, kMeshFan);
- canvas->drawVertices(v, mode, paint);
- } else {
- canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode,
- kMeshVertexCnt, fPts, texs, colors, mode,
- kMeshFan, kMeshIndexCnt, paint);
- }
+ auto v = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode,
+ kMeshVertexCnt, fPts, texs, colors,
+ kMeshIndexCnt, kMeshFan);
+ canvas->drawVertices(v, mode, paint);
canvas->translate(40, 0);
++x;
}
@@ -200,14 +189,13 @@ private:
/////////////////////////////////////////////////////////////////////////////////////
-DEF_GM(return new VerticesGM(true);)
-DEF_GM(return new VerticesGM(false);)
-DEF_GM(return new VerticesGM(false, 1 / kShaderSize);)
+DEF_GM(return new VerticesGM(1);)
+DEF_GM(return new VerticesGM(1 / kShaderSize);)
-static void draw_batching(SkCanvas* canvas, bool useObject) {
+static void draw_batching(SkCanvas* canvas) {
// Triangle fans can't batch so we convert to regular triangles,
static constexpr int kNumTris = kMeshIndexCnt - 2;
- SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, kMeshVertexCnt, 3 * kNumTris,
+ SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, kMeshVertexCnt, 3 * kNumTris,
SkVertices::kHasColors_BuilderFlag |
SkVertices::kHasTexCoords_BuilderFlag);
@@ -245,14 +233,9 @@ static void draw_batching(SkCanvas* canvas, bool useObject) {
paint.setShader(useShader ? shader : nullptr);
const SkPoint* t = useTex ? texs : nullptr;
- if (useObject) {
- auto v = SkVertices::MakeCopy(SkCanvas::kTriangles_VertexMode, kMeshVertexCnt,
- pts, t, colors, kNumTris * 3, indices);
- canvas->drawVertices(v, SkBlendMode::kModulate, paint);
- } else {
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, kMeshVertexCnt, pts,
- t, colors, indices, kNumTris * 3, paint);
- }
+ auto v = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, kMeshVertexCnt,
+ pts, t, colors, kNumTris * 3, indices);
+ canvas->drawVertices(v, SkBlendMode::kModulate, paint);
canvas->restore();
}
canvas->translate(0, 120);
@@ -263,7 +246,7 @@ static void draw_batching(SkCanvas* canvas, bool useObject) {
// This test exists to exercise batching in the gpu backend.
DEF_SIMPLE_GM(vertices_batching, canvas, 100, 500) {
- draw_batching(canvas, false);
+ draw_batching(canvas);
canvas->translate(50, 0);
- draw_batching(canvas, true);
+ draw_batching(canvas);
}
diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni
index f84c275294..364ea39fd5 100644
--- a/gn/android_framework_defines.gni
+++ b/gn/android_framework_defines.gni
@@ -16,4 +16,5 @@ android_framework_defines = [
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
"SK_SUPPORT_LEGACY_CANVAS_HELPERS",
+ "SK_SUPPORT_LEGACY_CANVAS_VERTICES",
]
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index a1ba4c50e7..a40b434739 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1138,6 +1138,7 @@ public:
}
#endif
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
enum VertexMode {
kTriangles_VertexMode,
kTriangleStrip_VertexMode,
@@ -1178,6 +1179,7 @@ public:
this->drawVertices(vmode, vertexCount, vertices, texs, colors, SkBlendMode::kModulate,
indices, indexCount, paint);
}
+#endif
/** Draw vertices from an immutable SkVertices object.
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h
index e4b5bcb80b..7006850fbc 100644
--- a/include/core/SkVertices.h
+++ b/include/core/SkVertices.h
@@ -8,36 +8,64 @@
#ifndef SkVertices_DEFINED
#define SkVertices_DEFINED
-#include "SkCanvas.h"
#include "SkColor.h"
#include "SkData.h"
#include "SkPoint.h"
#include "SkRect.h"
#include "SkRefCnt.h"
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
+#include "SkCanvas.h"
+#endif
+
/**
* An immutable set of vertex data that can be used with SkCanvas::drawVertices.
*/
class SkVertices : public SkNVRefCnt<SkVertices> {
public:
+ enum VertexMode {
+ kTriangles_VertexMode,
+ kTriangleStrip_VertexMode,
+ kTriangleFan_VertexMode,
+ };
+
/**
* Create a vertices by copying the specified arrays. texs and colors may be nullptr,
* and indices is ignored if indexCount == 0.
*/
- static sk_sp<SkVertices> MakeCopy(SkCanvas::VertexMode mode, int vertexCount,
+ static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount,
const SkPoint positions[],
const SkPoint texs[],
const SkColor colors[],
int indexCount,
const uint16_t indices[]);
- static sk_sp<SkVertices> MakeCopy(SkCanvas::VertexMode mode, int vertexCount,
+ static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount,
const SkPoint positions[],
const SkPoint texs[],
const SkColor colors[]) {
return MakeCopy(mode, vertexCount, positions, texs, colors, 0, nullptr);
}
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
+ static sk_sp<SkVertices> MakeCopy(SkCanvas::VertexMode mode, int vertexCount,
+ const SkPoint positions[],
+ const SkPoint texs[],
+ const SkColor colors[],
+ int indexCount,
+ const uint16_t indices[]) {
+ return MakeCopy(static_cast<VertexMode>(mode), vertexCount, positions, texs, colors,
+ indexCount, indices);
+ }
+
+ static sk_sp<SkVertices> MakeCopy(SkCanvas::VertexMode mode, int vertexCount,
+ const SkPoint positions[],
+ const SkPoint texs[],
+ const SkColor colors[]) {
+ return MakeCopy(static_cast<VertexMode>(mode), vertexCount, positions, texs, colors);
+ }
+#endif
+
struct Sizes;
enum BuilderFlags {
@@ -46,7 +74,11 @@ public:
};
class Builder {
public:
+ Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags);
+
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount, uint32_t flags);
+#endif
bool isValid() const { return fVertices != nullptr; }
@@ -62,9 +94,9 @@ public:
sk_sp<SkVertices> detach();
private:
- Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount, const Sizes&);
+ Builder(VertexMode mode, int vertexCount, int indexCount, const Sizes&);
- void init(SkCanvas::VertexMode mode, int vertexCount, int indexCount, const Sizes&);
+ void init(VertexMode mode, int vertexCount, int indexCount, const Sizes&);
// holds a partially complete object. only completed in detach()
sk_sp<SkVertices> fVertices;
@@ -73,7 +105,7 @@ public:
};
uint32_t uniqueID() const { return fUniqueID; }
- SkCanvas::VertexMode mode() const { return fMode; }
+ VertexMode mode() const { return fMode; }
const SkRect& bounds() const { return fBounds; }
bool hasColors() const { return SkToBool(this->colors()); }
@@ -127,7 +159,7 @@ private:
int fVertexCnt;
int fIndexCnt;
- SkCanvas::VertexMode fMode;
+ VertexMode fMode;
// below here is where the actual array data is stored.
};
diff --git a/samplecode/SamplePatch.cpp b/samplecode/SamplePatch.cpp
index 54de942fc8..47786bfa3d 100644
--- a/samplecode/SamplePatch.cpp
+++ b/samplecode/SamplePatch.cpp
@@ -21,6 +21,7 @@
#include "SkColorFilter.h"
#include "SkTime.h"
#include "SkTypeface.h"
+#include "SkVertices.h"
#include "SkOSFile.h"
#include "SkStream.h"
@@ -179,9 +180,10 @@ void Patch::draw(SkCanvas* canvas, const SkPaint& paint, int nu, int nv,
s += ds;
}
t += dt;
- canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount,
- strip, doTextures ? tex : nullptr,
- doColors ? colors : nullptr, nullptr, 0, paint);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangleStrip_VertexMode, stripCount,
+ strip, doTextures ? tex : nullptr,
+ doColors ? colors : nullptr),
+ SkBlendMode::kModulate, paint);
}
}
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index 2322c24446..b8cf3800e0 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -13,6 +13,7 @@
#include "SkGradientShader.h"
#include "SkLayerRasterizer.h"
#include "SkPaint.h"
+#include "SkVertices.h"
#include "SkView.h"
#include "sk_tool_utils.h"
@@ -328,7 +329,7 @@ static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
class Rec {
public:
- SkCanvas::VertexMode fMode;
+ SkVertices::VertexMode fMode;
int fCount;
SkPoint* fVerts;
SkPoint* fTexs;
@@ -341,7 +342,7 @@ static void make_tris(Rec* rec) {
int n = 10;
SkRandom rand;
- rec->fMode = SkCanvas::kTriangles_VertexMode;
+ rec->fMode = SkVertices::kTriangles_VertexMode;
rec->fCount = n * 3;
rec->fVerts = new SkPoint[rec->fCount];
@@ -358,7 +359,7 @@ static void make_fan(Rec* rec, int texWidth, int texHeight) {
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
- rec->fMode = SkCanvas::kTriangleFan_VertexMode;
+ rec->fMode = SkVertices::kTriangleFan_VertexMode;
rec->fCount = n + 2;
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
@@ -388,7 +389,7 @@ static void make_strip(Rec* rec, int texWidth, int texHeight) {
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
- rec->fMode = SkCanvas::kTriangleStrip_VertexMode;
+ rec->fMode = SkVertices::kTriangleStrip_VertexMode;
rec->fCount = 2 * (n + 1);
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
@@ -433,26 +434,22 @@ static void mesh_slide(SkCanvas* canvas) {
paint.setFilterQuality(kLow_SkFilterQuality);
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
+ auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
+ fRecs[i].fVerts, fRecs[i].fTexs, nullptr);
canvas->save();
paint.setShader(nullptr);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->translate(SkIntToScalar(210), 0);
paint.setShader(fShader0);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->translate(SkIntToScalar(210), 0);
paint.setShader(fShader1);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->restore();
canvas->translate(0, SkIntToScalar(250));
diff --git a/samplecode/SampleVertices.cpp b/samplecode/SampleVertices.cpp
index d08726c027..9d3e6015ee 100644
--- a/samplecode/SampleVertices.cpp
+++ b/samplecode/SampleVertices.cpp
@@ -18,6 +18,7 @@
#include "SkColorFilter.h"
#include "SkTime.h"
#include "SkTypeface.h"
+#include "SkVertices.h"
#include "SkOSFile.h"
#include "SkStream.h"
@@ -84,26 +85,23 @@ protected:
paint.setFilterQuality(kLow_SkFilterQuality);
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
+ auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
+ fRecs[i].fVerts, fRecs[i].fTexs,
+ nullptr);
canvas->save();
paint.setShader(nullptr);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->translate(SkIntToScalar(250), 0);
paint.setShader(fShader0);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->translate(SkIntToScalar(250), 0);
paint.setShader(fShader1);
- canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
- fRecs[i].fVerts, fRecs[i].fTexs,
- nullptr, nullptr, 0, paint);
+ canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
canvas->restore();
canvas->translate(0, SkIntToScalar(250));
@@ -123,7 +121,7 @@ protected:
private:
struct Rec {
- SkCanvas::VertexMode fMode;
+ SkVertices::VertexMode fMode;
int fCount;
SkPoint* fVerts;
SkPoint* fTexs;
@@ -136,7 +134,7 @@ private:
int n = 10;
SkRandom rand;
- rec->fMode = SkCanvas::kTriangles_VertexMode;
+ rec->fMode = SkVertices::kTriangles_VertexMode;
rec->fCount = n * 3;
rec->fVerts = new SkPoint[rec->fCount];
@@ -153,7 +151,7 @@ private:
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
- rec->fMode = SkCanvas::kTriangleFan_VertexMode;
+ rec->fMode = SkVertices::kTriangleFan_VertexMode;
rec->fCount = n + 2;
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
@@ -183,7 +181,7 @@ private:
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
- rec->fMode = SkCanvas::kTriangleStrip_VertexMode;
+ rec->fMode = SkVertices::kTriangleStrip_VertexMode;
rec->fCount = 2 * (n + 1);
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 030180475d..d20179a290 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -51,6 +51,12 @@
#include "SkClipOpPriv.h"
#include "SkVertices.h"
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
+static_assert((int)SkCanvas::kTriangles_VertexMode == (int)SkVertices::kTriangles_VertexMode, "");
+static_assert((int)SkCanvas::kTriangleStrip_VertexMode == (int)SkVertices::kTriangleStrip_VertexMode, "");
+static_assert((int)SkCanvas::kTriangleFan_VertexMode == (int)SkVertices::kTriangleFan_VertexMode, "");
+#endif
+
#define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
class SkNoPixelsDevice : public SkBaseDevice {
@@ -1796,6 +1802,7 @@ void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], con
this->onDrawPoints(mode, count, pts, paint);
}
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, const SkPoint positions[],
const SkPoint texs[], const SkColor colors[], SkBlendMode bmode,
const uint16_t indices[], int indexCount, const SkPaint& paint) {
@@ -1805,6 +1812,7 @@ void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, const SkPoint pos
this->onDrawVerticesObject(vertices.get(), bmode, paint);
}
}
+#endif
void SkCanvas::drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode,
const SkPaint& paint) {
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 689e5b7c34..07129f62b3 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1943,7 +1943,7 @@ sk_sp<SkShader> MakeTextureShader(const VertState& state, const SkPoint verts[],
} // anonymous ns
-void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
+void SkDraw::drawVertices(SkVertices::VertexMode vmode, int count,
const SkPoint vertices[], const SkPoint textures[],
const SkColor colors[], SkBlendMode bmode,
const uint16_t indices[], int indexCount,
diff --git a/src/core/SkDraw.h b/src/core/SkDraw.h
index 0b29468d8e..3168735799 100644
--- a/src/core/SkDraw.h
+++ b/src/core/SkDraw.h
@@ -14,6 +14,7 @@
#include "SkMask.h"
#include "SkPaint.h"
#include "SkStrokeRec.h"
+#include "SkVertices.h"
class SkBitmap;
class SkClipStack;
@@ -68,7 +69,7 @@ public:
void drawPosText(const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkPaint&, const SkSurfaceProps*) const;
- void drawVertices(SkCanvas::VertexMode mode, int count,
+ void drawVertices(SkVertices::VertexMode mode, int count,
const SkPoint vertices[], const SkPoint textures[],
const SkColor colors[], SkBlendMode bmode,
const uint16_t indices[], int ptCount,
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index e5fc4fd916..51a3da9b0d 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -651,7 +651,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
case DRAW_VERTICES_RETIRED_03_2017: {
const SkPaint* paint = fPictureData->getPaint(reader);
DrawVertexFlags flags = (DrawVertexFlags)reader->readInt();
- SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt();
+ SkVertices::VertexMode vmode = (SkVertices::VertexMode)reader->readInt();
int vCount = reader->readInt();
const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
const SkPoint* texs = nullptr;
diff --git a/src/core/SkVertState.cpp b/src/core/SkVertState.cpp
index 7c3047ec40..ef3604d736 100644
--- a/src/core/SkVertState.cpp
+++ b/src/core/SkVertState.cpp
@@ -92,13 +92,13 @@ bool VertState::TriangleFanX(VertState* state) {
return true;
}
-VertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) {
+VertState::Proc VertState::chooseProc(SkVertices::VertexMode mode) {
switch (mode) {
- case SkCanvas::kTriangles_VertexMode:
+ case SkVertices::kTriangles_VertexMode:
return fIndices ? TrianglesX : Triangles;
- case SkCanvas::kTriangleStrip_VertexMode:
+ case SkVertices::kTriangleStrip_VertexMode:
return fIndices ? TriangleStripX : TriangleStrip;
- case SkCanvas::kTriangleFan_VertexMode:
+ case SkVertices::kTriangleFan_VertexMode:
return fIndices ? TriangleFanX : TriangleFan;
default:
return nullptr;
diff --git a/src/core/SkVertState.h b/src/core/SkVertState.h
index ab794521b0..89d224ee6e 100644
--- a/src/core/SkVertState.h
+++ b/src/core/SkVertState.h
@@ -8,7 +8,7 @@
#ifndef SkVertState_DEFINED
#define SkVertState_DEFINED
-#include "SkCanvas.h"
+#include "SkVertices.h"
/** \struct VertState
This is a helper for drawVertices(). It is used to iterate over the triangles
@@ -40,7 +40,7 @@ struct VertState {
* Choose an appropriate function to traverse the vertices.
* @param mode Specifies the SkCanvas::VertexMode.
*/
- Proc chooseProc(SkCanvas::VertexMode mode);
+ Proc chooseProc(SkVertices::VertexMode mode);
private:
int fCount;
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index 297b424e77..83204b54d5 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -50,7 +50,7 @@ struct SkVertices::Sizes {
size_t fISize;
};
-SkVertices::Builder::Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount,
+SkVertices::Builder::Builder(VertexMode mode, int vertexCount, int indexCount,
uint32_t builderFlags) {
bool hasTexs = SkToBool(builderFlags & SkVertices::kHasTexCoords_BuilderFlag);
bool hasColors = SkToBool(builderFlags & SkVertices::kHasColors_BuilderFlag);
@@ -58,12 +58,22 @@ SkVertices::Builder::Builder(SkCanvas::VertexMode mode, int vertexCount, int ind
SkVertices::Sizes(vertexCount, indexCount, hasTexs, hasColors));
}
-SkVertices::Builder::Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount,
+SkVertices::Builder::Builder(VertexMode mode, int vertexCount, int indexCount,
const SkVertices::Sizes& sizes) {
this->init(mode, vertexCount, indexCount, sizes);
}
-void SkVertices::Builder::init(SkCanvas::VertexMode mode, int vertexCount, int indexCount,
+#ifdef SK_SUPPORT_LEGACY_CANVAS_VERTICES
+SkVertices::Builder::Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount,
+ uint32_t builderFlags) {
+ bool hasTexs = SkToBool(builderFlags & SkVertices::kHasTexCoords_BuilderFlag);
+ bool hasColors = SkToBool(builderFlags & SkVertices::kHasColors_BuilderFlag);
+ this->init(static_cast<VertexMode>(mode), vertexCount, indexCount,
+ SkVertices::Sizes(vertexCount, indexCount, hasTexs, hasColors));
+}
+#endif
+
+void SkVertices::Builder::init(VertexMode mode, int vertexCount, int indexCount,
const SkVertices::Sizes& sizes) {
if (!sizes.isValid()) {
return; // fVertices will already be null
@@ -120,7 +130,7 @@ uint16_t* SkVertices::Builder::indices() {
///////////////////////////////////////////////////////////////////////////////////////////////////
-sk_sp<SkVertices> SkVertices::MakeCopy(SkCanvas::VertexMode mode, int vertexCount,
+sk_sp<SkVertices> SkVertices::MakeCopy(VertexMode mode, int vertexCount,
const SkPoint pos[], const SkPoint texs[],
const SkColor colors[], int indexCount,
const uint16_t indices[]) {
@@ -196,7 +206,7 @@ sk_sp<SkVertices> SkVertices::Decode(const void* data, size_t length) {
const int vertexCount = reader.readInt();
const int indexCount = reader.readInt();
- const SkCanvas::VertexMode mode = static_cast<SkCanvas::VertexMode>(packed & kMode_Mask);
+ const VertexMode mode = static_cast<VertexMode>(packed & kMode_Mask);
const bool hasTexs = SkToBool(packed & kHasTexs_Mask);
const bool hasColors = SkToBool(packed & kHasColors_Mask);
Sizes sizes(vertexCount, indexCount, hasTexs, hasColors);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 4e16d5965f..11ed637250 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1586,7 +1586,7 @@ static bool init_vertices_paint(GrContext* context, GrRenderTargetContext* rtc,
}
}
-void SkGpuDevice::wireframeVertices(SkCanvas::VertexMode vmode, int vertexCount,
+void SkGpuDevice::wireframeVertices(SkVertices::VertexMode vmode, int vertexCount,
const SkPoint vertices[], SkBlendMode bmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
@@ -1607,11 +1607,11 @@ void SkGpuDevice::wireframeVertices(SkCanvas::VertexMode vmode, int vertexCount,
int triangleCount = 0;
int n = (nullptr == indices) ? vertexCount : indexCount;
switch (vmode) {
- case SkCanvas::kTriangles_VertexMode:
+ case SkVertices::kTriangles_VertexMode:
triangleCount = n / 3;
break;
- case SkCanvas::kTriangleStrip_VertexMode:
- case SkCanvas::kTriangleFan_VertexMode:
+ case SkVertices::kTriangleStrip_VertexMode:
+ case SkVertices::kTriangleFan_VertexMode:
triangleCount = n - 2;
break;
}
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index b40eaddcb1..4558c1b17a 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -230,7 +230,7 @@ private:
bool drawDashLine(const SkPoint pts[2], const SkPaint& paint);
void drawStrokedLine(const SkPoint pts[2], const SkPaint&);
- void wireframeVertices(SkCanvas::VertexMode, int vertexCount, const SkPoint verts[],
+ void wireframeVertices(SkVertices::VertexMode, int vertexCount, const SkPoint verts[],
SkBlendMode, const uint16_t indices[], int indexCount, const SkPaint&);
static sk_sp<GrRenderTargetContext> MakeRenderTargetContext(GrContext*,
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index 5a7e1e2cd6..866dcce984 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -19,6 +19,7 @@
#include "SkImageInfo.h"
#include "SkMatrix.h"
#include "SkPM4f.h"
+#include "SkVertices.h"
#include "SkXfermodePriv.h"
class GrCaps;
@@ -164,13 +165,13 @@ GrSamplerParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain
//////////////////////////////////////////////////////////////////////////////
-static inline GrPrimitiveType SkVertexModeToGrPrimitiveType(const SkCanvas::VertexMode mode) {
+static inline GrPrimitiveType SkVertexModeToGrPrimitiveType(SkVertices::VertexMode mode) {
switch (mode) {
- case SkCanvas::kTriangles_VertexMode:
+ case SkVertices::kTriangles_VertexMode:
return kTriangles_GrPrimitiveType;
- case SkCanvas::kTriangleStrip_VertexMode:
+ case SkVertices::kTriangleStrip_VertexMode:
return kTriangleStrip_GrPrimitiveType;
- case SkCanvas::kTriangleFan_VertexMode:
+ case SkVertices::kTriangleFan_VertexMode:
return kTriangleFan_GrPrimitiveType;
}
SkFAIL("Invalid mode");
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index 71835dba9e..c67233c9ed 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -15,7 +15,7 @@ std::unique_ptr<GrLegacyMeshDrawOp> GrDrawVerticesOp::Make(
const SkPoint* positions, int vertexCount, const uint16_t* indices, int indexCount,
const uint32_t* colors, const SkPoint* localCoords, const SkRect& bounds,
GrRenderTargetContext::ColorArrayType colorArrayType) {
- static constexpr SkCanvas::VertexMode kIgnoredMode = SkCanvas::kTriangles_VertexMode;
+ static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode;
SkASSERT(positions);
if (!colors) {
// When we tessellate we will fill a color array with the GrColor value passed above as
diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp
index 6310b15bae..974e6b005d 100644
--- a/src/pipe/SkPipeReader.cpp
+++ b/src/pipe/SkPipeReader.cpp
@@ -17,6 +17,7 @@
#include "SkRSXform.h"
#include "SkTextBlob.h"
#include "SkTypeface.h"
+#include "SkVertices.h"
class SkPipeReader;
@@ -567,32 +568,9 @@ static void drawImageLattice_handler(SkPipeReader& reader, uint32_t packedVerb,
static void drawVertices_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) {
SkASSERT(SkPipeVerb::kDrawVertices == unpack_verb(packedVerb));
- SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)
- ((packedVerb & kVMode_DrawVerticesMask) >> kVMode_DrawVerticesShift);
- int vertexCount = packedVerb & kVCount_DrawVerticesMask;
- if (0 == vertexCount) {
- vertexCount = reader.read32();
- }
- SkBlendMode bmode = (SkBlendMode)
- ((packedVerb & kXMode_DrawVerticesMask) >> kXMode_DrawVerticesShift);
- const SkPoint* vertices = skip<SkPoint>(reader, vertexCount);
- const SkPoint* texs = nullptr;
- if (packedVerb & kHasTex_DrawVerticesMask) {
- texs = skip<SkPoint>(reader, vertexCount);
- }
- const SkColor* colors = nullptr;
- if (packedVerb & kHasColors_DrawVerticesMask) {
- colors = skip<SkColor>(reader, vertexCount);
- }
- int indexCount = 0;
- const uint16_t* indices = nullptr;
- if (packedVerb & kHasIndices_DrawVerticesMask) {
- indexCount = reader.read32();
- indices = skip<uint16_t>(reader, indexCount);
- }
-
- canvas->drawVertices(vmode, vertexCount, vertices, texs, colors, bmode,
- indices, indexCount, read_paint(reader));
+ SkBlendMode bmode = (SkBlendMode)unpack_verb_extra(packedVerb);
+ sk_sp<SkData> data = reader.readByteArrayAsData();
+ canvas->drawVertices(SkVertices::Decode(data->data(), data->size()), bmode, read_paint(reader));
}
static void drawPicture_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) {
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 030f4deed3..8e1f554998 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -121,7 +121,7 @@ static void toString(const SkRegion& rgn, SkString* str) {
}
}
-static const char* toString(SkCanvas::VertexMode vm) {
+static const char* toString(SkVertices::VertexMode vm) {
static const char* gVMNames[] = {
"TRIANGLES", "STRIP", "FAN"
};
diff --git a/src/utils/SkPatchUtils.cpp b/src/utils/SkPatchUtils.cpp
index 52ecfb1ec5..7567304835 100644
--- a/src/utils/SkPatchUtils.cpp
+++ b/src/utils/SkPatchUtils.cpp
@@ -348,7 +348,7 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
flags |= SkVertices::kHasColors_BuilderFlag;
}
- SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, vertexCount, indexCount, flags);
+ SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
SkPoint* pos = builder.positions();
SkPoint* texs = builder.texCoords();
SkColor* colors = builder.colors();
diff --git a/src/utils/SkShadowTessellator.cpp b/src/utils/SkShadowTessellator.cpp
index ce161ca8de..fa3f3f479f 100644
--- a/src/utils/SkShadowTessellator.cpp
+++ b/src/utils/SkShadowTessellator.cpp
@@ -29,7 +29,7 @@ public:
if (!fSucceeded) {
return nullptr;
}
- return SkVertices::MakeCopy(SkCanvas::kTriangles_VertexMode, this->vertexCount(),
+ return SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, this->vertexCount(),
fPositions.begin(), nullptr, fColors.begin(),
this->indexCount(), fIndices.begin());
}
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp
index 3439a5e09d..d2f333dbb6 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -10,6 +10,7 @@
#include "SkColorPriv.h"
#include "SkGradientShader.h"
#include "SkRect.h"
+#include "SkVertices.h"
#include "Test.h"
#include "sk_tool_utils.h"
@@ -173,8 +174,9 @@ struct Mesh {
}
void draw(SkCanvas* canvas, SkPaint* paint) {
- canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, fPts, fPts,
- nullptr, SkBlendMode::kModulate, nullptr, 0, *paint);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, fPts,
+ fPts, nullptr),
+ SkBlendMode::kModulate, *paint);
}
};
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 8327b555cc..9e7de67165 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -65,6 +65,7 @@
#include "SkSurface.h"
#include "SkTemplates.h"
#include "SkTDArray.h"
+#include "SkVertices.h"
#include "Test.h"
DEF_TEST(canvas_clipbounds, reporter) {
@@ -476,8 +477,9 @@ static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& d,
SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader(d.fBitmap, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode));
- canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts,
- nullptr, SkBlendMode::kModulate, nullptr, 0, paint);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, pts, pts,
+ nullptr),
+ SkBlendMode::kModulate, paint);
}
// NYI: issue 240.
TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep);
diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp
index 9621d80cd0..5c5c6af41d 100644
--- a/tests/VerticesTest.cpp
+++ b/tests/VerticesTest.cpp
@@ -59,7 +59,7 @@ DEF_TEST(Vertices, reporter) {
for (auto colF : colFlags) {
uint32_t flags = texF | colF;
- SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, vCount, iCount, flags);
+ SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vCount, iCount, flags);
for (int i = 0; i < vCount; ++i) {
float x = (float)i;
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index fecb14d59d..de4c6e0cbf 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -33,6 +33,7 @@
#include "SkSwizzle.h"
#include "SkTaskGroup.h"
#include "SkTime.h"
+#include "SkVertices.h"
#include "imgui.h"
@@ -1209,10 +1210,12 @@ void Viewer::drawImGui(SkCanvas* canvas) {
canvas->save();
canvas->clipRect(SkRect::MakeLTRB(drawCmd->ClipRect.x, drawCmd->ClipRect.y,
drawCmd->ClipRect.z, drawCmd->ClipRect.w));
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, drawList->VtxBuffer.size(),
- pos.begin(), uv.begin(), color.begin(),
- drawList->IdxBuffer.begin() + indexOffset, drawCmd->ElemCount,
- *paint);
+ canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode,
+ drawList->VtxBuffer.size(), pos.begin(),
+ uv.begin(), color.begin(),
+ drawCmd->ElemCount,
+ drawList->IdxBuffer.begin() + indexOffset),
+ SkBlendMode::kModulate, *paint);
indexOffset += drawCmd->ElemCount;
canvas->restore();
}