Increase testing of GrThreadSafeUniquelyKeyedProxyViewCache wrt GrResourceCache purging

Bug: 1108408
Change-Id: I2d6f89ce71b8d94be22b1ff38b9e205df94ca765
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318205
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
index 4a40198..1732677 100644
--- a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
+++ b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
@@ -7,6 +7,8 @@
 
 #include "src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h"
 
+#include "src/gpu/GrResourceCache.h"
+
 GrThreadSafeUniquelyKeyedProxyViewCache::GrThreadSafeUniquelyKeyedProxyViewCache()
     : fFreeEntryList(nullptr) {
 }
@@ -40,21 +42,26 @@
     // TODO: should we empty out the fFreeEntryList and reset fEntryAllocator?
 }
 
-void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllUniqueRefs() {
+void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllUniqueRefs(GrResourceCache* resourceCache) {
     SkAutoSpinlock lock{fSpinLock};
 
-    Entry* cur = fUniquelyKeyedProxyViewList.head();
-    Entry* next = cur ? cur->fNext : nullptr;
+    // Iterate from LRU to MRU
+    Entry* cur = fUniquelyKeyedProxyViewList.tail();
+    Entry* prev = cur ? cur->fPrev : nullptr;
 
     while (cur) {
+        if (resourceCache && !resourceCache->overBudget()) {
+            return;
+        }
+
         if (cur->fView.proxy()->unique()) {
             fUniquelyKeyedProxyViewMap.remove(cur->fKey);
             fUniquelyKeyedProxyViewList.remove(cur);
             this->recycleEntry(cur);
         }
 
-        cur = next;
-        next = cur ? cur->fNext : nullptr;
+        cur = prev;
+        prev = cur ? cur->fPrev : nullptr;
     }
 }