From 6087975e5d9aed5b975831ade25daadedd485d2f Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Thu, 15 Sep 2011 20:43:53 +0000 Subject: [PATCH] Fix assertions in GrResourceCache::removeAll, don't reattached invalidated resources Review URL: http://codereview.appspot.com/5000048/ git-svn-id: http://skia.googlecode.com/svn/trunk@2272 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/src/GrResourceCache.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gpu/src/GrResourceCache.cpp b/gpu/src/GrResourceCache.cpp index 2b95f26155..3094721cee 100644 --- a/gpu/src/GrResourceCache.cpp +++ b/gpu/src/GrResourceCache.cpp @@ -206,9 +206,23 @@ void GrResourceCache::detach(GrResourceEntry* entry) { } void GrResourceCache::reattachAndUnlock(GrResourceEntry* entry) { - attachToHead(entry, true); - fCache.insert(entry->key(), entry); - unlock(entry); + GrAutoResourceCacheValidate atcv(this); + if (entry->resource()->isValid()) { + attachToHead(entry, true); + fCache.insert(entry->key(), entry); + } else { + // If the resource went invalid while it was detached then purge it + // This can happen when a 3D context was lost, + // the client called GrContext::contextDestroyed() to notify Gr, + // and then later an SkGpuDevice's destructor releases its backing + // texture (which was invalidated at contextDestroyed time). + fClientDetachedCount -= 1; + fEntryCount -= 1; + size_t size = entry->resource()->sizeInBytes(); + fClientDetachedBytes -= size; + fEntryBytes -= size; + } + this->unlock(entry); } void GrResourceCache::unlock(GrResourceEntry* entry) { @@ -273,8 +287,6 @@ void GrResourceCache::purgeAsNeeded() { void GrResourceCache::removeAll() { GrAutoResourceCacheValidate atcv(this); - GrAssert(!fClientDetachedCount); - GrAssert(!fClientDetachedBytes); GrResourceEntry* entry = fHead; @@ -290,8 +302,10 @@ void GrResourceCache::removeAll() { GrAssert(!fCache.count()); GrAssert(!fUnlockedEntryCount); - GrAssert(!fEntryCount); - GrAssert(!fEntryBytes); + // Items may have been detached from the cache (such as the backing texture + // for an SkGpuDevice). The above purge would not have removed them. + GrAssert(fEntryCount == fClientDetachedCount); + GrAssert(fEntryBytes == fClientDetachedBytes); GrAssert(NULL == fHead); GrAssert(NULL == fTail); @@ -360,5 +374,3 @@ void GrResourceCache::validate() const { } } #endif - -