move vertex-mode enum into SkVertices
BUG=skia:6366 Change-Id: I3c0bf96cce6d32c9b8d12d16a772aaa6f18981aa Reviewed-on: https://skia-review.googlesource.com/11062 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
b55dd55312
commit
887cdf1128
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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";
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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];
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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*,
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user