From 82866fd5a7ac55a7abe7bc1069741fa353e608d8 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Fri, 5 Aug 2011 16:27:32 +0000 Subject: [PATCH] Fail path rendering gracefully when vb/ib space alloc fails Review URL: http://codereview.appspot.com/4839050/ git-svn-id: http://skia.googlecode.com/svn/trunk@2052 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/src/GrPathRenderer.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/gpu/src/GrPathRenderer.cpp b/gpu/src/GrPathRenderer.cpp index 7220d0e4aa..26c92b8400 100644 --- a/gpu/src/GrPathRenderer.cpp +++ b/gpu/src/GrPathRenderer.cpp @@ -233,6 +233,9 @@ bool GrDefaultPathRenderer::requiresStencilPass(const GrDrawTarget* target, void GrDefaultPathRenderer::pathWillClear() { fSubpathVertCount.realloc(0); fTarget->resetVertexSource(); + if (fUseIndexedDraw) { + fTarget->resetIndexSource(); + } fPreviousSrcTol = -GR_Scalar1; fPreviousStages = -1; } @@ -268,9 +271,6 @@ bool GrDefaultPathRenderer::createGeom(GrScalar srcSpaceTol, return false; } - fPreviousSrcTol = srcSpaceTol; - fPreviousStages = stages; - GrVertexLayout layout = 0; for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { if ((1 << s) & stages) { @@ -298,14 +298,21 @@ bool GrDefaultPathRenderer::createGeom(GrScalar srcSpaceTol, } GrPoint* base; - fTarget->reserveVertexSpace(layout, maxPts, (void**)&base); + if (!fTarget->reserveVertexSpace(layout, maxPts, (void**)&base)) { + return false; + } + GrAssert(NULL != base); GrPoint* vert = base; uint16_t* idxBase = NULL; uint16_t* idx = NULL; uint16_t subpathIdxStart = 0; if (fUseIndexedDraw) { - fTarget->reserveIndexSpace(maxIdxs, (void**)&idxBase); + if (!fTarget->reserveIndexSpace(maxIdxs, (void**)&idxBase)) { + fTarget->resetVertexSource(); + return false; + } + GrAssert(NULL != idxBase); idx = idxBase; } @@ -393,6 +400,11 @@ FINISHED: } } } + // set these at the end so if we failed on first drawPath inside a + // setPath/clearPath block we won't assume geom was created on a subsequent + // drawPath in the same block. + fPreviousSrcTol = srcSpaceTol; + fPreviousStages = stages; return true; }