Hide GrDrawVerticesBatch::Geometry and rename to Mesh
authorbsalomon <bsalomon@google.com>
Thu, 30 Jun 2016 14:59:23 +0000 (07:59 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 30 Jun 2016 14:59:24 +0000 (07:59 -0700)
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2104383003

Review-Url: https://codereview.chromium.org/2104383003

src/gpu/GrDrawContext.cpp
src/gpu/batches/GrDrawVerticesBatch.cpp
src/gpu/batches/GrDrawVerticesBatch.h

index 6b3346ca603f8fb78c1fce5624a0c05d557aa912..d057984f9c67b61e399cfc967437091aad4230f7 100644 (file)
@@ -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);
index dd1ed627c60c05e7be6d0b62e4a4bd6639feff62..81f418f2db3586c056797c7563b8770dc8135bd2 100644 (file)
@@ -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
index f2b1ea9f8afc62e09af86b143301f4b4ec83862e..9665c1a905a84005277dbcbb925190ea1c6d456a 100644 (file)
@@ -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;
 };