From f2e93fc989129f11881919de99a3b8f12081beae Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Wed, 5 Sep 2012 19:44:18 +0000 Subject: [PATCH] Resource cache now explicitly takes ref of managed resources https://codereview.appspot.com/6489085/ git-svn-id: http://skia.googlecode.com/svn/trunk@5407 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrContext.cpp | 10 +++++----- src/gpu/GrResourceCache.cpp | 1 + src/gpu/GrStencilBuffer.h | 4 ++-- src/gpu/gl/GrGpuGL.cpp | 9 +++------ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a2158e2..edf45b8 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -381,13 +381,13 @@ GrTexture* GrContext::createAndLockTexture( GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheData, false); - GrTexture* texture = NULL; + SkAutoTUnref texture; if (GrTexture::NeedsResizing(resourceKey)) { - texture = this->createResizedTexture(desc, cacheData, + texture.reset(this->createResizedTexture(desc, cacheData, srcData, rowBytes, - GrTexture::NeedsFiltering(resourceKey)); + GrTexture::NeedsFiltering(resourceKey))); } else { - texture = fGpu->createTexture(desc, srcData, rowBytes); + texture.reset(fGpu->createTexture(desc, srcData, rowBytes)); } if (NULL != texture) { @@ -450,7 +450,7 @@ GrTexture* GrContext::lockScratchTexture(const GrTextureDesc& inDesc, desc.fFlags = inDesc.fFlags; desc.fWidth = origWidth; desc.fHeight = origHeight; - GrTexture* texture = fGpu->createTexture(desc, NULL, 0); + SkAutoTUnref texture(fGpu->createTexture(desc, NULL, 0)); if (NULL != texture) { GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, texture->desc(), diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 4561aea..4b262d4 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -17,6 +17,7 @@ GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource) // we assume ownership of the resource, and will unref it when we die GrAssert(resource); + resource->ref(); } GrResourceEntry::~GrResourceEntry() { diff --git a/src/gpu/GrStencilBuffer.h b/src/gpu/GrStencilBuffer.h index 27c0a0c..690fa32 100644 --- a/src/gpu/GrStencilBuffer.h +++ b/src/gpu/GrStencilBuffer.h @@ -59,8 +59,8 @@ public: return fLastClipData; } - // places the sb in the cache and locks it. Caller transfers - // a ref to the the cache which will unref when purged. + // Places the sb in the cache and locks it. The cache takes a ref + // of the stencil buffer. void transferToCacheAndLock(); static GrResourceKey ComputeKey(int width, int height, int sampleCnt); diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 8d55abb..74f9953 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -1105,19 +1105,16 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, // whatever sizes GL gives us. In that case we query for the size. GrGLStencilBuffer::Format format = sFmt; get_stencil_rb_sizes(this->glInterface(), sbID, &format); - sb = SkNEW_ARGS(GrGLStencilBuffer, - (this, sbID, width, height, - samples, format)); + SkAutoTUnref sb(SkNEW_ARGS(GrGLStencilBuffer, + (this, sbID, width, height, + samples, format))); if (this->attachStencilBufferToRenderTarget(sb, rt)) { fLastSuccessfulStencilFmtIdx = sIdx; - // This code transfers the creation ref to the - // cache and then adds a ref for the render target sb->transferToCacheAndLock(); rt->setStencilBuffer(sb); return true; } sb->abandon(); // otherwise we lose sbID - sb->unref(); } } GL_CALL(DeleteRenderbuffers(1, &sbID)); -- 2.7.4