Don't read from unref'ed RT in GrContext::readSurfacePixels
authorbsalomon <bsalomon@google.com>
Tue, 28 Jul 2015 22:39:45 +0000 (15:39 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 28 Jul 2015 22:39:45 +0000 (15:39 -0700)
BUG=chromium:514716

TBR=robertphillips@google.com

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

src/gpu/GrContext.cpp

index 9077bc0..6b7f552 100755 (executable)
@@ -484,7 +484,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
         return false;
     }
 
-    GrRenderTarget* rtToRead = src->asRenderTarget();
+    SkAutoTUnref<GrRenderTarget> rtToRead(SkSafeRef(src->asRenderTarget()));
     bool didTempDraw = false;
     if (GrGpu::kNoDraw_DrawPreference != drawPreference) {
         GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_ScratchTexMatch;
@@ -496,7 +496,8 @@ bool GrContext::readSurfacePixels(GrSurface* src,
             }
         }
         SkAutoTUnref<GrTexture> temp;
-        temp.reset(this->textureProvider()->refScratchTexture(tempDrawInfo.fTempSurfaceDesc, match));
+        temp.reset(this->textureProvider()->refScratchTexture(tempDrawInfo.fTempSurfaceDesc,
+                                                              match));
         if (temp) {
             SkMatrix textureMatrix;
             textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
@@ -526,7 +527,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
                 GrDrawContext* drawContext = this->drawContext();
                 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen(), paint,
                                       SkMatrix::I(), rect, NULL);
-                rtToRead = temp->asRenderTarget();
+                rtToRead.reset(SkRef(temp->asRenderTarget()));
                 left = 0;
                 top = 0;
                 didTempDraw = true;