Fix a GrThreadSafeUniquelyKeyedProxyViewCache test
I broke this when I switched over to the SkTDynamicHash
Bug: 1108408
Change-Id: I906b41330440d084ba2e97c0162af38a79da0529
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318696
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h
index 4585571..7f6c037 100644
--- a/src/core/SkTDynamicHash.h
+++ b/src/core/SkTDynamicHash.h
@@ -37,6 +37,8 @@
int count() const { return fTable.count(); }
+ size_t approxBytesUsed() const { return fTable.approxBytesUsed(); }
+
T* find(const Key& key) const { return fTable.findOrNull(key); }
void add(T* entry) { fTable.set(entry); }
diff --git a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
index 1732677..56748f4 100644
--- a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
+++ b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
@@ -24,10 +24,10 @@
return fUniquelyKeyedProxyViewMap.count();
}
-int GrThreadSafeUniquelyKeyedProxyViewCache::count() const {
+size_t GrThreadSafeUniquelyKeyedProxyViewCache::approxBytesUsedForHash() const {
SkAutoSpinlock lock{fSpinLock};
- return fUniquelyKeyedProxyViewMap.count();
+ return fUniquelyKeyedProxyViewMap.approxBytesUsed();
}
#endif
diff --git a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h
index f692505..1093bae 100644
--- a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h
+++ b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h
@@ -38,6 +38,16 @@
// an entry in this cache, however, doesn't guarantee that there is a corresponding entry in
// the resource cache - although the entry here should be able to generate that entry
// (i.e., be a lazy proxy)
+//
+// Wrt interactions w/ GrContext/GrResourceCache purging, we have:
+//
+// Both GrContext::abandonContext and GrContext::releaseResourcesAndAbandonContext will cause
+// all the refs held in this cache to be dropped prior to clearing out the resource cache.
+//
+// For the size_t-variant of GrContext::purgeUnlockedResources, after an initial attempt
+// to purge the requested amount of resources fails, uniquely held resources in this cache
+// will be dropped in LRU to MRU order until the cache is under budget. Note that this
+// prioritizes the survival of resources in this cache over those just in the resource cache.
class GrThreadSafeUniquelyKeyedProxyViewCache {
public:
GrThreadSafeUniquelyKeyedProxyViewCache();
@@ -45,7 +55,8 @@
#if GR_TEST_UTILS
int numEntries() const SK_EXCLUDES(fSpinLock);
- int count() const SK_EXCLUDES(fSpinLock);
+
+ size_t approxBytesUsedForHash() const SK_EXCLUDES(fSpinLock);
#endif
void dropAllRefs() SK_EXCLUDES(fSpinLock);
diff --git a/tests/GrThreadSafeViewCacheTest.cpp b/tests/GrThreadSafeViewCacheTest.cpp
index 2420323..91eba8a 100644
--- a/tests/GrThreadSafeViewCacheTest.cpp
+++ b/tests/GrThreadSafeViewCacheTest.cpp
@@ -380,9 +380,9 @@
int size = 16;
helper.accessCachedView(helper.ddlCanvas1(), size);
- int initialCount = threadSafeViewCache->count();
+ size_t initialSize = threadSafeViewCache->approxBytesUsedForHash();
- while (initialCount == threadSafeViewCache->count()) {
+ while (initialSize == threadSafeViewCache->approxBytesUsedForHash()) {
size *= 2;
helper.accessCachedView(helper.ddlCanvas1(), size);
}