From 1f47f4f7325971dd53991e2bb02da94fa7c6d962 Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Thu, 16 Aug 2012 14:49:16 +0000 Subject: Replaced TextureCacheEntry with GrTexture* and a back pointer to GrResourceEntry (in GrTexture) http://codereview.appspot.com/6460089/ git-svn-id: http://skia.googlecode.com/svn/trunk@5122 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrResourceCache.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/gpu/GrResourceCache.cpp') diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index b82cdb2d4b..982d45e3dd 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -28,6 +28,7 @@ GrResourceEntry::~GrResourceEntry() { void GrResourceEntry::validate() const { GrAssert(fLockCount >= 0); GrAssert(fResource); + GrAssert(fResource->getCacheEntry() == this); fResource->validate(); } #endif @@ -158,21 +159,24 @@ public: #endif }; -GrResourceEntry* GrResourceCache::findAndLock(const GrResourceKey& key, - LockType type) { +GrResource* GrResourceCache::findAndLock(const GrResourceKey& key, + LockType type) { GrAutoResourceCacheValidate atcv(this); GrResourceEntry* entry = fCache.find(key); - if (entry) { - this->internalDetach(entry, false); - // mark the entry as "busy" so it doesn't get purged - // do this between detach and attach for locked count tracking - if (kNested_LockType == type || !entry->isLocked()) { - entry->lock(); - } - this->attachToHead(entry, false); + if (NULL == entry) { + return NULL; } - return entry; + + this->internalDetach(entry, false); + // mark the entry as "busy" so it doesn't get purged + // do this between detach and attach for locked count tracking + if (kNested_LockType == type || !entry->isLocked()) { + entry->lock(); + } + this->attachToHead(entry, false); + + return entry->fResource; } bool GrResourceCache::hasKey(const GrResourceKey& key) const { @@ -192,6 +196,8 @@ GrResourceEntry* GrResourceCache::create(const GrResourceKey& key, GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource)); + resource->setCacheEntry(entry); + if (lock) { // mark the entry as "busy" so it doesn't get purged // do this before attach for locked count tracking @@ -210,13 +216,15 @@ GrResourceEntry* GrResourceCache::create(const GrResourceKey& key, return entry; } -GrResourceEntry* GrResourceCache::createAndLock(const GrResourceKey& key, - GrResource* resource) { - return this->create(key, resource, true, false); +void GrResourceCache::createAndLock(const GrResourceKey& key, + GrResource* resource) { + GrAssert(NULL == resource->getCacheEntry()); + this->create(key, resource, true, false); } void GrResourceCache::attach(const GrResourceKey& key, GrResource* resource) { + GrAssert(NULL == resource->getCacheEntry()); this->create(key, resource, false, true); } -- cgit v1.2.3