Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrProxyProvider.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkBitmap.h" |
| 11 | #include "include/core/SkImage.h" |
| 12 | #include "include/gpu/GrContext.h" |
| 13 | #include "include/gpu/GrRenderTarget.h" |
| 14 | #include "include/gpu/GrTexture.h" |
| 15 | #include "include/private/GrImageContext.h" |
| 16 | #include "include/private/GrResourceKey.h" |
| 17 | #include "include/private/GrSingleOwner.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/private/SkImageInfoPriv.h" |
| 19 | #include "src/core/SkAutoPixmapStorage.h" |
| 20 | #include "src/core/SkImagePriv.h" |
| 21 | #include "src/core/SkMipMap.h" |
| 22 | #include "src/core/SkTraceEvent.h" |
| 23 | #include "src/gpu/GrCaps.h" |
| 24 | #include "src/gpu/GrContextPriv.h" |
| 25 | #include "src/gpu/GrImageContextPriv.h" |
| 26 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 27 | #include "src/gpu/GrSurfaceProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #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 Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 33 | |
| 34 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 35 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fImageContext->priv().singleOwner());) |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 36 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 37 | GrProxyProvider::GrProxyProvider(GrImageContext* imageContext) : fImageContext(imageContext) {} |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 38 | |
| 39 | GrProxyProvider::~GrProxyProvider() { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 40 | if (this->renderingDirectly()) { |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 41 | // 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 Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 48 | bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 49 | ASSERT_SINGLE_OWNER |
| 50 | SkASSERT(key.isValid()); |
| 51 | if (this->isAbandoned() || !proxy) { |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 52 | return false; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 55 | #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 Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 67 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 68 | 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 Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 73 | return true; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void 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 Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 85 | void GrProxyProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 86 | ASSERT_SINGLE_OWNER |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 87 | SkASSERT(proxy); |
| 88 | SkASSERT(proxy->getUniqueKey().isValid()); |
| 89 | |
| 90 | if (this->isAbandoned()) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 91 | return; |
| 92 | } |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 93 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 94 | this->processInvalidUniqueKey(proxy->getUniqueKey(), proxy, InvalidateGPUResource::kYes); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | sk_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 Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 105 | GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key); |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 106 | if (proxy) { |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 107 | SkASSERT(proxy->getProxyRefCnt() >= 1); |
| 108 | SkASSERT(proxy->origin() == origin); |
| 109 | return sk_ref_sp(proxy); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 110 | } |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 111 | return nullptr; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 114 | /////////////////////////////////////////////////////////////////////////////// |
| 115 | |
| 116 | #if GR_TEST_UTILS |
| 117 | sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 118 | 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 Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 127 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 128 | if (!direct) { |
| 129 | return nullptr; |
| 130 | } |
| 131 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 132 | 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 Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 145 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 146 | sk_sp<GrTexture> tex; |
| 147 | |
| 148 | if (SkBackingFit::kApprox == fit) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 149 | tex = resourceProvider->createApproxTexture(desc, format, renderable, renderTargetSampleCnt, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 150 | isProtected, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 151 | GrResourceProvider::Flags::kNoPendingIO); |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 152 | } else { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 153 | tex = resourceProvider->createTexture(desc, format, renderable, renderTargetSampleCnt, |
| 154 | budgeted, isProtected, |
| 155 | GrResourceProvider::Flags::kNoPendingIO); |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 156 | } |
| 157 | if (!tex) { |
| 158 | return nullptr; |
| 159 | } |
| 160 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 161 | return this->createWrapped(std::move(tex), colorType, origin); |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 164 | sk_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 Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 185 | sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createWrapped(sk_sp<GrTexture> tex, |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 186 | GrColorType colorType, |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 187 | GrSurfaceOrigin origin) { |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 188 | return this->createWrapped(std::move(tex), colorType, origin); |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 189 | } |
| 190 | #endif |
| 191 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 192 | sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex, GrColorType colorType, |
| 193 | GrSurfaceOrigin origin) { |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 194 | #ifdef SK_DEBUG |
| 195 | if (tex->getUniqueKey().isValid()) { |
| 196 | SkASSERT(!this->findProxyByUniqueKey(tex->getUniqueKey(), origin)); |
| 197 | } |
| 198 | #endif |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 199 | GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 200 | |
| 201 | if (tex->asRenderTarget()) { |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 202 | GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(tex->backendFormat(), colorType); |
| 203 | return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, |
| 204 | texSwizzle, outSwizzle)); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 205 | } else { |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 206 | return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle)); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 210 | sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key, |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 211 | GrColorType colorType, |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 212 | 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 Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 224 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 225 | if (!direct) { |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 226 | return nullptr; |
| 227 | } |
| 228 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 229 | GrResourceCache* resourceCache = direct->priv().getResourceCache(); |
| 230 | |
| 231 | GrGpuResource* resource = resourceCache->findAndRefUniqueResource(key); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 232 | if (!resource) { |
| 233 | return nullptr; |
| 234 | } |
| 235 | |
| 236 | sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture()); |
| 237 | SkASSERT(texture); |
| 238 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 239 | result = this->createWrapped(std::move(texture), colorType, origin); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 240 | SkASSERT(result->getUniqueKey() == key); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 241 | // createWrapped should've added this for us |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 242 | SkASSERT(fUniquelyKeyedProxies.find(key)); |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 243 | SkASSERT(result->textureSwizzle() == |
| 244 | this->caps()->getTextureSwizzle(result->backendFormat(), colorType)); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 245 | return result; |
| 246 | } |
| 247 | |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 248 | sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImage, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 249 | GrRenderable renderable, |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 250 | int sampleCnt, |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 251 | SkBudgeted budgeted, |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 252 | SkBackingFit fit, |
| 253 | GrInternalSurfaceFlags surfaceFlags) { |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 254 | ASSERT_SINGLE_OWNER |
| 255 | SkASSERT(srcImage); |
| 256 | |
| 257 | if (this->isAbandoned()) { |
| 258 | return nullptr; |
| 259 | } |
| 260 | |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 261 | const SkImageInfo& info = srcImage->imageInfo(); |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 262 | GrColorType ct = SkColorTypeToGrColorType(info.colorType()); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 263 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 264 | GrBackendFormat format = this->caps()->getDefaultBackendFormat(ct, renderable); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 265 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 266 | if (!format.isValid()) { |
Brian Osman | d29dcd1 | 2018-09-13 15:04:29 -0400 | [diff] [blame] | 267 | SkBitmap copy8888; |
| 268 | if (!copy8888.tryAllocPixels(info.makeColorType(kRGBA_8888_SkColorType)) || |
| 269 | !srcImage->readPixels(copy8888.pixmap(), 0, 0)) { |
| 270 | return nullptr; |
| 271 | } |
| 272 | copy8888.setImmutable(); |
| 273 | srcImage = SkMakeImageFromRasterBitmap(copy8888, kNever_SkCopyPixelsMode); |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 274 | ct = GrColorType::kRGBA_8888; |
| 275 | format = this->caps()->getDefaultBackendFormat(ct, renderable); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 276 | if (!format.isValid()) { |
| 277 | return nullptr; |
| 278 | } |
Brian Osman | d29dcd1 | 2018-09-13 15:04:29 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 281 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 282 | sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, format); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 283 | if (!sampleCnt) { |
| 284 | return nullptr; |
| 285 | } |
| 286 | } |
| 287 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 288 | GrPixelConfig config = GrColorTypeToPixelConfig(ct); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 289 | if (kUnknown_GrPixelConfig == config) { |
| 290 | return nullptr; |
| 291 | } |
| 292 | |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 293 | GrSurfaceDesc desc; |
| 294 | desc.fWidth = srcImage->width(); |
| 295 | desc.fHeight = srcImage->height(); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 296 | desc.fConfig = config; |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 297 | |
| 298 | sk_sp<GrTextureProxy> proxy = this->createLazyProxy( |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 299 | [desc, format, renderable, sampleCnt, budgeted, srcImage, fit, |
| 300 | ct](GrResourceProvider* resourceProvider) { |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 301 | SkPixmap pixMap; |
| 302 | SkAssertResult(srcImage->peekPixels(&pixMap)); |
| 303 | GrMipLevel mipLevel = { pixMap.addr(), pixMap.rowBytes() }; |
| 304 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 305 | return LazyInstantiationResult(resourceProvider->createTexture( |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame^] | 306 | desc, format, renderable, sampleCnt, budgeted, fit, GrProtected::kNo, ct, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 307 | mipLevel, GrResourceProvider::Flags::kNoPendingIO)); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 308 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 309 | format, desc, renderable, sampleCnt, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 310 | GrMipMapsStatus::kNotAllocated, surfaceFlags, fit, budgeted, GrProtected::kNo); |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 311 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 312 | if (!proxy) { |
| 313 | return nullptr; |
| 314 | } |
| 315 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 316 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 317 | if (direct) { |
| 318 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 319 | |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 320 | // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however |
| 321 | // we're better off instantiating the proxy immediately here. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 322 | if (!proxy->priv().doLazyInstantiation(resourceProvider)) { |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 323 | return nullptr; |
| 324 | } |
| 325 | } |
Robert Phillips | c1b6066 | 2018-06-26 10:20:08 -0400 | [diff] [blame] | 326 | |
| 327 | SkASSERT(proxy->width() == desc.fWidth); |
| 328 | SkASSERT(proxy->height() == desc.fHeight); |
Greg Daniel | 9d86f1d | 2018-01-29 09:33:59 -0500 | [diff] [blame] | 329 | return proxy; |
| 330 | } |
| 331 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 332 | sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrBackendFormat& format, |
| 333 | const GrSurfaceDesc& desc, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 334 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 335 | int renderTargetSampleCnt, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 336 | GrSurfaceOrigin origin, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 337 | SkBudgeted budgeted, |
| 338 | GrProtected isProtected) { |
Robert Phillips | 579f094 | 2018-01-08 14:53:35 -0500 | [diff] [blame] | 339 | ASSERT_SINGLE_OWNER |
| 340 | |
| 341 | if (this->isAbandoned()) { |
| 342 | return nullptr; |
| 343 | } |
| 344 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 345 | return this->createProxy(format, desc, renderable, renderTargetSampleCnt, origin, |
| 346 | GrMipMapped::kYes, SkBackingFit::kExact, budgeted, isProtected, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 347 | GrInternalSurfaceFlags::kNone); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 348 | } |
| 349 | |
Brian Osman | de49665 | 2019-03-22 13:42:33 -0400 | [diff] [blame] | 350 | sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap, |
| 351 | GrMipMapped mipMapped) { |
Brian Osman | 412674f | 2019-02-07 15:34:58 -0500 | [diff] [blame] | 352 | ASSERT_SINGLE_OWNER |
Brian Osman | 7dcc616 | 2019-03-25 10:12:57 -0400 | [diff] [blame] | 353 | SkASSERT(GrMipMapped::kNo == mipMapped || this->caps()->mipMapSupport()); |
Brian Osman | 412674f | 2019-02-07 15:34:58 -0500 | [diff] [blame] | 354 | |
| 355 | if (this->isAbandoned()) { |
| 356 | return nullptr; |
| 357 | } |
| 358 | |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 359 | if (!SkImageInfoIsValid(bitmap.info())) { |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 360 | return nullptr; |
| 361 | } |
| 362 | |
Brian Osman | de49665 | 2019-03-22 13:42:33 -0400 | [diff] [blame] | 363 | ATRACE_ANDROID_FRAMEWORK("Upload %sTexture [%ux%u]", |
| 364 | GrMipMapped::kYes == mipMapped ? "MipMap " : "", |
| 365 | bitmap.width(), bitmap.height()); |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 366 | |
| 367 | // In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap |
| 368 | // even if its mutable. In ddl, if the bitmap is mutable then we must make a copy since the |
| 369 | // upload of the data to the gpu can happen at anytime and the bitmap may change by then. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 370 | SkCopyPixelsMode copyMode = this->renderingDirectly() ? kNever_SkCopyPixelsMode |
| 371 | : kIfMutable_SkCopyPixelsMode; |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 372 | sk_sp<SkImage> baseLevel = SkMakeImageFromRasterBitmap(bitmap, copyMode); |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 373 | if (!baseLevel) { |
| 374 | return nullptr; |
| 375 | } |
| 376 | |
Brian Osman | de49665 | 2019-03-22 13:42:33 -0400 | [diff] [blame] | 377 | // If mips weren't requested (or this was too small to have any), then take the fast path |
| 378 | if (GrMipMapped::kNo == mipMapped || |
| 379 | 0 == SkMipMap::ComputeLevelCount(baseLevel->width(), baseLevel->height())) { |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 380 | return this->createTextureProxy(std::move(baseLevel), GrRenderable::kNo, 1, |
Brian Osman | 7dcc616 | 2019-03-25 10:12:57 -0400 | [diff] [blame] | 381 | SkBudgeted::kYes, SkBackingFit::kExact); |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Brian Osman | d29dcd1 | 2018-09-13 15:04:29 -0400 | [diff] [blame] | 384 | GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); |
Greg Daniel | 3fc5df4 | 2019-06-14 09:42:17 -0400 | [diff] [blame] | 385 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 386 | GrColorType grColorType = SkColorTypeToGrColorType(bitmap.info().colorType()); |
| 387 | GrBackendFormat format = this->caps()->getDefaultBackendFormat(grColorType, GrRenderable::kNo); |
| 388 | if (!format.isValid()) { |
Brian Osman | d29dcd1 | 2018-09-13 15:04:29 -0400 | [diff] [blame] | 389 | SkBitmap copy8888; |
| 390 | if (!copy8888.tryAllocPixels(bitmap.info().makeColorType(kRGBA_8888_SkColorType)) || |
| 391 | !bitmap.readPixels(copy8888.pixmap())) { |
| 392 | return nullptr; |
| 393 | } |
| 394 | copy8888.setImmutable(); |
| 395 | baseLevel = SkMakeImageFromRasterBitmap(copy8888, kNever_SkCopyPixelsMode); |
| 396 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 627d053 | 2019-07-08 16:48:14 -0400 | [diff] [blame] | 397 | grColorType = GrColorType::kRGBA_8888; |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 398 | format = this->caps()->getDefaultBackendFormat(grColorType, GrRenderable::kNo); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 399 | if (!format.isValid()) { |
| 400 | return nullptr; |
| 401 | } |
Greg Daniel | 3fc5df4 | 2019-06-14 09:42:17 -0400 | [diff] [blame] | 402 | } |
| 403 | |
Brian Osman | d29dcd1 | 2018-09-13 15:04:29 -0400 | [diff] [blame] | 404 | SkPixmap pixmap; |
| 405 | SkAssertResult(baseLevel->peekPixels(&pixmap)); |
| 406 | sk_sp<SkMipMap> mipmaps(SkMipMap::Build(pixmap, nullptr)); |
Brian Osman | bc6b9cb | 2018-09-13 13:43:25 -0400 | [diff] [blame] | 407 | if (!mipmaps) { |
| 408 | return nullptr; |
| 409 | } |
| 410 | |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 411 | sk_sp<GrTextureProxy> proxy = this->createLazyProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 412 | [desc, format, baseLevel, mipmaps](GrResourceProvider* resourceProvider) { |
Brian Osman | 1b97f13 | 2018-09-13 17:33:48 +0000 | [diff] [blame] | 413 | const int mipLevelCount = mipmaps->countLevels() + 1; |
| 414 | std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]); |
| 415 | |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 416 | SkPixmap pixmap; |
| 417 | SkAssertResult(baseLevel->peekPixels(&pixmap)); |
| 418 | |
| 419 | // DDL TODO: Instead of copying all this info into GrMipLevels we should just plumb |
| 420 | // the use of SkMipMap down through Ganesh. |
| 421 | texels[0].fPixels = pixmap.addr(); |
| 422 | texels[0].fRowBytes = pixmap.rowBytes(); |
| 423 | |
| 424 | for (int i = 1; i < mipLevelCount; ++i) { |
| 425 | SkMipMap::Level generatedMipLevel; |
| 426 | mipmaps->getLevel(i - 1, &generatedMipLevel); |
| 427 | texels[i].fPixels = generatedMipLevel.fPixmap.addr(); |
| 428 | texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes(); |
| 429 | SkASSERT(texels[i].fPixels); |
| 430 | } |
| 431 | |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 432 | return LazyInstantiationResult(resourceProvider->createTexture( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 433 | desc, format, GrRenderable::kNo, 1, SkBudgeted::kYes, GrProtected::kNo, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 434 | texels.get(), mipLevelCount)); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 435 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 436 | format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 437 | GrMipMapsStatus::kValid, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo); |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 438 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 439 | if (!proxy) { |
| 440 | return nullptr; |
| 441 | } |
| 442 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 443 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 444 | if (direct) { |
| 445 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 446 | // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however |
| 447 | // we're better off instantiating the proxy immediately here. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 448 | if (!proxy->priv().doLazyInstantiation(resourceProvider)) { |
Greg Daniel | a4ead65 | 2018-02-07 10:21:48 -0500 | [diff] [blame] | 449 | return nullptr; |
| 450 | } |
| 451 | } |
| 452 | return proxy; |
| 453 | } |
| 454 | |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 455 | #ifdef SK_DEBUG |
| 456 | static bool validate_backend_format_and_config(const GrCaps* caps, |
| 457 | const GrBackendFormat& format, |
| 458 | GrPixelConfig config) { |
| 459 | if (kUnknown_GrPixelConfig == config) { |
| 460 | return false; |
| 461 | } |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 462 | if (GrPixelConfigIsCompressed(config)) { |
| 463 | // We have no way to verify these at the moment. |
| 464 | return true; |
| 465 | } |
Robert Phillips | c046ff0 | 2019-07-01 10:34:03 -0400 | [diff] [blame] | 466 | |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 467 | GrColorType grCT = GrPixelConfigToColorType(config); |
| 468 | |
| 469 | return caps->areColorTypeAndFormatCompatible(grCT, format); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 470 | } |
| 471 | #endif |
| 472 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 473 | sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format, |
| 474 | const GrSurfaceDesc& desc, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 475 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 476 | int renderTargetSampleCnt, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 477 | GrSurfaceOrigin origin, |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 478 | GrMipMapped mipMapped, |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 479 | SkBackingFit fit, |
| 480 | SkBudgeted budgeted, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 481 | GrProtected isProtected, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 482 | GrInternalSurfaceFlags surfaceFlags) { |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 483 | const GrCaps* caps = this->caps(); |
| 484 | |
| 485 | if (caps->isFormatCompressed(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 486 | // Deferred proxies for compressed textures are not supported. |
| 487 | return nullptr; |
| 488 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 489 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 490 | GrColorType colorType = GrPixelConfigToColorType(desc.fConfig); |
| 491 | |
| 492 | SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig, |
| 493 | caps->getConfigFromBackendFormat(format, colorType))); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 494 | SkASSERT(caps->areColorTypeAndFormatCompatible(colorType, format)); |
| 495 | |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 496 | if (GrMipMapped::kYes == mipMapped) { |
| 497 | // SkMipMap doesn't include the base level in the level count so we have to add 1 |
| 498 | int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1; |
| 499 | if (1 == mipCount) { |
| 500 | mipMapped = GrMipMapped::kNo; |
| 501 | } |
| 502 | } |
| 503 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 504 | if (!caps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable, |
| 505 | renderTargetSampleCnt, mipMapped)) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 506 | return nullptr; |
| 507 | } |
Brian Salomon | 3a2cc2c | 2018-02-03 00:25:12 +0000 | [diff] [blame] | 508 | GrSurfaceDesc copyDesc = desc; |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 509 | GrMipMapsStatus mipMapsStatus = (GrMipMapped::kYes == mipMapped) |
| 510 | ? GrMipMapsStatus::kDirty |
| 511 | : GrMipMapsStatus::kNotAllocated; |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 512 | GrSwizzle texSwizzle = caps->getTextureSwizzle(format, colorType); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 513 | if (renderable == GrRenderable::kYes) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 514 | renderTargetSampleCnt = |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 515 | caps->getRenderTargetSampleCount(renderTargetSampleCnt, format); |
| 516 | SkASSERT(renderTargetSampleCnt); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 517 | // We know anything we instantiate later from this deferred path will be |
| 518 | // both texturable and renderable |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 519 | GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 520 | return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy( |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 521 | *caps, format, copyDesc, renderTargetSampleCnt, origin, mipMapped, mipMapsStatus, |
| 522 | texSwizzle, outSwizzle, fit, budgeted, isProtected, surfaceFlags)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 525 | return sk_sp<GrTextureProxy>(new GrTextureProxy( |
| 526 | format, copyDesc, origin, mipMapped, mipMapsStatus, texSwizzle, fit, budgeted, |
| 527 | isProtected, surfaceFlags)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 528 | } |
| 529 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 530 | sk_sp<GrTextureProxy> GrProxyProvider::createCompressedTextureProxy( |
| 531 | int width, int height, SkBudgeted budgeted, SkImage::CompressionType compressionType, |
| 532 | sk_sp<SkData> data) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 533 | |
| 534 | GrSurfaceDesc desc; |
| 535 | desc.fConfig = GrCompressionTypePixelConfig(compressionType); |
| 536 | desc.fWidth = width; |
| 537 | desc.fHeight = height; |
| 538 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 539 | GrColorType grColorType = GrCompressionTypeClosestColorType(compressionType); |
| 540 | GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType); |
| 541 | |
| 542 | if (!this->caps()->isFormatTexturable(grColorType, format)) { |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 543 | return nullptr; |
| 544 | } |
| 545 | |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 546 | sk_sp<GrTextureProxy> proxy = this->createLazyProxy( |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 547 | [width, height, compressionType, budgeted, data](GrResourceProvider* resourceProvider) { |
| 548 | return LazyInstantiationResult(resourceProvider->createCompressedTexture( |
| 549 | width, height, compressionType, budgeted, data.get())); |
| 550 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 551 | format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 552 | GrMipMapsStatus::kNotAllocated, SkBackingFit::kExact, SkBudgeted::kYes, |
| 553 | GrProtected::kNo); |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 554 | |
| 555 | if (!proxy) { |
| 556 | return nullptr; |
| 557 | } |
| 558 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 559 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 560 | if (direct) { |
| 561 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 562 | // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however |
| 563 | // we're better off instantiating the proxy immediately here. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 564 | if (!proxy->priv().doLazyInstantiation(resourceProvider)) { |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 565 | return nullptr; |
| 566 | } |
| 567 | } |
| 568 | return proxy; |
| 569 | } |
| 570 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 571 | sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 572 | GrColorType grColorType, |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 573 | GrSurfaceOrigin origin, |
| 574 | GrWrapOwnership ownership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 575 | GrWrapCacheable cacheable, |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 576 | GrIOType ioType, |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 577 | ReleaseProc releaseProc, |
| 578 | ReleaseContext releaseCtx) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 579 | SkASSERT(ioType != kWrite_GrIOType); |
Robert Phillips | f9bec20 | 2018-01-16 09:21:01 -0500 | [diff] [blame] | 580 | if (this->isAbandoned()) { |
| 581 | return nullptr; |
| 582 | } |
| 583 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 584 | // This is only supported on a direct GrContext. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 585 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 586 | if (!direct) { |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 587 | return nullptr; |
| 588 | } |
| 589 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 590 | const GrCaps* caps = this->caps(); |
| 591 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 592 | SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendTex.getBackendFormat())); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 593 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 594 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 595 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 596 | sk_sp<GrTexture> tex = |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 597 | resourceProvider->wrapBackendTexture(backendTex, grColorType, |
| 598 | ownership, cacheable, ioType); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 599 | if (!tex) { |
| 600 | return nullptr; |
| 601 | } |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 602 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 603 | if (releaseProc) { |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 604 | tex->setRelease(releaseProc, releaseCtx); |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 605 | } |
| 606 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 607 | SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture |
| 608 | // Make sure we match how we created the proxy with SkBudgeted::kNo |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 609 | SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType()); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 610 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 611 | GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), grColorType); |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 612 | |
| 613 | return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 614 | } |
| 615 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 616 | sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture( |
Brian Salomon | 02bd295 | 2018-03-07 15:20:21 -0500 | [diff] [blame] | 617 | const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 618 | GrColorType colorType, GrWrapOwnership ownership, GrWrapCacheable cacheable, |
| 619 | ReleaseProc releaseProc, ReleaseContext releaseCtx) { |
Robert Phillips | f9bec20 | 2018-01-16 09:21:01 -0500 | [diff] [blame] | 620 | if (this->isAbandoned()) { |
| 621 | return nullptr; |
| 622 | } |
| 623 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 624 | // This is only supported on a direct GrContext. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 625 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 626 | if (!direct) { |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 627 | return nullptr; |
| 628 | } |
| 629 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 630 | const GrCaps* caps = this->caps(); |
| 631 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 632 | SkASSERT(caps->areColorTypeAndFormatCompatible(colorType, backendTex.getBackendFormat())); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 633 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 634 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 635 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 636 | // TODO: This should have been checked and validated before getting into GrProxyProvider. |
| 637 | if (!caps->isFormatAsColorTypeRenderable(colorType, backendTex.getBackendFormat(), sampleCnt)) { |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 638 | return nullptr; |
| 639 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 640 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 641 | sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, backendTex.getBackendFormat()); |
| 642 | SkASSERT(sampleCnt); |
| 643 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 644 | sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 645 | colorType, ownership, |
| 646 | cacheable); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 647 | if (!tex) { |
| 648 | return nullptr; |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 651 | if (releaseProc) { |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 652 | tex->setRelease(releaseProc, releaseCtx); |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 653 | } |
| 654 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 655 | SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget |
| 656 | // Make sure we match how we created the proxy with SkBudgeted::kNo |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 657 | SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType()); |
Greg Daniel | 6abda43 | 2018-02-15 14:55:00 -0500 | [diff] [blame] | 658 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 659 | GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), colorType); |
| 660 | GrSwizzle outSwizzle = caps->getOutputSwizzle(tex->backendFormat(), colorType); |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 661 | |
| 662 | return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, texSwizzle, |
| 663 | outSwizzle)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 664 | } |
| 665 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 666 | sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 667 | const GrBackendRenderTarget& backendRT, GrColorType grColorType, |
| 668 | GrSurfaceOrigin origin, ReleaseProc releaseProc, ReleaseContext releaseCtx) { |
Robert Phillips | f9bec20 | 2018-01-16 09:21:01 -0500 | [diff] [blame] | 669 | if (this->isAbandoned()) { |
| 670 | return nullptr; |
| 671 | } |
| 672 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 673 | // This is only supported on a direct GrContext. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 674 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 675 | if (!direct) { |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 676 | return nullptr; |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 677 | } |
| 678 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 679 | const GrCaps* caps = this->caps(); |
| 680 | |
| 681 | SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendRT.getBackendFormat())); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 682 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 683 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 684 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 685 | sk_sp<GrRenderTarget> rt = resourceProvider->wrapBackendRenderTarget(backendRT, grColorType); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 686 | if (!rt) { |
| 687 | return nullptr; |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 688 | } |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 689 | |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 690 | if (releaseProc) { |
Brian Salomon | 2ca31f8 | 2019-03-05 13:28:58 -0500 | [diff] [blame] | 691 | rt->setRelease(releaseProc, releaseCtx); |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 692 | } |
| 693 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 694 | SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable |
| 695 | SkASSERT(!rt->getUniqueKey().isValid()); |
| 696 | // Make sure we match how we created the proxy with SkBudgeted::kNo |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 697 | SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 698 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 699 | GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType); |
| 700 | GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType); |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 701 | |
| 702 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle, |
| 703 | outSwizzle)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 704 | } |
| 705 | |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 706 | sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 707 | const GrBackendTexture& backendTex, GrColorType grColorType, |
| 708 | GrSurfaceOrigin origin, int sampleCnt) { |
Robert Phillips | f9bec20 | 2018-01-16 09:21:01 -0500 | [diff] [blame] | 709 | if (this->isAbandoned()) { |
| 710 | return nullptr; |
| 711 | } |
| 712 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 713 | // This is only supported on a direct GrContext. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 714 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 715 | if (!direct) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 716 | return nullptr; |
| 717 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 718 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 719 | const GrCaps* caps = this->caps(); |
| 720 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 721 | SkASSERT(caps->areColorTypeAndFormatCompatible(grColorType, backendTex.getBackendFormat())); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 722 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 723 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 724 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 725 | sk_sp<GrRenderTarget> rt = |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 726 | resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt, grColorType); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 727 | if (!rt) { |
| 728 | return nullptr; |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 729 | } |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 730 | SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable |
| 731 | SkASSERT(!rt->getUniqueKey().isValid()); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 732 | // This proxy should be unbudgeted because we're just wrapping an external resource |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 733 | SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); |
Greg Daniel | f87651e | 2018-02-21 11:36:53 -0500 | [diff] [blame] | 734 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 735 | GrSwizzle texSwizzle = caps->getTextureSwizzle(rt->backendFormat(), grColorType); |
| 736 | GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType); |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 737 | |
| 738 | return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle, |
| 739 | outSwizzle)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 740 | } |
| 741 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 742 | sk_sp<GrRenderTargetProxy> GrProxyProvider::wrapVulkanSecondaryCBAsRenderTarget( |
| 743 | const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo) { |
| 744 | if (this->isAbandoned()) { |
| 745 | return nullptr; |
| 746 | } |
| 747 | |
| 748 | // This is only supported on a direct GrContext. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 749 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 750 | if (!direct) { |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 751 | return nullptr; |
| 752 | } |
| 753 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 754 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 755 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 756 | sk_sp<GrRenderTarget> rt = resourceProvider->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, |
| 757 | vkInfo); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 758 | if (!rt) { |
| 759 | return nullptr; |
| 760 | } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 761 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 762 | SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable |
| 763 | SkASSERT(!rt->getUniqueKey().isValid()); |
| 764 | // This proxy should be unbudgeted because we're just wrapping an external resource |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 765 | SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 766 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 767 | GrColorType colorType = SkColorTypeToGrColorType(imageInfo.colorType()); |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 768 | GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(rt->backendFormat(), colorType); |
| 769 | GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(rt->backendFormat(), colorType); |
| 770 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 771 | if (!this->caps()->isFormatAsColorTypeRenderable(colorType, rt->backendFormat(), |
| 772 | rt->numSamples())) { |
| 773 | return nullptr; |
| 774 | } |
| 775 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 776 | // All Vulkan surfaces uses top left origins. |
| 777 | return sk_sp<GrRenderTargetProxy>( |
| 778 | new GrRenderTargetProxy(std::move(rt), |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 779 | kTopLeft_GrSurfaceOrigin, texSwizzle, outSwizzle, |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 780 | GrRenderTargetProxy::WrapsVkSecondaryCB::kYes)); |
| 781 | } |
| 782 | |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 783 | sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 784 | const GrBackendFormat& format, |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 785 | const GrSurfaceDesc& desc, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 786 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 787 | int renderTargetSampleCnt, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 788 | GrSurfaceOrigin origin, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 789 | GrMipMapped mipMapped, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 790 | GrMipMapsStatus mipMapsStatus, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 791 | SkBackingFit fit, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 792 | SkBudgeted budgeted, |
| 793 | GrProtected isProtected) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 794 | return this->createLazyProxy(std::move(callback), format, desc, renderable, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 795 | renderTargetSampleCnt, origin, mipMapped, mipMapsStatus, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 796 | GrInternalSurfaceFlags::kNone, fit, budgeted, isProtected); |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 800 | const GrBackendFormat& format, |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 801 | const GrSurfaceDesc& desc, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 802 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 803 | int renderTargetSampleCnt, |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 804 | GrSurfaceOrigin origin, |
| 805 | GrMipMapped mipMapped, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 806 | GrMipMapsStatus mipMapsStatus, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 807 | GrInternalSurfaceFlags surfaceFlags, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 808 | SkBackingFit fit, |
| 809 | SkBudgeted budgeted, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 810 | GrProtected isProtected) { |
| 811 | // For non-ddl draws always make lazy proxy's single use. |
| 812 | LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse |
| 813 | : LazyInstantiationType::kMultipleUse; |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 814 | return this->createLazyProxy(std::move(callback), format, desc, renderable, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 815 | renderTargetSampleCnt, origin, mipMapped, mipMapsStatus, |
| 816 | surfaceFlags, fit, budgeted, isProtected, lazyType); |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, |
| 820 | const GrBackendFormat& format, |
| 821 | const GrSurfaceDesc& desc, |
| 822 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 823 | int renderTargetSampleCnt, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 824 | GrSurfaceOrigin origin, |
| 825 | GrMipMapped mipMapped, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 826 | GrMipMapsStatus mipMapsStatus, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 827 | GrInternalSurfaceFlags surfaceFlags, |
| 828 | SkBackingFit fit, |
| 829 | SkBudgeted budgeted, |
| 830 | GrProtected isProtected, |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 831 | LazyInstantiationType lazyType) { |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 832 | SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) || |
| 833 | (desc.fWidth > 0 && desc.fHeight > 0)); |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 834 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 835 | if (!format.isValid()) { |
| 836 | return nullptr; |
| 837 | } |
| 838 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 839 | if (desc.fWidth > this->caps()->maxTextureSize() || |
| 840 | desc.fHeight > this->caps()->maxTextureSize()) { |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 841 | return nullptr; |
| 842 | } |
| 843 | |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 844 | SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig)); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 845 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 846 | GrColorType colorType = GrPixelConfigToColorType(desc.fConfig); |
| 847 | GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType); |
| 848 | GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType); |
| 849 | |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 850 | return sk_sp<GrTextureProxy>((renderable == GrRenderable::kYes) |
| 851 | ? new GrTextureRenderTargetProxy( |
| 852 | std::move(callback), lazyType, format, desc, renderTargetSampleCnt, origin, |
| 853 | mipMapped, mipMapsStatus, texSwizzle, outSwizzle, fit, budgeted, isProtected, |
| 854 | surfaceFlags) |
| 855 | : new GrTextureProxy( |
| 856 | std::move(callback), lazyType, format, desc, origin, mipMapped, mipMapsStatus, |
| 857 | texSwizzle, fit, budgeted, isProtected, surfaceFlags)); |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 858 | } |
| 859 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 860 | sk_sp<GrRenderTargetProxy> GrProxyProvider::createLazyRenderTargetProxy( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 861 | LazyInstantiateCallback&& callback, const GrBackendFormat& format, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 862 | const GrSurfaceDesc& desc, int sampleCnt, GrSurfaceOrigin origin, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 863 | GrInternalSurfaceFlags surfaceFlags, const TextureInfo* textureInfo, |
| 864 | GrMipMapsStatus mipMapsStatus, SkBackingFit fit, SkBudgeted budgeted, |
| 865 | GrProtected isProtected, bool wrapsVkSecondaryCB) { |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 866 | SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) || |
| 867 | (desc.fWidth > 0 && desc.fHeight > 0)); |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 868 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 869 | if (desc.fWidth > this->caps()->maxRenderTargetSize() || |
| 870 | desc.fHeight > this->caps()->maxRenderTargetSize()) { |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 871 | return nullptr; |
| 872 | } |
| 873 | |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 874 | SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig)); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 875 | |
| 876 | using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType; |
| 877 | // For non-ddl draws always make lazy proxy's single use. |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 878 | LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse |
| 879 | : LazyInstantiationType::kMultipleUse; |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 880 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 881 | GrColorType colorType = GrPixelConfigToColorType(desc.fConfig); |
| 882 | GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType); |
| 883 | GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType); |
| 884 | |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 885 | if (textureInfo) { |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 886 | // Wrapped vulkan secondary command buffers don't support texturing since we won't have an |
| 887 | // actual VkImage to texture from. |
| 888 | SkASSERT(!wrapsVkSecondaryCB); |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 889 | return sk_sp<GrRenderTargetProxy>(new GrTextureRenderTargetProxy( |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 890 | std::move(callback), lazyType, format, desc, sampleCnt, origin, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 891 | textureInfo->fMipMapped, mipMapsStatus, texSwizzle, outSwizzle, fit, budgeted, |
| 892 | isProtected, surfaceFlags)); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 893 | } |
| 894 | |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 895 | GrRenderTargetProxy::WrapsVkSecondaryCB vkSCB = |
| 896 | wrapsVkSecondaryCB ? GrRenderTargetProxy::WrapsVkSecondaryCB::kYes |
| 897 | : GrRenderTargetProxy::WrapsVkSecondaryCB::kNo; |
| 898 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 899 | return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy( |
| 900 | std::move(callback), lazyType, format, desc, sampleCnt, origin, texSwizzle, outSwizzle, |
| 901 | fit, budgeted, isProtected, surfaceFlags, vkSCB)); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 902 | } |
| 903 | |
Chris Dalton | 19cc00f | 2019-04-15 09:06:28 -0600 | [diff] [blame] | 904 | sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 905 | LazyInstantiateCallback&& callback, const GrBackendFormat& format, GrRenderable renderable, |
| 906 | int renderTargetSampleCnt, GrProtected isProtected, GrSurfaceOrigin origin, |
| 907 | GrPixelConfig config, const GrCaps& caps) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 908 | if (!format.isValid()) { |
| 909 | return nullptr; |
| 910 | } |
| 911 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 912 | SkASSERT(renderTargetSampleCnt == 1 || renderable == GrRenderable::kYes); |
Greg Daniel | fa55f2e | 2019-06-13 15:21:38 -0400 | [diff] [blame] | 913 | SkASSERT(validate_backend_format_and_config(&caps, format, config)); |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 914 | GrSurfaceDesc desc; |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 915 | GrInternalSurfaceFlags surfaceFlags = GrInternalSurfaceFlags::kNone; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 916 | desc.fWidth = -1; |
| 917 | desc.fHeight = -1; |
| 918 | desc.fConfig = config; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 919 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 920 | GrColorType colorType = GrPixelConfigToColorType(desc.fConfig); |
| 921 | GrSwizzle texSwizzle = caps.getTextureSwizzle(format, colorType); |
| 922 | GrSwizzle outSwizzle = caps.getOutputSwizzle(format, colorType); |
| 923 | |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 924 | return sk_sp<GrTextureProxy>((GrRenderable::kYes == renderable) |
| 925 | ? new GrTextureRenderTargetProxy( |
| 926 | std::move(callback), LazyInstantiationType::kSingleUse, format, desc, |
| 927 | renderTargetSampleCnt, origin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, |
| 928 | texSwizzle, outSwizzle, SkBackingFit::kApprox, SkBudgeted::kYes, isProtected, |
| 929 | surfaceFlags) |
| 930 | : new GrTextureProxy( |
| 931 | std::move(callback), LazyInstantiationType::kSingleUse, format, desc, origin, |
| 932 | GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, texSwizzle, |
| 933 | SkBackingFit::kApprox, SkBudgeted::kYes, isProtected, surfaceFlags)); |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 934 | } |
| 935 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 936 | bool GrProxyProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 937 | const bool isInstantiated = proxy->isInstantiated(); |
Robert Phillips | db3b979 | 2018-06-12 15:18:00 -0400 | [diff] [blame] | 938 | // A proxy is functionally exact if: |
| 939 | // it is exact (obvs) |
| 940 | // when it is instantiated it will be exact (i.e., power of two dimensions) |
| 941 | // it is already instantiated and the proxy covers the entire backing surface |
| 942 | return proxy->priv().isExact() || |
| 943 | (!isInstantiated && SkIsPow2(proxy->width()) && SkIsPow2(proxy->height())) || |
| 944 | (isInstantiated && proxy->worstCaseWidth() == proxy->width() && |
| 945 | proxy->worstCaseHeight() == proxy->height()); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 946 | } |
| 947 | |
Robert Phillips | 427966a | 2018-12-20 17:20:43 -0500 | [diff] [blame] | 948 | void GrProxyProvider::processInvalidUniqueKey(const GrUniqueKey& key, GrTextureProxy* proxy, |
| 949 | InvalidateGPUResource invalidateGPUResource) { |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 950 | SkASSERT(key.isValid()); |
| 951 | |
Robert Phillips | 427966a | 2018-12-20 17:20:43 -0500 | [diff] [blame] | 952 | if (!proxy) { |
| 953 | proxy = fUniquelyKeyedProxies.find(key); |
| 954 | } |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 955 | SkASSERT(!proxy || proxy->getUniqueKey() == key); |
| 956 | |
| 957 | // Locate the corresponding GrGpuResource (if it needs to be invalidated) before clearing the |
| 958 | // proxy's unique key. We must do it in this order because 'key' may alias the proxy's key. |
| 959 | sk_sp<GrGpuResource> invalidGpuResource; |
| 960 | if (InvalidateGPUResource::kYes == invalidateGPUResource) { |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 961 | GrContext* direct = fImageContext->priv().asDirectContext(); |
| 962 | if (direct) { |
| 963 | GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); |
| 964 | invalidGpuResource = resourceProvider->findByUniqueKey<GrGpuResource>(key); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 965 | } |
| 966 | SkASSERT(!invalidGpuResource || invalidGpuResource->getUniqueKey() == key); |
| 967 | } |
Robert Phillips | 427966a | 2018-12-20 17:20:43 -0500 | [diff] [blame] | 968 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 969 | // Note: this method is called for the whole variety of GrGpuResources so often 'key' |
| 970 | // will not be in 'fUniquelyKeyedProxies'. |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 971 | if (proxy) { |
Robert Phillips | 427966a | 2018-12-20 17:20:43 -0500 | [diff] [blame] | 972 | fUniquelyKeyedProxies.remove(key); |
| 973 | proxy->cacheAccess().clearUniqueKey(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 974 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 975 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 976 | if (invalidGpuResource) { |
| 977 | invalidGpuResource->resourcePriv().removeUniqueKey(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 981 | uint32_t GrProxyProvider::contextID() const { |
| 982 | return fImageContext->priv().contextID(); |
| 983 | } |
| 984 | |
| 985 | const GrCaps* GrProxyProvider::caps() const { |
| 986 | return fImageContext->priv().caps(); |
| 987 | } |
| 988 | |
| 989 | sk_sp<const GrCaps> GrProxyProvider::refCaps() const { |
| 990 | return fImageContext->priv().refCaps(); |
| 991 | } |
| 992 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 993 | bool GrProxyProvider::isAbandoned() const { |
| 994 | return fImageContext->priv().abandoned(); |
| 995 | } |
| 996 | |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 997 | void GrProxyProvider::orphanAllUniqueKeys() { |
| 998 | UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); |
| 999 | for (UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); !iter.done(); ++iter) { |
| 1000 | GrTextureProxy& tmp = *iter; |
| 1001 | |
| 1002 | tmp.fProxyProvider = nullptr; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1006 | void GrProxyProvider::removeAllUniqueKeys() { |
| 1007 | UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); |
| 1008 | for (UniquelyKeyedProxyHash::Iter iter(&fUniquelyKeyedProxies); !iter.done(); ++iter) { |
| 1009 | GrTextureProxy& tmp = *iter; |
| 1010 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 1011 | this->processInvalidUniqueKey(tmp.getUniqueKey(), &tmp, InvalidateGPUResource::kNo); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1012 | } |
| 1013 | SkASSERT(!fUniquelyKeyedProxies.count()); |
| 1014 | } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 1015 | |
| 1016 | bool GrProxyProvider::renderingDirectly() const { |
| 1017 | return fImageContext->priv().asDirectContext(); |
| 1018 | } |