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

Unified Diff: tests/SkResourceCacheTest.cpp

Issue 518983002: The key for SkBitmapCache can now be genID+SkIRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Canonicalize subset in SkBitmapCache::Add (and test) 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
« src/core/SkBitmapCache.cpp ('K') | « src/core/SkBitmapCache.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 b71c7443e57ad6ad7c26a7f72c8078415a9cd9c4..aa41663ed6533c5ce633e51caec41c590537e8b8 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -72,3 +72,47 @@ DEF_TEST(ResourceCache_SingleAllocationByteLimit, reporter) {
SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimit);
SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit);
}
+
+static SkBitmap createAllocatedBitmap(const SkImageInfo& info) {
+ SkBitmap cachedBitmap;
+ cachedBitmap.setInfo(info);
+ SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
+ if (NULL != allocator) {
+ allocator->allocPixelRef(&cachedBitmap, 0);
+ } else {
+ cachedBitmap.allocPixels();
+ }
+
+ return cachedBitmap;
+}
+
+// http://skbug.com/2894
+DEF_TEST(BitmapCache_add_rect, reporter) {
+ SkBitmap bm;
+ SkIRect rect = SkIRect::MakeWH(5, 5);
+ SkBitmap cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
+ cachedBitmap.setImmutable();
+
+
+ // Should not be in the cache
+ REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+
+ SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap);
+ // Should be in the cache, we just added it
+ REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+}
+DEF_TEST(BitmapCache_add_rect_canonicalize, reporter) {
+ SkBitmap bm;
+ SkIRect rect = SkIRect::MakeWH(5, 5);
+ SkBitmap cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
+ cachedBitmap.setImmutable();
+
+
+ SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeEmpty(), cachedBitmap);
+ // Should not be in the cache, rect was empty when calling Add
+ REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+
+ SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeWH(6, 6), cachedBitmap);
+ // Should be in the cache, we just added it and SkIRect(6, 6) has been canonicalized to SkIRect(5, 5)
+ REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm));
+}
« src/core/SkBitmapCache.cpp ('K') | « src/core/SkBitmapCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698