blob: c1c14d61a62db63f4fe5f5b49d7acfdca7ec5985 [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
Brian Salomon72050802020-10-12 20:45:06 -040012#include "include/core/SkImage.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/gpu/GrBackendSurface.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040014#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040015#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrProxyProvider.h"
Robert Phillipse94b4e12020-07-23 13:54:35 -040017#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrResourceCache.h"
19#include "src/gpu/GrResourceProvider.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000020#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040021#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/SkGr.h"
Brian Salomon72050802020-10-12 20:45:06 -040023#include "tools/gpu/ManagedBackendTexture.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
Brian Salomon72050802020-10-12 20:45:06 -040099static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext) {
100 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
101 dContext,
102 kSize.width(),
103 kSize.height(),
104 GrColorTypeToSkColorType(kColorType),
105 GrMipmapped::kNo,
106 GrRenderable::kNo,
107 GrProtected::kNo);
108 if (!mbet) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400109 return nullptr;
110 }
Brian Salomon72050802020-10-12 20:45:06 -0400111 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
112 return proxyProvider->wrapBackendTexture(mbet->texture(),
113 kBorrow_GrWrapOwnership,
114 GrWrapCacheable::kYes,
115 kRead_GrIOType,
116 mbet->refCountedCallback());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400117}
118
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400119// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
120// and looking them up work, etc.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400121static void basic_test(GrDirectContext* dContext,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400122 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400123 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400124 static int id = 1;
125
Robert Phillipse94b4e12020-07-23 13:54:35 -0400126 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
127 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
128 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400129
130 int startCacheCount = cache->getResourceCount();
131
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400132 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400133 if (proxy->getUniqueKey().isValid()) {
134 key = proxy->getUniqueKey();
135 } else {
136 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
137 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400138
Greg Danielcd871402017-09-26 12:49:26 -0400139 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500140 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500141 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400142 }
143
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500144 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400145 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
146
147 // setUniqueKey had better stick
148 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
149
150 // We just added it, surely we can find it
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400151 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500152 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400153
Greg Daniel303e83e2018-09-10 14:10:19 -0400154 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
155
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400156 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500157 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500158 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400159 REPORTER_ASSERT(reporter, texKey.isValid());
160 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400161
Brian Salomon9bc76d92019-01-24 12:18:33 -0500162 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
163 // deleted.
164 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
165 GrBudgetedType::kUnbudgetedCacheable;
166
167 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
168 // it has a key.
169 bool expectDeletingProxyToDeleteResource =
170 proxy->peekSurface()->resourcePriv().budgetedType() ==
171 GrBudgetedType::kUnbudgetedUncacheable;
172
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400173 // deleting the proxy should delete it from the hash but not the cache
174 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500175 if (expectDeletingProxyToDeleteResource) {
176 expectedCacheCount -= 1;
177 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500178 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400179 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400180
181 // If the proxy was cached refinding it should bring it back to life
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400182 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Greg Daniel303e83e2018-09-10 14:10:19 -0400183 REPORTER_ASSERT(reporter, proxy);
184 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
185 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400186
187 // Mega-purging it should remove it from both the hash and the cache
188 proxy = nullptr;
189 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500190 if (!expectResourceToOutliveProxy) {
191 expectedCacheCount--;
192 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400193 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400194
Brian Salomon9bc76d92019-01-24 12:18:33 -0500195 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
196 // be.
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400197 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500198 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400199 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500200
201 if (expectResourceToOutliveProxy) {
202 proxy.reset();
Robert Phillipse94b4e12020-07-23 13:54:35 -0400203 GrUniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500204 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
205 cache->purgeAsNeeded();
206 expectedCacheCount--;
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400207 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500208 REPORTER_ASSERT(reporter, !proxy);
209 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
210 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400211}
212
213///////////////////////////////////////////////////////////////////////////////////////////////////
214// Invalidation test
215
216// Test if invalidating unique ids operates as expected for texture proxies.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400217static void invalidation_test(GrDirectContext* dContext, skiatest::Reporter* reporter) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400218
Robert Phillipse94b4e12020-07-23 13:54:35 -0400219 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
220 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400221 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
222
223 sk_sp<SkImage> rasterImg;
224
225 {
226 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
227
228 SkBitmap bm;
229 bm.allocPixels(ii);
230
231 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500232 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400233 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
234 }
235
Greg Daniela58db7f2020-07-15 09:17:59 -0400236 // Some of our backends use buffers to do uploads that will live in our resource cache. So we
237 // need to account for those extra resources here.
238 int bufferResources = 0;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400239 if (dContext->backend() == GrBackendApi::kDawn ||
240 dContext->backend() == GrBackendApi::kVulkan ||
Jim Van Verth1e950102020-07-31 09:47:08 -0400241 dContext->backend() == GrBackendApi::kDirect3D ||
242 dContext->backend() == GrBackendApi::kMetal) {
Greg Daniela58db7f2020-07-15 09:17:59 -0400243 bufferResources = 1;
244 }
245
Robert Phillipse94b4e12020-07-23 13:54:35 -0400246 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(dContext);
Brian Salomonbc074a62020-03-18 10:06:13 -0400247 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400248 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400249
250 rasterImg = nullptr; // this invalidates the uniqueKey
251
252 // this forces the cache to respond to the inval msg
Robert Phillipse94b4e12020-07-23 13:54:35 -0400253 size_t maxBytes = dContext->getResourceCacheLimit();
254 dContext->setResourceCacheLimit(maxBytes-1);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400255
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500256 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400257 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400258
259 textureImg = nullptr;
Greg Daniela58db7f2020-07-15 09:17:59 -0400260
261 // For backends that use buffers to upload lets make sure that work has been submit and done
262 // before we try to purge all resources.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400263 dContext->submit(true);
Greg Daniela58db7f2020-07-15 09:17:59 -0400264
265#ifdef SK_DAWN
266 // The forced cpu sync in dawn doesn't actually mean the async map will finish thus we may
267 // still have a ref on the GrGpuBuffer and it will not get purged by the call below. We dig
268 // deep into the dawn gpu to make sure we wait for the async map to finish.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400269 if (dContext->backend() == GrBackendApi::kDawn) {
270 GrDawnGpu* gpu = static_cast<GrDawnGpu*>(dContext->priv().getGpu());
Greg Daniela58db7f2020-07-15 09:17:59 -0400271 gpu->waitOnAllBusyStagingBuffers();
272 }
273#endif
274
Robert Phillipse94b4e12020-07-23 13:54:35 -0400275 dContext->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400276
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500277 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400278 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
279}
280
Brian Osman28c434b2017-09-27 13:11:16 -0400281// Test if invalidating unique ids prior to instantiating operates as expected
Robert Phillipse94b4e12020-07-23 13:54:35 -0400282static void invalidation_and_instantiation_test(GrDirectContext* dContext,
283 skiatest::Reporter* reporter) {
284 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
285 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
286 GrResourceCache* cache = dContext->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400287 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
288
289 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
290 GrUniqueKey key;
291 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
292 builder[0] = 0;
293 builder.finish();
294
295 // Create proxy, assign unique key
Robert Phillipse94b4e12020-07-23 13:54:35 -0400296 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
Greg Daniel4065d452018-11-16 15:43:41 -0500297 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500298 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400299
300 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400301 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillipse94b4e12020-07-23 13:54:35 -0400302 GrUniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400303
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500304 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400305 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
306
307 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
308 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500309 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400310
311 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400312 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500313 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400314 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
315
316 proxy = nullptr;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400317 dContext->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400318
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500319 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400320 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
321}
322
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400323DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
Adlai Holler4caa9352020-07-16 10:58:58 -0400324 auto direct = ctxInfo.directContext();
325 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
326 GrResourceCache* cache = direct->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400327
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500328 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400329 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
330
331 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400332 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400333 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Adlai Holler4caa9352020-07-16 10:58:58 -0400334 basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400335 }
336
337 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400338 cache->purgeAllUnlocked();
339 }
340
Brian Salomon72050802020-10-12 20:45:06 -0400341 basic_test(direct, reporter, create_wrapped_backend(direct));
342
Adlai Holler4caa9352020-07-16 10:58:58 -0400343 invalidation_test(direct, reporter);
344 invalidation_and_instantiation_test(direct, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400345}