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