aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ImageCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-02-24 13:54:23 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-24 13:54:23 -0800
commit7eeba2587760a0802fd2b90765b4fd0e5e895375 (patch)
treedad9caa7dde038c52728034710c3d6d4926bfff2 /tests/ImageCacheTest.cpp
parent4b583ac54b92ad6e7685bdfa2b68e7dd11ba0d28 (diff)
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
Diffstat (limited to 'tests/ImageCacheTest.cpp')
-rw-r--r--tests/ImageCacheTest.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index a4cfa73989..45dee92a2f 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -14,8 +14,8 @@ static void* gGlobalAddress;
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 @@ static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache, boo
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 @@ DEF_TEST(ImageCache, reporter) {
SkResourceCache cache(SkDiscardableMemory::Create);
test_cache(reporter, cache, false);
}
+ {
+ SkResourceCache cache(defLimit);
+ test_cache_purge_shared_id(reporter, cache);
+ }
}
DEF_TEST(ImageCache_doubleAdd, r) {