OLD | NEW |
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 enum CachedState { | 136 enum CachedState { |
137 kNotInCache, | 137 kNotInCache, |
138 kInCache, | 138 kInCache, |
139 }; | 139 }; |
140 | 140 |
141 static void check_data(skiatest::Reporter* reporter, const SkCachedData* data, | 141 static void check_data(skiatest::Reporter* reporter, const SkCachedData* data, |
142 int refcnt, CachedState cacheState, LockedState lockedSta
te) { | 142 int refcnt, CachedState cacheState, LockedState lockedSta
te) { |
143 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); | 143 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
144 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); | 144 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); |
145 bool isLocked = (data->data() != NULL); | 145 bool isLocked = (data->data() != nullptr); |
146 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); | 146 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
147 } | 147 } |
148 | 148 |
149 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
e) { | 149 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
e) { |
150 cache->purgeAll(); | 150 cache->purgeAll(); |
151 | 151 |
152 SkBitmap src; | 152 SkBitmap src; |
153 src.allocN32Pixels(5, 5); | 153 src.allocN32Pixels(5, 5); |
154 src.setImmutable(); | 154 src.setImmutable(); |
155 | 155 |
156 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache); | 156 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache); |
157 REPORTER_ASSERT(reporter, NULL == mipmap); | 157 REPORTER_ASSERT(reporter, nullptr == mipmap); |
158 | 158 |
159 mipmap = SkMipMapCache::AddAndRef(src, cache); | 159 mipmap = SkMipMapCache::AddAndRef(src, cache); |
160 REPORTER_ASSERT(reporter, mipmap); | 160 REPORTER_ASSERT(reporter, mipmap); |
161 | 161 |
162 { | 162 { |
163 const SkMipMap* mm = SkMipMapCache::FindAndRef(src, cache); | 163 const SkMipMap* mm = SkMipMapCache::FindAndRef(src, cache); |
164 REPORTER_ASSERT(reporter, mm); | 164 REPORTER_ASSERT(reporter, mm); |
165 REPORTER_ASSERT(reporter, mm == mipmap); | 165 REPORTER_ASSERT(reporter, mm == mipmap); |
166 mm->unref(); | 166 mm->unref(); |
167 } | 167 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 cachedBitmap.unlockPixels(); | 279 cachedBitmap.unlockPixels(); |
280 | 280 |
281 // We can add the bitmap back to the cache and find it again. | 281 // We can add the bitmap back to the cache and find it again. |
282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); | 282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); |
283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); | 283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); |
284 | 284 |
285 test_mipmapcache(reporter, cache); | 285 test_mipmapcache(reporter, cache); |
286 test_bitmap_notify(reporter, cache); | 286 test_bitmap_notify(reporter, cache); |
287 test_mipmap_notify(reporter, cache); | 287 test_mipmap_notify(reporter, cache); |
288 } | 288 } |
OLD | NEW |