blob: fe2a0cda659d2b39c171244122b37912cfb083df [file] [log] [blame]
Robert Phillipsae7d3f32017-09-21 08:26:08 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "tests/Test.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040011
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/GrBackendSurface.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040013#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrProxyProvider.h"
Robert Phillipse94b4e12020-07-23 13:54:35 -040016#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrResourceCache.h"
18#include "src/gpu/GrResourceProvider.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000019#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040020#include "src/gpu/GrTextureProxy.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040021
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "include/core/SkImage.h"
23#include "src/gpu/SkGr.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040024
Greg Daniela58db7f2020-07-15 09:17:59 -040025#ifdef SK_DAWN
26#include "src/gpu/dawn/GrDawnGpu.h"
27#endif
28
Robert Phillips1afd4cd2018-01-08 13:40:32 -050029int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040030 return fUniquelyKeyedProxies.count();
31}
32
Brian Salomon4eb38b72019-08-05 12:58:39 -040033static constexpr auto kColorType = GrColorType::kRGBA_8888;
34static constexpr auto kSize = SkISize::Make(64, 64);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040035
36///////////////////////////////////////////////////////////////////////////////////////////////////
37// Basic test
38
Robert Phillipse94b4e12020-07-23 13:54:35 -040039static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter,
40 GrRecordingContext* rContext,
41 GrProxyProvider* proxyProvider,
42 SkBackingFit fit) {
43 const GrCaps* caps = rContext->priv().caps();
Robert Phillips0a15cc62019-07-30 12:49:10 -040044
Brian Salomon4eb38b72019-08-05 12:58:39 -040045 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040046
Greg Daniel3a365112020-02-14 10:47:18 -050047 sk_sp<GrTextureProxy> proxy =
Brian Salomon7e67dca2020-07-21 09:27:25 -040048 proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipmapped::kNo, fit,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040049 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040050 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040051 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
52 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040053}
54
Robert Phillipse94b4e12020-07-23 13:54:35 -040055static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter,
56 GrRecordingContext* rContext,
57 GrProxyProvider* proxyProvider,
58 SkBackingFit fit) {
59 const GrCaps* caps = rContext->priv().caps();
Robert Phillips0a15cc62019-07-30 12:49:10 -040060
Brian Salomon4eb38b72019-08-05 12:58:39 -040061 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040062
Greg Daniel3a365112020-02-14 10:47:18 -050063 sk_sp<GrTextureProxy> proxy =
Brian Salomon7e67dca2020-07-21 09:27:25 -040064 proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipmapped::kNo, fit,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040065 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040066 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040067 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
68 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040069}
70
Robert Phillipse94b4e12020-07-23 13:54:35 -040071static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrRecordingContext*,
Robert Phillipsadbe1322018-01-17 13:35:46 -050072 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -060073 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050074 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050075 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040076 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
77 return proxy;
78}
79
Robert Phillipse94b4e12020-07-23 13:54:35 -040080static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*,
Robert Phillipsadbe1322018-01-17 13:35:46 -050081 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Greg Danielcd871402017-09-26 12:49:26 -040082 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
83 static int kUniqueKeyData = 0;
84
85 GrUniqueKey key;
86
87 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
88 builder[0] = kUniqueKeyData++;
89 builder.finish();
90
Robert Phillipsadbe1322018-01-17 13:35:46 -050091 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Chris Daltond004e0b2018-09-27 09:28:03 -060092 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050093 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsadbe1322018-01-17 13:35:46 -050094 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -040095 REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
96 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040097}
98
Robert Phillipse94b4e12020-07-23 13:54:35 -040099static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext,
100 SkBackingFit fit,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400101 sk_sp<GrTexture>* backingSurface) {
Robert Phillipse94b4e12020-07-23 13:54:35 -0400102 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
103 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400104
Brian Salomon4eb38b72019-08-05 12:58:39 -0400105 GrBackendFormat format =
106 proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400107
Brian Salomona90382f2019-09-17 09:01:56 -0400108 *backingSurface =
Brian Salomon7e67dca2020-07-21 09:27:25 -0400109 resourceProvider->createTexture(kSize, format, GrRenderable::kNo, 1, GrMipmapped::kNo,
Brian Salomona90382f2019-09-17 09:01:56 -0400110 SkBudgeted::kNo, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400111 if (!(*backingSurface)) {
112 return nullptr;
113 }
114
Robert Phillipsb67821d2017-12-13 15:00:45 -0500115 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400116
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400117 return proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
118 GrWrapCacheable::kYes, kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400119}
120
121
122// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
123// and looking them up work, etc.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400124static void basic_test(GrDirectContext* dContext,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400125 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400126 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400127 static int id = 1;
128
Robert Phillipse94b4e12020-07-23 13:54:35 -0400129 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
130 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
131 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400132
133 int startCacheCount = cache->getResourceCount();
134
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400135 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400136 if (proxy->getUniqueKey().isValid()) {
137 key = proxy->getUniqueKey();
138 } else {
139 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
140 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400141
Greg Danielcd871402017-09-26 12:49:26 -0400142 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500143 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500144 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400145 }
146
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500147 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400148 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
149
150 // setUniqueKey had better stick
151 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
152
153 // We just added it, surely we can find it
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400154 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500155 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400156
Greg Daniel303e83e2018-09-10 14:10:19 -0400157 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
158
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400159 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500160 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500161 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400162 REPORTER_ASSERT(reporter, texKey.isValid());
163 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400164
Brian Salomon9bc76d92019-01-24 12:18:33 -0500165 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
166 // deleted.
167 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
168 GrBudgetedType::kUnbudgetedCacheable;
169
170 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
171 // it has a key.
172 bool expectDeletingProxyToDeleteResource =
173 proxy->peekSurface()->resourcePriv().budgetedType() ==
174 GrBudgetedType::kUnbudgetedUncacheable;
175
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400176 // deleting the proxy should delete it from the hash but not the cache
177 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500178 if (expectDeletingProxyToDeleteResource) {
179 expectedCacheCount -= 1;
180 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500181 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400182 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400183
184 // If the proxy was cached refinding it should bring it back to life
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400185 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Greg Daniel303e83e2018-09-10 14:10:19 -0400186 REPORTER_ASSERT(reporter, proxy);
187 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
188 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400189
190 // Mega-purging it should remove it from both the hash and the cache
191 proxy = nullptr;
192 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500193 if (!expectResourceToOutliveProxy) {
194 expectedCacheCount--;
195 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400196 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400197
Brian Salomon9bc76d92019-01-24 12:18:33 -0500198 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
199 // be.
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400200 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500201 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400202 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500203
204 if (expectResourceToOutliveProxy) {
205 proxy.reset();
Robert Phillipse94b4e12020-07-23 13:54:35 -0400206 GrUniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500207 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
208 cache->purgeAsNeeded();
209 expectedCacheCount--;
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400210 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500211 REPORTER_ASSERT(reporter, !proxy);
212 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
213 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400214}
215
216///////////////////////////////////////////////////////////////////////////////////////////////////
217// Invalidation test
218
219// Test if invalidating unique ids operates as expected for texture proxies.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400220static void invalidation_test(GrDirectContext* dContext, skiatest::Reporter* reporter) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400221
Robert Phillipse94b4e12020-07-23 13:54:35 -0400222 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
223 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400224 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
225
226 sk_sp<SkImage> rasterImg;
227
228 {
229 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
230
231 SkBitmap bm;
232 bm.allocPixels(ii);
233
234 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500235 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400236 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
237 }
238
Greg Daniela58db7f2020-07-15 09:17:59 -0400239 // Some of our backends use buffers to do uploads that will live in our resource cache. So we
240 // need to account for those extra resources here.
241 int bufferResources = 0;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400242 if (dContext->backend() == GrBackendApi::kDawn ||
243 dContext->backend() == GrBackendApi::kVulkan ||
Jim Van Verth1e950102020-07-31 09:47:08 -0400244 dContext->backend() == GrBackendApi::kDirect3D ||
245 dContext->backend() == GrBackendApi::kMetal) {
Greg Daniela58db7f2020-07-15 09:17:59 -0400246 bufferResources = 1;
247 }
248
Robert Phillipse94b4e12020-07-23 13:54:35 -0400249 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(dContext);
Brian Salomonbc074a62020-03-18 10:06:13 -0400250 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400251 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400252
253 rasterImg = nullptr; // this invalidates the uniqueKey
254
255 // this forces the cache to respond to the inval msg
Robert Phillipse94b4e12020-07-23 13:54:35 -0400256 size_t maxBytes = dContext->getResourceCacheLimit();
257 dContext->setResourceCacheLimit(maxBytes-1);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400258
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500259 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400260 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400261
262 textureImg = nullptr;
Greg Daniela58db7f2020-07-15 09:17:59 -0400263
264 // For backends that use buffers to upload lets make sure that work has been submit and done
265 // before we try to purge all resources.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400266 dContext->submit(true);
Greg Daniela58db7f2020-07-15 09:17:59 -0400267
268#ifdef SK_DAWN
269 // The forced cpu sync in dawn doesn't actually mean the async map will finish thus we may
270 // still have a ref on the GrGpuBuffer and it will not get purged by the call below. We dig
271 // deep into the dawn gpu to make sure we wait for the async map to finish.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400272 if (dContext->backend() == GrBackendApi::kDawn) {
273 GrDawnGpu* gpu = static_cast<GrDawnGpu*>(dContext->priv().getGpu());
Greg Daniela58db7f2020-07-15 09:17:59 -0400274 gpu->waitOnAllBusyStagingBuffers();
275 }
276#endif
277
Robert Phillipse94b4e12020-07-23 13:54:35 -0400278 dContext->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400279
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500280 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400281 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
282}
283
Brian Osman28c434b2017-09-27 13:11:16 -0400284// Test if invalidating unique ids prior to instantiating operates as expected
Robert Phillipse94b4e12020-07-23 13:54:35 -0400285static void invalidation_and_instantiation_test(GrDirectContext* dContext,
286 skiatest::Reporter* reporter) {
287 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
288 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
289 GrResourceCache* cache = dContext->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400290 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
291
292 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
293 GrUniqueKey key;
294 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
295 builder[0] = 0;
296 builder.finish();
297
298 // Create proxy, assign unique key
Robert Phillipse94b4e12020-07-23 13:54:35 -0400299 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
Greg Daniel4065d452018-11-16 15:43:41 -0500300 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500301 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400302
303 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400304 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillipse94b4e12020-07-23 13:54:35 -0400305 GrUniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400306
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500307 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400308 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
309
310 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
311 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500312 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400313
314 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400315 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500316 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400317 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
318
319 proxy = nullptr;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400320 dContext->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400321
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500322 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400323 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
324}
325
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400326DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
Adlai Holler4caa9352020-07-16 10:58:58 -0400327 auto direct = ctxInfo.directContext();
328 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
329 GrResourceCache* cache = direct->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400330
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500331 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400332 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
333
334 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400335 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400336 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Adlai Holler4caa9352020-07-16 10:58:58 -0400337 basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400338 }
339
340 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
341 sk_sp<GrTexture> backingTex;
Adlai Holler4caa9352020-07-16 10:58:58 -0400342 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(direct, fit, &backingTex);
343 basic_test(direct, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400344
345 backingTex = nullptr;
346 cache->purgeAllUnlocked();
347 }
348
Adlai Holler4caa9352020-07-16 10:58:58 -0400349 invalidation_test(direct, reporter);
350 invalidation_and_instantiation_test(direct, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400351}