From ed6f03e5edea3fb803ac937184796a5bef65cd9b Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 30 Jul 2014 07:31:35 -0700 Subject: Fix ref counting of cached layer's texture R=bsalomon@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/431603002 --- src/gpu/GrLayerCache.cpp | 6 ++++-- src/gpu/GrLayerCache.h | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/gpu') 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 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; } -- cgit v1.2.3