Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | // This is a GPU-backend specific test. |
| 9 | |
| 10 | #include "Test.h" |
| 11 | |
| 12 | #if SK_SUPPORT_GPU |
| 13 | |
| 14 | #include "GrBackendSurface.h" |
| 15 | #include "GrContextPriv.h" |
| 16 | #include "GrResourceCache.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 17 | #include "GrProxyProvider.h" |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 18 | #include "GrResourceProvider.h" |
| 19 | #include "GrTest.h" |
| 20 | #include "GrTexture.h" |
| 21 | #include "GrTextureProxy.h" |
| 22 | |
| 23 | #include "SkGr.h" |
| 24 | #include "SkImage.h" |
| 25 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 26 | int GrProxyProvider::numUniqueKeyProxies_TestOnly() const { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 27 | return fUniquelyKeyedProxies.count(); |
| 28 | } |
| 29 | |
| 30 | static GrSurfaceDesc make_desc(GrSurfaceFlags flags) { |
| 31 | GrSurfaceDesc desc; |
| 32 | desc.fFlags = flags; |
| 33 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 34 | desc.fWidth = 64; |
| 35 | desc.fHeight = 64; |
| 36 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 37 | desc.fSampleCnt = 0; |
| 38 | |
| 39 | return desc; |
| 40 | } |
| 41 | |
| 42 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | // Basic test |
| 44 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 45 | static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 46 | GrContext* context, SkBackingFit fit) { |
| 47 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 48 | const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 49 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 50 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, fit, SkBudgeted::kYes); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 51 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 53 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 56 | static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 57 | GrContext* context, SkBackingFit fit) { |
| 58 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 59 | const GrSurfaceDesc desc = make_desc(kRenderTarget_GrSurfaceFlag); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 60 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 61 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, fit, SkBudgeted::kYes); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 62 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 64 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 67 | static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 68 | GrContext* context, SkBackingFit fit) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 69 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| 70 | const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 71 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 72 | sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy(desc, fit, |
| 73 | SkBudgeted::kYes); |
| 74 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 76 | return proxy; |
| 77 | } |
| 78 | |
| 79 | static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 80 | GrContext* context, SkBackingFit fit) { |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 81 | GrResourceProvider* resourceProvider = context->resourceProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 82 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 83 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
| 84 | static int kUniqueKeyData = 0; |
| 85 | |
| 86 | GrUniqueKey key; |
| 87 | |
| 88 | GrUniqueKey::Builder builder(&key, d, 1, nullptr); |
| 89 | builder[0] = kUniqueKeyData++; |
| 90 | builder.finish(); |
| 91 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 92 | const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 93 | |
| 94 | sk_sp<GrTexture> tex; |
| 95 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 96 | tex = sk_sp<GrTexture>(resourceProvider->createApproxTexture(desc, 0)); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 97 | } else { |
| 98 | // Only budgeted & wrapped external proxies get to carry uniqueKeys |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 99 | tex = resourceProvider->createTexture(desc, SkBudgeted::kYes); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | tex->resourcePriv().setUniqueKey(key); |
| 103 | |
| 104 | sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(tex), |
| 105 | kBottomLeft_GrSurfaceOrigin); |
| 106 | REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid()); |
| 107 | return proxy; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit, |
| 111 | sk_sp<GrTexture>* backingSurface) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 112 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 113 | GrResourceProvider* resourceProvider = context->resourceProvider(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 114 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 115 | const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 116 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 117 | *backingSurface = resourceProvider->createTexture(desc, SkBudgeted::kNo); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 118 | if (!(*backingSurface)) { |
| 119 | return nullptr; |
| 120 | } |
| 121 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 122 | GrBackendTexture backendTex = (*backingSurface)->getBackendTexture(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 123 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 124 | return proxyProvider->createWrappedTextureProxy(backendTex, kBottomLeft_GrSurfaceOrigin); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
| 128 | // This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning |
| 129 | // and looking them up work, etc. |
| 130 | static void basic_test(GrContext* context, |
| 131 | skiatest::Reporter* reporter, |
| 132 | sk_sp<GrTextureProxy> proxy, bool proxyIsCached) { |
| 133 | static int id = 1; |
| 134 | |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 135 | GrResourceProvider* resourceProvider = context->resourceProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 136 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 137 | GrResourceCache* cache = context->getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 138 | |
| 139 | int startCacheCount = cache->getResourceCount(); |
| 140 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 141 | GrUniqueKey key; |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 142 | if (proxy->getUniqueKey().isValid()) { |
| 143 | key = proxy->getUniqueKey(); |
| 144 | } else { |
| 145 | GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64)); |
| 146 | ++id; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 147 | |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 148 | // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly()); |
| 150 | proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 153 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 154 | REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount()); |
| 155 | |
| 156 | // setUniqueKey had better stick |
| 157 | REPORTER_ASSERT(reporter, key == proxy->getUniqueKey()); |
| 158 | |
| 159 | // We just added it, surely we can find it |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 160 | REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey( |
| 161 | key, kBottomLeft_GrSurfaceOrigin)); |
| 162 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 163 | |
| 164 | // Once instantiated, the backing resource should have the same key |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 165 | SkAssertResult(proxy->instantiate(resourceProvider)); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 166 | const GrUniqueKey& texKey = proxy->priv().peekSurface()->getUniqueKey(); |
| 167 | REPORTER_ASSERT(reporter, texKey.isValid()); |
| 168 | REPORTER_ASSERT(reporter, key == texKey); |
| 169 | if (proxyIsCached) { |
| 170 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 171 | } |
| 172 | |
| 173 | // deleting the proxy should delete it from the hash but not the cache |
| 174 | proxy = nullptr; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 175 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 176 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 177 | |
| 178 | // If the proxy was cached refinding it should bring it back to life |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 179 | proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 180 | if (proxyIsCached) { |
| 181 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 182 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 183 | } else { |
| 184 | REPORTER_ASSERT(reporter, !proxy); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 185 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 186 | } |
| 187 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 188 | |
| 189 | // Mega-purging it should remove it from both the hash and the cache |
| 190 | proxy = nullptr; |
| 191 | cache->purgeAllUnlocked(); |
| 192 | if (proxyIsCached) { |
| 193 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 194 | } else { |
| 195 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 196 | } |
| 197 | |
| 198 | // We can bring neither the texture nor proxy back from perma-death |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 199 | proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 200 | REPORTER_ASSERT(reporter, !proxy); |
| 201 | if (proxyIsCached) { |
| 202 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 203 | } else { |
| 204 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 209 | // Invalidation test |
| 210 | |
| 211 | // Test if invalidating unique ids operates as expected for texture proxies. |
| 212 | static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) { |
| 213 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 214 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 215 | GrResourceCache* cache = context->getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 216 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 217 | |
| 218 | sk_sp<SkImage> rasterImg; |
| 219 | |
| 220 | { |
| 221 | SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 222 | |
| 223 | SkBitmap bm; |
| 224 | bm.allocPixels(ii); |
| 225 | |
| 226 | rasterImg = SkImage::MakeFromBitmap(bm); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 227 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 228 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 229 | } |
| 230 | |
| 231 | sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context, nullptr); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 232 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 233 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 234 | |
| 235 | rasterImg = nullptr; // this invalidates the uniqueKey |
| 236 | |
| 237 | // this forces the cache to respond to the inval msg |
| 238 | int maxNum; |
| 239 | size_t maxBytes; |
| 240 | context->getResourceCacheLimits(&maxNum, &maxBytes); |
| 241 | context->setResourceCacheLimits(maxNum-1, maxBytes); |
| 242 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 243 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 244 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 245 | |
| 246 | textureImg = nullptr; |
| 247 | context->purgeAllUnlockedResources(); |
| 248 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 249 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 250 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 251 | } |
| 252 | |
Robert Phillips | fa8c080 | 2017-10-04 08:42:28 -0400 | [diff] [blame] | 253 | #ifndef SK_DISABLE_DEFERRED_PROXIES |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 254 | // Test if invalidating unique ids prior to instantiating operates as expected |
| 255 | static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 256 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 257 | GrResourceProvider* resourceProvider = context->resourceProvider(); |
| 258 | GrResourceCache* cache = context->getResourceCache(); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 259 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 260 | |
| 261 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
| 262 | GrUniqueKey key; |
| 263 | GrUniqueKey::Builder builder(&key, d, 1, nullptr); |
| 264 | builder[0] = 0; |
| 265 | builder.finish(); |
| 266 | |
| 267 | // Create proxy, assign unique key |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 268 | sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, SkBackingFit::kExact); |
| 269 | proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 270 | |
| 271 | // Send an invalidation message, which will be sitting in the cache's inbox |
| 272 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(GrUniqueKeyInvalidatedMessage(key)); |
| 273 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 274 | REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 275 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 276 | |
| 277 | // Instantiate the proxy. This will trigger the message to be processed, so the resulting |
| 278 | // texture should *not* have the unique key on it! |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 279 | SkAssertResult(proxy->instantiate(resourceProvider)); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 280 | |
| 281 | REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); |
| 282 | REPORTER_ASSERT(reporter, !proxy->priv().peekTexture()->getUniqueKey().isValid()); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 283 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 284 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 285 | |
| 286 | proxy = nullptr; |
| 287 | context->purgeAllUnlockedResources(); |
| 288 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 289 | REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 290 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 291 | } |
Robert Phillips | 73f7e1d | 2017-10-02 14:05:46 -0400 | [diff] [blame] | 292 | #endif |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 293 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 294 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) { |
| 295 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 296 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 297 | GrResourceCache* cache = context->getResourceCache(); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 298 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 299 | REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly()); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 300 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 301 | |
| 302 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
Greg Daniel | cd87140 | 2017-09-26 12:49:26 -0400 | [diff] [blame] | 303 | for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 304 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 305 | basic_test(context, reporter, create(reporter, context, fit), true); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 309 | sk_sp<GrTexture> backingTex; |
| 310 | sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex); |
| 311 | basic_test(context, reporter, std::move(proxy), false); |
| 312 | |
| 313 | backingTex = nullptr; |
| 314 | cache->purgeAllUnlocked(); |
| 315 | } |
| 316 | |
| 317 | invalidation_test(context, reporter); |
Robert Phillips | fa8c080 | 2017-10-04 08:42:28 -0400 | [diff] [blame] | 318 | #ifndef SK_DISABLE_DEFERRED_PROXIES |
| 319 | invalidation_and_instantiation_test(context, reporter); |
| 320 | #endif |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | #endif |