handle null vertex or index buffers in batch
authorjoshualitt <joshualitt@chromium.org>
Thu, 5 Mar 2015 22:33:41 +0000 (14:33 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 5 Mar 2015 22:33:41 +0000 (14:33 -0800)
BUG=skia:

Review URL: https://codereview.chromium.org/979343002

gm/beziereffects.cpp
gm/convexpolyeffect.cpp
src/gpu/GrAAConvexPathRenderer.cpp
src/gpu/GrAAHairLinePathRenderer.cpp
src/gpu/GrAARectRenderer.cpp
src/gpu/GrContext.cpp
src/gpu/GrDefaultPathRenderer.cpp
src/gpu/GrInOrderDrawBuffer.cpp
src/gpu/GrOvalRenderer.cpp
src/gpu/GrTessellatingPathRenderer.cpp
src/gpu/effects/GrDashingEffect.cpp

index 45c6341..d86a8b8 100644 (file)
@@ -76,6 +76,11 @@ private:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         SkASSERT(vertexStride == sizeof(Vertex));
         Vertex* verts = reinterpret_cast<Vertex*>(vertices);
 
@@ -478,6 +483,11 @@ private:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         SkASSERT(vertexStride == sizeof(Vertex));
         Vertex* verts = reinterpret_cast<Vertex*>(vertices);
 
index 0a3be28..f3335c9 100644 (file)
@@ -62,6 +62,11 @@ private:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         SkASSERT(vertexStride == sizeof(SkPoint));
         SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
 
index 3ab8af5..317f9a0 100644 (file)
@@ -784,6 +784,11 @@ public:
                                                                   &vertexBuffer,
                                                                   &firstVertex);
 
+            if (!vertices) {
+                SkDebugf("Could not allocate vertices\n");
+                return;
+            }
+
             const GrIndexBuffer* indexBuffer;
             int firstIndex;
 
@@ -791,6 +796,11 @@ public:
                                                                 &indexBuffer,
                                                                 &firstIndex);
 
+            if (!indices) {
+                SkDebugf("Could not allocate indices\n");
+                return;
+            }
+
             QuadVertex* verts = reinterpret_cast<QuadVertex*>(vertices);
             uint16_t* idxs = reinterpret_cast<uint16_t*>(indices);
 
index 57c3b5a..26cf607 100644 (file)
@@ -895,6 +895,11 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget, const GrPipel
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex));
 
         LineVertex* verts = reinterpret_cast<LineVertex*>(vertices);
@@ -934,6 +939,11 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget, const GrPipel
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         // Setup vertices
         BezierVertex* verts = reinterpret_cast<BezierVertex*>(vertices);
 
@@ -1021,6 +1031,11 @@ bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target,
                                           const SkPath& path,
                                           const SkStrokeRec& stroke,
                                           bool) {
+    if (!fLinesIndexBuffer || !fQuadsIndexBuffer) {
+        SkDebugf("unable to allocate indices\n");
+        return false;
+    }
+
     SkScalar hairlineCoverage;
     uint8_t newCoverage = 0xff;
     if (IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) {
index 7c34c25..6affc92 100644 (file)
@@ -134,6 +134,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         for (int i = 0; i < instanceCount; i++) {
             const Geometry& args = fGeoData[i];
             this->generateAAFillRectGeometry(vertices,
@@ -445,13 +450,18 @@ void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target,
                                           const SkMatrix& viewMatrix,
                                           const SkRect& rect,
                                           const SkRect& devRect) {
-    if (NULL == fAAFillRectIndexBuffer) {
+    if (!fAAFillRectIndexBuffer) {
         fAAFillRectIndexBuffer = fGpu->createInstancedIndexBuffer(gFillAARectIdx,
                                                                   kIndicesPerAAFillRect,
                                                                   kNumAAFillRectsInIndexBuffer,
                                                                   kVertsPerAAFillRect);
     }
 
+    if (!fAAFillRectIndexBuffer) {
+        SkDebugf("Unable to create index buffer\n");
+        return;
+    }
+
     AAFillRectBatch::Geometry geometry;
     geometry.fRect = rect;
     geometry.fViewMatrix = viewMatrix;
@@ -623,6 +633,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         for (int i = 0; i < instanceCount; i++) {
             const Geometry& args = fGeoData[i];
             this->generateAAStrokeRectGeometry(vertices,
@@ -846,7 +861,7 @@ void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target,
                                             const SkRect& devInside,
                                             bool miterStroke) {
     GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke);
-    if (NULL == indexBuffer) {
+    if (!indexBuffer) {
         SkDebugf("Failed to create index buffer!\n");
         return;
     }
index ac44644..78f29e7 100755 (executable)
@@ -567,6 +567,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         SkPoint* vertex = reinterpret_cast<SkPoint*>(vertices);
 
         GrPrimitiveType primType;
@@ -900,6 +905,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         const GrIndexBuffer* indexBuffer;
         int firstIndex;
 
@@ -908,6 +918,11 @@ public:
             indices = batchTarget->indexPool()->makeSpace(this->indexCount(),
                                                           &indexBuffer,
                                                           &firstIndex);
+
+            if (!indices) {
+                SkDebugf("Could not allocate indices\n");
+                return;
+            }
         }
 
         int indexOffset = 0;
index 302aad7..9619e2a 100644 (file)
@@ -323,6 +323,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         const GrIndexBuffer* indexBuffer;
         int firstIndex;
 
@@ -331,6 +336,11 @@ public:
             indices = batchTarget->indexPool()->makeSpace(maxIndices,
                                                           &indexBuffer,
                                                           &firstIndex);
+
+            if (!indices) {
+                SkDebugf("Could not allocate indices\n");
+                return;
+            }
         }
 
         // fill buffers
index 2584635..4d8fa5e 100644 (file)
@@ -147,6 +147,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         for (int i = 0; i < instanceCount; i++) {
             const Geometry& args = fGeoData[i];
 
index fc8c184..20ae77c 100644 (file)
@@ -762,6 +762,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices);
 
         for (int i = 0; i < instanceCount; i++) {
@@ -1012,6 +1017,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(vertices);
 
         for (int i = 0; i < instanceCount; i++) {
@@ -1303,6 +1313,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(vertices);
 
         for (int i = 0; i < instanceCount; i++) {
@@ -1692,6 +1707,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices);
 
         for (int i = 0; i < instanceCount; i++) {
@@ -1896,6 +1916,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(vertices);
 
         for (int i = 0; i < instanceCount; i++) {
index 955e6c1..1170e1c 100644 (file)
@@ -1515,6 +1515,12 @@ public:
                                                               count,
                                                               &vertexBuffer,
                                                               &firstVertex);
+
+        if (!vertices) {
+            SkDebugf("Could not allocate vertices\n");
+            return;
+        }
+
         LOG("emitting %d verts\n", count);
         void* end = polys_to_triangles(polys, fillType, vertices);
         int actualCount = static_cast<int>(
index fc3fc67..eb0467c 100644 (file)
@@ -536,6 +536,11 @@ public:
                                                               &vertexBuffer,
                                                               &firstVertex);
 
+        if (!vertices || !batchTarget->quadIndexBuffer()) {
+            SkDebugf("Could not allocate buffers\n");
+            return;
+        }
+
         int curVIdx = 0;
         int rectIndex = 0;
         for (int i = 0; i < instanceCount; i++) {