From: joshualitt Date: Thu, 5 Mar 2015 22:33:41 +0000 (-0800) Subject: handle null vertex or index buffers in batch X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~3297 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b31de8328bbf3ee789157ae1dc6fe7cc74c796a;p=platform%2Fupstream%2FlibSkiaSharp.git handle null vertex or index buffers in batch BUG=skia: Review URL: https://codereview.chromium.org/979343002 --- diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 45c6341..d86a8b8 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -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(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(vertices); diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index 0a3be28..f3335c9 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -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(vertices); diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 3ab8af5..317f9a0 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -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(vertices); uint16_t* idxs = reinterpret_cast(indices); diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp index 57c3b5a..26cf607 100644 --- a/src/gpu/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/GrAAHairLinePathRenderer.cpp @@ -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(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(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)) { diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp index 7c34c25..6affc92 100644 --- a/src/gpu/GrAARectRenderer.cpp +++ b/src/gpu/GrAARectRenderer.cpp @@ -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; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index ac44644..78f29e7 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -567,6 +567,11 @@ public: &vertexBuffer, &firstVertex); + if (!vertices) { + SkDebugf("Could not allocate vertices\n"); + return; + } + SkPoint* vertex = reinterpret_cast(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; diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp index 302aad7..9619e2a 100644 --- a/src/gpu/GrDefaultPathRenderer.cpp +++ b/src/gpu/GrDefaultPathRenderer.cpp @@ -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 diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp index 2584635..4d8fa5e 100644 --- a/src/gpu/GrInOrderDrawBuffer.cpp +++ b/src/gpu/GrInOrderDrawBuffer.cpp @@ -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]; diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index fc8c184..20ae77c 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -762,6 +762,11 @@ public: &vertexBuffer, &firstVertex); + if (!vertices || !batchTarget->quadIndexBuffer()) { + SkDebugf("Could not allocate buffers\n"); + return; + } + CircleVertex* verts = reinterpret_cast(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(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(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(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(vertices); for (int i = 0; i < instanceCount; i++) { diff --git a/src/gpu/GrTessellatingPathRenderer.cpp b/src/gpu/GrTessellatingPathRenderer.cpp index 955e6c1..1170e1c 100644 --- a/src/gpu/GrTessellatingPathRenderer.cpp +++ b/src/gpu/GrTessellatingPathRenderer.cpp @@ -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( diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index fc3fc67..eb0467c 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -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++) {