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

Unified Diff: tests/SkResourceCacheTest.cpp

Issue 592843003: Add SkCachedData and use it for SkMipMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 2 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 | « tests/MipMapTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SkResourceCacheTest.cpp
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index f13476a5a3b681056b07aae7e9923250c92327f1..0e941758eede8bce9de3d51d53376eb9b398c3e7 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -121,6 +121,55 @@ DEF_TEST(BitmapCache_add_rect, reporter) {
REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache));
}
+#include "SkMipMap.h"
+
+enum LockedState {
+ kNotLocked,
+ kLocked,
+};
+
+enum CachedState {
+ kNotInCache,
+ kInCache,
+};
+
+static void check_data(skiatest::Reporter* reporter, const SkCachedData* data,
+ int refcnt, CachedState cacheState, LockedState lockedState) {
+ REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
+ REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
+ bool isLocked = (data->data() != NULL);
+ REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
+}
+
+static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cache) {
+ cache->purgeAll();
+
+ SkBitmap src;
+ src.allocN32Pixels(5, 5);
+ src.setImmutable();
+
+ const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache);
+ REPORTER_ASSERT(reporter, NULL == mipmap);
+
+ mipmap = SkMipMapCache::AddAndRef(src, cache);
+ REPORTER_ASSERT(reporter, mipmap);
+ check_data(reporter, mipmap, 2, kInCache, kLocked);
+
+ mipmap->unref();
+ // tricky, since technically after this I'm no longer an owner, but since the cache is
+ // local, I know it won't get purged behind my back
+ check_data(reporter, mipmap, 1, kInCache, kNotLocked);
+
+ // find us again
+ mipmap = SkMipMapCache::FindAndRef(src, cache);
+ check_data(reporter, mipmap, 2, kInCache, kLocked);
+
+ cache->purgeAll();
+ check_data(reporter, mipmap, 1, kNotInCache, kLocked);
+
+ mipmap->unref();
+}
+
DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory();
SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
@@ -165,4 +214,6 @@ DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
// We can add the bitmap back to the cache and find it again.
REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache));
REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache));
+
+ test_mipmapcache(reporter, cache);
}
« no previous file with comments | « tests/MipMapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698