Prefer a texture pixel ref to a render target pixel ref when creating an SkGpuDevice
Review URL: http://codereview.appspot.com/5570050/
git-svn-id: http://skia.googlecode.com/svn/trunk@3081 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index ad15553..25ded63 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -167,8 +167,18 @@
// if this RT is also a texture, hold a ref on it
fTexture = fRenderTarget->asTexture();
SkSafeRef(fTexture);
-
- SkGrRenderTargetPixelRef* pr = new SkGrRenderTargetPixelRef(fRenderTarget);
+
+ // Create a pixel ref for the underlying SkBitmap. We prefer a texture pixel
+ // ref to a render target pixel reft. The pixel ref may get ref'ed outside
+ // the device via accessBitmap. This external ref may outlive the device.
+ // Since textures own their render targets (but not vice-versa) we
+ // are ensuring that both objects will live as long as the pixel ref.
+ SkPixelRef* pr;
+ if (fTexture) {
+ pr = new SkGrTexturePixelRef(fTexture);
+ } else {
+ pr = new SkGrRenderTargetPixelRef(fRenderTarget);
+ }
this->setPixelRef(pr, 0)->unref();
}