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