robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | |
| 10 | #include "SkBitmap.h" |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 11 | #include "SkColorFilter.h" |
| 12 | #include "SkColorFilterImageFilter.h" |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 13 | #include "SkImage.h" |
| 14 | #include "SkImageFilter.h" |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 15 | #include "SkImageFilterCache.h" |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 16 | #include "SkMatrix.h" |
| 17 | #include "SkSpecialImage.h" |
| 18 | |
| 19 | static const int kSmallerSize = 10; |
| 20 | static const int kPad = 3; |
| 21 | static const int kFullSize = kSmallerSize + 2 * kPad; |
| 22 | |
| 23 | static SkBitmap create_bm() { |
| 24 | SkBitmap bm; |
| 25 | bm.allocN32Pixels(kFullSize, kFullSize, true); |
| 26 | bm.eraseColor(SK_ColorTRANSPARENT); |
| 27 | return bm; |
| 28 | } |
| 29 | |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 30 | static sk_sp<SkImageFilter> make_filter() { |
| 31 | sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, |
| 32 | SkBlendMode::kSrcIn)); |
| 33 | return SkColorFilterImageFilter::Make(std::move(filter), nullptr, nullptr); |
| 34 | } |
| 35 | |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 36 | // Ensure the cache can return a cached image |
| 37 | static void test_find_existing(skiatest::Reporter* reporter, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 38 | const sk_sp<SkSpecialImage>& image, |
| 39 | const sk_sp<SkSpecialImage>& subset) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 40 | static const size_t kCacheSize = 1000000; |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 41 | sk_sp<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 42 | |
| 43 | SkIRect clip = SkIRect::MakeWH(100, 100); |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 44 | SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset()); |
| 45 | SkImageFilterCacheKey key2(0, SkMatrix::I(), clip, subset->uniqueID(), subset->subset()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 46 | |
| 47 | SkIPoint offset = SkIPoint::Make(3, 4); |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 48 | auto filter = make_filter(); |
| 49 | cache->set(key1, image.get(), offset, filter.get()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 50 | |
| 51 | SkIPoint foundOffset; |
| 52 | |
Florin Malita | a022e2d | 2017-01-12 12:06:14 -0500 | [diff] [blame] | 53 | sk_sp<SkSpecialImage> foundImage = cache->get(key1, &foundOffset); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, foundImage); |
| 55 | REPORTER_ASSERT(reporter, offset == foundOffset); |
| 56 | |
| 57 | REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); |
| 58 | } |
| 59 | |
| 60 | // If either id is different or the clip or the matrix are different the |
| 61 | // cached image won't be found. Even if it is caching the same bitmap. |
| 62 | static void test_dont_find_if_diff_key(skiatest::Reporter* reporter, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 63 | const sk_sp<SkSpecialImage>& image, |
| 64 | const sk_sp<SkSpecialImage>& subset) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 65 | static const size_t kCacheSize = 1000000; |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 66 | sk_sp<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 67 | |
| 68 | SkIRect clip1 = SkIRect::MakeWH(100, 100); |
| 69 | SkIRect clip2 = SkIRect::MakeWH(200, 200); |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 70 | SkImageFilterCacheKey key0(0, SkMatrix::I(), clip1, image->uniqueID(), image->subset()); |
| 71 | SkImageFilterCacheKey key1(1, SkMatrix::I(), clip1, image->uniqueID(), image->subset()); |
| 72 | SkImageFilterCacheKey key2(0, SkMatrix::MakeTrans(5, 5), clip1, |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 73 | image->uniqueID(), image->subset()); |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 74 | SkImageFilterCacheKey key3(0, SkMatrix::I(), clip2, image->uniqueID(), image->subset()); |
| 75 | SkImageFilterCacheKey key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 76 | |
| 77 | SkIPoint offset = SkIPoint::Make(3, 4); |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 78 | auto filter = make_filter(); |
| 79 | cache->set(key0, image.get(), offset, filter.get()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 80 | |
| 81 | SkIPoint foundOffset; |
| 82 | REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); |
| 83 | REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); |
| 84 | REPORTER_ASSERT(reporter, !cache->get(key3, &foundOffset)); |
| 85 | REPORTER_ASSERT(reporter, !cache->get(key4, &foundOffset)); |
| 86 | } |
| 87 | |
| 88 | // Test purging when the max cache size is exceeded |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 89 | static void test_internal_purge(skiatest::Reporter* reporter, const sk_sp<SkSpecialImage>& image) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 90 | SkASSERT(image->getSize()); |
mtklein | 03762fe | 2016-02-21 13:36:50 -0800 | [diff] [blame] | 91 | const size_t kCacheSize = image->getSize() + 10; |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 92 | sk_sp<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 93 | |
| 94 | SkIRect clip = SkIRect::MakeWH(100, 100); |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 95 | SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset()); |
| 96 | SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, image->uniqueID(), image->subset()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 97 | |
| 98 | SkIPoint offset = SkIPoint::Make(3, 4); |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 99 | auto filter1 = make_filter(); |
| 100 | cache->set(key1, image.get(), offset, filter1.get()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 101 | |
| 102 | SkIPoint foundOffset; |
| 103 | |
| 104 | REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset)); |
| 105 | |
| 106 | // This should knock the first one out of the cache |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 107 | auto filter2 = make_filter(); |
| 108 | cache->set(key2, image.get(), offset, filter2.get()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 109 | |
| 110 | REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset)); |
| 111 | REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); |
| 112 | } |
| 113 | |
xidachen | 185a379 | 2017-06-29 11:19:42 -0400 | [diff] [blame] | 114 | // Exercise the purgeByKey and purge methods |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 115 | static void test_explicit_purging(skiatest::Reporter* reporter, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 116 | const sk_sp<SkSpecialImage>& image, |
| 117 | const sk_sp<SkSpecialImage>& subset) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 118 | static const size_t kCacheSize = 1000000; |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 119 | sk_sp<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 120 | |
| 121 | SkIRect clip = SkIRect::MakeWH(100, 100); |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 122 | SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset()); |
| 123 | SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, subset->uniqueID(), image->subset()); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 124 | |
| 125 | SkIPoint offset = SkIPoint::Make(3, 4); |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 126 | auto filter1 = make_filter(); |
| 127 | auto filter2 = make_filter(); |
| 128 | cache->set(key1, image.get(), offset, filter1.get()); |
| 129 | cache->set(key2, image.get(), offset, filter2.get()); |
robertphillips | bde57ed | 2016-04-18 14:49:57 -0700 | [diff] [blame] | 130 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->count());) |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 131 | |
| 132 | SkIPoint foundOffset; |
| 133 | |
| 134 | REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset)); |
| 135 | REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset)); |
| 136 | |
Ben Wagner | da926db | 2018-05-03 14:39:57 -0400 | [diff] [blame] | 137 | cache->purgeByImageFilter(filter1.get()); |
robertphillips | bde57ed | 2016-04-18 14:49:57 -0700 | [diff] [blame] | 138 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->count());) |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 139 | |
| 140 | REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); |
| 141 | REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset)); |
| 142 | |
| 143 | cache->purge(); |
robertphillips | bde57ed | 2016-04-18 14:49:57 -0700 | [diff] [blame] | 144 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->count());) |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 145 | |
| 146 | REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); |
| 147 | REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); |
| 148 | } |
| 149 | |
| 150 | DEF_TEST(ImageFilterCache_RasterBacked, reporter) { |
| 151 | SkBitmap srcBM = create_bm(); |
| 152 | |
| 153 | const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); |
| 154 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 155 | sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromRaster(full, srcBM)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 156 | |
| 157 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 158 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 159 | sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromRaster(subset, srcBM)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 160 | |
| 161 | test_find_existing(reporter, fullImg, subsetImg); |
| 162 | test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 163 | test_internal_purge(reporter, fullImg); |
| 164 | test_explicit_purging(reporter, fullImg, subsetImg); |
| 165 | } |
| 166 | |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 167 | |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 168 | // Shared test code for both the raster and gpu-backed image cases |
Robert Phillips | 2746765 | 2019-01-10 16:34:22 -0500 | [diff] [blame] | 169 | static void test_image_backed(skiatest::Reporter* reporter, |
| 170 | GrContext* context, |
| 171 | const sk_sp<SkImage>& srcImage) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 172 | const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); |
| 173 | |
Robert Phillips | 2746765 | 2019-01-10 16:34:22 -0500 | [diff] [blame] | 174 | sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromImage(context, full, srcImage)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 175 | |
| 176 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 177 | |
Robert Phillips | 2746765 | 2019-01-10 16:34:22 -0500 | [diff] [blame] | 178 | sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromImage(context, subset, srcImage)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 179 | |
| 180 | test_find_existing(reporter, fullImg, subsetImg); |
| 181 | test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 182 | test_internal_purge(reporter, fullImg); |
| 183 | test_explicit_purging(reporter, fullImg, subsetImg); |
| 184 | } |
| 185 | |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 186 | DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) { |
| 187 | SkBitmap srcBM = create_bm(); |
| 188 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 189 | sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM)); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 190 | |
Robert Phillips | 2746765 | 2019-01-10 16:34:22 -0500 | [diff] [blame] | 191 | test_image_backed(reporter, nullptr, srcImage); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 192 | } |
| 193 | |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 194 | #include "GrContext.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 195 | #include "GrContextPriv.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 196 | #include "GrProxyProvider.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 197 | #include "GrResourceProvider.h" |
Robert Phillips | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 198 | #include "GrSurfaceProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 199 | #include "GrTexture.h" |
Robert Phillips | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 200 | #include "GrTextureProxy.h" |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 201 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 202 | static sk_sp<GrTextureProxy> create_proxy(GrProxyProvider* proxyProvider) { |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 203 | SkBitmap srcBM = create_bm(); |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 204 | sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM)); |
| 205 | return proxyProvider->createTextureProxy(srcImage, kNone_GrSurfaceFlags, 1, |
| 206 | SkBudgeted::kYes, SkBackingFit::kExact); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 207 | } |
| 208 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 209 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 210 | GrContext* context = ctxInfo.grContext(); |
| 211 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 212 | sk_sp<GrTextureProxy> srcProxy(create_proxy(context->contextPriv().proxyProvider())); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 213 | if (!srcProxy) { |
| 214 | return; |
| 215 | } |
| 216 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 217 | if (!srcProxy->instantiate(context->contextPriv().resourceProvider())) { |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 218 | return; |
| 219 | } |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 220 | GrTexture* tex = srcProxy->peekTexture(); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 221 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 222 | GrBackendTexture backendTex = tex->getBackendTexture(); |
| 223 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 224 | GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 225 | sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 226 | backendTex, |
| 227 | texOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 228 | kRGBA_8888_SkColorType, |
| 229 | kPremul_SkAlphaType, nullptr, |
| 230 | nullptr, nullptr)); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 231 | if (!srcImage) { |
| 232 | return; |
| 233 | } |
| 234 | |
Robert Phillips | 3390e15 | 2017-01-31 17:53:34 -0500 | [diff] [blame] | 235 | GrSurfaceOrigin readBackOrigin; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 236 | GrBackendTexture readBackBackendTex = srcImage->getBackendTexture(false, &readBackOrigin); |
| 237 | if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex)) { |
| 238 | ERRORF(reporter, "backend mismatch\n"); |
Robert Phillips | 3390e15 | 2017-01-31 17:53:34 -0500 | [diff] [blame] | 239 | } |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 240 | REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex)); |
| 241 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 242 | if (readBackOrigin != texOrigin) { |
| 243 | ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin); |
Robert Phillips | 3390e15 | 2017-01-31 17:53:34 -0500 | [diff] [blame] | 244 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 245 | REPORTER_ASSERT(reporter, readBackOrigin == texOrigin); |
Robert Phillips | 3390e15 | 2017-01-31 17:53:34 -0500 | [diff] [blame] | 246 | |
Robert Phillips | 2746765 | 2019-01-10 16:34:22 -0500 | [diff] [blame] | 247 | test_image_backed(reporter, context, srcImage); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 248 | } |
| 249 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 250 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) { |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 251 | GrContext* context = ctxInfo.grContext(); |
robertphillips | cbc5bcc | 2016-02-19 10:41:12 -0800 | [diff] [blame] | 252 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 253 | sk_sp<GrTextureProxy> srcProxy(create_proxy(context->contextPriv().proxyProvider())); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 254 | if (!srcProxy) { |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 255 | return; |
| 256 | } |
| 257 | |
| 258 | const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); |
| 259 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 260 | sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeDeferredFromGpu( |
| 261 | context, full, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 262 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 263 | srcProxy, nullptr)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 264 | |
| 265 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 266 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 267 | sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeDeferredFromGpu( |
| 268 | context, subset, |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 269 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 270 | srcProxy, nullptr)); |
robertphillips | df7bb47 | 2016-02-19 08:19:40 -0800 | [diff] [blame] | 271 | |
| 272 | test_find_existing(reporter, fullImg, subsetImg); |
| 273 | test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 274 | test_internal_purge(reporter, fullImg); |
| 275 | test_explicit_purging(reporter, fullImg, subsetImg); |
| 276 | } |