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" |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 13 | #include "SkPicture.h" |
| 14 | #include "SkPictureRecorder.h" |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 15 | #include "SkResourceCache.h" |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 16 | #include "SkSurface.h" |
aleksandar.stojiljkovic | 07e2692 | 2015-11-10 04:55:15 -0800 | [diff] [blame] | 17 | #include "SkTypes.h" |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 18 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 19 | //////////////////////////////////////////////////////////////////////////////////////// |
mtklein | 26abcf1 | 2014-09-04 10:50:53 -0700 | [diff] [blame] | 20 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 21 | static void make_bitmap(SkBitmap* bitmap, const SkImageInfo& info, SkBitmap::Allocator* allocator) { |
aleksandar.stojiljkovic | 07e2692 | 2015-11-10 04:55:15 -0800 | [diff] [blame] | 22 | if (info.colorType() == kIndex_8_SkColorType) { |
| 23 | bitmap->setInfo(info); |
| 24 | SkPMColor ctStorage[256]; |
| 25 | memset(ctStorage, 0xFF, sizeof(ctStorage)); // init with opaque-white for the moment |
| 26 | SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); |
| 27 | bitmap->allocPixels(allocator, ctable); |
| 28 | } else if (allocator) { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 29 | bitmap->setInfo(info); |
| 30 | allocator->allocPixelRef(bitmap, 0); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 31 | } else { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 32 | bitmap->allocPixels(info); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 33 | } |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 34 | } |
| 35 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 36 | // https://bug.skia.org/2894 |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 37 | DEF_TEST(BitmapCache_add_rect, reporter) { |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 38 | SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory(); |
| 39 | SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 40 | |
| 41 | SkAutoTDelete<SkResourceCache> cache; |
| 42 | if (factory) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 43 | cache.reset(new SkResourceCache(factory)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 44 | } else { |
| 45 | const size_t byteLimit = 100 * 1024; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 46 | cache.reset(new SkResourceCache(byteLimit)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 47 | } |
| 48 | SkBitmap cachedBitmap; |
| 49 | make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 50 | cachedBitmap.setImmutable(); |
| 51 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 52 | SkBitmap bm; |
| 53 | SkIRect rect = SkIRect::MakeWH(5, 5); |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 54 | uint32_t cachedID = cachedBitmap.getGenerationID(); |
| 55 | SkPixelRef* cachedPR = cachedBitmap.pixelRef(); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 56 | |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 57 | // Wrong subset size |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache)); |
| 59 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 60 | // Wrong offset value |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); |
| 62 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 63 | |
| 64 | // Should not be in the cache |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 66 | |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 68 | // Should be in the cache, we just added it |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache)); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 70 | } |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 71 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 72 | #include "SkMipMap.h" |
| 73 | |
| 74 | enum LockedState { |
| 75 | kNotLocked, |
| 76 | kLocked, |
| 77 | }; |
| 78 | |
| 79 | enum CachedState { |
| 80 | kNotInCache, |
| 81 | kInCache, |
| 82 | }; |
| 83 | |
| 84 | static void check_data(skiatest::Reporter* reporter, const SkCachedData* data, |
| 85 | int refcnt, CachedState cacheState, LockedState lockedState) { |
| 86 | REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
| 87 | REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 88 | bool isLocked = (data->data() != nullptr); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
| 90 | } |
| 91 | |
| 92 | static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cache) { |
| 93 | cache->purgeAll(); |
| 94 | |
| 95 | SkBitmap src; |
| 96 | src.allocN32Pixels(5, 5); |
| 97 | src.setImmutable(); |
| 98 | |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 99 | const SkSourceGammaTreatment treatment = SkSourceGammaTreatment::kIgnore; |
| 100 | |
| 101 | const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), treatment, |
| 102 | cache); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 103 | REPORTER_ASSERT(reporter, nullptr == mipmap); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 104 | |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 105 | mipmap = SkMipMapCache::AddAndRef(src, treatment, cache); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, mipmap); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 107 | |
| 108 | { |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 109 | const SkMipMap* mm = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), treatment, |
| 110 | cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, mm); |
| 112 | REPORTER_ASSERT(reporter, mm == mipmap); |
| 113 | mm->unref(); |
| 114 | } |
| 115 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 116 | check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 117 | |
| 118 | mipmap->unref(); |
| 119 | // tricky, since technically after this I'm no longer an owner, but since the cache is |
| 120 | // local, I know it won't get purged behind my back |
| 121 | check_data(reporter, mipmap, 1, kInCache, kNotLocked); |
| 122 | |
| 123 | // find us again |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 124 | mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), treatment, cache); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 125 | check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 126 | |
| 127 | cache->purgeAll(); |
| 128 | check_data(reporter, mipmap, 1, kNotInCache, kLocked); |
| 129 | |
| 130 | mipmap->unref(); |
| 131 | } |
| 132 | |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 133 | static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* cache) { |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 134 | const SkSourceGammaTreatment treatment = SkSourceGammaTreatment::kIgnore; |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 135 | const int N = 3; |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 136 | |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 137 | SkBitmap src[N]; |
| 138 | for (int i = 0; i < N; ++i) { |
| 139 | src[i].allocN32Pixels(5, 5); |
| 140 | src[i].setImmutable(); |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 141 | SkMipMapCache::AddAndRef(src[i], treatment, cache)->unref(); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | for (int i = 0; i < N; ++i) { |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 145 | const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), |
| 146 | treatment, cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 147 | if (cache) { |
| 148 | // if cache is null, we're working on the global cache, and other threads might purge |
| 149 | // it, making this check fragile. |
| 150 | REPORTER_ASSERT(reporter, mipmap); |
| 151 | } |
| 152 | SkSafeUnref(mipmap); |
| 153 | |
| 154 | src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache |
| 155 | |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 156 | mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), treatment, cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 157 | REPORTER_ASSERT(reporter, !mipmap); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* cache) { |
| 162 | const SkIRect subset = SkIRect::MakeWH(5, 5); |
| 163 | const int N = 3; |
| 164 | SkBitmap src[N], dst[N]; |
| 165 | for (int i = 0; i < N; ++i) { |
| 166 | src[i].allocN32Pixels(5, 5); |
| 167 | src[i].setImmutable(); |
| 168 | dst[i].allocN32Pixels(5, 5); |
| 169 | dst[i].setImmutable(); |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame] | 170 | SkBitmapCache::Add(src[i].pixelRef(), subset, dst[i], cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | for (int i = 0; i < N; ++i) { |
| 174 | const uint32_t genID = src[i].getGenerationID(); |
| 175 | SkBitmap result; |
| 176 | bool found = SkBitmapCache::Find(genID, subset, &result, cache); |
| 177 | if (cache) { |
| 178 | // if cache is null, we're working on the global cache, and other threads might purge |
| 179 | // it, making this check fragile. |
| 180 | REPORTER_ASSERT(reporter, found); |
| 181 | } |
| 182 | |
| 183 | src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache |
| 184 | |
| 185 | found = SkBitmapCache::Find(genID, subset, &result, cache); |
| 186 | REPORTER_ASSERT(reporter, !found); |
| 187 | } |
| 188 | } |
| 189 | |
aleksandar.stojiljkovic | 07e2692 | 2015-11-10 04:55:15 -0800 | [diff] [blame] | 190 | #include "SkDiscardableMemoryPool.h" |
| 191 | |
| 192 | static SkDiscardableMemoryPool* gPool = 0; |
| 193 | static SkDiscardableMemory* pool_factory(size_t bytes) { |
| 194 | SkASSERT(gPool); |
| 195 | return gPool->create(bytes); |
| 196 | } |
| 197 | |
| 198 | static void testBitmapCache_discarded_bitmap(skiatest::Reporter* reporter, SkResourceCache* cache, |
| 199 | SkResourceCache::DiscardableFactory factory) { |
| 200 | SkBitmap::Allocator* allocator = cache->allocator(); |
| 201 | const SkColorType testTypes[] = { |
| 202 | kAlpha_8_SkColorType, |
| 203 | kRGB_565_SkColorType, |
| 204 | kRGBA_8888_SkColorType, |
| 205 | kBGRA_8888_SkColorType, |
| 206 | kIndex_8_SkColorType, |
| 207 | kGray_8_SkColorType |
| 208 | }; |
| 209 | for (const SkColorType testType : testTypes) { |
| 210 | SkBitmap cachedBitmap; |
| 211 | make_bitmap(&cachedBitmap, SkImageInfo::Make(5, 5, testType, kPremul_SkAlphaType), |
| 212 | allocator); |
| 213 | cachedBitmap.setImmutable(); |
| 214 | cachedBitmap.unlockPixels(); |
| 215 | |
| 216 | SkBitmap bm; |
| 217 | SkIRect rect = SkIRect::MakeWH(5, 5); |
| 218 | |
| 219 | // Add a bitmap to the cache. |
| 220 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, |
| 221 | cache)); |
| 222 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, |
| 223 | cache)); |
| 224 | |
| 225 | // Finding more than once works fine. |
| 226 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, |
| 227 | cache)); |
| 228 | bm.unlockPixels(); |
| 229 | |
| 230 | // Drop the pixels in the bitmap. |
| 231 | if (factory) { |
| 232 | REPORTER_ASSERT(reporter, gPool->getRAMUsed() > 0); |
| 233 | gPool->dumpPool(); |
| 234 | |
| 235 | // The bitmap is not in the cache since it has been dropped. |
| 236 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, |
| 237 | &bm, cache)); |
| 238 | } |
| 239 | |
| 240 | make_bitmap(&cachedBitmap, SkImageInfo::Make(5, 5, testType, kPremul_SkAlphaType), |
| 241 | allocator); |
| 242 | cachedBitmap.setImmutable(); |
| 243 | cachedBitmap.unlockPixels(); |
| 244 | |
| 245 | // We can add the bitmap back to the cache and find it again. |
| 246 | REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect, cachedBitmap, |
| 247 | cache)); |
| 248 | REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, |
| 249 | cache)); |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 250 | } |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 251 | test_mipmapcache(reporter, cache); |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 252 | test_bitmap_notify(reporter, cache); |
| 253 | test_mipmap_notify(reporter, cache); |
danakj | 790ffe3 | 2014-09-11 10:49:52 -0700 | [diff] [blame] | 254 | } |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 255 | |
aleksandar.stojiljkovic | 07e2692 | 2015-11-10 04:55:15 -0800 | [diff] [blame] | 256 | DEF_TEST(BitmapCache_discarded_bitmap, reporter) { |
| 257 | const size_t byteLimit = 100 * 1024; |
| 258 | { |
| 259 | SkResourceCache cache(byteLimit); |
| 260 | testBitmapCache_discarded_bitmap(reporter, &cache, nullptr); |
| 261 | } |
| 262 | { |
| 263 | SkAutoTUnref<SkDiscardableMemoryPool> pool( |
| 264 | SkDiscardableMemoryPool::Create(byteLimit, nullptr)); |
| 265 | gPool = pool.get(); |
| 266 | SkResourceCache::DiscardableFactory factory = pool_factory; |
| 267 | SkResourceCache cache(factory); |
| 268 | testBitmapCache_discarded_bitmap(reporter, &cache, factory); |
| 269 | } |
| 270 | } |
| 271 | |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 272 | static void test_discarded_image(skiatest::Reporter* reporter, const SkMatrix& transform, |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 273 | sk_sp<SkImage> (*buildImage)()) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 274 | auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 275 | SkCanvas* canvas = surface->getCanvas(); |
| 276 | |
| 277 | // SkBitmapCache is global, so other threads could be evicting our bitmaps. Loop a few times |
| 278 | // to mitigate this risk. |
| 279 | const unsigned kRepeatCount = 42; |
| 280 | for (unsigned i = 0; i < kRepeatCount; ++i) { |
| 281 | SkAutoCanvasRestore acr(canvas, true); |
| 282 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 283 | sk_sp<SkImage> image(buildImage()); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 284 | |
| 285 | // always use high quality to ensure caching when scaled |
| 286 | SkPaint paint; |
| 287 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 288 | |
| 289 | // draw the image (with a transform, to tickle different code paths) to ensure |
| 290 | // any associated resources get cached |
| 291 | canvas->concat(transform); |
| 292 | canvas->drawImage(image, 0, 0, &paint); |
| 293 | |
| 294 | auto imageId = image->uniqueID(); |
| 295 | |
| 296 | // delete the image |
| 297 | image.reset(nullptr); |
| 298 | |
| 299 | // all resources should have been purged |
| 300 | SkBitmap result; |
| 301 | REPORTER_ASSERT(reporter, !SkBitmapCache::Find(imageId, &result)); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | |
| 306 | // Verify that associated bitmap cache entries are purged on SkImage destruction. |
| 307 | DEF_TEST(BitmapCache_discarded_image, reporter) { |
| 308 | // Cache entries associated with SkImages fall into two categories: |
| 309 | // |
| 310 | // 1) generated image bitmaps (managed by the image cacherator) |
| 311 | // 2) scaled/resampled bitmaps (cached when HQ filters are used) |
| 312 | // |
| 313 | // To exercise the first cache type, we use generated/picture-backed SkImages. |
| 314 | // To exercise the latter, we draw scaled bitmap images using HQ filters. |
| 315 | |
| 316 | const SkMatrix xforms[] = { |
| 317 | SkMatrix::MakeScale(1, 1), |
| 318 | SkMatrix::MakeScale(1.7f, 0.5f), |
| 319 | }; |
| 320 | |
| 321 | for (size_t i = 0; i < SK_ARRAY_COUNT(xforms); ++i) { |
| 322 | test_discarded_image(reporter, xforms[i], []() { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 323 | auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 324 | surface->getCanvas()->clear(SK_ColorCYAN); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 325 | return surface->makeImageSnapshot(); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 326 | }); |
| 327 | |
| 328 | test_discarded_image(reporter, xforms[i], []() { |
| 329 | SkPictureRecorder recorder; |
| 330 | SkCanvas* canvas = recorder.beginRecording(10, 10); |
| 331 | canvas->clear(SK_ColorCYAN); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 332 | return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
| 333 | SkISize::Make(10, 10), nullptr, nullptr); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 334 | }); |
| 335 | } |
| 336 | } |