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

Unified Diff: tests/SkResourceCacheTest.cpp

Issue 561953002: Make SkBitmapCache remove invalid bitmaps from the SkResourceCache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cache: Created 6 years, 3 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/SkResourceCache.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 b660890e87dfd0d81e696c4346c4248479272227..20c3f7f0a0961f2daf0b2144688779048f3e7104 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -8,6 +8,7 @@
#include "SkCanvas.h"
#include "SkGraphics.h"
#include "SkBitmapCache.h"
+#include "SkDiscardableMemoryPool.h"
static const int kCanvasSize = 1;
static const int kBitmapSize = 16;
@@ -109,4 +110,36 @@ DEF_TEST(BitmapCache_add_rect, reporter) {
// Should be in the cache, we just added it
REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
}
+
+DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
+ SkBitmap bm;
+ SkIRect rect = SkIRect::MakeWH(5, 5);
+ SkBitmap cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
+ cachedBitmap.setImmutable();
+ cachedBitmap.unlockPixels();
+
+ // Add a bitmap to the cache.
+ REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap));
+ REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+
+ // Finding more than once works fine.
+ REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+ bm.unlockPixels();
+
+ // Drop the pixels in the bitmap.
+ REPORTER_ASSERT(reporter, SkGetGlobalDiscardableMemoryPool()->getRAMUsed() > 0);
+ SkGetGlobalDiscardableMemoryPool()->dumpPool();
+ REPORTER_ASSERT(reporter, SkGetGlobalDiscardableMemoryPool()->getRAMUsed() == 0);
+
+ // The bitmap is not in the cache since it has been dropped.
+ REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+
+ cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
+ cachedBitmap.setImmutable();
+ cachedBitmap.unlockPixels();
+
+ // We can add the bitmap back to the cache and find it again.
+ REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap));
+ REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+}
#endif
« no previous file with comments | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698