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