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

Side by Side Diff: tests/ImageCacheTest.cpp

Issue 185263009: Replace scaled bitmap if entry already exist in cache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unit test Created 6 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDiscardableMemory.h" 8 #include "SkDiscardableMemory.h"
9 #include "SkScaledImageCache.h" 9 #include "SkScaledImageCache.h"
10 #include "Test.h" 10 #include "Test.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 test_cache(reporter, cache, true); 98 test_cache(reporter, cache, true);
99 } 99 }
100 { 100 {
101 SkScaledImageCache cache(SkDiscardableMemory::Create); 101 SkScaledImageCache cache(SkDiscardableMemory::Create);
102 test_cache(reporter, cache, false); 102 test_cache(reporter, cache, false);
103 } 103 }
104 } 104 }
105 105
106 DEF_TEST(ImageCache_doubleAdd, r) { 106 DEF_TEST(ImageCache_doubleAdd, r) {
107 // Adding the same key twice should be safe. 107 // Adding the same key twice should be safe.
108 SkScaledImageCache cache(1024); 108 SkScaledImageCache cache(4096);
109 109
110 SkBitmap original; 110 SkBitmap original;
111 original.allocN32Pixels(40, 40); 111 original.allocN32Pixels(40, 40);
112 112
113 SkBitmap scaled; 113 SkBitmap scaled1;
114 scaled.allocN32Pixels(20, 20); 114 scaled1.allocN32Pixels(20, 20);
115 115
116 SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ; 116 SkBitmap scaled2;
117 SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ; 117 scaled2.allocN32Pixels(20, 20);
118
119 SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled1 );
120 SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled2 );
118 // We don't really care if id1 == id2 as long as unlocking both works. 121 // We don't really care if id1 == id2 as long as unlocking both works.
119 cache.unlock(id1); 122 cache.unlock(id1);
120 cache.unlock(id2); 123 cache.unlock(id2);
124
125 SkBitmap tmp;
126 // Lookup should return the value that was added last.
127 SkScaledImageCache::ID* id = cache.findAndLock(original, 0.5f, 0.5f, &tmp);
128 REPORTER_ASSERT(r, NULL != id);
129 REPORTER_ASSERT(r, tmp.getGenerationID() == scaled2.getGenerationID());
130 cache.unlock(id);
121 } 131 }
OLDNEW
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698