blob: 4b2c78634cdc62b3f341048e2082dcf3c47badc6 [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"
16#include "src/gpu/GrResourceCache.h"
17#include "src/gpu/GrResourceProvider.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000018#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040019#include "src/gpu/GrTextureProxy.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040020
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "include/core/SkImage.h"
22#include "src/gpu/SkGr.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040023
Greg Daniela58db7f2020-07-15 09:17:59 -040024#ifdef SK_DAWN
25#include "src/gpu/dawn/GrDawnGpu.h"
26#endif
27
Robert Phillips1afd4cd2018-01-08 13:40:32 -050028int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040029 return fUniquelyKeyedProxies.count();
30}
31
Brian Salomon4eb38b72019-08-05 12:58:39 -040032static constexpr auto kColorType = GrColorType::kRGBA_8888;
33static constexpr auto kSize = SkISize::Make(64, 64);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040034
35///////////////////////////////////////////////////////////////////////////////////////////////////
36// Basic test
37
Greg Daniel4065d452018-11-16 15:43:41 -050038static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050039 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0a15cc62019-07-30 12:49:10 -040040 const GrCaps* caps = ctx->priv().caps();
41
Brian Salomon4eb38b72019-08-05 12:58:39 -040042 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040043
Greg Daniel3a365112020-02-14 10:47:18 -050044 sk_sp<GrTextureProxy> proxy =
Brian Salomondf1bd6d2020-03-26 20:37:01 -040045 proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipMapped::kNo, fit,
46 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040047 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040048 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
49 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040050}
51
Greg Daniel4065d452018-11-16 15:43:41 -050052static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050053 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0a15cc62019-07-30 12:49:10 -040054 const GrCaps* caps = ctx->priv().caps();
55
Brian Salomon4eb38b72019-08-05 12:58:39 -040056 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040057
Greg Daniel3a365112020-02-14 10:47:18 -050058 sk_sp<GrTextureProxy> proxy =
Brian Salomondf1bd6d2020-03-26 20:37:01 -040059 proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipMapped::kNo, fit,
60 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040061 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040062 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
63 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040064}
65
Greg Daniel4065d452018-11-16 15:43:41 -050066static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050067 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Chris Daltond004e0b2018-09-27 09:28:03 -060068 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050069 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050070 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040071 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
72 return proxy;
73}
74
Greg Daniel4065d452018-11-16 15:43:41 -050075static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050076 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Greg Danielcd871402017-09-26 12:49:26 -040077 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
78 static int kUniqueKeyData = 0;
79
80 GrUniqueKey key;
81
82 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
83 builder[0] = kUniqueKeyData++;
84 builder.finish();
85
Robert Phillipsadbe1322018-01-17 13:35:46 -050086 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Chris Daltond004e0b2018-09-27 09:28:03 -060087 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Greg Daniel3a365112020-02-14 10:47:18 -050088 kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsadbe1322018-01-17 13:35:46 -050089 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -040090 REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
91 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040092}
93
94static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit,
95 sk_sp<GrTexture>* backingSurface) {
Robert Phillips9da87e02019-02-04 13:26:26 -050096 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
97 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
Robert Phillipsae7d3f32017-09-21 08:26:08 -040098
Brian Salomon4eb38b72019-08-05 12:58:39 -040099 GrBackendFormat format =
100 proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400101
Brian Salomona90382f2019-09-17 09:01:56 -0400102 *backingSurface =
Brian Salomona56a7462020-02-07 14:17:25 -0500103 resourceProvider->createTexture(kSize, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
Brian Salomona90382f2019-09-17 09:01:56 -0400104 SkBudgeted::kNo, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400105 if (!(*backingSurface)) {
106 return nullptr;
107 }
108
Robert Phillipsb67821d2017-12-13 15:00:45 -0500109 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400110
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400111 return proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
112 GrWrapCacheable::kYes, kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400113}
114
115
116// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
117// and looking them up work, etc.
118static void basic_test(GrContext* context,
119 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400120 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400121 static int id = 1;
122
Robert Phillips9da87e02019-02-04 13:26:26 -0500123 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
124 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
125 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400126
127 int startCacheCount = cache->getResourceCount();
128
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400129 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400130 if (proxy->getUniqueKey().isValid()) {
131 key = proxy->getUniqueKey();
132 } else {
133 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
134 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400135
Greg Danielcd871402017-09-26 12:49:26 -0400136 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500137 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500138 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400139 }
140
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500141 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400142 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
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400148 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500149 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400150
Greg Daniel303e83e2018-09-10 14:10:19 -0400151 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
152
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400153 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500154 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500155 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400156 REPORTER_ASSERT(reporter, texKey.isValid());
157 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400158
Brian Salomon9bc76d92019-01-24 12:18:33 -0500159 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
160 // deleted.
161 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
162 GrBudgetedType::kUnbudgetedCacheable;
163
164 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
165 // it has a key.
166 bool expectDeletingProxyToDeleteResource =
167 proxy->peekSurface()->resourcePriv().budgetedType() ==
168 GrBudgetedType::kUnbudgetedUncacheable;
169
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400170 // deleting the proxy should delete it from the hash but not the cache
171 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500172 if (expectDeletingProxyToDeleteResource) {
173 expectedCacheCount -= 1;
174 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500175 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400176 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400177
178 // If the proxy was cached refinding it should bring it back to life
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400179 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Greg Daniel303e83e2018-09-10 14:10:19 -0400180 REPORTER_ASSERT(reporter, proxy);
181 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
182 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400183
184 // Mega-purging it should remove it from both the hash and the cache
185 proxy = nullptr;
186 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500187 if (!expectResourceToOutliveProxy) {
188 expectedCacheCount--;
189 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400190 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400191
Brian Salomon9bc76d92019-01-24 12:18:33 -0500192 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
193 // be.
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400194 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500195 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400196 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500197
198 if (expectResourceToOutliveProxy) {
199 proxy.reset();
Robert Phillips9da87e02019-02-04 13:26:26 -0500200 GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500201 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
202 cache->purgeAsNeeded();
203 expectedCacheCount--;
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400204 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500205 REPORTER_ASSERT(reporter, !proxy);
206 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
207 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400208}
209
210///////////////////////////////////////////////////////////////////////////////////////////////////
211// Invalidation test
212
213// Test if invalidating unique ids operates as expected for texture proxies.
Adlai Holler4caa9352020-07-16 10:58:58 -0400214static void invalidation_test(GrDirectContext* direct, skiatest::Reporter* reporter) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400215
Adlai Holler4caa9352020-07-16 10:58:58 -0400216 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
217 GrResourceCache* cache = direct->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400218 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
219
220 sk_sp<SkImage> rasterImg;
221
222 {
223 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
224
225 SkBitmap bm;
226 bm.allocPixels(ii);
227
228 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500229 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400230 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
231 }
232
Greg Daniela58db7f2020-07-15 09:17:59 -0400233 // Some of our backends use buffers to do uploads that will live in our resource cache. So we
234 // need to account for those extra resources here.
235 int bufferResources = 0;
Greg Danielcffb0622020-07-16 13:19:17 -0400236 if (direct->backend() == GrBackendApi::kDawn || direct->backend() == GrBackendApi::kVulkan ||
237 direct->backend() == GrBackendApi::kDirect3D) {
Greg Daniela58db7f2020-07-15 09:17:59 -0400238 bufferResources = 1;
239 }
240
Adlai Holler4caa9352020-07-16 10:58:58 -0400241 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(direct);
Brian Salomonbc074a62020-03-18 10:06:13 -0400242 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400243 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400244
245 rasterImg = nullptr; // this invalidates the uniqueKey
246
247 // this forces the cache to respond to the inval msg
Adlai Holler4caa9352020-07-16 10:58:58 -0400248 size_t maxBytes = direct->getResourceCacheLimit();
249 direct->setResourceCacheLimit(maxBytes-1);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400250
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500251 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniela58db7f2020-07-15 09:17:59 -0400252 REPORTER_ASSERT(reporter, 1 + bufferResources == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400253
254 textureImg = nullptr;
Greg Daniela58db7f2020-07-15 09:17:59 -0400255
256 // For backends that use buffers to upload lets make sure that work has been submit and done
257 // before we try to purge all resources.
Adlai Holler4caa9352020-07-16 10:58:58 -0400258 direct->submit(true);
Greg Daniela58db7f2020-07-15 09:17:59 -0400259
260#ifdef SK_DAWN
261 // The forced cpu sync in dawn doesn't actually mean the async map will finish thus we may
262 // still have a ref on the GrGpuBuffer and it will not get purged by the call below. We dig
263 // deep into the dawn gpu to make sure we wait for the async map to finish.
Adlai Holler4caa9352020-07-16 10:58:58 -0400264 if (direct->backend() == GrBackendApi::kDawn) {
265 GrDawnGpu* gpu = static_cast<GrDawnGpu*>(direct->priv().getGpu());
Greg Daniela58db7f2020-07-15 09:17:59 -0400266 gpu->waitOnAllBusyStagingBuffers();
267 }
268#endif
269
Adlai Holler4caa9352020-07-16 10:58:58 -0400270 direct->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400271
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500272 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400273 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
274}
275
Brian Osman28c434b2017-09-27 13:11:16 -0400276// Test if invalidating unique ids prior to instantiating operates as expected
277static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500278 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
279 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
280 GrResourceCache* cache = context->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400281 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
282
283 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
284 GrUniqueKey key;
285 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
286 builder[0] = 0;
287 builder.finish();
288
289 // Create proxy, assign unique key
Greg Daniel4065d452018-11-16 15:43:41 -0500290 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider,
291 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500292 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400293
294 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400295 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillips9da87e02019-02-04 13:26:26 -0500296 GrUniqueKeyInvalidatedMessage(key, context->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400297
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500298 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400299 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
300
301 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
302 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500303 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400304
305 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400306 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500307 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400308 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
309
310 proxy = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500311 context->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400312
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, 0 == cache->getResourceCount());
315}
316
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400317DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
Adlai Holler4caa9352020-07-16 10:58:58 -0400318 auto direct = ctxInfo.directContext();
319 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
320 GrResourceCache* cache = direct->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400321
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500322 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400323 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
324
325 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400326 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400327 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Adlai Holler4caa9352020-07-16 10:58:58 -0400328 basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400329 }
330
331 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
332 sk_sp<GrTexture> backingTex;
Adlai Holler4caa9352020-07-16 10:58:58 -0400333 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(direct, fit, &backingTex);
334 basic_test(direct, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400335
336 backingTex = nullptr;
337 cache->purgeAllUnlocked();
338 }
339
Adlai Holler4caa9352020-07-16 10:58:58 -0400340 invalidation_test(direct, reporter);
341 invalidation_and_instantiation_test(direct, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400342}