blob: c241e22700a6fca87869990b8df986ed56c535c2 [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 Salomonf2c2ba92019-07-17 09:59:59 -040027static GrSurfaceDesc make_desc() {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040028 GrSurfaceDesc desc;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040029 desc.fWidth = 64;
30 desc.fHeight = 64;
31 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -050032 desc.fSampleCnt = 1;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040033
34 return desc;
35}
36
37///////////////////////////////////////////////////////////////////////////////////////////////////
38// Basic test
39
Greg Daniel4065d452018-11-16 15:43:41 -050040static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050041 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040042 const GrSurfaceDesc desc = make_desc();
Greg Daniel4065d452018-11-16 15:43:41 -050043 GrBackendFormat format =
Greg Daniel627d0532019-07-08 16:48:14 -040044 ctx->priv().caps()->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040045
Brian Salomone8a766b2019-07-19 14:24:36 -040046 sk_sp<GrTextureProxy> proxy =
47 proxyProvider->createProxy(format, desc, GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin,
48 fit, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040049 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040050 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
51 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040052}
53
Greg Daniel4065d452018-11-16 15:43:41 -050054static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050055 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040056 const GrSurfaceDesc desc = make_desc();
Greg Daniel4065d452018-11-16 15:43:41 -050057 GrBackendFormat format =
Greg Daniel627d0532019-07-08 16:48:14 -040058 ctx->priv().caps()->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040059
Brian Salomone8a766b2019-07-19 14:24:36 -040060 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, GrRenderable::kYes,
61 kBottomLeft_GrSurfaceOrigin, fit,
62 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040063 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040064 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
65 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040066}
67
Greg Daniel4065d452018-11-16 15:43:41 -050068static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050069 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040070 const GrSurfaceDesc desc = make_desc();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050071
Chris Daltond004e0b2018-09-27 09:28:03 -060072 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomone8a766b2019-07-19 14:24:36 -040073 desc, GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
74 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
Greg Daniel4065d452018-11-16 15:43:41 -050080static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrContext* ctx,
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
Brian Salomonf2c2ba92019-07-17 09:59:59 -040091 const GrSurfaceDesc desc = make_desc();
Greg Danielcd871402017-09-26 12:49:26 -040092
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 Salomone8a766b2019-07-19 14:24:36 -040095 desc, GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
96 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();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400108
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400109 *backingSurface = resourceProvider->createTexture(desc, GrRenderable::kNo, SkBudgeted::kNo,
Brian Salomone8a766b2019-07-19 14:24:36 -0400110 GrProtected::kNo,
Robert Phillips9313aa72019-04-09 18:41:27 -0400111 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400112 if (!(*backingSurface)) {
113 return nullptr;
114 }
115
Robert Phillipsb67821d2017-12-13 15:00:45 -0500116 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Greg Daniel108bb232018-07-03 16:18:29 -0400117 backendTex.setPixelConfig(desc.fConfig);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400118
Robert Phillipsdd399802019-07-18 12:28:00 +0000119 return proxyProvider->wrapBackendTexture(backendTex, kBottomLeft_GrSurfaceOrigin,
120 kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
121 kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400122}
123
124
125// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
126// and looking them up work, etc.
127static void basic_test(GrContext* context,
128 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400129 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400130 static int id = 1;
131
Robert Phillips9da87e02019-02-04 13:26:26 -0500132 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
133 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
134 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400135
136 int startCacheCount = cache->getResourceCount();
137
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400138 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400139 if (proxy->getUniqueKey().isValid()) {
140 key = proxy->getUniqueKey();
141 } else {
142 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
143 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400144
Greg Danielcd871402017-09-26 12:49:26 -0400145 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500146 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500147 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400148 }
149
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500150 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400151 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
152
153 // setUniqueKey had better stick
154 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
155
156 // We just added it, surely we can find it
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500157 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(
158 key, kBottomLeft_GrSurfaceOrigin));
159 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400160
Greg Daniel303e83e2018-09-10 14:10:19 -0400161 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
162
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400163 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500164 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500165 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400166 REPORTER_ASSERT(reporter, texKey.isValid());
167 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400168
Brian Salomon9bc76d92019-01-24 12:18:33 -0500169 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
170 // deleted.
171 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
172 GrBudgetedType::kUnbudgetedCacheable;
173
174 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
175 // it has a key.
176 bool expectDeletingProxyToDeleteResource =
177 proxy->peekSurface()->resourcePriv().budgetedType() ==
178 GrBudgetedType::kUnbudgetedUncacheable;
179
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400180 // deleting the proxy should delete it from the hash but not the cache
181 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500182 if (expectDeletingProxyToDeleteResource) {
183 expectedCacheCount -= 1;
184 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500185 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400186 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400187
188 // If the proxy was cached refinding it should bring it back to life
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500189 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Greg Daniel303e83e2018-09-10 14:10:19 -0400190 REPORTER_ASSERT(reporter, proxy);
191 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
192 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400193
194 // Mega-purging it should remove it from both the hash and the cache
195 proxy = nullptr;
196 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500197 if (!expectResourceToOutliveProxy) {
198 expectedCacheCount--;
199 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400200 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400201
Brian Salomon9bc76d92019-01-24 12:18:33 -0500202 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
203 // be.
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500204 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500205 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400206 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500207
208 if (expectResourceToOutliveProxy) {
209 proxy.reset();
Robert Phillips9da87e02019-02-04 13:26:26 -0500210 GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500211 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
212 cache->purgeAsNeeded();
213 expectedCacheCount--;
214 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
215 REPORTER_ASSERT(reporter, !proxy);
216 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
217 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400218}
219
220///////////////////////////////////////////////////////////////////////////////////////////////////
221// Invalidation test
222
223// Test if invalidating unique ids operates as expected for texture proxies.
224static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) {
225
Robert Phillips9da87e02019-02-04 13:26:26 -0500226 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
227 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400228 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
229
230 sk_sp<SkImage> rasterImg;
231
232 {
233 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
234
235 SkBitmap bm;
236 bm.allocPixels(ii);
237
238 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500239 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400240 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
241 }
242
243 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context, nullptr);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500244 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400245 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
246
247 rasterImg = nullptr; // this invalidates the uniqueKey
248
249 // this forces the cache to respond to the inval msg
250 int maxNum;
251 size_t maxBytes;
252 context->getResourceCacheLimits(&maxNum, &maxBytes);
253 context->setResourceCacheLimits(maxNum-1, maxBytes);
254
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500255 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400256 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
257
258 textureImg = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500259 context->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400260
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500261 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400262 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
263}
264
Brian Osman28c434b2017-09-27 13:11:16 -0400265// Test if invalidating unique ids prior to instantiating operates as expected
266static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500267 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
268 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
269 GrResourceCache* cache = context->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400270 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
271
272 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
273 GrUniqueKey key;
274 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
275 builder[0] = 0;
276 builder.finish();
277
278 // Create proxy, assign unique key
Greg Daniel4065d452018-11-16 15:43:41 -0500279 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider,
280 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500281 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400282
283 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400284 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillips9da87e02019-02-04 13:26:26 -0500285 GrUniqueKeyInvalidatedMessage(key, context->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400286
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500287 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400288 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
289
290 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
291 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500292 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400293
294 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400295 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500296 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400297 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
298
299 proxy = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500300 context->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400301
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500302 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400303 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
304}
305
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400306DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
307 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500308 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
309 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400310
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500311 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400312 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
313
314 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400315 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400316 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Greg Daniel4065d452018-11-16 15:43:41 -0500317 basic_test(context, reporter, create(reporter, context, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400318 }
319
320 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
321 sk_sp<GrTexture> backingTex;
322 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex);
Greg Daniel303e83e2018-09-10 14:10:19 -0400323 basic_test(context, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400324
325 backingTex = nullptr;
326 cache->purgeAllUnlocked();
327 }
328
329 invalidation_test(context, reporter);
Robert Phillipsfa8c0802017-10-04 08:42:28 -0400330 invalidation_and_instantiation_test(context, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400331}