Notify resource caches when pixelref genID goes stale
patch from issue 954443002 at patchset 40001 (http://crrev.com/954443002#ps40001)
BUG=skia:
Review URL: https://codereview.chromium.org/950363002
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index a4cfa73..45dee92 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -14,8 +14,8 @@
struct TestingKey : public SkResourceCache::Key {
intptr_t fValue;
- TestingKey(intptr_t value) : fValue(value) {
- this->init(&gGlobalAddress, sizeof(fValue));
+ TestingKey(intptr_t value, uint64_t sharedID = 0) : fValue(value) {
+ this->init(&gGlobalAddress, sharedID, sizeof(fValue));
}
};
struct TestingRec : public SkResourceCache::Rec {
@@ -71,6 +71,38 @@
cache.setTotalByteLimit(0);
}
+static void test_cache_purge_shared_id(skiatest::Reporter* reporter, SkResourceCache& cache) {
+ for (int i = 0; i < COUNT; ++i) {
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID
+ cache.add(SkNEW_ARGS(TestingRec, (key, i)));
+ }
+
+ // Ensure that everyone is present
+ for (int i = 0; i < COUNT; ++i) {
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID
+ intptr_t value = -1;
+
+ REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value));
+ REPORTER_ASSERT(reporter, value == i);
+ }
+
+ // Now purge the ones that had a non-zero sharedID (the odd-indexed ones)
+ cache.purgeSharedID(1);
+
+ // Ensure that only the even ones are still present
+ for (int i = 0; i < COUNT; ++i) {
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID
+ intptr_t value = -1;
+
+ if (i & 1) {
+ REPORTER_ASSERT(reporter, !cache.find(key, TestingRec::Visitor, &value));
+ } else {
+ REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value));
+ REPORTER_ASSERT(reporter, value == i);
+ }
+ }
+}
+
#include "SkDiscardableMemoryPool.h"
static SkDiscardableMemoryPool* gPool;
@@ -97,6 +129,10 @@
SkResourceCache cache(SkDiscardableMemory::Create);
test_cache(reporter, cache, false);
}
+ {
+ SkResourceCache cache(defLimit);
+ test_cache_purge_shared_id(reporter, cache);
+ }
}
DEF_TEST(ImageCache_doubleAdd, r) {