AutoScratchTexture can now release its texture and it will return to the texture cache when freed

http://codereview.appspot.com/6262043/



git-svn-id: http://skia.googlecode.com/svn/trunk@4301 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 6a6c166..8c93971 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -81,6 +81,9 @@
         --fUnlockedEntryCount;
     }
 
+    entry->fPrev = NULL;
+    entry->fNext = NULL;
+
     // update our stats
     if (clientDetach) {
         fClientDetachedCount += 1;
@@ -165,8 +168,9 @@
     return NULL != fCache.find(key);
 }
 
-GrResourceEntry* GrResourceCache::createAndLock(const GrResourceKey& key,
-                                              GrResource* resource) {
+GrResourceEntry* GrResourceCache::create(const GrResourceKey& key,
+                                         GrResource* resource,
+                                         bool lock) {
     // we don't expect to create new resources during a purge. In theory
     // this could cause purgeAsNeeded() into an infinite loop (e.g.
     // each resource destroyed creates and locks 2 resources and
@@ -176,9 +180,11 @@
 
     GrResourceEntry* entry = new GrResourceEntry(key, resource);
 
-    // mark the entry as "busy" so it doesn't get purged
-    // do this before attach for locked count tracking
-    entry->lock();
+    if (lock) {
+        // mark the entry as "busy" so it doesn't get purged
+        // do this before attach for locked count tracking
+        entry->lock();
+    }
 
     this->attachToHead(entry, false);
     fCache.insert(key, entry);
@@ -192,12 +198,27 @@
     return entry;
 }
 
+GrResourceEntry* GrResourceCache::createAndLock(const GrResourceKey& key,
+                                                GrResource* resource) {
+    return this->create(key, resource, true);
+}
+
+void GrResourceCache::attach(const GrResourceKey& key,
+                             GrResource* resource) {
+    this->create(key, resource, false);
+}
+
 void GrResourceCache::detach(GrResourceEntry* entry) {
     GrAutoResourceCacheValidate atcv(this);
-    internalDetach(entry, true);
+    this->internalDetach(entry, true);
     fCache.remove(entry->fKey, entry);
 }
 
+void GrResourceCache::freeEntry(GrResourceEntry* entry) {
+    GrAssert(NULL == entry->fNext && NULL == entry->fPrev);
+    delete entry;
+}
+
 void GrResourceCache::reattachAndUnlock(GrResourceEntry* entry) {
     GrAutoResourceCacheValidate atcv(this);
     if (entry->resource()->isValid()) {