Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [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 "include/core/SkPromiseImageTexture.h" |
| 9 | #include "include/gpu/GrBackendSurface.h" |
| 10 | #include "include/gpu/GrContext.h" |
| 11 | #include "include/gpu/GrTexture.h" |
| 12 | #include "include/private/GrRecordingContext.h" |
| 13 | #include "src/core/SkBitmapCache.h" |
| 14 | #include "src/core/SkTLList.h" |
| 15 | #include "src/gpu/GrClip.h" |
| 16 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrRecordingContextPriv.h" |
| 19 | #include "src/gpu/GrRenderTargetContext.h" |
| 20 | #include "src/gpu/GrTextureAdjuster.h" |
| 21 | #include "src/gpu/effects/GrYUVtoRGBEffect.h" |
| 22 | #include "src/image/SkImage_Gpu.h" |
| 23 | #include "src/image/SkImage_GpuBase.h" |
| 24 | #include "src/image/SkReadPixelsRec.h" |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 25 | |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 26 | SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrContext> context, SkISize size, uint32_t uniqueID, |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 27 | SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 28 | : INHERITED(SkImageInfo::Make(size, ct, at, std::move(cs)), uniqueID) |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 29 | , fContext(std::move(context)) {} |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 30 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 31 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 33 | #if GR_TEST_UTILS |
| 34 | void SkImage_GpuBase::resetContext(sk_sp<GrContext> newContext) { |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 35 | SkASSERT(fContext->priv().matches(newContext.get())); |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 36 | fContext = newContext; |
| 37 | } |
| 38 | #endif |
| 39 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 40 | bool SkImage_GpuBase::ValidateBackendTexture(const GrCaps* caps, const GrBackendTexture& tex, |
| 41 | GrColorType grCT, SkColorType ct, SkAlphaType at, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 42 | sk_sp<SkColorSpace> cs) { |
| 43 | if (!tex.isValid()) { |
| 44 | return false; |
| 45 | } |
| 46 | // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to |
| 47 | // create a fake image info here. |
| 48 | SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs); |
| 49 | if (!SkImageInfoIsValid(info)) { |
| 50 | return false; |
| 51 | } |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 52 | GrBackendFormat backendFormat = tex.getBackendFormat(); |
| 53 | if (!backendFormat.isValid()) { |
| 54 | return false; |
| 55 | } |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 56 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 57 | return caps->areColorTypeAndFormatCompatible(grCT, backendFormat); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 60 | bool SkImage_GpuBase::ValidateCompressedBackendTexture(const GrCaps* caps, |
| 61 | const GrBackendTexture& tex, |
| 62 | SkAlphaType at) { |
| 63 | |
| 64 | if (!tex.isValid() || tex.width() <= 0 || tex.height() <= 0) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (tex.width() > caps->maxTextureSize() || tex.height() > caps->maxTextureSize()) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | if (at == kUnknown_SkAlphaType) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | GrBackendFormat backendFormat = tex.getBackendFormat(); |
| 77 | if (!backendFormat.isValid()) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | if (!caps->isFormatCompressed(backendFormat)) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | return true; |
| 86 | } |
| 87 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 88 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 89 | |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 90 | bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const { |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 91 | auto direct = fContext->priv().asDirectContext(); |
| 92 | if (!direct) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 93 | // DDL TODO: buffer up the readback so it occurs when the DDL is drawn? |
| 94 | return false; |
| 95 | } |
| 96 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 97 | const auto desc = SkBitmapCacheDesc::Make(this); |
| 98 | if (SkBitmapCache::Find(desc, dst)) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 99 | SkASSERT(dst->isImmutable()); |
| 100 | SkASSERT(dst->getPixels()); |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | SkBitmapCache::RecPtr rec = nullptr; |
| 105 | SkPixmap pmap; |
| 106 | if (kAllow_CachingHint == chint) { |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 107 | rec = SkBitmapCache::Alloc(desc, this->imageInfo(), &pmap); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 108 | if (!rec) { |
| 109 | return false; |
| 110 | } |
| 111 | } else { |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 112 | if (!dst->tryAllocPixels(this->imageInfo()) || !dst->peekPixels(&pmap)) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 113 | return false; |
| 114 | } |
| 115 | } |
| 116 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 117 | GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 118 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(), |
| 119 | this->colorType(), |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 120 | view.proxy()->backendFormat()); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 121 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 122 | auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 123 | this->alphaType(), this->refColorSpace()); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 124 | if (!sContext) { |
| 125 | return false; |
| 126 | } |
| 127 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 128 | if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), {0, 0})) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 129 | return false; |
| 130 | } |
| 131 | |
| 132 | if (rec) { |
| 133 | SkBitmapCache::Add(std::move(rec), dst); |
| 134 | this->notifyAddedToRasterCache(); |
| 135 | } |
| 136 | return true; |
| 137 | } |
| 138 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 139 | sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(GrRecordingContext* context, |
| 140 | const SkIRect& subset) const { |
| 141 | if (!context || !fContext->priv().matches(context)) { |
| 142 | return nullptr; |
| 143 | } |
| 144 | |
| 145 | sk_sp<GrSurfaceProxy> proxy = this->asTextureProxyRef(context); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 146 | |
Greg Daniel | 3155f7f | 2020-01-16 16:54:26 -0500 | [diff] [blame] | 147 | GrColorType grColorType = SkColorTypeToGrColorType(this->colorType()); |
| 148 | |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 149 | sk_sp<GrTextureProxy> copyProxy = |
Greg Daniel | 3155f7f | 2020-01-16 16:54:26 -0500 | [diff] [blame] | 150 | GrSurfaceProxy::Copy(context, proxy.get(), grColorType, GrMipMapped::kNo, subset, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 151 | SkBackingFit::kExact, proxy->isBudgeted()); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 152 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 153 | if (!copyProxy) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 154 | return nullptr; |
| 155 | } |
| 156 | |
Greg Daniel | 1a372c3 | 2019-12-17 13:53:38 -0500 | [diff] [blame] | 157 | const GrSurfaceProxyView& currView = this->getSurfaceProxyView(context); |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 158 | if (!currView.proxy()) { |
| 159 | return nullptr; |
| 160 | } |
| 161 | |
| 162 | GrSurfaceProxyView view(std::move(copyProxy), currView.origin(), currView.swizzle()); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 163 | // MDB: this call is okay bc we know 'sContext' was kExact |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 164 | return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, std::move(view), |
| 165 | this->colorType(), this->alphaType(), this->refColorSpace()); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 168 | bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, |
| 169 | int srcX, int srcY, CachingHint) const { |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 170 | auto direct = fContext->priv().asDirectContext(); |
| 171 | if (!direct) { |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 172 | // DDL TODO: buffer up the readback so it occurs when the DDL is drawn? |
| 173 | return false; |
| 174 | } |
| 175 | |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 176 | if (!SkImageInfoValidConversion(dstInfo, this->imageInfo())) { |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 177 | return false; |
| 178 | } |
| 179 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 180 | GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 181 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(), |
| 182 | this->colorType(), |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 183 | view.proxy()->backendFormat()); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 184 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 185 | auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 186 | this->alphaType(), this->refColorSpace()); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 187 | if (!sContext) { |
| 188 | return false; |
| 189 | } |
| 190 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 191 | return sContext->readPixels(dstInfo, dstPixels, dstRB, {srcX, srcY}); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 194 | sk_sp<GrTextureProxy> SkImage_GpuBase::asTextureProxyRef(GrRecordingContext* context, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 195 | GrSamplerState params, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 196 | SkScalar scaleAdjust[2]) const { |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 197 | if (!context || !fContext->priv().matches(context)) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 198 | SkASSERT(0); |
| 199 | return nullptr; |
| 200 | } |
| 201 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 202 | GrTextureAdjuster adjuster(fContext.get(), this->asTextureProxyRef(context), |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 203 | this->imageInfo().colorInfo(), this->uniqueID()); |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 204 | return adjuster.refTextureProxyForParams(params, scaleAdjust); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | GrBackendTexture SkImage_GpuBase::onGetBackendTexture(bool flushPendingGrContextIO, |
| 208 | GrSurfaceOrigin* origin) const { |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 209 | auto direct = fContext->priv().asDirectContext(); |
| 210 | if (!direct) { |
| 211 | // This image was created with a DDL context and cannot be instantiated. |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 212 | return GrBackendTexture(); // invalid |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 213 | } |
| 214 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 215 | sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef(direct); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 216 | SkASSERT(proxy); |
| 217 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 218 | if (!proxy->isInstantiated()) { |
| 219 | auto resourceProvider = direct->priv().resourceProvider(); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 220 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 221 | if (!proxy->instantiate(resourceProvider)) { |
| 222 | return GrBackendTexture(); // invalid |
| 223 | } |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | GrTexture* texture = proxy->peekTexture(); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 227 | if (texture) { |
| 228 | if (flushPendingGrContextIO) { |
Greg Daniel | 4aa13e7 | 2019-04-15 14:42:20 -0400 | [diff] [blame] | 229 | direct->priv().flushSurface(proxy.get()); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 230 | } |
| 231 | if (origin) { |
| 232 | *origin = proxy->origin(); |
| 233 | } |
| 234 | return texture->getBackendTexture(); |
| 235 | } |
| 236 | return GrBackendTexture(); // invalid |
| 237 | } |
| 238 | |
| 239 | GrTexture* SkImage_GpuBase::onGetTexture() const { |
| 240 | GrTextureProxy* proxy = this->peekProxy(); |
Robert Phillips | 193c421 | 2019-03-04 12:18:53 -0500 | [diff] [blame] | 241 | if (proxy && proxy->isInstantiated()) { |
| 242 | return proxy->peekTexture(); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 243 | } |
| 244 | |
Robert Phillips | 193c421 | 2019-03-04 12:18:53 -0500 | [diff] [blame] | 245 | auto direct = fContext->priv().asDirectContext(); |
| 246 | if (!direct) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 247 | // This image was created with a DDL context and cannot be instantiated. |
| 248 | return nullptr; |
| 249 | } |
| 250 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 251 | sk_sp<GrTextureProxy> proxyRef = this->asTextureProxyRef(direct); |
Robert Phillips | 193c421 | 2019-03-04 12:18:53 -0500 | [diff] [blame] | 252 | SkASSERT(proxyRef && !proxyRef->isInstantiated()); |
| 253 | |
| 254 | if (!proxyRef->instantiate(direct->priv().resourceProvider())) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 255 | return nullptr; |
| 256 | } |
| 257 | |
Robert Phillips | 193c421 | 2019-03-04 12:18:53 -0500 | [diff] [blame] | 258 | return proxyRef->peekTexture(); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 259 | } |
| 260 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 261 | bool SkImage_GpuBase::onIsValid(GrContext* context) const { |
| 262 | // The base class has already checked that context isn't abandoned (if it's not nullptr) |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 263 | if (fContext->priv().abandoned()) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 267 | if (context && !fContext->priv().matches(context)) { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 268 | return false; |
| 269 | } |
| 270 | |
| 271 | return true; |
| 272 | } |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 273 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 274 | bool SkImage_GpuBase::MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[], |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 275 | int numTextures, const SkYUVAIndex yuvaIndices[4], |
| 276 | GrSurfaceOrigin imageOrigin, |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 277 | sk_sp<GrTextureProxy> tempTextureProxies[4]) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 278 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 279 | const GrCaps* caps = ctx->priv().caps(); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 280 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 281 | for (int textureIndex = 0; textureIndex < numTextures; ++textureIndex) { |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 282 | GrBackendFormat backendFormat = yuvaTextures[textureIndex].getBackendFormat(); |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 283 | if (!backendFormat.isValid()) { |
| 284 | return false; |
| 285 | } |
Robert Phillips | 1cd1ed8 | 2019-07-23 13:21:01 -0400 | [diff] [blame] | 286 | |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame] | 287 | GrColorType grColorType = caps->getYUVAColorTypeFromBackendFormat( |
| 288 | backendFormat, |
| 289 | yuvaIndices[3].fIndex == textureIndex); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 290 | if (GrColorType::kUnknown == grColorType) { |
| 291 | return false; |
| 292 | } |
| 293 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 294 | SkASSERT(yuvaTextures[textureIndex].isValid()); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 295 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 296 | tempTextureProxies[textureIndex] = proxyProvider->wrapBackendTexture( |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 297 | yuvaTextures[textureIndex], grColorType, imageOrigin, kBorrow_GrWrapOwnership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 298 | GrWrapCacheable::kNo, kRead_GrIOType); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 299 | if (!tempTextureProxies[textureIndex]) { |
| 300 | return false; |
| 301 | } |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 302 | |
| 303 | // Check that each texture contains the channel data for the corresponding YUVA index |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 304 | auto componentFlags = GrColorTypeComponentFlags(grColorType); |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 305 | for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) { |
| 306 | if (yuvaIndices[yuvaIndex].fIndex == textureIndex) { |
| 307 | switch (yuvaIndices[yuvaIndex].fChannel) { |
| 308 | case SkColorChannel::kR: |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 309 | // TODO: Chrome needs to be patched before this can be |
| 310 | // enforced. |
| 311 | // if (!(kRed_SkColorTypeComponentFlag & componentFlags)) { |
| 312 | // return false; |
| 313 | // } |
| 314 | break; |
| 315 | case SkColorChannel::kG: |
| 316 | if (!(kGreen_SkColorTypeComponentFlag & componentFlags)) { |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 317 | return false; |
| 318 | } |
| 319 | break; |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 320 | case SkColorChannel::kB: |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 321 | if (!(kBlue_SkColorTypeComponentFlag & componentFlags)) { |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | break; |
| 325 | case SkColorChannel::kA: |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 326 | if (!(kAlpha_SkColorTypeComponentFlag & componentFlags)) { |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 327 | return false; |
| 328 | } |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | bool SkImage_GpuBase::RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext, |
| 339 | const SkRect& rect, SkYUVColorSpace yuvColorSpace, |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 340 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 341 | const sk_sp<GrTextureProxy> proxies[4], |
| 342 | const SkYUVAIndex yuvaIndices[4]) { |
| 343 | SkASSERT(renderTargetContext); |
| 344 | if (!renderTargetContext->asSurfaceProxy()) { |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | GrPaint paint; |
| 349 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 350 | |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 351 | auto fp = GrYUVtoRGBEffect::Make(proxies, yuvaIndices, yuvColorSpace, |
| 352 | GrSamplerState::Filter::kNearest); |
| 353 | if (colorSpaceXform) { |
| 354 | fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform)); |
| 355 | } |
| 356 | paint.addColorFragmentProcessor(std::move(fp)); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 357 | |
| 358 | renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), rect); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 362 | sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 363 | GrContext* context, int width, int height, GrSurfaceOrigin origin, GrColorType colorType, |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 364 | GrBackendFormat backendFormat, GrMipMapped mipMapped, |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 365 | PromiseImageTextureFulfillProc fulfillProc, |
| 366 | PromiseImageTextureReleaseProc releaseProc, |
| 367 | PromiseImageTextureDoneProc doneProc, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 368 | PromiseImageTextureContext textureContext, |
| 369 | PromiseImageApiVersion version) { |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 370 | SkASSERT(context); |
| 371 | SkASSERT(width > 0 && height > 0); |
| 372 | SkASSERT(doneProc); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 373 | SkASSERT(colorType != GrColorType::kUnknown); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 374 | |
| 375 | if (!fulfillProc || !releaseProc) { |
| 376 | doneProc(textureContext); |
| 377 | return nullptr; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 378 | } |
| 379 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 380 | if (mipMapped == GrMipMapped::kYes && |
| 381 | GrTextureTypeHasRestrictedSampling(backendFormat.textureType())) { |
| 382 | // It is invalid to have a GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE and have mips as |
| 383 | // well. |
| 384 | doneProc(textureContext); |
| 385 | return nullptr; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 386 | } |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 387 | |
| 388 | /** |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 389 | * This class is the lazy instantiation callback for promise images. It manages calling the |
| 390 | * client's Fulfill, Release, and Done procs. It attempts to reuse a GrTexture instance in |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 391 | * cases where the client provides the same SkPromiseImageTexture as Fulfill results for |
| 392 | * multiple SkImages. The created GrTexture is given a key based on a unique ID associated with |
| 393 | * the SkPromiseImageTexture. |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 394 | * |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 395 | * The GrTexutre idle proc mechanism is used to call the Release and Done procs. We use this |
| 396 | * instead of the GrSurface release proc because the GrTexture is cached and therefore may |
| 397 | * outlive the proxy into which this callback is installed. |
| 398 | * |
| 399 | * A key invalidation message is installed on the SkPromiseImageTexture so that the GrTexture |
| 400 | * is deleted once it can no longer be used to instantiate a proxy. |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 401 | */ |
| 402 | class PromiseLazyInstantiateCallback { |
| 403 | public: |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 404 | PromiseLazyInstantiateCallback(PromiseImageTextureFulfillProc fulfillProc, |
| 405 | PromiseImageTextureReleaseProc releaseProc, |
| 406 | PromiseImageTextureDoneProc doneProc, |
| 407 | PromiseImageTextureContext context, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 408 | GrColorType colorType, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 409 | PromiseImageApiVersion version) |
| 410 | : fFulfillProc(fulfillProc) |
| 411 | , fReleaseProc(releaseProc) |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 412 | , fColorType(colorType) |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 413 | , fVersion(version) { |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 414 | fDoneCallback = sk_make_sp<GrRefCntedCallback>(doneProc, context); |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 415 | } |
| 416 | PromiseLazyInstantiateCallback(PromiseLazyInstantiateCallback&&) = default; |
| 417 | PromiseLazyInstantiateCallback(const PromiseLazyInstantiateCallback&) { |
| 418 | // Because we get wrapped in std::function we must be copyable. But we should never |
| 419 | // be copied. |
| 420 | SkASSERT(false); |
| 421 | } |
| 422 | PromiseLazyInstantiateCallback& operator=(PromiseLazyInstantiateCallback&&) = default; |
| 423 | PromiseLazyInstantiateCallback& operator=(const PromiseLazyInstantiateCallback&) { |
| 424 | SkASSERT(false); |
| 425 | return *this; |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 426 | } |
Brian Salomon | 553610d | 2019-01-14 17:34:12 -0500 | [diff] [blame] | 427 | |
Brian Salomon | 88b8d11 | 2019-03-07 15:25:34 +0000 | [diff] [blame] | 428 | ~PromiseLazyInstantiateCallback() { |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 429 | // Our destructor can run on any thread. We trigger the unref of fTexture by message. |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 430 | // This unreffed texture pointer is a real problem! When the context has been |
| 431 | // abandoned, the GrTexture pointed to by this pointer is deleted! Due to virtual |
| 432 | // inheritance any manipulation of this pointer at that point will cause a crash. |
| 433 | // For now we "work around" the problem by just passing it, untouched, into the |
| 434 | // message bus but this very fragile. |
| 435 | // In the future the GrSurface class hierarchy refactoring should eliminate this |
| 436 | // difficulty by removing the virtual inheritance. |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 437 | if (fTexture) { |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 438 | SkMessageBus<GrTextureFreedMessage>::Post({fTexture, fTextureContextID}); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 439 | } |
Brian Salomon | 88b8d11 | 2019-03-07 15:25:34 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 442 | GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 443 | // We use the unique key in a way that is unrelated to the SkImage-based key that the |
| 444 | // proxy may receive, hence kUnsynced. |
| 445 | static constexpr auto kKeySyncMode = |
| 446 | GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced; |
| 447 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 448 | // In order to make the SkImage "thread safe" we rely on holding an extra ref to the |
| 449 | // texture in the callback and signalling the unref via a message to the resource cache. |
| 450 | // We need to extend the callback's lifetime to that of the proxy. |
| 451 | static constexpr auto kReleaseCallbackOnInstantiation = false; |
| 452 | |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 453 | // Our proxy is getting instantiated for the second+ time. We are only allowed to call |
| 454 | // Fulfill once. So return our cached result. |
| 455 | if (fTexture) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 456 | return {sk_ref_sp(fTexture), kReleaseCallbackOnInstantiation, kKeySyncMode}; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 457 | } else if (fColorType == GrColorType::kUnknown) { |
Brian Salomon | d538d3d | 2019-04-04 12:18:17 -0400 | [diff] [blame] | 458 | // We've already called fulfill and it failed. Our contract says that we should only |
| 459 | // call each callback once. |
| 460 | return {}; |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 461 | } |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 462 | SkASSERT(fDoneCallback); |
| 463 | PromiseImageTextureContext textureContext = fDoneCallback->context(); |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 464 | sk_sp<SkPromiseImageTexture> promiseTexture = fFulfillProc(textureContext); |
| 465 | // From here on out our contract is that the release proc must be called, even if |
| 466 | // the return from fulfill was invalid or we fail for some other reason. |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 467 | auto releaseCallback = sk_make_sp<GrRefCntedCallback>(fReleaseProc, textureContext); |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 468 | if (!promiseTexture) { |
Brian Salomon | d538d3d | 2019-04-04 12:18:17 -0400 | [diff] [blame] | 469 | // This records that we have failed. |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 470 | fColorType = GrColorType::kUnknown; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 471 | return {}; |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 472 | } |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 473 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 474 | const GrBackendTexture& backendTexture = promiseTexture->backendTexture(); |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 475 | if (!backendTexture.isValid()) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 476 | return {}; |
Brian Salomon | 559c617 | 2019-01-10 10:23:44 -0500 | [diff] [blame] | 477 | } |
| 478 | |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 479 | sk_sp<GrTexture> tex; |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 480 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
Brian Salomon | 7d88f31 | 2019-02-28 10:03:03 -0500 | [diff] [blame] | 481 | GrUniqueKey key; |
| 482 | GrUniqueKey::Builder builder(&key, kDomain, 2, "promise"); |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 483 | builder[0] = promiseTexture->uniqueID(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 484 | builder[1] = (uint32_t) fColorType; |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 485 | builder.finish(); |
Brian Salomon | 0d60676 | 2019-01-25 09:58:38 -0500 | [diff] [blame] | 486 | // A texture with this key may already exist from a different instance of this lazy |
| 487 | // callback. This could happen if the client fulfills a promise image with a texture |
| 488 | // that was previously used to fulfill a different promise image. |
Brian Salomon | 7d88f31 | 2019-02-28 10:03:03 -0500 | [diff] [blame] | 489 | if (auto surf = resourceProvider->findByUniqueKey<GrSurface>(key)) { |
Brian Salomon | 0d60676 | 2019-01-25 09:58:38 -0500 | [diff] [blame] | 490 | tex = sk_ref_sp(surf->asTexture()); |
| 491 | SkASSERT(tex); |
| 492 | } else { |
| 493 | if ((tex = resourceProvider->wrapBackendTexture( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 494 | backendTexture, fColorType, kBorrow_GrWrapOwnership, |
| 495 | GrWrapCacheable::kYes, kRead_GrIOType))) { |
Brian Salomon | 7d88f31 | 2019-02-28 10:03:03 -0500 | [diff] [blame] | 496 | tex->resourcePriv().setUniqueKey(key); |
Brian Salomon | 0d60676 | 2019-01-25 09:58:38 -0500 | [diff] [blame] | 497 | } else { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 498 | return {}; |
Brian Salomon | 0d60676 | 2019-01-25 09:58:38 -0500 | [diff] [blame] | 499 | } |
| 500 | } |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 501 | auto releaseIdleState = fVersion == PromiseImageApiVersion::kLegacy |
| 502 | ? GrTexture::IdleState::kFinished |
| 503 | : GrTexture::IdleState::kFlushed; |
| 504 | tex->addIdleProc(std::move(releaseCallback), releaseIdleState); |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 505 | tex->addIdleProc(std::move(fDoneCallback), GrTexture::IdleState::kFinished); |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 506 | promiseTexture->addKeyToInvalidate(tex->getContext()->priv().contextID(), key); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 507 | fTexture = tex.get(); |
| 508 | // We need to hold on to the GrTexture in case our proxy gets reinstantiated. However, |
| 509 | // we can't unref in our destructor because we may be on another thread then. So we |
| 510 | // let the cache know it is waiting on an unref message. We will send that message from |
| 511 | // our destructor. |
| 512 | GrContext* context = fTexture->getContext(); |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 513 | context->priv().getResourceCache()->insertDelayedTextureUnref(fTexture); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 514 | fTextureContextID = context->priv().contextID(); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 515 | return {std::move(tex), kReleaseCallbackOnInstantiation, kKeySyncMode}; |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | private: |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 519 | PromiseImageTextureFulfillProc fFulfillProc; |
| 520 | PromiseImageTextureReleaseProc fReleaseProc; |
| 521 | sk_sp<GrRefCntedCallback> fDoneCallback; |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 522 | GrTexture* fTexture = nullptr; |
| 523 | uint32_t fTextureContextID = SK_InvalidUniqueID; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 524 | GrColorType fColorType; |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 525 | PromiseImageApiVersion fVersion; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 526 | } callback(fulfillProc, releaseProc, doneProc, textureContext, colorType, version); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 527 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 528 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 529 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 530 | GrPixelConfig config = context->priv().caps()->getConfigFromBackendFormat( |
| 531 | backendFormat, |
| 532 | colorType); |
| 533 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 534 | GrSurfaceDesc desc; |
| 535 | desc.fWidth = width; |
| 536 | desc.fHeight = height; |
| 537 | desc.fConfig = config; |
| 538 | |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 539 | // Ganesh assumes that, when wrapping a mipmapped backend texture from a client, that its |
| 540 | // mipmaps are fully fleshed out. |
| 541 | GrMipMapsStatus mipMapsStatus = (GrMipMapped::kYes == mipMapped) |
| 542 | ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; |
| 543 | |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame^] | 544 | GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(backendFormat, colorType); |
| 545 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 546 | // We pass kReadOnly here since we should treat content of the client's texture as immutable. |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 547 | // The promise API provides no way for the client to indicated that the texture is protected. |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 548 | return proxyProvider->createLazyProxy( |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame^] | 549 | std::move(callback), backendFormat, desc, readSwizzle, GrRenderable::kNo, 1, origin, |
| 550 | mipMapped, mipMapsStatus, GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, |
| 551 | SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 552 | } |