Make the SkGrPixelRef be responsible for unlocking device's scratch texture in the cache
Review URL: https://codereview.appspot.com/6498046/
git-svn-id: http://skia.googlecode.com/svn/trunk@5313 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 8d43f70..fa0f60e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -172,23 +172,23 @@
SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture)
: SkDevice(make_bitmap(context, texture->asRenderTarget())) {
- this->initFromRenderTarget(context, texture->asRenderTarget());
+ this->initFromRenderTarget(context, texture->asRenderTarget(), false);
}
SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget)
: SkDevice(make_bitmap(context, renderTarget)) {
- this->initFromRenderTarget(context, renderTarget);
+ this->initFromRenderTarget(context, renderTarget, false);
}
void SkGpuDevice::initFromRenderTarget(GrContext* context,
- GrRenderTarget* renderTarget) {
+ GrRenderTarget* renderTarget,
+ bool cached) {
fNeedPrepareRenderTarget = false;
fDrawProcs = NULL;
fContext = context;
fContext->ref();
- fCached = false;
fRenderTarget = NULL;
fNeedClear = false;
@@ -204,7 +204,7 @@
if (NULL == surface) {
surface = fRenderTarget;
}
- SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface));
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached));
this->setPixelRef(pr, 0)->unref();
}
@@ -221,7 +221,6 @@
fContext = context;
fContext->ref();
- fCached = false;
fRenderTarget = NULL;
fNeedClear = false;
@@ -264,10 +263,6 @@
// This call gives the context a chance to relinquish it
fContext->setRenderTarget(NULL);
- GrTexture* texture = fRenderTarget->asTexture();
- if (NULL != texture && fCached) {
- fContext->unlockTexture(texture);
- }
SkSafeUnref(fRenderTarget);
fContext->unref();
}
@@ -1964,7 +1959,8 @@
: SkDevice(make_bitmap(context, texture->asRenderTarget())) {
GrAssert(texture && texture->asRenderTarget());
- this->initFromRenderTarget(context, texture->asRenderTarget());
- fCached = true;
+ // This constructor is called from onCreateCompatibleDevice. It has locked the RT in the texture
+ // cache. We pass true for the third argument so that it will get unlocked.
+ this->initFromRenderTarget(context, texture->asRenderTarget(), true);
fNeedClear = needClear;
}