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

Side by Side Diff: tests/SkResourceCacheTest.cpp

Issue 617613003: Speculative revert to diagnose crash in chrome. Revert "Add SkCachedData and use it for SkMipMap" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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 | « tests/MipMapTest.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 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm, cache)); 114 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm, cache));
115 115
116 // Should not be in the cache 116 // Should not be in the cache
117 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm, cache)); 117 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID( ), rect, &bm, cache));
118 118
119 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache)); 119 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache));
120 // Should be in the cache, we just added it 120 // Should be in the cache, we just added it
121 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm, cache)); 121 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm, cache));
122 } 122 }
123 123
124 #include "SkMipMap.h"
125
126 enum LockedState {
127 kNotLocked,
128 kLocked,
129 };
130
131 enum CachedState {
132 kNotInCache,
133 kInCache,
134 };
135
136 static void check_data(skiatest::Reporter* reporter, const SkCachedData* data,
137 int refcnt, CachedState cacheState, LockedState lockedSta te) {
138 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
139 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac heState));
140 bool isLocked = (data->data() != NULL);
141 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
142 }
143
144 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach e) {
145 cache->purgeAll();
146
147 SkBitmap src;
148 src.allocN32Pixels(5, 5);
149 src.setImmutable();
150
151 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache);
152 REPORTER_ASSERT(reporter, NULL == mipmap);
153
154 mipmap = SkMipMapCache::AddAndRef(src, cache);
155 REPORTER_ASSERT(reporter, mipmap);
156 check_data(reporter, mipmap, 2, kInCache, kLocked);
157
158 mipmap->unref();
159 // tricky, since technically after this I'm no longer an owner, but since th e cache is
160 // local, I know it won't get purged behind my back
161 check_data(reporter, mipmap, 1, kInCache, kNotLocked);
162
163 // find us again
164 mipmap = SkMipMapCache::FindAndRef(src, cache);
165 check_data(reporter, mipmap, 2, kInCache, kLocked);
166
167 cache->purgeAll();
168 check_data(reporter, mipmap, 1, kNotInCache, kLocked);
169
170 mipmap->unref();
171 }
172
173 DEF_TEST(BitmapCache_discarded_bitmap, reporter) { 124 DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
174 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl eFactory(); 125 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl eFactory();
175 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); 126 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
176 127
177 SkAutoTDelete<SkResourceCache> cache; 128 SkAutoTDelete<SkResourceCache> cache;
178 if (factory) { 129 if (factory) {
179 cache.reset(SkNEW_ARGS(SkResourceCache, (factory))); 130 cache.reset(SkNEW_ARGS(SkResourceCache, (factory)));
180 } else { 131 } else {
181 const size_t byteLimit = 100 * 1024; 132 const size_t byteLimit = 100 * 1024;
182 cache.reset(SkNEW_ARGS(SkResourceCache, (byteLimit))); 133 cache.reset(SkNEW_ARGS(SkResourceCache, (byteLimit)));
(...skipping 24 matching lines...) Expand all
207 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGeneratio nID(), rect, &bm, cache)); 158 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGeneratio nID(), rect, &bm, cache));
208 } 159 }
209 160
210 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); 161 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator);
211 cachedBitmap.setImmutable(); 162 cachedBitmap.setImmutable();
212 cachedBitmap.unlockPixels(); 163 cachedBitmap.unlockPixels();
213 164
214 // We can add the bitmap back to the cache and find it again. 165 // We can add the bitmap back to the cache and find it again.
215 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache)); 166 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache));
216 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm, cache)); 167 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID() , rect, &bm, cache));
217
218 test_mipmapcache(reporter, cache);
219 } 168 }
OLDNEW
« no previous file with comments | « tests/MipMapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698