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
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index b82cdb2..982d45e 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -28,6 +28,7 @@
void GrResourceEntry::validate() const {
GrAssert(fLockCount >= 0);
GrAssert(fResource);
+ GrAssert(fResource->getCacheEntry() == this);
fResource->validate();
}
#endif
@@ -158,21 +159,24 @@
#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* 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 @@
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);
}