Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: tests/ImageCacheTest.cpp

Issue 950363002: Notify resource caches when pixelref genID goes stale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkYUVPlanesCache.cpp ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageCacheTest.cpp
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index a4cfa739890ff08167cc2e959d3a965471ac231c..45dee92a2f02ba4b37436a80732564fb55be7938 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) {
« no previous file with comments | « src/core/SkYUVPlanesCache.cpp ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698