blob: 683d84c734dbe39ce8f0a7a0de856f0aef397385 [file] [log] [blame]
Robert Phillips1afd4cd2018-01-08 13:40:32 -05001/*
2 * Copyright 2018 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrProxyProvider.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkBitmap.h"
11#include "include/core/SkImage.h"
12#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/gpu/GrTexture.h"
14#include "include/private/GrImageContext.h"
15#include "include/private/GrResourceKey.h"
16#include "include/private/GrSingleOwner.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/private/SkImageInfoPriv.h"
18#include "src/core/SkAutoPixmapStorage.h"
19#include "src/core/SkImagePriv.h"
20#include "src/core/SkMipMap.h"
21#include "src/core/SkTraceEvent.h"
22#include "src/gpu/GrCaps.h"
23#include "src/gpu/GrContextPriv.h"
24#include "src/gpu/GrImageContextPriv.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040025#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "src/gpu/GrResourceProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040027#include "src/gpu/GrSurfaceProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "src/gpu/GrSurfaceProxyPriv.h"
29#include "src/gpu/GrTextureProxyCacheAccess.h"
30#include "src/gpu/GrTextureRenderTargetProxy.h"
31#include "src/gpu/SkGr.h"
32#include "src/image/SkImage_Base.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050033
34#define ASSERT_SINGLE_OWNER \
Robert Phillipsa41c6852019-02-07 10:44:10 -050035 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fImageContext->priv().singleOwner());)
Robert Phillips1afd4cd2018-01-08 13:40:32 -050036
Robert Phillipsa9162df2019-02-11 14:12:03 -050037GrProxyProvider::GrProxyProvider(GrImageContext* imageContext) : fImageContext(imageContext) {}
Robert Phillips1afd4cd2018-01-08 13:40:32 -050038
39GrProxyProvider::~GrProxyProvider() {
Robert Phillipsa41c6852019-02-07 10:44:10 -050040 if (this->renderingDirectly()) {
Robert Phillips0790f8a2018-09-18 13:11:03 -040041 // In DDL-mode a proxy provider can still have extant uniquely keyed proxies (since
42 // they need their unique keys to, potentially, find a cached resource when the
43 // DDL is played) but, in non-DDL-mode they should all have been cleaned up by this point.
44 SkASSERT(!fUniquelyKeyedProxies.count());
45 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -050046}
47
Robert Phillipsadbe1322018-01-17 13:35:46 -050048bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -050049 ASSERT_SINGLE_OWNER
50 SkASSERT(key.isValid());
51 if (this->isAbandoned() || !proxy) {
Robert Phillipsadbe1322018-01-17 13:35:46 -050052 return false;
Robert Phillips1afd4cd2018-01-08 13:40:32 -050053 }
54
Robert Phillipsa41c6852019-02-07 10:44:10 -050055#ifdef SK_DEBUG
56 {
57 GrContext* direct = fImageContext->priv().asDirectContext();
58 if (direct) {
59 GrResourceCache* resourceCache = direct->priv().getResourceCache();
60 // If there is already a GrResource with this key then the caller has violated the
61 // normal usage pattern of uniquely keyed resources (e.g., they have created one w/o
62 // first seeing if it already existed in the cache).
63 SkASSERT(!resourceCache->findAndRefUniqueResource(key));
64 }
65 }
66#endif
Robert Phillips1afd4cd2018-01-08 13:40:32 -050067
Robert Phillips1afd4cd2018-01-08 13:40:32 -050068 SkASSERT(!fUniquelyKeyedProxies.find(key)); // multiple proxies can't get the same key
69
70 proxy->cacheAccess().setUniqueKey(this, key);
71 SkASSERT(proxy->getUniqueKey() == key);
72 fUniquelyKeyedProxies.add(proxy);
Robert Phillipsadbe1322018-01-17 13:35:46 -050073 return true;
Robert Phillips1afd4cd2018-01-08 13:40:32 -050074}
75
76void GrProxyProvider::adoptUniqueKeyFromSurface(GrTextureProxy* proxy, const GrSurface* surf) {
77 SkASSERT(surf->getUniqueKey().isValid());
78 proxy->cacheAccess().setUniqueKey(this, surf->getUniqueKey());
79 SkASSERT(proxy->getUniqueKey() == surf->getUniqueKey());
80 // multiple proxies can't get the same key
81 SkASSERT(!fUniquelyKeyedProxies.find(surf->getUniqueKey()));
82 fUniquelyKeyedProxies.add(proxy);
83}
84
Chris Dalton2de13dd2019-01-03 15:11:59 -070085void GrProxyProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -050086 ASSERT_SINGLE_OWNER
Chris Dalton2de13dd2019-01-03 15:11:59 -070087 SkASSERT(proxy);
88 SkASSERT(proxy->getUniqueKey().isValid());
89
90 if (this->isAbandoned()) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -050091 return;
92 }
Robert Phillips0790f8a2018-09-18 13:11:03 -040093
Chris Dalton2de13dd2019-01-03 15:11:59 -070094 this->processInvalidUniqueKey(proxy->getUniqueKey(), proxy, InvalidateGPUResource::kYes);
Robert Phillips1afd4cd2018-01-08 13:40:32 -050095}
96
97sk_sp<GrTextureProxy> GrProxyProvider::findProxyByUniqueKey(const GrUniqueKey& key,
98 GrSurfaceOrigin origin) {
99 ASSERT_SINGLE_OWNER
100
101 if (this->isAbandoned()) {
102 return nullptr;
103 }
104
Brian Salomon01ceae92019-04-02 11:49:54 -0400105 GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key);
Brian Salomon01ceae92019-04-02 11:49:54 -0400106 if (proxy) {
Robert Phillipse5f73282019-06-18 17:15:04 -0400107 SkASSERT(proxy->getProxyRefCnt() >= 1);
108 SkASSERT(proxy->origin() == origin);
109 return sk_ref_sp(proxy);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500110 }
Robert Phillipse5f73282019-06-18 17:15:04 -0400111 return nullptr;
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500112}
113
Robert Phillipsa41c6852019-02-07 10:44:10 -0500114///////////////////////////////////////////////////////////////////////////////
115
116#if GR_TEST_UTILS
117sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400118 const SkISize& size,
119 GrColorType colorType,
120 const GrBackendFormat& format,
121 GrRenderable renderable,
122 int renderTargetSampleCnt,
123 GrSurfaceOrigin origin,
124 SkBackingFit fit,
125 SkBudgeted budgeted,
126 GrProtected isProtected) {
Robert Phillipsa41c6852019-02-07 10:44:10 -0500127 GrContext* direct = fImageContext->priv().asDirectContext();
128 if (!direct) {
129 return nullptr;
130 }
131
Brian Salomon4eb38b72019-08-05 12:58:39 -0400132 if (this->caps()->isFormatCompressed(format)) {
133 // TODO: Allow this to go to GrResourceProvider::createCompressedTexture() once we no longer
134 // rely on GrColorType to get to GrPixelConfig. Currently this will cause
135 // makeConfigSpecific() to assert because GrColorTypeToPixelConfig() never returns a
136 // compressed GrPixelConfig.
137 return nullptr;
138 }
139 GrSurfaceDesc desc;
140 desc.fConfig = GrColorTypeToPixelConfig(colorType);
141 desc.fConfig = this->caps()->makeConfigSpecific(desc.fConfig, format);
142 desc.fWidth = size.width();
143 desc.fHeight = size.height();
144
Robert Phillipsa41c6852019-02-07 10:44:10 -0500145 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
146 sk_sp<GrTexture> tex;
147
148 if (SkBackingFit::kApprox == fit) {
Brian Salomon4eb38b72019-08-05 12:58:39 -0400149 tex = resourceProvider->createApproxTexture(desc, format, renderable, renderTargetSampleCnt,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400150 isProtected,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400151 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillipsa41c6852019-02-07 10:44:10 -0500152 } else {
Brian Salomon4eb38b72019-08-05 12:58:39 -0400153 tex = resourceProvider->createTexture(desc, format, renderable, renderTargetSampleCnt,
154 budgeted, isProtected,
155 GrResourceProvider::Flags::kNoPendingIO);
Robert Phillipsa41c6852019-02-07 10:44:10 -0500156 }
157 if (!tex) {
158 return nullptr;
159 }
160
Brian Salomon2af3e702019-08-11 19:10:31 -0400161 return this->createWrapped(std::move(tex), colorType, origin);
Robert Phillipsa41c6852019-02-07 10:44:10 -0500162}
163
Brian Salomon4eb38b72019-08-05 12:58:39 -0400164sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy(
165 const SkISize& size,
166 GrColorType colorType,
167 GrRenderable renderable,
168 int renderTargetSampleCnt,
169 GrSurfaceOrigin origin,
170 SkBackingFit fit,
171 SkBudgeted budgeted,
172 GrProtected isProtected) {
173 auto format = this->caps()->getDefaultBackendFormat(colorType, renderable);
174 return this->testingOnly_createInstantiatedProxy(size,
175 colorType,
176 format,
177 renderable,
178 renderTargetSampleCnt,
179 origin,
180 fit,
181 budgeted,
182 isProtected);
183}
184
Robert Phillipsa41c6852019-02-07 10:44:10 -0500185sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createWrapped(sk_sp<GrTexture> tex,
Brian Salomon2af3e702019-08-11 19:10:31 -0400186 GrColorType colorType,
Robert Phillipsa41c6852019-02-07 10:44:10 -0500187 GrSurfaceOrigin origin) {
Brian Salomon2af3e702019-08-11 19:10:31 -0400188 return this->createWrapped(std::move(tex), colorType, origin);
Robert Phillipsa41c6852019-02-07 10:44:10 -0500189}
190#endif
191
Brian Salomon2af3e702019-08-11 19:10:31 -0400192sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex, GrColorType colorType,
193 GrSurfaceOrigin origin) {
Robert Phillipsadbe1322018-01-17 13:35:46 -0500194#ifdef SK_DEBUG
195 if (tex->getUniqueKey().isValid()) {
196 SkASSERT(!this->findProxyByUniqueKey(tex->getUniqueKey(), origin));
197 }
198#endif
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400199 GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500200
201 if (tex->asRenderTarget()) {
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400202 GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(tex->backendFormat(), colorType);
203 return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin,
204 texSwizzle, outSwizzle));
Robert Phillipsadbe1322018-01-17 13:35:46 -0500205 } else {
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400206 return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
Robert Phillipsadbe1322018-01-17 13:35:46 -0500207 }
208}
209
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500210sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key,
Brian Salomon2af3e702019-08-11 19:10:31 -0400211 GrColorType colorType,
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500212 GrSurfaceOrigin origin) {
213 ASSERT_SINGLE_OWNER
214
215 if (this->isAbandoned()) {
216 return nullptr;
217 }
218
219 sk_sp<GrTextureProxy> result = this->findProxyByUniqueKey(key, origin);
220 if (result) {
221 return result;
222 }
223
Robert Phillipsa41c6852019-02-07 10:44:10 -0500224 GrContext* direct = fImageContext->priv().asDirectContext();
225 if (!direct) {
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -0500226 return nullptr;
227 }
228
Robert Phillipsa41c6852019-02-07 10:44:10 -0500229 GrResourceCache* resourceCache = direct->priv().getResourceCache();
230
231 GrGpuResource* resource = resourceCache->findAndRefUniqueResource(key);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500232 if (!resource) {
233 return nullptr;
234 }
235
236 sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture());
237 SkASSERT(texture);
238
Brian Salomon2af3e702019-08-11 19:10:31 -0400239 result = this->createWrapped(std::move(texture), colorType, origin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500240 SkASSERT(result->getUniqueKey() == key);
Robert Phillipsadbe1322018-01-17 13:35:46 -0500241 // createWrapped should've added this for us
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500242 SkASSERT(fUniquelyKeyedProxies.find(key));
Brian Salomon2af3e702019-08-11 19:10:31 -0400243 SkASSERT(result->textureSwizzle() ==
244 this->caps()->getTextureSwizzle(result->backendFormat(), colorType));
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500245 return result;
246}
247
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500248sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImage,
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500249 int sampleCnt,
Greg Danielfb3abcd2018-02-02 15:48:33 -0500250 SkBudgeted budgeted,
Chris Daltond004e0b2018-09-27 09:28:03 -0600251 SkBackingFit fit,
252 GrInternalSurfaceFlags surfaceFlags) {
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500253 ASSERT_SINGLE_OWNER
254 SkASSERT(srcImage);
255
256 if (this->isAbandoned()) {
257 return nullptr;
258 }
259
Brian Salomon5ad6fd32019-03-21 15:30:08 -0400260 const SkImageInfo& info = srcImage->imageInfo();
Brian Salomon2af3e702019-08-11 19:10:31 -0400261 GrColorType ct = SkColorTypeToGrColorType(info.colorType());
Greg Danielf87651e2018-02-21 11:36:53 -0500262
Brian Salomon96b383a2019-08-13 16:55:41 -0400263 GrBackendFormat format = this->caps()->getDefaultBackendFormat(ct, GrRenderable::kNo);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500264
Robert Phillips0a15cc62019-07-30 12:49:10 -0400265 if (!format.isValid()) {
Brian Osmand29dcd12018-09-13 15:04:29 -0400266 SkBitmap copy8888;
267 if (!copy8888.tryAllocPixels(info.makeColorType(kRGBA_8888_SkColorType)) ||
268 !srcImage->readPixels(copy8888.pixmap(), 0, 0)) {
269 return nullptr;
270 }
271 copy8888.setImmutable();
272 srcImage = SkMakeImageFromRasterBitmap(copy8888, kNever_SkCopyPixelsMode);
Brian Salomon2af3e702019-08-11 19:10:31 -0400273 ct = GrColorType::kRGBA_8888;
Brian Salomon96b383a2019-08-13 16:55:41 -0400274 format = this->caps()->getDefaultBackendFormat(ct, GrRenderable::kNo);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400275 if (!format.isValid()) {
276 return nullptr;
277 }
Brian Osmand29dcd12018-09-13 15:04:29 -0400278 }
279
Brian Salomon2af3e702019-08-11 19:10:31 -0400280 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400281 if (kUnknown_GrPixelConfig == config) {
282 return nullptr;
283 }
284
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500285 GrSurfaceDesc desc;
286 desc.fWidth = srcImage->width();
287 desc.fHeight = srcImage->height();
Greg Danielf87651e2018-02-21 11:36:53 -0500288 desc.fConfig = config;
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500289
290 sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
Brian Salomon96b383a2019-08-13 16:55:41 -0400291 [desc, format, sampleCnt, budgeted, srcImage, fit,
Brian Salomon2af3e702019-08-11 19:10:31 -0400292 ct](GrResourceProvider* resourceProvider) {
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500293 SkPixmap pixMap;
294 SkAssertResult(srcImage->peekPixels(&pixMap));
295 GrMipLevel mipLevel = { pixMap.addr(), pixMap.rowBytes() };
296
Brian Salomone8a766b2019-07-19 14:24:36 -0400297 return LazyInstantiationResult(resourceProvider->createTexture(
Brian Salomon96b383a2019-08-13 16:55:41 -0400298 desc, format, GrRenderable::kNo, sampleCnt, budgeted, fit, GrProtected::kNo,
299 ct, mipLevel, GrResourceProvider::Flags::kNoPendingIO));
Brian Salomon2a4f9832018-03-03 22:43:43 -0500300 },
Brian Salomon96b383a2019-08-13 16:55:41 -0400301 format, desc, GrRenderable::kNo, sampleCnt, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600302 GrMipMapsStatus::kNotAllocated, surfaceFlags, fit, budgeted, GrProtected::kNo);
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500303
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400304 if (!proxy) {
305 return nullptr;
306 }
307
Robert Phillipsa41c6852019-02-07 10:44:10 -0500308 GrContext* direct = fImageContext->priv().asDirectContext();
309 if (direct) {
310 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
311
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500312 // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
313 // we're better off instantiating the proxy immediately here.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500314 if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500315 return nullptr;
316 }
317 }
Robert Phillipsc1b60662018-06-26 10:20:08 -0400318
319 SkASSERT(proxy->width() == desc.fWidth);
320 SkASSERT(proxy->height() == desc.fHeight);
Greg Daniel9d86f1d2018-01-29 09:33:59 -0500321 return proxy;
322}
323
Greg Daniel4065d452018-11-16 15:43:41 -0500324sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrBackendFormat& format,
325 const GrSurfaceDesc& desc,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400326 GrRenderable renderable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400327 int renderTargetSampleCnt,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500328 GrSurfaceOrigin origin,
Brian Salomone8a766b2019-07-19 14:24:36 -0400329 SkBudgeted budgeted,
330 GrProtected isProtected) {
Robert Phillips579f0942018-01-08 14:53:35 -0500331 ASSERT_SINGLE_OWNER
332
333 if (this->isAbandoned()) {
334 return nullptr;
335 }
336
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400337 return this->createProxy(format, desc, renderable, renderTargetSampleCnt, origin,
338 GrMipMapped::kYes, SkBackingFit::kExact, budgeted, isProtected,
Brian Salomone8a766b2019-07-19 14:24:36 -0400339 GrInternalSurfaceFlags::kNone);
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500340}
341
Brian Osmande496652019-03-22 13:42:33 -0400342sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
343 GrMipMapped mipMapped) {
Brian Osman412674f2019-02-07 15:34:58 -0500344 ASSERT_SINGLE_OWNER
Brian Osman7dcc6162019-03-25 10:12:57 -0400345 SkASSERT(GrMipMapped::kNo == mipMapped || this->caps()->mipMapSupport());
Brian Osman412674f2019-02-07 15:34:58 -0500346
347 if (this->isAbandoned()) {
348 return nullptr;
349 }
350
Brian Osman2b23c4b2018-06-01 12:25:08 -0400351 if (!SkImageInfoIsValid(bitmap.info())) {
Greg Daniela4ead652018-02-07 10:21:48 -0500352 return nullptr;
353 }
354
Brian Osmande496652019-03-22 13:42:33 -0400355 ATRACE_ANDROID_FRAMEWORK("Upload %sTexture [%ux%u]",
356 GrMipMapped::kYes == mipMapped ? "MipMap " : "",
357 bitmap.width(), bitmap.height());
Greg Daniela4ead652018-02-07 10:21:48 -0500358
359 // In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap
360 // even if its mutable. In ddl, if the bitmap is mutable then we must make a copy since the
361 // upload of the data to the gpu can happen at anytime and the bitmap may change by then.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500362 SkCopyPixelsMode copyMode = this->renderingDirectly() ? kNever_SkCopyPixelsMode
363 : kIfMutable_SkCopyPixelsMode;
Greg Daniela4ead652018-02-07 10:21:48 -0500364 sk_sp<SkImage> baseLevel = SkMakeImageFromRasterBitmap(bitmap, copyMode);
Greg Daniela4ead652018-02-07 10:21:48 -0500365 if (!baseLevel) {
366 return nullptr;
367 }
368
Brian Osmande496652019-03-22 13:42:33 -0400369 // If mips weren't requested (or this was too small to have any), then take the fast path
370 if (GrMipMapped::kNo == mipMapped ||
371 0 == SkMipMap::ComputeLevelCount(baseLevel->width(), baseLevel->height())) {
Brian Salomon96b383a2019-08-13 16:55:41 -0400372 return this->createTextureProxy(std::move(baseLevel), 1, SkBudgeted::kYes,
373 SkBackingFit::kExact);
Greg Daniela4ead652018-02-07 10:21:48 -0500374 }
375
Brian Osmand29dcd12018-09-13 15:04:29 -0400376 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
Greg Daniel3fc5df42019-06-14 09:42:17 -0400377
Robert Phillips0a15cc62019-07-30 12:49:10 -0400378 GrColorType grColorType = SkColorTypeToGrColorType(bitmap.info().colorType());
379 GrBackendFormat format = this->caps()->getDefaultBackendFormat(grColorType, GrRenderable::kNo);
380 if (!format.isValid()) {
Brian Osmand29dcd12018-09-13 15:04:29 -0400381 SkBitmap copy8888;
382 if (!copy8888.tryAllocPixels(bitmap.info().makeColorType(kRGBA_8888_SkColorType)) ||
383 !bitmap.readPixels(copy8888.pixmap())) {
384 return nullptr;
385 }
386 copy8888.setImmutable();
387 baseLevel = SkMakeImageFromRasterBitmap(copy8888, kNever_SkCopyPixelsMode);
388 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Daniel627d0532019-07-08 16:48:14 -0400389 grColorType = GrColorType::kRGBA_8888;
Robert Phillips0a15cc62019-07-30 12:49:10 -0400390 format = this->caps()->getDefaultBackendFormat(grColorType, GrRenderable::kNo);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400391 if (!format.isValid()) {
392 return nullptr;
393 }
Greg Daniel3fc5df42019-06-14 09:42:17 -0400394 }
395
Brian Osmand29dcd12018-09-13 15:04:29 -0400396 SkPixmap pixmap;
397 SkAssertResult(baseLevel->peekPixels(&pixmap));
398 sk_sp<SkMipMap> mipmaps(SkMipMap::Build(pixmap, nullptr));
Brian Osmanbc6b9cb2018-09-13 13:43:25 -0400399 if (!mipmaps) {
400 return nullptr;
401 }
402
Greg Daniela4ead652018-02-07 10:21:48 -0500403 sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400404 [desc, format, baseLevel, mipmaps](GrResourceProvider* resourceProvider) {
Brian Osman1b97f132018-09-13 17:33:48 +0000405 const int mipLevelCount = mipmaps->countLevels() + 1;
406 std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
407
Greg Daniela4ead652018-02-07 10:21:48 -0500408 SkPixmap pixmap;
409 SkAssertResult(baseLevel->peekPixels(&pixmap));
410
411 // DDL TODO: Instead of copying all this info into GrMipLevels we should just plumb
412 // the use of SkMipMap down through Ganesh.
413 texels[0].fPixels = pixmap.addr();
414 texels[0].fRowBytes = pixmap.rowBytes();
415
416 for (int i = 1; i < mipLevelCount; ++i) {
417 SkMipMap::Level generatedMipLevel;
418 mipmaps->getLevel(i - 1, &generatedMipLevel);
419 texels[i].fPixels = generatedMipLevel.fPixmap.addr();
420 texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
421 SkASSERT(texels[i].fPixels);
422 }
423
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400424 return LazyInstantiationResult(resourceProvider->createTexture(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400425 desc, format, GrRenderable::kNo, 1, SkBudgeted::kYes, GrProtected::kNo,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400426 texels.get(), mipLevelCount));
Brian Salomon2a4f9832018-03-03 22:43:43 -0500427 },
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400428 format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600429 GrMipMapsStatus::kValid, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo);
Greg Daniela4ead652018-02-07 10:21:48 -0500430
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400431 if (!proxy) {
432 return nullptr;
433 }
434
Robert Phillipsa41c6852019-02-07 10:44:10 -0500435 GrContext* direct = fImageContext->priv().asDirectContext();
436 if (direct) {
437 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
Greg Daniela4ead652018-02-07 10:21:48 -0500438 // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
439 // we're better off instantiating the proxy immediately here.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500440 if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
Greg Daniela4ead652018-02-07 10:21:48 -0500441 return nullptr;
442 }
443 }
444 return proxy;
445}
446
Greg Danielfa55f2e2019-06-13 15:21:38 -0400447#ifdef SK_DEBUG
448static bool validate_backend_format_and_config(const GrCaps* caps,
449 const GrBackendFormat& format,
450 GrPixelConfig config) {
451 if (kUnknown_GrPixelConfig == config) {
452 return false;
453 }
Brian Salomonbb8dde82019-06-27 10:52:13 -0400454 if (GrPixelConfigIsCompressed(config)) {
455 // We have no way to verify these at the moment.
456 return true;
457 }
Robert Phillipsc046ff02019-07-01 10:34:03 -0400458
Robert Phillips1e2cb442019-07-02 15:51:28 -0400459 GrColorType grCT = GrPixelConfigToColorType(config);
460
461 return caps->areColorTypeAndFormatCompatible(grCT, format);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400462}
463#endif
464
Greg Daniel4065d452018-11-16 15:43:41 -0500465sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format,
466 const GrSurfaceDesc& desc,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400467 GrRenderable renderable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400468 int renderTargetSampleCnt,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500469 GrSurfaceOrigin origin,
Greg Danielf6f7b672018-02-15 13:06:26 -0500470 GrMipMapped mipMapped,
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500471 SkBackingFit fit,
472 SkBudgeted budgeted,
Brian Salomone8a766b2019-07-19 14:24:36 -0400473 GrProtected isProtected,
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400474 GrInternalSurfaceFlags surfaceFlags) {
Robert Phillips8ff8bcc2019-07-29 17:03:35 -0400475 const GrCaps* caps = this->caps();
476
477 if (caps->isFormatCompressed(format)) {
Brian Salomonbb8dde82019-06-27 10:52:13 -0400478 // Deferred proxies for compressed textures are not supported.
479 return nullptr;
480 }
Robert Phillips0902c982019-07-16 07:47:56 -0400481
Robert Phillips0902c982019-07-16 07:47:56 -0400482 GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
483
484 SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig,
485 caps->getConfigFromBackendFormat(format, colorType)));
Greg Daniel0fac8692019-08-16 13:13:17 -0400486 // TODO: This check should be removed once we get the swizzle outside of GrProxyProvider and
487 // either pass them to the proxy or store the on some view object.
488 if (!caps->areColorTypeAndFormatCompatible(colorType, format)) {
489 return nullptr;
490 }
Robert Phillips62221e72019-07-24 15:07:38 -0400491
Greg Danielf6f7b672018-02-15 13:06:26 -0500492 if (GrMipMapped::kYes == mipMapped) {
493 // SkMipMap doesn't include the base level in the level count so we have to add 1
494 int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
495 if (1 == mipCount) {
496 mipMapped = GrMipMapped::kNo;
497 }
498 }
499
Greg Daniel6fa62e22019-08-07 15:52:37 -0400500 if (!caps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
501 renderTargetSampleCnt, mipMapped)) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500502 return nullptr;
503 }
Brian Salomon3a2cc2c2018-02-03 00:25:12 +0000504 GrSurfaceDesc copyDesc = desc;
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600505 GrMipMapsStatus mipMapsStatus = (GrMipMapped::kYes == mipMapped)
506 ? GrMipMapsStatus::kDirty
507 : GrMipMapsStatus::kNotAllocated;
Robert Phillips0902c982019-07-16 07:47:56 -0400508 GrSwizzle texSwizzle = caps->getTextureSwizzle(format, colorType);
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400509 if (renderable == GrRenderable::kYes) {
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400510 renderTargetSampleCnt =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400511 caps->getRenderTargetSampleCount(renderTargetSampleCnt, format);
512 SkASSERT(renderTargetSampleCnt);
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500513 // We know anything we instantiate later from this deferred path will be
514 // both texturable and renderable
Robert Phillips0902c982019-07-16 07:47:56 -0400515 GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType);
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400516 return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600517 *caps, format, copyDesc, renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
518 texSwizzle, outSwizzle, fit, budgeted, isProtected, surfaceFlags));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500519 }
520
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600521 return sk_sp<GrTextureProxy>(new GrTextureProxy(
522 format, copyDesc, origin, mipMapped, mipMapsStatus, texSwizzle, fit, budgeted,
523 isProtected, surfaceFlags));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500524}
525
Brian Salomonbb8dde82019-06-27 10:52:13 -0400526sk_sp<GrTextureProxy> GrProxyProvider::createCompressedTextureProxy(
527 int width, int height, SkBudgeted budgeted, SkImage::CompressionType compressionType,
528 sk_sp<SkData> data) {
Brian Salomonbb8dde82019-06-27 10:52:13 -0400529
530 GrSurfaceDesc desc;
531 desc.fConfig = GrCompressionTypePixelConfig(compressionType);
532 desc.fWidth = width;
533 desc.fHeight = height;
534
Robert Phillips8ff8bcc2019-07-29 17:03:35 -0400535 GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType);
536
Greg Daniel7bfc9132019-08-14 14:23:53 -0400537 if (!this->caps()->isFormatTexturable(format)) {
Jim Van Verthee06b332019-01-18 10:36:32 -0500538 return nullptr;
539 }
540
Jim Van Verthee06b332019-01-18 10:36:32 -0500541 sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
Greg Daniel7bfc9132019-08-14 14:23:53 -0400542 [width, height, format, compressionType, budgeted, data]
543 (GrResourceProvider* resourceProvider) {
Brian Salomonbb8dde82019-06-27 10:52:13 -0400544 return LazyInstantiationResult(resourceProvider->createCompressedTexture(
Greg Daniel7bfc9132019-08-14 14:23:53 -0400545 width, height, format, compressionType, budgeted, data.get()));
Brian Salomonbb8dde82019-06-27 10:52:13 -0400546 },
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400547 format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600548 GrMipMapsStatus::kNotAllocated, SkBackingFit::kExact, SkBudgeted::kYes,
549 GrProtected::kNo);
Jim Van Verthee06b332019-01-18 10:36:32 -0500550
551 if (!proxy) {
552 return nullptr;
553 }
554
Robert Phillipsa41c6852019-02-07 10:44:10 -0500555 GrContext* direct = fImageContext->priv().asDirectContext();
556 if (direct) {
557 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
Jim Van Verthee06b332019-01-18 10:36:32 -0500558 // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
559 // we're better off instantiating the proxy immediately here.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500560 if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
Jim Van Verthee06b332019-01-18 10:36:32 -0500561 return nullptr;
562 }
563 }
564 return proxy;
565}
566
Brian Salomon7578f3e2018-03-07 14:39:54 -0500567sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400568 GrColorType grColorType,
Brian Salomon7578f3e2018-03-07 14:39:54 -0500569 GrSurfaceOrigin origin,
570 GrWrapOwnership ownership,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500571 GrWrapCacheable cacheable,
Brian Salomonc67c31c2018-12-06 10:00:03 -0500572 GrIOType ioType,
Brian Salomon7578f3e2018-03-07 14:39:54 -0500573 ReleaseProc releaseProc,
574 ReleaseContext releaseCtx) {
Brian Salomonc67c31c2018-12-06 10:00:03 -0500575 SkASSERT(ioType != kWrite_GrIOType);
Robert Phillipsf9bec202018-01-16 09:21:01 -0500576 if (this->isAbandoned()) {
577 return nullptr;
578 }
579
Brian Salomonf7778972018-03-08 10:13:17 -0500580 // This is only supported on a direct GrContext.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500581 GrContext* direct = fImageContext->priv().asDirectContext();
582 if (!direct) {
Brian Salomonf7778972018-03-08 10:13:17 -0500583 return nullptr;
584 }
585
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400586 const GrCaps* caps = this->caps();
587
Robert Phillips62221e72019-07-24 15:07:38 -0400588 SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendTex.getBackendFormat()));
Greg Danielfa55f2e2019-06-13 15:21:38 -0400589
Robert Phillipsa41c6852019-02-07 10:44:10 -0500590 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
591
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500592 sk_sp<GrTexture> tex =
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400593 resourceProvider->wrapBackendTexture(backendTex, grColorType,
594 ownership, cacheable, ioType);
Brian Salomonf7778972018-03-08 10:13:17 -0500595 if (!tex) {
596 return nullptr;
597 }
Robert Phillipsadbe1322018-01-17 13:35:46 -0500598
Greg Daniel6a0176b2018-01-30 09:28:44 -0500599 if (releaseProc) {
Brian Salomonb2c5dae2019-03-04 10:25:17 -0500600 tex->setRelease(releaseProc, releaseCtx);
Greg Daniel6a0176b2018-01-30 09:28:44 -0500601 }
602
Brian Salomonf7778972018-03-08 10:13:17 -0500603 SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture
604 // Make sure we match how we created the proxy with SkBudgeted::kNo
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500605 SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500606
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400607 GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), grColorType);
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400608
609 return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500610}
611
Brian Salomon7578f3e2018-03-07 14:39:54 -0500612sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
Brian Salomon02bd2952018-03-07 15:20:21 -0500613 const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
Robert Phillips0902c982019-07-16 07:47:56 -0400614 GrColorType colorType, GrWrapOwnership ownership, GrWrapCacheable cacheable,
615 ReleaseProc releaseProc, ReleaseContext releaseCtx) {
Robert Phillipsf9bec202018-01-16 09:21:01 -0500616 if (this->isAbandoned()) {
617 return nullptr;
618 }
619
Brian Salomonf7778972018-03-08 10:13:17 -0500620 // This is only supported on a direct GrContext.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500621 GrContext* direct = fImageContext->priv().asDirectContext();
622 if (!direct) {
Brian Salomonf7778972018-03-08 10:13:17 -0500623 return nullptr;
624 }
625
Robert Phillips0902c982019-07-16 07:47:56 -0400626 const GrCaps* caps = this->caps();
627
Robert Phillips62221e72019-07-24 15:07:38 -0400628 SkASSERT(caps->areColorTypeAndFormatCompatible(colorType, backendTex.getBackendFormat()));
Greg Danielfa55f2e2019-06-13 15:21:38 -0400629
Robert Phillipsa41c6852019-02-07 10:44:10 -0500630 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
631
Greg Daniel6fa62e22019-08-07 15:52:37 -0400632 // TODO: This should have been checked and validated before getting into GrProxyProvider.
633 if (!caps->isFormatAsColorTypeRenderable(colorType, backendTex.getBackendFormat(), sampleCnt)) {
Greg Danielf87651e2018-02-21 11:36:53 -0500634 return nullptr;
635 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500636
Greg Daniel6fa62e22019-08-07 15:52:37 -0400637 sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, backendTex.getBackendFormat());
638 SkASSERT(sampleCnt);
639
Robert Phillipsa41c6852019-02-07 10:44:10 -0500640 sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt,
Robert Phillips0902c982019-07-16 07:47:56 -0400641 colorType, ownership,
642 cacheable);
Brian Salomonf7778972018-03-08 10:13:17 -0500643 if (!tex) {
644 return nullptr;
Greg Daniel2a303902018-02-20 10:25:54 -0500645 }
646
Greg Daniel8ce79912019-02-05 10:08:43 -0500647 if (releaseProc) {
Brian Salomonb2c5dae2019-03-04 10:25:17 -0500648 tex->setRelease(releaseProc, releaseCtx);
Greg Daniel8ce79912019-02-05 10:08:43 -0500649 }
650
Brian Salomonf7778972018-03-08 10:13:17 -0500651 SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget
652 // Make sure we match how we created the proxy with SkBudgeted::kNo
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500653 SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
Greg Daniel6abda432018-02-15 14:55:00 -0500654
Robert Phillips0902c982019-07-16 07:47:56 -0400655 GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), colorType);
656 GrSwizzle outSwizzle = caps->getOutputSwizzle(tex->backendFormat(), colorType);
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400657
658 return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, texSwizzle,
659 outSwizzle));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500660}
661
Brian Salomon7578f3e2018-03-07 14:39:54 -0500662sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400663 const GrBackendRenderTarget& backendRT, GrColorType grColorType,
664 GrSurfaceOrigin origin, ReleaseProc releaseProc, ReleaseContext releaseCtx) {
Robert Phillipsf9bec202018-01-16 09:21:01 -0500665 if (this->isAbandoned()) {
666 return nullptr;
667 }
668
Brian Salomonf7778972018-03-08 10:13:17 -0500669 // This is only supported on a direct GrContext.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500670 GrContext* direct = fImageContext->priv().asDirectContext();
671 if (!direct) {
Brian Salomonf7778972018-03-08 10:13:17 -0500672 return nullptr;
Greg Daniel2a303902018-02-20 10:25:54 -0500673 }
674
Robert Phillips62221e72019-07-24 15:07:38 -0400675 const GrCaps* caps = this->caps();
676
677 SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendRT.getBackendFormat()));
Greg Danielfa55f2e2019-06-13 15:21:38 -0400678
Robert Phillipsa41c6852019-02-07 10:44:10 -0500679 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
680
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400681 sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT, grColorType);
Brian Salomonf7778972018-03-08 10:13:17 -0500682 if (!rt) {
683 return nullptr;
Greg Daniel2a303902018-02-20 10:25:54 -0500684 }
Greg Daniel8ce79912019-02-05 10:08:43 -0500685
Greg Daniel8ce79912019-02-05 10:08:43 -0500686 if (releaseProc) {
Brian Salomon2ca31f82019-03-05 13:28:58 -0500687 rt->setRelease(releaseProc, releaseCtx);
Greg Daniel8ce79912019-02-05 10:08:43 -0500688 }
689
Brian Salomonf7778972018-03-08 10:13:17 -0500690 SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
691 SkASSERT(!rt->getUniqueKey().isValid());
692 // Make sure we match how we created the proxy with SkBudgeted::kNo
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500693 SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
Brian Salomonf7778972018-03-08 10:13:17 -0500694
Robert Phillips62221e72019-07-24 15:07:38 -0400695 GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType);
696 GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400697
698 return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
699 outSwizzle));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500700}
701
Brian Salomon7578f3e2018-03-07 14:39:54 -0500702sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400703 const GrBackendTexture& backendTex, GrColorType grColorType,
704 GrSurfaceOrigin origin, int sampleCnt) {
Robert Phillipsf9bec202018-01-16 09:21:01 -0500705 if (this->isAbandoned()) {
706 return nullptr;
707 }
708
Brian Salomonf7778972018-03-08 10:13:17 -0500709 // This is only supported on a direct GrContext.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500710 GrContext* direct = fImageContext->priv().asDirectContext();
711 if (!direct) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500712 return nullptr;
713 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500714
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400715 const GrCaps* caps = this->caps();
716
Robert Phillips62221e72019-07-24 15:07:38 -0400717 SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendTex.getBackendFormat()));
Greg Danielfa55f2e2019-06-13 15:21:38 -0400718
Robert Phillipsa41c6852019-02-07 10:44:10 -0500719 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
720
Brian Salomonf7778972018-03-08 10:13:17 -0500721 sk_sp<GrRenderTarget> rt =
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400722 resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt, grColorType);
Brian Salomonf7778972018-03-08 10:13:17 -0500723 if (!rt) {
724 return nullptr;
Greg Danielf87651e2018-02-21 11:36:53 -0500725 }
Brian Salomonf7778972018-03-08 10:13:17 -0500726 SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
727 SkASSERT(!rt->getUniqueKey().isValid());
Greg Danielb46add82019-01-02 14:51:29 -0500728 // This proxy should be unbudgeted because we're just wrapping an external resource
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500729 SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
Greg Danielf87651e2018-02-21 11:36:53 -0500730
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400731 GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType);
732 GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400733
734 return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
735 outSwizzle));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500736}
737
Greg Danielb46add82019-01-02 14:51:29 -0500738sk_sp<GrRenderTargetProxy> GrProxyProvider::wrapVulkanSecondaryCBAsRenderTarget(
739 const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo) {
740 if (this->isAbandoned()) {
741 return nullptr;
742 }
743
744 // This is only supported on a direct GrContext.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500745 GrContext* direct = fImageContext->priv().asDirectContext();
746 if (!direct) {
Greg Danielb46add82019-01-02 14:51:29 -0500747 return nullptr;
748 }
749
Robert Phillipsa41c6852019-02-07 10:44:10 -0500750 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
Greg Danielb46add82019-01-02 14:51:29 -0500751
Robert Phillipsa41c6852019-02-07 10:44:10 -0500752 sk_sp<GrRenderTarget> rt = resourceProvider->wrapVulkanSecondaryCBAsRenderTarget(imageInfo,
753 vkInfo);
Greg Danielb46add82019-01-02 14:51:29 -0500754 if (!rt) {
755 return nullptr;
756 }
Robert Phillipsa41c6852019-02-07 10:44:10 -0500757
Greg Danielb46add82019-01-02 14:51:29 -0500758 SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
759 SkASSERT(!rt->getUniqueKey().isValid());
760 // This proxy should be unbudgeted because we're just wrapping an external resource
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500761 SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
Greg Danielb46add82019-01-02 14:51:29 -0500762
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400763 GrColorType colorType = SkColorTypeToGrColorType(imageInfo.colorType());
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400764 GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType);
765 GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType);
766
Brian Salomon1c53a9f2019-08-12 14:10:12 -0400767 if (!this->caps()->isFormatAsColorTypeRenderable(colorType, rt->backendFormat(),
768 rt->numSamples())) {
769 return nullptr;
770 }
771
Greg Danielb46add82019-01-02 14:51:29 -0500772 // All Vulkan surfaces uses top left origins.
773 return sk_sp<GrRenderTargetProxy>(
774 new GrRenderTargetProxy(std::move(rt),
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400775 kTopLeft_GrSurfaceOrigin, texSwizzle, outSwizzle,
Greg Danielb46add82019-01-02 14:51:29 -0500776 GrRenderTargetProxy::WrapsVkSecondaryCB::kYes));
777}
778
Robert Phillips777707b2018-01-17 11:40:14 -0500779sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
Greg Daniel4065d452018-11-16 15:43:41 -0500780 const GrBackendFormat& format,
Robert Phillips777707b2018-01-17 11:40:14 -0500781 const GrSurfaceDesc& desc,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400782 GrRenderable renderable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400783 int renderTargetSampleCnt,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500784 GrSurfaceOrigin origin,
Brian Salomon7226c232018-07-30 13:13:17 -0400785 GrMipMapped mipMapped,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600786 GrMipMapsStatus mipMapsStatus,
Brian Salomon7226c232018-07-30 13:13:17 -0400787 SkBackingFit fit,
Brian Salomone8a766b2019-07-19 14:24:36 -0400788 SkBudgeted budgeted,
789 GrProtected isProtected) {
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400790 return this->createLazyProxy(std::move(callback), format, desc, renderable,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600791 renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
Brian Salomone8a766b2019-07-19 14:24:36 -0400792 GrInternalSurfaceFlags::kNone, fit, budgeted, isProtected);
Greg Daniela8d92112018-03-09 12:05:04 -0500793}
794
795sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
Greg Daniel4065d452018-11-16 15:43:41 -0500796 const GrBackendFormat& format,
Greg Daniela8d92112018-03-09 12:05:04 -0500797 const GrSurfaceDesc& desc,
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400798 GrRenderable renderable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400799 int renderTargetSampleCnt,
Greg Daniela8d92112018-03-09 12:05:04 -0500800 GrSurfaceOrigin origin,
801 GrMipMapped mipMapped,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600802 GrMipMapsStatus mipMapsStatus,
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400803 GrInternalSurfaceFlags surfaceFlags,
Brian Salomon7226c232018-07-30 13:13:17 -0400804 SkBackingFit fit,
805 SkBudgeted budgeted,
Brian Salomone8a766b2019-07-19 14:24:36 -0400806 GrProtected isProtected) {
807 // For non-ddl draws always make lazy proxy's single use.
808 LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse
809 : LazyInstantiationType::kMultipleUse;
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400810 return this->createLazyProxy(std::move(callback), format, desc, renderable,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600811 renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
812 surfaceFlags, fit, budgeted, isProtected, lazyType);
Brian Salomone8a766b2019-07-19 14:24:36 -0400813}
814
815sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
816 const GrBackendFormat& format,
817 const GrSurfaceDesc& desc,
818 GrRenderable renderable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400819 int renderTargetSampleCnt,
Brian Salomone8a766b2019-07-19 14:24:36 -0400820 GrSurfaceOrigin origin,
821 GrMipMapped mipMapped,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600822 GrMipMapsStatus mipMapsStatus,
Brian Salomone8a766b2019-07-19 14:24:36 -0400823 GrInternalSurfaceFlags surfaceFlags,
824 SkBackingFit fit,
825 SkBudgeted budgeted,
826 GrProtected isProtected,
Greg Daniela8d92112018-03-09 12:05:04 -0500827 LazyInstantiationType lazyType) {
Robert Phillips777707b2018-01-17 11:40:14 -0500828 SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
829 (desc.fWidth > 0 && desc.fHeight > 0));
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400830
Robert Phillips0a15cc62019-07-30 12:49:10 -0400831 if (!format.isValid()) {
832 return nullptr;
833 }
834
Robert Phillipsa41c6852019-02-07 10:44:10 -0500835 if (desc.fWidth > this->caps()->maxTextureSize() ||
836 desc.fHeight > this->caps()->maxTextureSize()) {
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400837 return nullptr;
838 }
839
Greg Danielfa55f2e2019-06-13 15:21:38 -0400840 SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig));
Greg Daniel457469c2018-02-08 15:05:44 -0500841
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400842 GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
843 GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
844 GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
845
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600846 return sk_sp<GrTextureProxy>((renderable == GrRenderable::kYes)
847 ? new GrTextureRenderTargetProxy(
848 std::move(callback), lazyType, format, desc, renderTargetSampleCnt, origin,
849 mipMapped, mipMapsStatus, texSwizzle, outSwizzle, fit, budgeted, isProtected,
850 surfaceFlags)
851 : new GrTextureProxy(
852 std::move(callback), lazyType, format, desc, origin, mipMapped, mipMapsStatus,
853 texSwizzle, fit, budgeted, isProtected, surfaceFlags));
Robert Phillips777707b2018-01-17 11:40:14 -0500854}
855
Robert Phillipse8fabb22018-02-04 14:33:21 -0500856sk_sp<GrRenderTargetProxy> GrProxyProvider::createLazyRenderTargetProxy(
Greg Daniel4065d452018-11-16 15:43:41 -0500857 LazyInstantiateCallback&& callback, const GrBackendFormat& format,
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400858 const GrSurfaceDesc& desc, int sampleCnt, GrSurfaceOrigin origin,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600859 GrInternalSurfaceFlags surfaceFlags, const TextureInfo* textureInfo,
860 GrMipMapsStatus mipMapsStatus, SkBackingFit fit, SkBudgeted budgeted,
861 GrProtected isProtected, bool wrapsVkSecondaryCB) {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500862 SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
863 (desc.fWidth > 0 && desc.fHeight > 0));
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400864
Robert Phillipsa41c6852019-02-07 10:44:10 -0500865 if (desc.fWidth > this->caps()->maxRenderTargetSize() ||
866 desc.fHeight > this->caps()->maxRenderTargetSize()) {
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400867 return nullptr;
868 }
869
Greg Danielfa55f2e2019-06-13 15:21:38 -0400870 SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig));
Greg Daniel457469c2018-02-08 15:05:44 -0500871
872 using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
873 // For non-ddl draws always make lazy proxy's single use.
Robert Phillipsa41c6852019-02-07 10:44:10 -0500874 LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse
875 : LazyInstantiationType::kMultipleUse;
Greg Daniel457469c2018-02-08 15:05:44 -0500876
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400877 GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
878 GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
879 GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
880
Brian Salomon7226c232018-07-30 13:13:17 -0400881 if (textureInfo) {
Greg Danielb085fa92019-03-05 16:55:12 -0500882 // Wrapped vulkan secondary command buffers don't support texturing since we won't have an
883 // actual VkImage to texture from.
884 SkASSERT(!wrapsVkSecondaryCB);
Brian Salomon7226c232018-07-30 13:13:17 -0400885 return sk_sp<GrRenderTargetProxy>(new GrTextureRenderTargetProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400886 std::move(callback), lazyType, format, desc, sampleCnt, origin,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600887 textureInfo->fMipMapped, mipMapsStatus, texSwizzle, outSwizzle, fit, budgeted,
888 isProtected, surfaceFlags));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500889 }
890
Greg Danielb085fa92019-03-05 16:55:12 -0500891 GrRenderTargetProxy::WrapsVkSecondaryCB vkSCB =
892 wrapsVkSecondaryCB ? GrRenderTargetProxy::WrapsVkSecondaryCB::kYes
893 : GrRenderTargetProxy::WrapsVkSecondaryCB::kNo;
894
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400895 return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(
896 std::move(callback), lazyType, format, desc, sampleCnt, origin, texSwizzle, outSwizzle,
897 fit, budgeted, isProtected, surfaceFlags, vkSCB));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500898}
899
Chris Dalton19cc00f2019-04-15 09:06:28 -0600900sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy(
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400901 LazyInstantiateCallback&& callback, const GrBackendFormat& format, GrRenderable renderable,
902 int renderTargetSampleCnt, GrProtected isProtected, GrSurfaceOrigin origin,
903 GrPixelConfig config, const GrCaps& caps) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400904 if (!format.isValid()) {
905 return nullptr;
906 }
907
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400908 SkASSERT(renderTargetSampleCnt == 1 || renderable == GrRenderable::kYes);
Greg Danielfa55f2e2019-06-13 15:21:38 -0400909 SkASSERT(validate_backend_format_and_config(&caps, format, config));
Robert Phillips777707b2018-01-17 11:40:14 -0500910 GrSurfaceDesc desc;
Robert Phillips10d17212019-04-24 14:09:10 -0400911 GrInternalSurfaceFlags surfaceFlags = GrInternalSurfaceFlags::kNone;
Robert Phillips777707b2018-01-17 11:40:14 -0500912 desc.fWidth = -1;
913 desc.fHeight = -1;
914 desc.fConfig = config;
Robert Phillips777707b2018-01-17 11:40:14 -0500915
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400916 GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
917 GrSwizzle texSwizzle = caps.getTextureSwizzle(format, colorType);
918 GrSwizzle outSwizzle = caps.getOutputSwizzle(format, colorType);
919
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600920 return sk_sp<GrTextureProxy>((GrRenderable::kYes == renderable)
921 ? new GrTextureRenderTargetProxy(
922 std::move(callback), LazyInstantiationType::kSingleUse, format, desc,
923 renderTargetSampleCnt, origin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated,
924 texSwizzle, outSwizzle, SkBackingFit::kApprox, SkBudgeted::kYes, isProtected,
925 surfaceFlags)
926 : new GrTextureProxy(
927 std::move(callback), LazyInstantiationType::kSingleUse, format, desc, origin,
928 GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, texSwizzle,
929 SkBackingFit::kApprox, SkBudgeted::kYes, isProtected, surfaceFlags));
Robert Phillips777707b2018-01-17 11:40:14 -0500930}
931
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500932bool GrProxyProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400933 const bool isInstantiated = proxy->isInstantiated();
Robert Phillipsdb3b9792018-06-12 15:18:00 -0400934 // A proxy is functionally exact if:
935 // it is exact (obvs)
936 // when it is instantiated it will be exact (i.e., power of two dimensions)
937 // it is already instantiated and the proxy covers the entire backing surface
938 return proxy->priv().isExact() ||
939 (!isInstantiated && SkIsPow2(proxy->width()) && SkIsPow2(proxy->height())) ||
940 (isInstantiated && proxy->worstCaseWidth() == proxy->width() &&
941 proxy->worstCaseHeight() == proxy->height());
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500942}
943
Robert Phillips427966a2018-12-20 17:20:43 -0500944void GrProxyProvider::processInvalidUniqueKey(const GrUniqueKey& key, GrTextureProxy* proxy,
945 InvalidateGPUResource invalidateGPUResource) {
Chris Dalton2de13dd2019-01-03 15:11:59 -0700946 SkASSERT(key.isValid());
947
Robert Phillips427966a2018-12-20 17:20:43 -0500948 if (!proxy) {
949 proxy = fUniquelyKeyedProxies.find(key);
950 }
Chris Dalton2de13dd2019-01-03 15:11:59 -0700951 SkASSERT(!proxy || proxy->getUniqueKey() == key);
952
953 // Locate the corresponding GrGpuResource (if it needs to be invalidated) before clearing the
954 // proxy's unique key. We must do it in this order because 'key' may alias the proxy's key.
955 sk_sp<GrGpuResource> invalidGpuResource;
956 if (InvalidateGPUResource::kYes == invalidateGPUResource) {
Brian Salomon01ceae92019-04-02 11:49:54 -0400957 GrContext* direct = fImageContext->priv().asDirectContext();
958 if (direct) {
959 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
960 invalidGpuResource = resourceProvider->findByUniqueKey<GrGpuResource>(key);
Chris Dalton2de13dd2019-01-03 15:11:59 -0700961 }
962 SkASSERT(!invalidGpuResource || invalidGpuResource->getUniqueKey() == key);
963 }
Robert Phillips427966a2018-12-20 17:20:43 -0500964
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500965 // Note: this method is called for the whole variety of GrGpuResources so often 'key'
966 // will not be in 'fUniquelyKeyedProxies'.
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500967 if (proxy) {
Robert Phillips427966a2018-12-20 17:20:43 -0500968 fUniquelyKeyedProxies.remove(key);
969 proxy->cacheAccess().clearUniqueKey();
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500970 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500971
Chris Dalton2de13dd2019-01-03 15:11:59 -0700972 if (invalidGpuResource) {
973 invalidGpuResource->resourcePriv().removeUniqueKey();
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500974 }
975}
976
Robert Phillipsa41c6852019-02-07 10:44:10 -0500977uint32_t GrProxyProvider::contextID() const {
978 return fImageContext->priv().contextID();
979}
980
981const GrCaps* GrProxyProvider::caps() const {
982 return fImageContext->priv().caps();
983}
984
985sk_sp<const GrCaps> GrProxyProvider::refCaps() const {
986 return fImageContext->priv().refCaps();
987}
988
Robert Phillipsa9162df2019-02-11 14:12:03 -0500989bool GrProxyProvider::isAbandoned() const {
990 return fImageContext->priv().abandoned();
991}
992
Robert Phillips0790f8a2018-09-18 13:11:03 -0400993void GrProxyProvider::orphanAllUniqueKeys() {
994 UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies);
995 for (UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); !iter.done(); ++iter) {
996 GrTextureProxy& tmp = *iter;
997
998 tmp.fProxyProvider = nullptr;
999 }
1000}
1001
Robert Phillips1afd4cd2018-01-08 13:40:32 -05001002void GrProxyProvider::removeAllUniqueKeys() {
1003 UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies);
1004 for (UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); !iter.done(); ++iter) {
1005 GrTextureProxy& tmp = *iter;
1006
Chris Dalton2de13dd2019-01-03 15:11:59 -07001007 this->processInvalidUniqueKey(tmp.getUniqueKey(), &tmp, InvalidateGPUResource::kNo);
Robert Phillips1afd4cd2018-01-08 13:40:32 -05001008 }
1009 SkASSERT(!fUniquelyKeyedProxies.count());
1010}
Robert Phillipsa41c6852019-02-07 10:44:10 -05001011
1012bool GrProxyProvider::renderingDirectly() const {
1013 return fImageContext->priv().asDirectContext();
1014}