blob: affb584ac2e56475aeb37d883712538197162947 [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 Reedac9f0c92020-12-23 10:11:33 -050012#include "include/core/SkBitmap.h"
Brian Salomon72050802020-10-12 20:45:06 -040013#include "include/core/SkImage.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/gpu/GrBackendSurface.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040015#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040016#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrProxyProvider.h"
Robert Phillipse94b4e12020-07-23 13:54:35 -040018#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/GrResourceCache.h"
20#include "src/gpu/GrResourceProvider.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000021#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040022#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/SkGr.h"
Brian Salomon72050802020-10-12 20:45:06 -040024#include "tools/gpu/ManagedBackendTexture.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040025
Greg Daniela58db7f2020-07-15 09:17:59 -040026#ifdef SK_DAWN
27#include "src/gpu/dawn/GrDawnGpu.h"
28#endif
29
Robert Phillips1afd4cd2018-01-08 13:40:32 -050030int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040031 return fUniquelyKeyedProxies.count();
32}
33
Brian Salomon4eb38b72019-08-05 12:58:39 -040034static constexpr auto kColorType = GrColorType::kRGBA_8888;
35static constexpr auto kSize = SkISize::Make(64, 64);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040036
37///////////////////////////////////////////////////////////////////////////////////////////////////
38// Basic test
39
Robert Phillipse94b4e12020-07-23 13:54:35 -040040static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter,
41 GrRecordingContext* rContext,
42 GrProxyProvider* proxyProvider,
43 SkBackingFit fit) {
44 const GrCaps* caps = rContext->priv().caps();
Robert Phillips0a15cc62019-07-30 12:49:10 -040045
Brian Salomon4eb38b72019-08-05 12:58:39 -040046 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040047
Greg Daniel3a365112020-02-14 10:47:18 -050048 sk_sp<GrTextureProxy> proxy =
Brian Salomon7e67dca2020-07-21 09:27:25 -040049 proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipmapped::kNo, fit,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040050 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040051 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040052 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
53 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040054}
55
Robert Phillipse94b4e12020-07-23 13:54:35 -040056static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter,
57 GrRecordingContext* rContext,
58 GrProxyProvider* proxyProvider,
59 SkBackingFit fit) {
60 const GrCaps* caps = rContext->priv().caps();
Robert Phillips0a15cc62019-07-30 12:49:10 -040061
Brian Salomon4eb38b72019-08-05 12:58:39 -040062 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040063
Greg Daniel3a365112020-02-14 10:47:18 -050064 sk_sp<GrTextureProxy> proxy =
Brian Salomon7e67dca2020-07-21 09:27:25 -040065 proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipmapped::kNo, fit,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040066 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040067 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040068 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
69 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040070}
71
Robert Phillipse94b4e12020-07-23 13:54:35 -040072static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrRecordingContext*,
Robert Phillipsadbe1322018-01-17 13:35:46 -050073 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -060074 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050075 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050076 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040077 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
78 return proxy;
79}
80
Robert Phillipse94b4e12020-07-23 13:54:35 -040081static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*,
Robert Phillipsadbe1322018-01-17 13:35:46 -050082 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Greg Danielcd871402017-09-26 12:49:26 -040083 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 Phillipsadbe1322018-01-17 13:35:46 -050092 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Chris Daltond004e0b2018-09-27 09:28:03 -060093 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050094 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsadbe1322018-01-17 13:35:46 -050095 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -040096 REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
97 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040098}
99
Brian Salomon72050802020-10-12 20:45:06 -0400100static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext) {
101 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
102 dContext,
103 kSize.width(),
104 kSize.height(),
105 GrColorTypeToSkColorType(kColorType),
106 GrMipmapped::kNo,
107 GrRenderable::kNo,
108 GrProtected::kNo);
109 if (!mbet) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400110 return nullptr;
111 }
Brian Salomon72050802020-10-12 20:45:06 -0400112 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
113 return proxyProvider->wrapBackendTexture(mbet->texture(),
114 kBorrow_GrWrapOwnership,
115 GrWrapCacheable::kYes,
116 kRead_GrIOType,
117 mbet->refCountedCallback());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400118}
119
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400120// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
121// and looking them up work, etc.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400122static void basic_test(GrDirectContext* dContext,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400123 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400124 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400125 static int id = 1;
126
Robert Phillipse94b4e12020-07-23 13:54:35 -0400127 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
128 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
129 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400130
131 int startCacheCount = cache->getResourceCount();
132
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400133 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400134 if (proxy->getUniqueKey().isValid()) {
135 key = proxy->getUniqueKey();
136 } else {
137 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
138 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400139
Greg Danielcd871402017-09-26 12:49:26 -0400140 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500141 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500142 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400143 }
144
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500145 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400146 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
147
148 // setUniqueKey had better stick
149 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
150
151 // We just added it, surely we can find it
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400152 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500153 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400154
Greg Daniel303e83e2018-09-10 14:10:19 -0400155 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
156
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400157 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500158 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500159 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400160 REPORTER_ASSERT(reporter, texKey.isValid());
161 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400162
Brian Salomon9bc76d92019-01-24 12:18:33 -0500163 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
164 // deleted.
165 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
166 GrBudgetedType::kUnbudgetedCacheable;
167
168 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
169 // it has a key.
170 bool expectDeletingProxyToDeleteResource =
171 proxy->peekSurface()->resourcePriv().budgetedType() ==
172 GrBudgetedType::kUnbudgetedUncacheable;
173
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400174 // deleting the proxy should delete it from the hash but not the cache
175 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500176 if (expectDeletingProxyToDeleteResource) {
177 expectedCacheCount -= 1;
178 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500179 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400180 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400181
182 // If the proxy was cached refinding it should bring it back to life
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400183 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Greg Daniel303e83e2018-09-10 14:10:19 -0400184 REPORTER_ASSERT(reporter, proxy);
185 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
186 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400187
188 // Mega-purging it should remove it from both the hash and the cache
189 proxy = nullptr;
190 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500191 if (!expectResourceToOutliveProxy) {
192 expectedCacheCount--;
193 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400194 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400195
Brian Salomon9bc76d92019-01-24 12:18:33 -0500196 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
197 // be.
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400198 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500199 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400200 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500201
202 if (expectResourceToOutliveProxy) {
203 proxy.reset();
Robert Phillipse94b4e12020-07-23 13:54:35 -0400204 GrUniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500205 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
206 cache->purgeAsNeeded();
207 expectedCacheCount--;
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400208 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500209 REPORTER_ASSERT(reporter, !proxy);
210 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
211 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400212}
213
214///////////////////////////////////////////////////////////////////////////////////////////////////
215// Invalidation test
216
217// Test if invalidating unique ids operates as expected for texture proxies.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400218static void invalidation_test(GrDirectContext* dContext, skiatest::Reporter* reporter) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400219
Robert Phillipse94b4e12020-07-23 13:54:35 -0400220 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
221 GrResourceCache* cache = dContext->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400222 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
223
224 sk_sp<SkImage> rasterImg;
225
226 {
227 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
228
229 SkBitmap bm;
230 bm.allocPixels(ii);
231
Mike Reeddc607e32020-12-23 11:50:36 -0500232 rasterImg = bm.asImage();
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500233 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400234 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
235 }
236
Greg Daniela58db7f2020-07-15 09:17:59 -0400237 // Some of our backends use buffers to do uploads that will live in our resource cache. So we
238 // need to account for those extra resources here.
239 int bufferResources = 0;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400240 if (dContext->backend() == GrBackendApi::kDawn ||
241 dContext->backend() == GrBackendApi::kVulkan ||
Jim Van Verth1e950102020-07-31 09:47:08 -0400242 dContext->backend() == GrBackendApi::kDirect3D ||
243 dContext->backend() == GrBackendApi::kMetal) {
Greg Daniela58db7f2020-07-15 09:17:59 -0400244 bufferResources = 1;
245 }
246
Robert Phillipse94b4e12020-07-23 13:54:35 -0400247 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(dContext);
Brian Salomonbc074a62020-03-18 10:06:13 -0400248 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400249 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400250
251 rasterImg = nullptr; // this invalidates the uniqueKey
252
253 // this forces the cache to respond to the inval msg
Robert Phillipse94b4e12020-07-23 13:54:35 -0400254 size_t maxBytes = dContext->getResourceCacheLimit();
255 dContext->setResourceCacheLimit(maxBytes-1);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400256
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500257 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400258 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400259
260 textureImg = nullptr;
Greg Daniela58db7f2020-07-15 09:17:59 -0400261
262 // For backends that use buffers to upload lets make sure that work has been submit and done
263 // before we try to purge all resources.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400264 dContext->submit(true);
Greg Daniela58db7f2020-07-15 09:17:59 -0400265
266#ifdef SK_DAWN
267 // The forced cpu sync in dawn doesn't actually mean the async map will finish thus we may
268 // still have a ref on the GrGpuBuffer and it will not get purged by the call below. We dig
269 // deep into the dawn gpu to make sure we wait for the async map to finish.
Robert Phillipse94b4e12020-07-23 13:54:35 -0400270 if (dContext->backend() == GrBackendApi::kDawn) {
271 GrDawnGpu* gpu = static_cast<GrDawnGpu*>(dContext->priv().getGpu());
Greg Daniela58db7f2020-07-15 09:17:59 -0400272 gpu->waitOnAllBusyStagingBuffers();
273 }
274#endif
275
Robert Phillipse94b4e12020-07-23 13:54:35 -0400276 dContext->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400277
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500278 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400279 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
280}
281
Brian Osman28c434b2017-09-27 13:11:16 -0400282// Test if invalidating unique ids prior to instantiating operates as expected
Robert Phillipse94b4e12020-07-23 13:54:35 -0400283static void invalidation_and_instantiation_test(GrDirectContext* dContext,
284 skiatest::Reporter* reporter) {
285 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
286 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
287 GrResourceCache* cache = dContext->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400288 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
289
290 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
291 GrUniqueKey key;
292 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
293 builder[0] = 0;
294 builder.finish();
295
296 // Create proxy, assign unique key
Robert Phillipse94b4e12020-07-23 13:54:35 -0400297 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
Greg Daniel4065d452018-11-16 15:43:41 -0500298 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500299 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400300
301 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400302 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillipse94b4e12020-07-23 13:54:35 -0400303 GrUniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400304
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500305 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400306 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
307
308 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
309 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500310 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400311
312 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400313 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500314 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400315 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
316
317 proxy = nullptr;
Robert Phillipse94b4e12020-07-23 13:54:35 -0400318 dContext->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400319
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500320 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400321 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
322}
323
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400324DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
Adlai Holler4caa9352020-07-16 10:58:58 -0400325 auto direct = ctxInfo.directContext();
326 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
327 GrResourceCache* cache = direct->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400328
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500329 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400330 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
331
332 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400333 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400334 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Adlai Holler4caa9352020-07-16 10:58:58 -0400335 basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400336 }
337
338 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400339 cache->purgeAllUnlocked();
340 }
341
Brian Salomon72050802020-10-12 20:45:06 -0400342 basic_test(direct, reporter, create_wrapped_backend(direct));
343
Adlai Holler4caa9352020-07-16 10:58:58 -0400344 invalidation_test(direct, reporter);
345 invalidation_and_instantiation_test(direct, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400346}