blob: 9414c8987e7137d4f5116bd0056c57d43efd105e [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;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040032
33 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) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040041 const GrSurfaceDesc desc = make_desc();
Greg Daniel4065d452018-11-16 15:43:41 -050042 GrBackendFormat format =
Greg Daniel627d0532019-07-08 16:48:14 -040043 ctx->priv().caps()->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040044
Brian Salomon27b4d8d2019-07-22 14:23:45 -040045 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, GrRenderable::kNo, 1,
46 kBottomLeft_GrSurfaceOrigin, fit,
47 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040048 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040049 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
50 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040051}
52
Greg Daniel4065d452018-11-16 15:43:41 -050053static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050054 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040055 const GrSurfaceDesc desc = make_desc();
Greg Daniel4065d452018-11-16 15:43:41 -050056 GrBackendFormat format =
Greg Daniel627d0532019-07-08 16:48:14 -040057 ctx->priv().caps()->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040058
Brian Salomon27b4d8d2019-07-22 14:23:45 -040059 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, GrRenderable::kYes, 1,
Brian Salomone8a766b2019-07-19 14:24:36 -040060 kBottomLeft_GrSurfaceOrigin, fit,
61 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040062 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040063 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
64 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040065}
66
Greg Daniel4065d452018-11-16 15:43:41 -050067static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050068 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Brian Salomonf2c2ba92019-07-17 09:59:59 -040069 const GrSurfaceDesc desc = make_desc();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050070
Chris Daltond004e0b2018-09-27 09:28:03 -060071 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -040072 desc, GrRenderable::kNo, 1, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
Brian Salomone8a766b2019-07-19 14:24:36 -040073 GrProtected::kNo);
Robert Phillips0bd24dc2018-01-16 08:06:32 -050074 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040075 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
76 return proxy;
77}
78
Greg Daniel4065d452018-11-16 15:43:41 -050079static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050080 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Greg Danielcd871402017-09-26 12:49:26 -040081 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
82 static int kUniqueKeyData = 0;
83
84 GrUniqueKey key;
85
86 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
87 builder[0] = kUniqueKeyData++;
88 builder.finish();
89
Brian Salomonf2c2ba92019-07-17 09:59:59 -040090 const GrSurfaceDesc desc = make_desc();
Greg Danielcd871402017-09-26 12:49:26 -040091
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(
Brian Salomon27b4d8d2019-07-22 14:23:45 -040094 desc, GrRenderable::kNo, 1, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
Brian Salomone8a766b2019-07-19 14:24:36 -040095 GrProtected::kNo);
Robert Phillipsadbe1322018-01-17 13:35:46 -050096 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -040097 REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
98 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040099}
100
101static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit,
102 sk_sp<GrTexture>* backingSurface) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500103 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
104 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400105
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400106 const GrSurfaceDesc desc = make_desc();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400107
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400108 *backingSurface = resourceProvider->createTexture(desc, GrRenderable::kNo, 1, SkBudgeted::kNo,
Brian Salomone8a766b2019-07-19 14:24:36 -0400109 GrProtected::kNo,
Robert Phillips9313aa72019-04-09 18:41:27 -0400110 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400111 if (!(*backingSurface)) {
112 return nullptr;
113 }
114
Robert Phillipsb67821d2017-12-13 15:00:45 -0500115 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Greg Daniel108bb232018-07-03 16:18:29 -0400116 backendTex.setPixelConfig(desc.fConfig);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400117
Robert Phillipsdd399802019-07-18 12:28:00 +0000118 return proxyProvider->wrapBackendTexture(backendTex, kBottomLeft_GrSurfaceOrigin,
119 kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
120 kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400121}
122
123
124// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
125// and looking them up work, etc.
126static void basic_test(GrContext* context,
127 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400128 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400129 static int id = 1;
130
Robert Phillips9da87e02019-02-04 13:26:26 -0500131 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
132 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
133 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400134
135 int startCacheCount = cache->getResourceCount();
136
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400137 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400138 if (proxy->getUniqueKey().isValid()) {
139 key = proxy->getUniqueKey();
140 } else {
141 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
142 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400143
Greg Danielcd871402017-09-26 12:49:26 -0400144 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500145 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500146 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400147 }
148
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500149 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400150 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
151
152 // setUniqueKey had better stick
153 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
154
155 // We just added it, surely we can find it
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500156 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(
157 key, kBottomLeft_GrSurfaceOrigin));
158 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400159
Greg Daniel303e83e2018-09-10 14:10:19 -0400160 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
161
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400162 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500163 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500164 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400165 REPORTER_ASSERT(reporter, texKey.isValid());
166 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400167
Brian Salomon9bc76d92019-01-24 12:18:33 -0500168 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
169 // deleted.
170 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
171 GrBudgetedType::kUnbudgetedCacheable;
172
173 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
174 // it has a key.
175 bool expectDeletingProxyToDeleteResource =
176 proxy->peekSurface()->resourcePriv().budgetedType() ==
177 GrBudgetedType::kUnbudgetedUncacheable;
178
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400179 // deleting the proxy should delete it from the hash but not the cache
180 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500181 if (expectDeletingProxyToDeleteResource) {
182 expectedCacheCount -= 1;
183 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500184 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400185 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400186
187 // If the proxy was cached refinding it should bring it back to life
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500188 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Greg Daniel303e83e2018-09-10 14:10:19 -0400189 REPORTER_ASSERT(reporter, proxy);
190 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
191 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400192
193 // Mega-purging it should remove it from both the hash and the cache
194 proxy = nullptr;
195 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500196 if (!expectResourceToOutliveProxy) {
197 expectedCacheCount--;
198 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400199 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400200
Brian Salomon9bc76d92019-01-24 12:18:33 -0500201 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
202 // be.
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500203 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500204 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400205 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500206
207 if (expectResourceToOutliveProxy) {
208 proxy.reset();
Robert Phillips9da87e02019-02-04 13:26:26 -0500209 GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500210 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
211 cache->purgeAsNeeded();
212 expectedCacheCount--;
213 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
214 REPORTER_ASSERT(reporter, !proxy);
215 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
216 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400217}
218
219///////////////////////////////////////////////////////////////////////////////////////////////////
220// Invalidation test
221
222// Test if invalidating unique ids operates as expected for texture proxies.
223static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) {
224
Robert Phillips9da87e02019-02-04 13:26:26 -0500225 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
226 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400227 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
228
229 sk_sp<SkImage> rasterImg;
230
231 {
232 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
233
234 SkBitmap bm;
235 bm.allocPixels(ii);
236
237 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500238 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400239 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
240 }
241
242 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context, nullptr);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500243 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400244 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
245
246 rasterImg = nullptr; // this invalidates the uniqueKey
247
248 // this forces the cache to respond to the inval msg
249 int maxNum;
250 size_t maxBytes;
251 context->getResourceCacheLimits(&maxNum, &maxBytes);
252 context->setResourceCacheLimits(maxNum-1, maxBytes);
253
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500254 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400255 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
256
257 textureImg = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500258 context->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400259
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500260 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400261 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
262}
263
Brian Osman28c434b2017-09-27 13:11:16 -0400264// Test if invalidating unique ids prior to instantiating operates as expected
265static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500266 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
267 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
268 GrResourceCache* cache = context->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400269 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
270
271 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
272 GrUniqueKey key;
273 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
274 builder[0] = 0;
275 builder.finish();
276
277 // Create proxy, assign unique key
Greg Daniel4065d452018-11-16 15:43:41 -0500278 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider,
279 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500280 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400281
282 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400283 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillips9da87e02019-02-04 13:26:26 -0500284 GrUniqueKeyInvalidatedMessage(key, context->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400285
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500286 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400287 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
288
289 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
290 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500291 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400292
293 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400294 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500295 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400296 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
297
298 proxy = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500299 context->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400300
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500301 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400302 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
303}
304
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400305DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
306 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500307 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
308 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400309
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500310 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400311 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
312
313 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400314 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400315 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Greg Daniel4065d452018-11-16 15:43:41 -0500316 basic_test(context, reporter, create(reporter, context, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400317 }
318
319 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
320 sk_sp<GrTexture> backingTex;
321 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex);
Greg Daniel303e83e2018-09-10 14:10:19 -0400322 basic_test(context, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400323
324 backingTex = nullptr;
325 cache->purgeAllUnlocked();
326 }
327
328 invalidation_test(context, reporter);
Robert Phillipsfa8c0802017-10-04 08:42:28 -0400329 invalidation_and_instantiation_test(context, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400330}