Replace scaled bitmap if entry already exist in cache.
BUG=skia:2251
R=reed@google.com
Author: reveman@chromium.org
Review URL: https://codereview.chromium.org/185263009
git-svn-id: http://skia.googlecode.com/svn/trunk@13667 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index 65c9068..43a5e70 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -105,17 +105,27 @@
DEF_TEST(ImageCache_doubleAdd, r) {
// Adding the same key twice should be safe.
- SkScaledImageCache cache(1024);
+ SkScaledImageCache cache(4096);
SkBitmap original;
original.allocN32Pixels(40, 40);
- SkBitmap scaled;
- scaled.allocN32Pixels(20, 20);
+ SkBitmap scaled1;
+ scaled1.allocN32Pixels(20, 20);
- SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled);
- SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled);
+ SkBitmap scaled2;
+ scaled2.allocN32Pixels(20, 20);
+
+ SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled1);
+ SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled2);
// We don't really care if id1 == id2 as long as unlocking both works.
cache.unlock(id1);
cache.unlock(id2);
+
+ SkBitmap tmp;
+ // Lookup should return the value that was added last.
+ SkScaledImageCache::ID* id = cache.findAndLock(original, 0.5f, 0.5f, &tmp);
+ REPORTER_ASSERT(r, NULL != id);
+ REPORTER_ASSERT(r, tmp.getGenerationID() == scaled2.getGenerationID());
+ cache.unlock(id);
}