diff options
author | 2013-02-05 17:00:02 +0000 | |
---|---|---|
committer | 2013-02-05 17:00:02 +0000 | |
commit | 19376b80476b0fdbdcc8ac33bfdbae9b0d3fdce7 (patch) | |
tree | aa1ff488656c435417c02892beb15052d914aa52 /src/core/SkDraw.cpp | |
parent | e7767cfca6663a2bd16e8f2de2c688c4a30bedac (diff) |
Fix unbalanced Shader set/endContext calls in drawVertices
Review URL: https://codereview.appspot.com/7309047
git-svn-id: http://skia.googlecode.com/svn/trunk@7588 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkDraw.cpp')
-rw-r--r-- | src/core/SkDraw.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 4b06b880de..0c8c7d36c6 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -2531,14 +2531,23 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, savedLocalM = shader->getLocalMatrix(); } + // setContext has already been called and verified to return true + // by the constructor of SkAutoBlitterChoose + bool prevContextSuccess = true; while (vertProc(&state)) { if (NULL != textures) { if (texture_to_matrix(state, vertices, textures, &tempM)) { tempM.postConcat(savedLocalM); shader->setLocalMatrix(tempM); - // need to recal setContext since we changed the local matrix - shader->endContext(); - if (!shader->setContext(*fBitmap, p, *fMatrix)) { + // Need to recall setContext since we changed the local matrix. + // However, we also need to balance the calls this with a + // call to endContext which requires tracking the result of + // the previous call to setContext. + if (prevContextSuccess) { + shader->endContext(); + } + prevContextSuccess = shader->setContext(*fBitmap, p, *fMatrix); + if (!prevContextSuccess) { continue; } } @@ -2555,10 +2564,18 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, }; SkScan::FillTriangle(tmp, *fRC, blitter.get()); } + // now restore the shader's original local matrix if (NULL != shader) { shader->setLocalMatrix(savedLocalM); } + + // If the final call to setContext fails we must make it suceed so that the + // call to endContext in the destructor for SkAutoBlitterChoose is balanced. + if (!prevContextSuccess) { + prevContextSuccess = shader->setContext(*fBitmap, paint, SkMatrix::I()); + SkASSERT(prevContextSuccess); + } } else { // no colors[] and no texture HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); |