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