aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkResourceCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar danakj <danakj@chromium.org>2014-09-11 10:49:52 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-11 10:49:52 -0700
commit790ffe3feb90370318f42b28eb9c6af6e38cd4f9 (patch)
tree57b311f69b8ac26a87bcebf843bdac301cf5efb1 /tests/SkResourceCacheTest.cpp
parent33a30503d76fdd989358cedd78445ba96bb809dd (diff)
Make SkBitmapCache remove invalid bitmaps from the SkResourceCache.
This adds SkResourceCache::Remove() which will remove a resource from its cache. The resource is required to be unlocked at the time Remove() is called. Then SkBitmapCache::Find() makes use of this to Remove() bitmaps from the cache whose pixels have been evicted. This allows the bitmap to be re-added to the cache with pixels again. After this change, background a tab (and discarding all the bitmaps' contents) no longer disables image caching for those discarded images once the tab is visible again. BUG=skia:2926 NOTRY=true R=reed@android.com, tomhudson@google.com, reed@google.com Author: danakj@chromium.org Review URL: https://codereview.chromium.org/561953002
Diffstat (limited to 'tests/SkResourceCacheTest.cpp')
-rw-r--r--tests/SkResourceCacheTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index b660890e87..20c3f7f0a0 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