blob: 1818051a84b9c593b5c95600deba6148a61f1fa6 [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"
13#include "include/gpu/GrTexture.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 Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrTextureProxy.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040019
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "include/core/SkImage.h"
21#include "src/gpu/SkGr.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040022
Robert Phillips1afd4cd2018-01-08 13:40:32 -050023int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040024 return fUniquelyKeyedProxies.count();
25}
26
Brian Salomon4eb38b72019-08-05 12:58:39 -040027static constexpr auto kColorType = GrColorType::kRGBA_8888;
28static constexpr auto kSize = SkISize::Make(64, 64);
Brian Salomonf2c2ba92019-07-17 09:59:59 -040029static GrSurfaceDesc make_desc() {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040030 GrSurfaceDesc desc;
Brian Salomon4eb38b72019-08-05 12:58:39 -040031 desc.fWidth = kSize.width();
32 desc.fHeight = kSize.height();
Robert Phillipsae7d3f32017-09-21 08:26:08 -040033 return desc;
34}
35
36///////////////////////////////////////////////////////////////////////////////////////////////////
37// Basic test
38
Greg Daniel4065d452018-11-16 15:43:41 -050039static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050040 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0a15cc62019-07-30 12:49:10 -040041 const GrCaps* caps = ctx->priv().caps();
42
Brian Salomonf2c2ba92019-07-17 09:59:59 -040043 const GrSurfaceDesc desc = make_desc();
Brian Salomon4eb38b72019-08-05 12:58:39 -040044 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
Greg Daniel47c20e82020-01-21 14:29:57 -050045 GrSwizzle swizzle = caps->getReadSwizzle(format, kColorType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040046
Brian Salomonbeb7f522019-08-30 16:19:42 -040047 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -050048 format, desc, swizzle, GrRenderable::kNo, 1, kBottomLeft_GrSurfaceOrigin,
49 GrMipMapped::kNo, fit, 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
Greg Daniel4065d452018-11-16 15:43:41 -050055static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050056 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0a15cc62019-07-30 12:49:10 -040057 const GrCaps* caps = ctx->priv().caps();
58
Brian Salomonf2c2ba92019-07-17 09:59:59 -040059 const GrSurfaceDesc desc = make_desc();
Robert Phillips0a15cc62019-07-30 12:49:10 -040060
Brian Salomon4eb38b72019-08-05 12:58:39 -040061 GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Greg Daniel47c20e82020-01-21 14:29:57 -050062 GrSwizzle swizzle = caps->getReadSwizzle(format, kColorType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040063
Brian Salomonbeb7f522019-08-30 16:19:42 -040064 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -050065 format, desc, swizzle, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
66 GrMipMapped::kNo, fit, 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
Greg Daniel4065d452018-11-16 15:43:41 -050072static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx,
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(
Brian Salomon4eb38b72019-08-05 12:58:39 -040075 kSize, kColorType, GrRenderable::kNo, 1, kBottomLeft_GrSurfaceOrigin, fit,
76 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050077 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040078 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
79 return proxy;
80}
81
Greg Daniel4065d452018-11-16 15:43:41 -050082static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050083 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Greg Danielcd871402017-09-26 12:49:26 -040084 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
85 static int kUniqueKeyData = 0;
86
87 GrUniqueKey key;
88
89 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
90 builder[0] = kUniqueKeyData++;
91 builder.finish();
92
Robert Phillipsadbe1322018-01-17 13:35:46 -050093 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Chris Daltond004e0b2018-09-27 09:28:03 -060094 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -040095 kSize, kColorType, GrRenderable::kNo, 1, kBottomLeft_GrSurfaceOrigin, fit,
96 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsadbe1322018-01-17 13:35:46 -050097 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -040098 REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
99 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400100}
101
102static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit,
103 sk_sp<GrTexture>* backingSurface) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500104 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
105 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400106
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400107 const GrSurfaceDesc desc = make_desc();
Brian Salomon4eb38b72019-08-05 12:58:39 -0400108 GrBackendFormat format =
109 proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400110
Brian Salomona90382f2019-09-17 09:01:56 -0400111 *backingSurface =
112 resourceProvider->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
113 SkBudgeted::kNo, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400114 if (!(*backingSurface)) {
115 return nullptr;
116 }
117
Robert Phillipsb67821d2017-12-13 15:00:45 -0500118 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400119
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400120 return proxyProvider->wrapBackendTexture(backendTex, GrColorType::kRGBA_8888,
121 kBottomLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership,
122 GrWrapCacheable::kYes, kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400123}
124
125
126// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
127// and looking them up work, etc.
128static void basic_test(GrContext* context,
129 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400130 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400131 static int id = 1;
132
Robert Phillips9da87e02019-02-04 13:26:26 -0500133 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
134 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
135 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400136
137 int startCacheCount = cache->getResourceCount();
138
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400139 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400140 if (proxy->getUniqueKey().isValid()) {
141 key = proxy->getUniqueKey();
142 } else {
143 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
144 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400145
Greg Danielcd871402017-09-26 12:49:26 -0400146 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500147 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500148 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400149 }
150
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500151 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400152 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
153
154 // setUniqueKey had better stick
155 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
156
157 // We just added it, surely we can find it
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500158 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(
Brian Salomon2af3e702019-08-11 19:10:31 -0400159 key, kColorType, kBottomLeft_GrSurfaceOrigin));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500160 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400161
Greg Daniel303e83e2018-09-10 14:10:19 -0400162 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
163
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400164 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500165 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500166 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400167 REPORTER_ASSERT(reporter, texKey.isValid());
168 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400169
Brian Salomon9bc76d92019-01-24 12:18:33 -0500170 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
171 // deleted.
172 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
173 GrBudgetedType::kUnbudgetedCacheable;
174
175 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
176 // it has a key.
177 bool expectDeletingProxyToDeleteResource =
178 proxy->peekSurface()->resourcePriv().budgetedType() ==
179 GrBudgetedType::kUnbudgetedUncacheable;
180
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400181 // deleting the proxy should delete it from the hash but not the cache
182 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500183 if (expectDeletingProxyToDeleteResource) {
184 expectedCacheCount -= 1;
185 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500186 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400187 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400188
189 // If the proxy was cached refinding it should bring it back to life
Brian Salomon2af3e702019-08-11 19:10:31 -0400190 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kColorType,
191 kBottomLeft_GrSurfaceOrigin);
Greg Daniel303e83e2018-09-10 14:10:19 -0400192 REPORTER_ASSERT(reporter, proxy);
193 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
194 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400195
196 // Mega-purging it should remove it from both the hash and the cache
197 proxy = nullptr;
198 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500199 if (!expectResourceToOutliveProxy) {
200 expectedCacheCount--;
201 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400202 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400203
Brian Salomon9bc76d92019-01-24 12:18:33 -0500204 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
205 // be.
Brian Salomon2af3e702019-08-11 19:10:31 -0400206 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kColorType,
207 kBottomLeft_GrSurfaceOrigin);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500208 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400209 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500210
211 if (expectResourceToOutliveProxy) {
212 proxy.reset();
Robert Phillips9da87e02019-02-04 13:26:26 -0500213 GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500214 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
215 cache->purgeAsNeeded();
216 expectedCacheCount--;
Brian Salomon2af3e702019-08-11 19:10:31 -0400217 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kColorType,
218 kBottomLeft_GrSurfaceOrigin);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500219 REPORTER_ASSERT(reporter, !proxy);
220 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
221 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400222}
223
224///////////////////////////////////////////////////////////////////////////////////////////////////
225// Invalidation test
226
227// Test if invalidating unique ids operates as expected for texture proxies.
228static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) {
229
Robert Phillips9da87e02019-02-04 13:26:26 -0500230 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
231 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400232 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
233
234 sk_sp<SkImage> rasterImg;
235
236 {
237 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
238
239 SkBitmap bm;
240 bm.allocPixels(ii);
241
242 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500243 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400244 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
245 }
246
Brian Osmand566e2e2019-08-14 13:19:04 -0400247 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500248 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400249 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
250
251 rasterImg = nullptr; // this invalidates the uniqueKey
252
253 // this forces the cache to respond to the inval msg
Robert Phillipscf39f372019-09-03 10:29:20 -0400254 size_t maxBytes = context->getResourceCacheLimit();
255 context->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());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400258 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
259
260 textureImg = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500261 context->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400262
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500263 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400264 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
265}
266
Brian Osman28c434b2017-09-27 13:11:16 -0400267// Test if invalidating unique ids prior to instantiating operates as expected
268static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500269 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
270 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
271 GrResourceCache* cache = context->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400272 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
273
274 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
275 GrUniqueKey key;
276 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
277 builder[0] = 0;
278 builder.finish();
279
280 // Create proxy, assign unique key
Greg Daniel4065d452018-11-16 15:43:41 -0500281 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider,
282 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500283 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400284
285 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400286 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillips9da87e02019-02-04 13:26:26 -0500287 GrUniqueKeyInvalidatedMessage(key, context->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400288
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500289 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400290 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
291
292 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
293 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500294 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400295
296 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400297 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500298 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400299 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
300
301 proxy = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500302 context->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400303
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500304 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400305 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
306}
307
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400308DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
309 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500310 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
311 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400312
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500313 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400314 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
315
316 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400317 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400318 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Greg Daniel4065d452018-11-16 15:43:41 -0500319 basic_test(context, reporter, create(reporter, context, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400320 }
321
322 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
323 sk_sp<GrTexture> backingTex;
324 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex);
Greg Daniel303e83e2018-09-10 14:10:19 -0400325 basic_test(context, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400326
327 backingTex = nullptr;
328 cache->purgeAllUnlocked();
329 }
330
331 invalidation_test(context, reporter);
Robert Phillipsfa8c0802017-10-04 08:42:28 -0400332 invalidation_and_instantiation_test(context, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400333}