Don't purge resources from cache if they have > 1 ref

https://codereview.appspot.com/6494069/



git-svn-id: http://skia.googlecode.com/svn/trunk@5380 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index ee127c8..f4919b1 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -332,9 +332,15 @@
     if (!fPurging) {
         fPurging = true;
         bool withinBudget = false;
+        int priorUnlockedEntryCount = 0;
+
+        // The purging process is repeated several times since one pass
+        // may free up other resources
         do {
             EntryList::Iter iter;
 
+            priorUnlockedEntryCount = fUnlockedEntryCount;
+
             // Note: the following code relies on the fact that the
             // doubly linked list doesn't invalidate its data/pointers
             // outside of the specific area where a deletion occurs (e.g.,
@@ -349,7 +355,7 @@
                 }
 
                 GrResourceEntry* prev = iter.prev();
-                if (!entry->isLocked()) {
+                if (!entry->isLocked() && entry->fResource->getRefCnt() == 1) {
                     // remove from our cache
                     fCache.remove(entry->key(), entry);
 
@@ -367,7 +373,7 @@
                 }
                 entry = prev;
             }
-        } while (!withinBudget && fUnlockedEntryCount);
+        } while (!withinBudget && (fUnlockedEntryCount != priorUnlockedEntryCount));
         fPurging = false;
     }
 }