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
This commit is contained in:
parent
8ef51b975c
commit
5e4112b33a
@ -425,6 +425,7 @@ SkScaledImageCache::ID* SkScaledImageCache::addAndLock(SkScaledImageCache::Rec*
|
||||
if (NULL != existing) {
|
||||
// Since we already have a matching entry, just delete the new one and return.
|
||||
// Call sites cannot assume the passed in object will live past this call.
|
||||
existing->fBitmap = rec->fBitmap;
|
||||
SkDELETE(rec);
|
||||
return rec_to_id(existing);
|
||||
}
|
||||
|
@ -105,17 +105,27 @@ DEF_TEST(ImageCache, reporter) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user