diff options
author | 2014-07-30 07:31:35 -0700 | |
---|---|---|
committer | 2014-07-30 07:31:35 -0700 | |
commit | ed6f03e5edea3fb803ac937184796a5bef65cd9b (patch) | |
tree | e385fc3c7f033c4055b4227b3afcf95fc296a9a4 /src/gpu | |
parent | ff65bb98638efb20fe8165496ab7f4a0968b21d0 (diff) |
Fix ref counting of cached layer's texture
R=bsalomon@google.com
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/431603002
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrLayerCache.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrLayerCache.h | 11 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index 58994790b7..2c97387c7f 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -198,8 +198,10 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) { // The texture wouldn't fit in the cache - give it it's own texture. // This path always uses a new scratch texture and (thus) doesn't cache anything. // This can yield a lot of re-rendering - layer->setTexture(fContext->lockAndRefScratchTexture(desc, GrContext::kApprox_ScratchTexMatch), - GrIRect16::MakeWH(SkToS16(desc.fWidth), SkToS16(desc.fHeight))); + SkAutoTUnref<GrTexture> tex(fContext->lockAndRefScratchTexture(desc, + GrContext::kApprox_ScratchTexMatch)); + + layer->setTexture(tex, GrIRect16::MakeWH(SkToS16(desc.fWidth), SkToS16(desc.fHeight))); layer->setLocked(true); return false; } diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h index c5fa236388..f4087d66f0 100644 --- a/src/gpu/GrLayerCache.h +++ b/src/gpu/GrLayerCache.h @@ -82,16 +82,15 @@ public: SkASSERT(SK_InvalidGenID != pictureID && layerID >= 0); } + ~GrCachedLayer() { + SkSafeUnref(fTexture); + } + uint32_t pictureID() const { return fKey.getPictureID(); } int layerID() const { return fKey.getLayerID(); } - // This call takes over the caller's ref void setTexture(GrTexture* texture, const GrIRect16& rect) { - if (NULL != fTexture) { - fTexture->unref(); - } - - fTexture = texture; // just take over caller's ref + SkRefCnt_SafeAssign(fTexture, texture); fRect = rect; } GrTexture* texture() { return fTexture; } |