aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-06-30 07:59:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-30 07:59:24 -0700
commitd92b4198aef1ba719222e737edf6e28a39b43b6d (patch)
treee53f3c5e07abd2a3cf6c5d745437c7da6936817a /src
parent9a7acdc213506aeb451f2c05143d342e32f20c69 (diff)
Hide GrDrawVerticesBatch::Geometry and rename to Mesh
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrDrawContext.cpp10
-rw-r--r--src/gpu/batches/GrDrawVerticesBatch.cpp69
-rw-r--r--src/gpu/batches/GrDrawVerticesBatch.h39
3 files changed, 51 insertions, 67 deletions
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 6b3346ca60..d057984f9c 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -558,12 +558,10 @@ void GrDrawContext::drawVertices(const GrClip& clip,
bounds.outset(0.5f, 0.5f);
}
- GrDrawVerticesBatch::Geometry geometry;
- geometry.fColor = paint.getColor();
- SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveType, viewMatrix,
- positions, vertexCount, indices,
- indexCount, colors, texCoords,
- bounds));
+ SkAutoTUnref<GrDrawBatch> batch(new GrDrawVerticesBatch(paint.getColor(),
+ primitiveType, viewMatrix, positions,
+ vertexCount, indices, indexCount,
+ colors, texCoords, bounds));
GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint));
this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
diff --git a/src/gpu/batches/GrDrawVerticesBatch.cpp b/src/gpu/batches/GrDrawVerticesBatch.cpp
index dd1ed627c6..81f418f2db 100644
--- a/src/gpu/batches/GrDrawVerticesBatch.cpp
+++ b/src/gpu/batches/GrDrawVerticesBatch.cpp
@@ -31,7 +31,7 @@ static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasLocalCoords,
coverage, localCoords, viewMatrix);
}
-GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
+GrDrawVerticesBatch::GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiveType,
const SkMatrix& viewMatrix,
const SkPoint* positions, int vertexCount,
const uint16_t* indices, int indexCount,
@@ -41,22 +41,23 @@ GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy
SkASSERT(positions);
fViewMatrix = viewMatrix;
- Geometry& installedGeo = fGeoData.push_back(geometry);
+ Mesh& mesh = fMeshes.push_back();
+ mesh.fColor = color;
- installedGeo.fPositions.append(vertexCount, positions);
+ mesh.fPositions.append(vertexCount, positions);
if (indices) {
- installedGeo.fIndices.append(indexCount, indices);
+ mesh.fIndices.append(indexCount, indices);
}
if (colors) {
fVariableColor = true;
- installedGeo.fColors.append(vertexCount, colors);
+ mesh.fColors.append(vertexCount, colors);
} else {
fVariableColor = false;
}
if (localCoords) {
- installedGeo.fLocalCoords.append(vertexCount, localCoords);
+ mesh.fLocalCoords.append(vertexCount, localCoords);
}
fVertexCount = vertexCount;
fIndexCount = indexCount;
@@ -68,31 +69,31 @@ GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy
void GrDrawVerticesBatch::computePipelineOptimizations(GrInitInvariantOutput* color,
GrInitInvariantOutput* coverage,
GrBatchToXPOverrides* overrides) const {
- // When this is called on a batch, there is only one geometry bundle
+ // When this is called on a batch, there is only one mesh
if (fVariableColor) {
color->setUnknownFourComponents();
} else {
- color->setKnownFourComponents(fGeoData[0].fColor);
+ color->setKnownFourComponents(fMeshes[0].fColor);
}
coverage->setKnownSingleComponent(0xff);
}
void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& overrides) {
- SkASSERT(fGeoData.count() == 1);
+ SkASSERT(fMeshes.count() == 1);
GrColor overrideColor;
if (overrides.getOverrideColorIfSet(&overrideColor)) {
- fGeoData[0].fColor = overrideColor;
- fGeoData[0].fColors.reset();
+ fMeshes[0].fColor = overrideColor;
+ fMeshes[0].fColors.reset();
fVariableColor = false;
}
fCoverageIgnored = !overrides.readsCoverage();
if (!overrides.readsLocalCoords()) {
- fGeoData[0].fLocalCoords.reset();
+ fMeshes[0].fLocalCoords.reset();
}
}
void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
- bool hasLocalCoords = !fGeoData[0].fLocalCoords.isEmpty();
+ bool hasLocalCoords = !fMeshes[0].fLocalCoords.isEmpty();
int colorOffset = -1, texOffset = -1;
sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOffset, &texOffset,
fViewMatrix, fCoverageIgnored));
@@ -101,7 +102,7 @@ void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0)
+ sizeof(GrColor));
- int instanceCount = fGeoData.count();
+ int instanceCount = fMeshes.count();
const GrBuffer* vertexBuffer;
int firstVertex;
@@ -117,7 +118,7 @@ void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
int firstIndex = 0;
uint16_t* indices = nullptr;
- if (!fGeoData[0].fIndices.isEmpty()) {
+ if (!fMeshes[0].fIndices.isEmpty()) {
indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
if (!indices) {
@@ -129,24 +130,24 @@ void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
int indexOffset = 0;
int vertexOffset = 0;
for (int i = 0; i < instanceCount; i++) {
- const Geometry& args = fGeoData[i];
+ const Mesh& mesh = fMeshes[i];
// TODO we can actually cache this interleaved and then just memcopy
if (indices) {
- for (int j = 0; j < args.fIndices.count(); ++j, ++indexOffset) {
- *(indices + indexOffset) = args.fIndices[j] + vertexOffset;
+ for (int j = 0; j < mesh.fIndices.count(); ++j, ++indexOffset) {
+ *(indices + indexOffset) = mesh.fIndices[j] + vertexOffset;
}
}
- for (int j = 0; j < args.fPositions.count(); ++j) {
- *((SkPoint*)verts) = args.fPositions[j];
- if (args.fColors.isEmpty()) {
- *(GrColor*)((intptr_t)verts + colorOffset) = args.fColor;
+ for (int j = 0; j < mesh.fPositions.count(); ++j) {
+ *((SkPoint*)verts) = mesh.fPositions[j];
+ if (mesh.fColors.isEmpty()) {
+ *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColor;
} else {
- *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j];
+ *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColors[j];
}
if (hasLocalCoords) {
- *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords[j];
+ *(SkPoint*)((intptr_t)verts + texOffset) = mesh.fLocalCoords[j];
}
verts = (void*)((intptr_t)verts + vertexStride);
vertexOffset++;
@@ -181,21 +182,21 @@ bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
return false;
}
- if (fGeoData[0].fIndices.isEmpty() != that->fGeoData[0].fIndices.isEmpty()) {
+ if (fMeshes[0].fIndices.isEmpty() != that->fMeshes[0].fIndices.isEmpty()) {
return false;
}
- if (fGeoData[0].fLocalCoords.isEmpty() != that->fGeoData[0].fLocalCoords.isEmpty()) {
+ if (fMeshes[0].fLocalCoords.isEmpty() != that->fMeshes[0].fLocalCoords.isEmpty()) {
return false;
}
if (!fVariableColor) {
- if (that->fVariableColor || that->fGeoData[0].fColor != fGeoData[0].fColor) {
+ if (that->fVariableColor || that->fMeshes[0].fColor != fMeshes[0].fColor) {
fVariableColor = true;
}
}
- fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+ fMeshes.push_back_n(that->fMeshes.count(), that->fMeshes.begin());
fVertexCount += that->fVertexCount;
fIndexCount += that->fIndexCount;
@@ -310,14 +311,10 @@ DRAW_BATCH_TEST_DEFINE(VerticesBatch) {
viewMatrix.mapRect(&bounds);
- GrDrawVerticesBatch::Geometry geometry;
- geometry.fColor = GrRandomColor(random);
- return GrDrawVerticesBatch::Create(geometry, type, viewMatrix,
- positions.begin(), vertexCount,
- indices.begin(), hasIndices ? vertexCount : 0,
- colors.begin(),
- texCoords.begin(),
- bounds);
+ GrColor color = GrRandomColor(random);
+ return new GrDrawVerticesBatch(color, type, viewMatrix, positions.begin(), vertexCount,
+ indices.begin(), hasIndices ? vertexCount : 0,
+ colors.begin(), texCoords.begin(), bounds);
}
#endif
diff --git a/src/gpu/batches/GrDrawVerticesBatch.h b/src/gpu/batches/GrDrawVerticesBatch.h
index f2b1ea9f8a..9665c1a905 100644
--- a/src/gpu/batches/GrDrawVerticesBatch.h
+++ b/src/gpu/batches/GrDrawVerticesBatch.h
@@ -22,23 +22,12 @@ class GrDrawVerticesBatch : public GrVertexBatch {
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor; // Only used if there are no per-vertex colors
- SkTDArray<SkPoint> fPositions;
- SkTDArray<uint16_t> fIndices;
- SkTDArray<GrColor> fColors;
- SkTDArray<SkPoint> fLocalCoords;
- };
- static GrDrawBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType,
- const SkMatrix& viewMatrix,
- const SkPoint* positions, int vertexCount,
- const uint16_t* indices, int indexCount,
- const GrColor* colors, const SkPoint* localCoords,
- const SkRect& bounds) {
- return new GrDrawVerticesBatch(geometry, primitiveType, viewMatrix, positions, vertexCount,
- indices, indexCount, colors, localCoords, bounds);
- }
+ GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiveType,
+ const SkMatrix& viewMatrix,
+ const SkPoint* positions, int vertexCount,
+ const uint16_t* indices, int indexCount,
+ const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds);
const char* name() const override { return "DrawVerticesBatch"; }
@@ -46,18 +35,10 @@ public:
GrInitInvariantOutput* coverage,
GrBatchToXPOverrides* overrides) const override;
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
private:
void onPrepareDraws(Target*) const override;
void initBatchTracker(const GrXPOverridesForBatch&) override;
- GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
- const SkMatrix& viewMatrix,
- const SkPoint* positions, int vertexCount,
- const uint16_t* indices, int indexCount,
- const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds);
-
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
bool batchablePrimitiveType() const {
return kTriangles_GrPrimitiveType == fPrimitiveType ||
@@ -67,6 +48,14 @@ private:
bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
+ struct Mesh {
+ GrColor fColor; // Only used if there are no per-vertex colors
+ SkTDArray<SkPoint> fPositions;
+ SkTDArray<uint16_t> fIndices;
+ SkTDArray<GrColor> fColors;
+ SkTDArray<SkPoint> fLocalCoords;
+ };
+
GrPrimitiveType fPrimitiveType;
SkMatrix fViewMatrix;
bool fVariableColor;
@@ -74,7 +63,7 @@ private:
int fIndexCount;
bool fCoverageIgnored; // comes from initBatchTracker.
- SkSTArray<1, Geometry, true> fGeoData;
+ SkSTArray<1, Mesh, true> fMeshes;
typedef GrVertexBatch INHERITED;
};