blob: 11e4f295c3c9fe1ff4584cf38c226d7eff93ef58 [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
10#include "Test.h"
11
Robert Phillipsae7d3f32017-09-21 08:26:08 -040012#include "GrBackendSurface.h"
13#include "GrContextPriv.h"
14#include "GrResourceCache.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050015#include "GrProxyProvider.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040016#include "GrResourceProvider.h"
Robert Phillipsae7d3f32017-09-21 08:26:08 -040017#include "GrTexture.h"
18#include "GrTextureProxy.h"
19
20#include "SkGr.h"
21#include "SkImage.h"
22
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
Robert Phillipsfe0253f2018-03-16 16:47:25 -040027static GrSurfaceDesc make_desc(GrSurfaceDescFlags descFlags) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -040028 GrSurfaceDesc desc;
Robert Phillipsfe0253f2018-03-16 16:47:25 -040029 desc.fFlags = descFlags;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040030 desc.fWidth = 64;
31 desc.fHeight = 64;
32 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomonbdecacf2018-02-02 20:32:49 -050033 desc.fSampleCnt = 1;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040034
35 return desc;
36}
37
38///////////////////////////////////////////////////////////////////////////////////////////////////
39// Basic test
40
Greg Daniel4065d452018-11-16 15:43:41 -050041static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050042 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050043 const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
Greg Daniel4065d452018-11-16 15:43:41 -050044 GrBackendFormat format =
Robert Phillips9da87e02019-02-04 13:26:26 -050045 ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040046
Brian Salomon2a4f9832018-03-03 22:43:43 -050047 sk_sp<GrTextureProxy> proxy =
Greg Daniel4065d452018-11-16 15:43:41 -050048 proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin, fit,
Robert Phillips7eeb74f2019-03-29 07:26:46 -040049 SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
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 Phillips0bd24dc2018-01-16 08:06:32 -050057 const GrSurfaceDesc desc = make_desc(kRenderTarget_GrSurfaceFlag);
Greg Daniel4065d452018-11-16 15:43:41 -050058 GrBackendFormat format =
Robert Phillips9da87e02019-02-04 13:26:26 -050059 ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040060
Brian Salomon2a4f9832018-03-03 22:43:43 -050061 sk_sp<GrTextureProxy> proxy =
Robert Phillips7eeb74f2019-03-29 07:26:46 -040062 proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin, fit,
63 SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
Robert Phillipsae7d3f32017-09-21 08:26:08 -040064 // Only budgeted & wrapped external proxies get to carry uniqueKeys
Greg Danielcd871402017-09-26 12:49:26 -040065 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
66 return proxy;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040067}
68
Greg Daniel4065d452018-11-16 15:43:41 -050069static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrContext* ctx,
Robert Phillipsadbe1322018-01-17 13:35:46 -050070 GrProxyProvider* proxyProvider, SkBackingFit fit) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -050071 const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
Robert Phillips1afd4cd2018-01-08 13:40:32 -050072
Chris Daltond004e0b2018-09-27 09:28:03 -060073 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomon2a4f9832018-03-03 22:43:43 -050074 desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes);
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
Robert Phillips0bd24dc2018-01-16 08:06:32 -050091 const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
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(
Robert Phillipsfe0253f2018-03-16 16:47:25 -040095 desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes);
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
Robert Phillipsb67821d2017-12-13 15:00:45 -0500106 const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400107
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500108 *backingSurface = resourceProvider->createTexture(desc, SkBudgeted::kNo);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400109 if (!(*backingSurface)) {
110 return nullptr;
111 }
112
Robert Phillipsb67821d2017-12-13 15:00:45 -0500113 GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
Greg Daniel108bb232018-07-03 16:18:29 -0400114 backendTex.setPixelConfig(desc.fConfig);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400115
Brian Salomonc67c31c2018-12-06 10:00:03 -0500116 return proxyProvider->wrapBackendTexture(backendTex, kBottomLeft_GrSurfaceOrigin,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500117 kBorrow_GrWrapOwnership, GrWrapCacheable::kYes,
118 kRead_GrIOType);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400119}
120
121
122// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
123// and looking them up work, etc.
124static void basic_test(GrContext* context,
125 skiatest::Reporter* reporter,
Greg Daniel303e83e2018-09-10 14:10:19 -0400126 sk_sp<GrTextureProxy> proxy) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400127 static int id = 1;
128
Robert Phillips9da87e02019-02-04 13:26:26 -0500129 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
130 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
131 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400132
133 int startCacheCount = cache->getResourceCount();
134
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400135 GrUniqueKey key;
Greg Danielcd871402017-09-26 12:49:26 -0400136 if (proxy->getUniqueKey().isValid()) {
137 key = proxy->getUniqueKey();
138 } else {
139 GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
140 ++id;
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400141
Greg Danielcd871402017-09-26 12:49:26 -0400142 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500143 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsadbe1322018-01-17 13:35:46 -0500144 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Greg Danielcd871402017-09-26 12:49:26 -0400145 }
146
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500147 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400148 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
149
150 // setUniqueKey had better stick
151 REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
152
153 // We just added it, surely we can find it
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500154 REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(
155 key, kBottomLeft_GrSurfaceOrigin));
156 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400157
Greg Daniel303e83e2018-09-10 14:10:19 -0400158 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : 1);
159
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400160 // Once instantiated, the backing resource should have the same key
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500161 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Salomon9bc76d92019-01-24 12:18:33 -0500162 const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400163 REPORTER_ASSERT(reporter, texKey.isValid());
164 REPORTER_ASSERT(reporter, key == texKey);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400165
Brian Salomon9bc76d92019-01-24 12:18:33 -0500166 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
167 // deleted.
168 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
169 GrBudgetedType::kUnbudgetedCacheable;
170
171 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
172 // it has a key.
173 bool expectDeletingProxyToDeleteResource =
174 proxy->peekSurface()->resourcePriv().budgetedType() ==
175 GrBudgetedType::kUnbudgetedUncacheable;
176
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400177 // deleting the proxy should delete it from the hash but not the cache
178 proxy = nullptr;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500179 if (expectDeletingProxyToDeleteResource) {
180 expectedCacheCount -= 1;
181 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500182 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Greg Daniel303e83e2018-09-10 14:10:19 -0400183 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400184
185 // If the proxy was cached refinding it should bring it back to life
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500186 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Greg Daniel303e83e2018-09-10 14:10:19 -0400187 REPORTER_ASSERT(reporter, proxy);
188 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
189 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400190
191 // Mega-purging it should remove it from both the hash and the cache
192 proxy = nullptr;
193 cache->purgeAllUnlocked();
Brian Salomon9bc76d92019-01-24 12:18:33 -0500194 if (!expectResourceToOutliveProxy) {
195 expectedCacheCount--;
196 }
Greg Daniel303e83e2018-09-10 14:10:19 -0400197 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400198
Brian Salomon9bc76d92019-01-24 12:18:33 -0500199 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
200 // be.
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500201 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
Brian Salomon9bc76d92019-01-24 12:18:33 -0500202 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
Greg Daniel303e83e2018-09-10 14:10:19 -0400203 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500204
205 if (expectResourceToOutliveProxy) {
206 proxy.reset();
Robert Phillips9da87e02019-02-04 13:26:26 -0500207 GrUniqueKeyInvalidatedMessage msg(texKey, context->priv().contextID());
Brian Salomon9bc76d92019-01-24 12:18:33 -0500208 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg);
209 cache->purgeAsNeeded();
210 expectedCacheCount--;
211 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
212 REPORTER_ASSERT(reporter, !proxy);
213 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
214 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400215}
216
217///////////////////////////////////////////////////////////////////////////////////////////////////
218// Invalidation test
219
220// Test if invalidating unique ids operates as expected for texture proxies.
221static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) {
222
Robert Phillips9da87e02019-02-04 13:26:26 -0500223 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
224 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400225 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
226
227 sk_sp<SkImage> rasterImg;
228
229 {
230 SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
231
232 SkBitmap bm;
233 bm.allocPixels(ii);
234
235 rasterImg = SkImage::MakeFromBitmap(bm);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500236 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400237 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
238 }
239
240 sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context, nullptr);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500241 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400242 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
243
244 rasterImg = nullptr; // this invalidates the uniqueKey
245
246 // this forces the cache to respond to the inval msg
247 int maxNum;
248 size_t maxBytes;
249 context->getResourceCacheLimits(&maxNum, &maxBytes);
250 context->setResourceCacheLimits(maxNum-1, maxBytes);
251
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500252 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400253 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
254
255 textureImg = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500256 context->priv().testingOnly_purgeAllUnlockedResources();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400257
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500258 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400259 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
260}
261
Brian Osman28c434b2017-09-27 13:11:16 -0400262// Test if invalidating unique ids prior to instantiating operates as expected
263static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500264 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
265 GrResourceProvider* resourceProvider = context->priv().resourceProvider();
266 GrResourceCache* cache = context->priv().getResourceCache();
Brian Osman28c434b2017-09-27 13:11:16 -0400267 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
268
269 static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
270 GrUniqueKey key;
271 GrUniqueKey::Builder builder(&key, d, 1, nullptr);
272 builder[0] = 0;
273 builder.finish();
274
275 // Create proxy, assign unique key
Greg Daniel4065d452018-11-16 15:43:41 -0500276 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider,
277 SkBackingFit::kExact);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500278 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
Brian Osman28c434b2017-09-27 13:11:16 -0400279
280 // Send an invalidation message, which will be sitting in the cache's inbox
Brian Salomon238069b2018-07-11 15:58:57 -0400281 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
Robert Phillips9da87e02019-02-04 13:26:26 -0500282 GrUniqueKeyInvalidatedMessage(key, context->priv().contextID()));
Brian Osman28c434b2017-09-27 13:11:16 -0400283
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500284 REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400285 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
286
287 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
288 // texture should *not* have the unique key on it!
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500289 SkAssertResult(proxy->instantiate(resourceProvider));
Brian Osman28c434b2017-09-27 13:11:16 -0400290
291 REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400292 REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500293 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400294 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
295
296 proxy = nullptr;
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500297 context->priv().testingOnly_purgeAllUnlockedResources();
Brian Osman28c434b2017-09-27 13:11:16 -0400298
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500299 REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
Brian Osman28c434b2017-09-27 13:11:16 -0400300 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
301}
302
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400303DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
304 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500305 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
306 GrResourceCache* cache = context->priv().getResourceCache();
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400307
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500308 REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400309 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
310
311 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
Greg Danielcd871402017-09-26 12:49:26 -0400312 for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400313 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
Greg Daniel4065d452018-11-16 15:43:41 -0500314 basic_test(context, reporter, create(reporter, context, proxyProvider, fit));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400315 }
316
317 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
318 sk_sp<GrTexture> backingTex;
319 sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex);
Greg Daniel303e83e2018-09-10 14:10:19 -0400320 basic_test(context, reporter, std::move(proxy));
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400321
322 backingTex = nullptr;
323 cache->purgeAllUnlocked();
324 }
325
326 invalidation_test(context, reporter);
Robert Phillipsfa8c0802017-10-04 08:42:28 -0400327 invalidation_and_instantiation_test(context, reporter);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400328}