Move SkDraw to use SkVerticesPriv, remove redundant private API
Change-Id: I84117c64177b263ed99638d055eda484a1959534
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280637
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h
index 2a4c299..83e5da1 100644
--- a/include/core/SkVertices.h
+++ b/include/core/SkVertices.h
@@ -130,7 +130,6 @@
SkVertices() {}
friend class SkVerticesPriv;
- friend class SkDraw;
// these are needed since we've manually sized our allocation (see Builder::init)
friend class SkNVRefCnt<SkVertices>;
@@ -138,23 +137,6 @@
Sizes getSizes() const;
- VertexMode mode() const { return fMode; }
-
- bool hasPerVertexData() const { return SkToBool(this->perVertexData()); }
- bool hasColors() const { return SkToBool(this->colors()); }
- bool hasTexCoords() const { return SkToBool(this->texCoords()); }
- bool hasIndices() const { return SkToBool(this->indices()); }
-
- int vertexCount() const { return fVertexCount; }
- int indexCount() const { return fIndexCount; }
- int perVertexDataCount() const { return fPerVertexDataCount; }
-
- const SkPoint* positions() const { return fPositions; }
- const float* perVertexData() const { return fPerVertexData; }
- const SkPoint* texCoords() const { return fTexs; }
- const SkColor* colors() const { return fColors; }
- const uint16_t* indices() const { return fIndices; }
-
// we store this first, to pair with the refcnt in our base-class, so we don't have an
// unnecessary pad between it and the (possibly 8-byte aligned) ptrs.
uint32_t fUniqueID;
diff --git a/src/core/SkDraw_vertices.cpp b/src/core/SkDraw_vertices.cpp
index dc3361a..f9116af 100644
--- a/src/core/SkDraw_vertices.cpp
+++ b/src/core/SkDraw_vertices.cpp
@@ -16,6 +16,7 @@
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkScan.h"
#include "src/core/SkVertState.h"
+#include "src/core/SkVerticesPriv.h"
#include "src/shaders/SkComposeShader.h"
#include "src/shaders/SkShaderBase.h"
@@ -260,14 +261,15 @@
const SkPaint& paint, const SkMatrix& ctmInv,
const SkPoint dev2[], const SkPoint3 dev3[],
SkArenaAlloc* outerAlloc) const {
- SkASSERT(vertices->perVertexDataCount() == 0);
+ SkVerticesPriv info(vertices->priv());
+ SkASSERT(!info.hasPerVertexData());
- const int vertexCount = vertices->vertexCount();
- const int indexCount = vertices->indexCount();
- const SkPoint* positions = vertices->positions();
- const SkPoint* textures = vertices->texCoords();
- const uint16_t* indices = vertices->indices();
- const SkColor* colors = vertices->colors();
+ const int vertexCount = info.vertexCount();
+ const int indexCount = info.indexCount();
+ const SkPoint* positions = info.positions();
+ const SkPoint* textures = info.texCoords();
+ const uint16_t* indices = info.indices();
+ const SkColor* colors = info.colors();
// make textures and shader mutually consistent
SkShader* shader = paint.getShader();
@@ -307,7 +309,7 @@
const bool usePerspective = fMatrix->hasPerspective();
VertState state(vertexCount, indices, indexCount);
- VertState::Proc vertProc = state.chooseProc(vertices->mode());
+ VertState::Proc vertProc = state.chooseProc(info.mode());
// Draw hairlines to show the skeleton
if (!(colors || textures)) {
@@ -436,20 +438,21 @@
SkASSERT(!!dev2 != !!dev3);
SkASSERT(!ctmInv.hasPerspective() || dev3 != nullptr);
- VertState state(vt->vertexCount(), vt->indices(), vt->indexCount());
- VertState::Proc vertProc = state.chooseProc(vt->mode());
+ SkVerticesPriv info(vt->priv());
+ VertState state(info.vertexCount(), info.indices(), info.indexCount());
+ VertState::Proc vertProc = state.chooseProc(info.mode());
SkPaint p(paint);
- if (vt->perVertexDataCount() >= 4) { // hack, treat as colors
+ if (info.perVertexDataCount() >= 4) { // hack, treat as colors
auto triShader = outerAlloc->make<SkTriColorShader>(false, dev3 != nullptr);
p.setShader(sk_ref_sp(triShader));
auto blitter = SkCreateRasterPipelineBlitter(fDst, p, *fMatrix, outerAlloc,
this->fRC->clipShader());
- auto colors = (const SkPMColor4f*)vt->perVertexData();
+ auto colors = (const SkPMColor4f*)info.perVertexData();
while (vertProc(&state)) {
- if (triShader->update(ctmInv, vt->positions(), colors, state.f0, state.f1, state.f2)) {
+ if (triShader->update(ctmInv, info.positions(), colors, state.f0, state.f1, state.f2)) {
fill_triangle(state, blitter, *fRC, dev2, dev3);
}
}
@@ -458,9 +461,10 @@
void SkDraw::drawVertices(const SkVertices* vertices, SkBlendMode bmode,
const SkPaint& paint) const {
- const int vertexCount = vertices->vertexCount();
- const int indexCount = vertices->indexCount();
- const int perVertexDataCount = vertices->perVertexDataCount();
+ SkVerticesPriv info(vertices->priv());
+ const int vertexCount = info.vertexCount();
+ const int indexCount = info.indexCount();
+ const int perVertexDataCount = info.perVertexDataCount();
// abort early if there is nothing to draw
if (vertexCount < 3 || (indexCount > 0 && indexCount < 3) || fRC->isEmpty()) {
@@ -482,14 +486,14 @@
if (fMatrix->hasPerspective()) {
dev3 = outerAlloc.makeArray<SkPoint3>(vertexCount);
- fMatrix->mapHomogeneousPoints(dev3, vertices->positions(), vertexCount);
+ fMatrix->mapHomogeneousPoints(dev3, info.positions(), vertexCount);
// similar to the bounds check for 2d points (below)
if (!SkScalarsAreFinite((const SkScalar*)dev3, vertexCount * 3)) {
return;
}
} else {
dev2 = outerAlloc.makeArray<SkPoint>(vertexCount);
- fMatrix->mapPoints(dev2, vertices->positions(), vertexCount);
+ fMatrix->mapPoints(dev2, info.positions(), vertexCount);
SkRect bounds;
// this also sets bounds to empty if we see a non-finite value
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index f2abaad..adfc833 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -190,11 +190,11 @@
}
int SkVertices::Builder::vertexCount() const {
- return fVertices ? fVertices->vertexCount() : 0;
+ return fVertices ? fVertices->fVertexCount : 0;
}
int SkVertices::Builder::indexCount() const {
- return fVertices ? fVertices->indexCount() : 0;
+ return fVertices ? fVertices->fIndexCount : 0;
}
int SkVertices::Builder::perVertexDataCount() const {
@@ -202,7 +202,7 @@
}
SkPoint* SkVertices::Builder::positions() {
- return fVertices ? const_cast<SkPoint*>(fVertices->positions()) : nullptr;
+ return fVertices ? const_cast<SkPoint*>(fVertices->fPositions) : nullptr;
}
float* SkVertices::Builder::perVertexData() {
@@ -210,11 +210,11 @@
}
SkPoint* SkVertices::Builder::texCoords() {
- return fVertices ? const_cast<SkPoint*>(fVertices->texCoords()) : nullptr;
+ return fVertices ? const_cast<SkPoint*>(fVertices->fTexs) : nullptr;
}
SkColor* SkVertices::Builder::colors() {
- return fVertices ? const_cast<SkColor*>(fVertices->colors()) : nullptr;
+ return fVertices ? const_cast<SkColor*>(fVertices->fColors) : nullptr;
}
uint16_t* SkVertices::Builder::indices() {
@@ -224,7 +224,7 @@
if (fIntermediateFanIndices) {
return reinterpret_cast<uint16_t*>(fIntermediateFanIndices.get());
}
- return const_cast<uint16_t*>(fVertices->indices());
+ return const_cast<uint16_t*>(fVertices->fIndices);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -255,10 +255,7 @@
}
SkVertices::Sizes SkVertices::getSizes() const {
- Sizes sizes({
- fMode, fVertexCount, fIndexCount, fPerVertexDataCount,
- this->hasTexCoords(), this->hasColors()
- });
+ Sizes sizes({fMode, fVertexCount, fIndexCount, fPerVertexDataCount, !!fTexs, !!fColors});
SkASSERT(sizes.isValid());
return sizes;
}
@@ -307,10 +304,10 @@
// packed has room for addtional flags in the future (e.g. versioning)
uint32_t packed = static_cast<uint32_t>(fMode);
SkASSERT((packed & ~kMode_Mask) == 0); // our mode fits in the mask bits
- if (this->hasTexCoords()) {
+ if (fTexs) {
packed |= kHasTexs_Mask;
}
- if (this->hasColors()) {
+ if (fColors) {
packed |= kHasColors_Mask;
}
packed |= kCurrent_Version << kVersion_Shift;
diff --git a/src/core/SkVerticesPriv.h b/src/core/SkVerticesPriv.h
index fd7cbef..81edc28 100644
--- a/src/core/SkVerticesPriv.h
+++ b/src/core/SkVerticesPriv.h
@@ -21,10 +21,10 @@
public:
SkVertices::VertexMode mode() const { return fVertices->fMode; }
- bool hasColors() const { return fVertices->hasColors(); }
- bool hasTexCoords() const { return fVertices->hasTexCoords(); }
- bool hasIndices() const { return fVertices->hasIndices(); }
- bool hasPerVertexData() const { return fVertices->hasPerVertexData(); }
+ bool hasPerVertexData() const { return SkToBool(fVertices->fPerVertexData); }
+ bool hasColors() const { return SkToBool(fVertices->fColors); }
+ bool hasTexCoords() const { return SkToBool(fVertices->fTexs); }
+ bool hasIndices() const { return SkToBool(fVertices->fIndices); }
int vertexCount() const { return fVertices->fVertexCount; }
int indexCount() const { return fVertices->fIndexCount; }