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

Side by Side 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 unified diff | Download patch
« src/core/SkBitmapCache.cpp ('K') | « src/core/SkBitmapCache.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 2014 Google Inc. 2 * Copyright 2014 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 #include "Test.h" 7 #include "Test.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkGraphics.h" 9 #include "SkGraphics.h"
10 #include "SkBitmapCache.h" 10 #include "SkBitmapCache.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache 66 SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache
67 SkGraphics::SetResourceCacheTotalByteLimit(2 * size); 67 SkGraphics::SetResourceCacheTotalByteLimit(2 * size);
68 SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too sma ll 68 SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too sma ll
69 69
70 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage()); 70 REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage());
71 71
72 SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimi t); 72 SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimi t);
73 SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit); 73 SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit);
74 } 74 }
75
76 static SkBitmap createAllocatedBitmap(const SkImageInfo& info) {
77 SkBitmap cachedBitmap;
78 cachedBitmap.setInfo(info);
79 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
80 if (NULL != allocator) {
81 allocator->allocPixelRef(&cachedBitmap, 0);
82 } else {
83 cachedBitmap.allocPixels();
84 }
85
86 return cachedBitmap;
87 }
88
89 // http://skbug.com/2894
90 DEF_TEST(BitmapCache_add_rect, reporter) {
91 SkBitmap bm;
92 SkIRect rect = SkIRect::MakeWH(5, 5);
93 SkBitmap cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
94 cachedBitmap.setImmutable();
95
96
97 // Should not be in the cache
98 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm));
99
100 SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap);
101 // Should be in the cache, we just added it
102 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm));
103 }
104 DEF_TEST(BitmapCache_add_rect_canonicalize, reporter) {
105 SkBitmap bm;
106 SkIRect rect = SkIRect::MakeWH(5, 5);
107 SkBitmap cachedBitmap = createAllocatedBitmap(SkImageInfo::MakeN32Premul(5, 5));
108 cachedBitmap.setImmutable();
109
110
111 SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeEmpty(), cac hedBitmap);
112 // Should not be in the cache, rect was empty when calling Add
113 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm));
114
115 SkBitmapCache::Add(cachedBitmap.getGenerationID(), SkIRect::MakeWH(6, 6), ca chedBitmap);
116 // Should be in the cache, we just added it and SkIRect(6, 6) has been canon icalized to SkIRect(5, 5)
117 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm));
118 }
OLDNEW
« 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