halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 7 | |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 8 | #include "Test.h" |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 9 | #include "SkBitmapCache.h" |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 10 | #include "SkCanvas.h" |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 11 | #include "SkDiscardableMemoryPool.h" |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 12 | #include "SkGraphics.h" |
| 13 | #include "SkResourceCache.h" |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 14 | #include "SkSurface.h" |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 15 | |
| 16 | static const int kCanvasSize = 1; |
| 17 | static const int kBitmapSize = 16; |
| 18 | static const int kScale = 8; |
| 19 | |
halcanary | 1d1795b | 2014-07-18 09:18:40 -0700 | [diff] [blame] | 20 | static bool is_in_scaled_image_cache(const SkBitmap& orig, |
| 21 | SkScalar xScale, |
| 22 | SkScalar yScale) { |
| 23 | SkBitmap scaled; |
reed | 9913887 | 2015-08-31 15:16:17 -0700 | [diff] [blame] | 24 | int width = SkScalarRoundToInt(orig.width() * xScale); |
| 25 | int height = SkScalarRoundToInt(orig.height() * yScale); |
| 26 | return SkBitmapCache::FindWH(orig, width, height, &scaled); |
halcanary | 1d1795b | 2014-07-18 09:18:40 -0700 | [diff] [blame] | 27 | } |
| 28 | |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 29 | // Draw a scaled bitmap, then return true if it has been cached. |
| 30 | static bool test_scaled_image_cache_usage() { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 31 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kCanvasSize, kCanvasSize)); |
| 32 | SkCanvas* canvas = surface->getCanvas(); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 33 | SkBitmap bitmap; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 34 | bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); |
halcanary | 0db38cc | 2014-07-17 10:17:28 -0700 | [diff] [blame] | 35 | bitmap.eraseColor(0xFFFFFFFF); |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 36 | SkScalar xScale = SkIntToScalar(kScale); |
| 37 | SkScalar yScale = xScale / 2; |
| 38 | SkScalar xScaledSize = SkIntToScalar(kBitmapSize) * xScale; |
| 39 | SkScalar yScaledSize = SkIntToScalar(kBitmapSize) * yScale; |
| 40 | canvas->clipRect(SkRect::MakeLTRB(0, 0, xScaledSize, yScaledSize)); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 41 | SkPaint paint; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 42 | paint.setFilterQuality(kHigh_SkFilterQuality); |
halcanary | 1d1795b | 2014-07-18 09:18:40 -0700 | [diff] [blame] | 43 | |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 44 | canvas->drawBitmapRect(bitmap, |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 45 | SkRect::MakeLTRB(0, 0, xScaledSize, yScaledSize), |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 46 | &paint); |
halcanary | 1d1795b | 2014-07-18 09:18:40 -0700 | [diff] [blame] | 47 | |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 48 | return is_in_scaled_image_cache(bitmap, xScale, yScale); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // http://crbug.com/389439 |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 52 | DEF_TEST(ResourceCache_SingleAllocationByteLimit, reporter) { |
| 53 | size_t originalByteLimit = SkGraphics::GetResourceCacheTotalByteLimit(); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 54 | size_t originalAllocationLimit = |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 55 | SkGraphics::GetResourceCacheSingleAllocationByteLimit(); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 56 | |
| 57 | size_t size = kBitmapSize * kScale * kBitmapSize * kScale |
| 58 | * SkColorTypeBytesPerPixel(kN32_SkColorType); |
| 59 | |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 60 | SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache |
| 61 | SkGraphics::SetResourceCacheTotalByteLimit(2 * size); |
| 62 | SkGraphics::SetResourceCacheSingleAllocationByteLimit(0); // No limit |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 63 | |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, test_scaled_image_cache_usage()); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 65 | |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 66 | SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache |
| 67 | SkGraphics::SetResourceCacheTotalByteLimit(2 * size); |
| 68 | SkGraphics::SetResourceCacheSingleAllocationByteLimit(size * 2); // big enough |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 69 | |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, test_scaled_image_cache_usage()); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 71 | |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 72 | SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache |
| 73 | SkGraphics::SetResourceCacheTotalByteLimit(2 * size); |
| 74 | SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too small |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 75 | |
yunchao.he | 90acb8e | 2015-01-23 17:06:20 -0800 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, !test_scaled_image_cache_usage()); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 77 | |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 78 | SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimit); |
| 79 | SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 80 | } |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 81 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 82 | //////////////////////////////////////////////////////////////////////////////////////// |
mtklein | 26abcf1 | 2014-09-04 10:50:53 -0700 | [diff] [blame] | 83 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 84 | static void make_bitmap(SkBitmap* bitmap, const SkImageInfo& info, SkBitmap::Allocator* allocator) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 85 | if (allocator) { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 86 | bitmap->setInfo(info); |
| 87 | allocator->allocPixelRef(bitmap, 0); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 88 | } else { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 89 | bitmap->allocPixels(info); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 90 | } |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // http://skbug.com/2894 |
| 94 | DEF_TEST(BitmapCache_add_rect, reporter) { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 95 | SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory(); |
| 96 | SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 97 | |
| 98 | SkAutoTDelete<SkResourceCache> cache; |
| 99 | if (factory) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 100 | cache.reset(new SkResourceCache(factory)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 101 | } else { |
| 102 | const size_t byteLimit = 100 * 1024; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 103 | cache.reset(new SkResourceCache(byteLimit)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 104 | } |
| 105 | SkBitmap cachedBitmap; |
| 106 | make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 107 | cachedBitmap.setImmutable(); |
| 108 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 109 | SkBitmap bm; |
| 110 | SkIRect rect = SkIRect::MakeWH(5, 5); |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 111 | uint32_t cachedID = cachedBitmap.getGenerationID(); |
| 112 | SkPixelRef* cachedPR = cachedBitmap.pixelRef(); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 113 | |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 114 | // Wrong subset size |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 115 | REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache)); |
| 116 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 117 | // Wrong offset value |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 118 | REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); |
| 119 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 120 | |
| 121 | // Should not be in the cache |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 122 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 123 | |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 125 | // Should be in the cache, we just added it |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 126 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 127 | } |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 128 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 129 | #include "SkMipMap.h" |
| 130 | |
| 131 | enum LockedState { |
| 132 | kNotLocked, |
| 133 | kLocked, |
| 134 | }; |
| 135 | |
| 136 | enum CachedState { |
| 137 | kNotInCache, |
| 138 | kInCache, |
| 139 | }; |
| 140 | |
| 141 | static void check_data(skiatest::Reporter* reporter, const SkCachedData* data, |
| 142 | int refcnt, CachedState cacheState, LockedState lockedState) { |
| 143 | REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
| 144 | REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 145 | bool isLocked = (data->data() != nullptr); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 146 | REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
| 147 | } |
| 148 | |
| 149 | static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cache) { |
| 150 | cache->purgeAll(); |
| 151 | |
| 152 | SkBitmap src; |
| 153 | src.allocN32Pixels(5, 5); |
| 154 | src.setImmutable(); |
| 155 | |
| 156 | const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 157 | REPORTER_ASSERT(reporter, nullptr == mipmap); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 158 | |
| 159 | mipmap = SkMipMapCache::AddAndRef(src, cache); |
| 160 | REPORTER_ASSERT(reporter, mipmap); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 161 | |
| 162 | { |
| 163 | const SkMipMap* mm = SkMipMapCache::FindAndRef(src, cache); |
| 164 | REPORTER_ASSERT(reporter, mm); |
| 165 | REPORTER_ASSERT(reporter, mm == mipmap); |
| 166 | mm->unref(); |
| 167 | } |
| 168 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 169 | check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 170 | |
| 171 | mipmap->unref(); |
| 172 | // tricky, since technically after this I'm no longer an owner, but since the cache is |
| 173 | // local, I know it won't get purged behind my back |
| 174 | check_data(reporter, mipmap, 1, kInCache, kNotLocked); |
| 175 | |
| 176 | // find us again |
| 177 | mipmap = SkMipMapCache::FindAndRef(src, cache); |
| 178 | check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 179 | |
| 180 | cache->purgeAll(); |
| 181 | check_data(reporter, mipmap, 1, kNotInCache, kLocked); |
| 182 | |
| 183 | mipmap->unref(); |
| 184 | } |
| 185 | |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 186 | static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* cache) { |
| 187 | const int N = 3; |
| 188 | SkBitmap src[N]; |
| 189 | for (int i = 0; i < N; ++i) { |
| 190 | src[i].allocN32Pixels(5, 5); |
| 191 | src[i].setImmutable(); |
| 192 | SkMipMapCache::AddAndRef(src[i], cache)->unref(); |
| 193 | } |
| 194 | |
| 195 | for (int i = 0; i < N; ++i) { |
| 196 | const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src[i], cache); |
| 197 | if (cache) { |
| 198 | // if cache is null, we're working on the global cache, and other threads might purge |
| 199 | // it, making this check fragile. |
| 200 | REPORTER_ASSERT(reporter, mipmap); |
| 201 | } |
| 202 | SkSafeUnref(mipmap); |
| 203 | |
| 204 | src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache |
| 205 | |
| 206 | mipmap = SkMipMapCache::FindAndRef(src[i], cache); |
| 207 | REPORTER_ASSERT(reporter, !mipmap); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* cache) { |
| 212 | const SkIRect subset = SkIRect::MakeWH(5, 5); |
| 213 | const int N = 3; |
| 214 | SkBitmap src[N], dst[N]; |
| 215 | for (int i = 0; i < N; ++i) { |
| 216 | src[i].allocN32Pixels(5, 5); |
| 217 | src[i].setImmutable(); |
| 218 | dst[i].allocN32Pixels(5, 5); |
| 219 | dst[i].setImmutable(); |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 220 | SkBitmapCache::Add(src[i].pixelRef(), subset, dst[i], cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | for (int i = 0; i < N; ++i) { |
| 224 | const uint32_t genID = src[i].getGenerationID(); |
| 225 | SkBitmap result; |
| 226 | bool found = SkBitmapCache::Find(genID, subset, &result, cache); |
| 227 | if (cache) { |
| 228 | // if cache is null, we're working on the global cache, and other threads might purge |
| 229 | // it, making this check fragile. |
| 230 | REPORTER_ASSERT(reporter, found); |
| 231 | } |
| 232 | |
| 233 | src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache |
| 234 | |
| 235 | found = SkBitmapCache::Find(genID, subset, &result, cache); |
| 236 | REPORTER_ASSERT(reporter, !found); |
| 237 | } |
| 238 | } |
| 239 | |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 240 | DEF_TEST(BitmapCache_discarded_bitmap, reporter) { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 241 | SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory(); |
| 242 | SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 243 | |
| 244 | SkAutoTDelete<SkResourceCache> cache; |
| 245 | if (factory) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 246 | cache.reset(new SkResourceCache(factory)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 247 | } else { |
| 248 | const size_t byteLimit = 100 * 1024; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 249 | cache.reset(new SkResourceCache(byteLimit)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 250 | } |
| 251 | SkBitmap cachedBitmap; |
| 252 | make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 253 | cachedBitmap.setImmutable(); |
| 254 | cachedBitmap.unlockPixels(); |
| 255 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 256 | SkBitmap bm; |
| 257 | SkIRect rect = SkIRect::MakeWH(5, 5); |
| 258 | |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 259 | // Add a bitmap to the cache. |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 260 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, cache)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 261 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 262 | |
| 263 | // Finding more than once works fine. |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 264 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 265 | bm.unlockPixels(); |
| 266 | |
| 267 | // Drop the pixels in the bitmap. |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 268 | if (factory) { |
| 269 | REPORTER_ASSERT(reporter, SkGetGlobalDiscardableMemoryPool()->getRAMUsed() > 0); |
| 270 | SkGetGlobalDiscardableMemoryPool()->dumpPool(); |
| 271 | REPORTER_ASSERT(reporter, SkGetGlobalDiscardableMemoryPool()->getRAMUsed() == 0); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 272 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 273 | // The bitmap is not in the cache since it has been dropped. |
| 274 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); |
| 275 | } |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 276 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 277 | make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 278 | cachedBitmap.setImmutable(); |
| 279 | cachedBitmap.unlockPixels(); |
| 280 | |
| 281 | // We can add the bitmap back to the cache and find it again. |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 282 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, cache)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 283 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache)); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 284 | |
| 285 | test_mipmapcache(reporter, cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 286 | test_bitmap_notify(reporter, cache); |
| 287 | test_mipmap_notify(reporter, cache); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 288 | } |