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
diff --git a/gpu/src/GrPathRenderer.cpp b/gpu/src/GrPathRenderer.cpp
index 7220d0e..26c92b8 100644
--- a/gpu/src/GrPathRenderer.cpp
+++ b/gpu/src/GrPathRenderer.cpp
@@ -233,6 +233,9 @@
void GrDefaultPathRenderer::pathWillClear() {
fSubpathVertCount.realloc(0);
fTarget->resetVertexSource();
+ if (fUseIndexedDraw) {
+ fTarget->resetIndexSource();
+ }
fPreviousSrcTol = -GR_Scalar1;
fPreviousStages = -1;
}
@@ -268,9 +271,6 @@
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 @@
}
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 @@
}
}
}
+ // 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;
}