blob: 033b77855961cd2e9ec07651b1df79f6a56d1e9c [file] [log] [blame]
Jim Van Verth8026ccc2018-10-04 13:10:39 -04001/*
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
8#include "GrBackendSurface.h"
9#include "GrClip.h"
10#include "GrContext.h"
11#include "GrContextPriv.h"
12#include "GrRenderTargetContext.h"
13#include "GrTexture.h"
14#include "GrTextureAdjuster.h"
Jim Van Verth0e671942018-11-09 12:03:57 -050015#include "effects/GrYUVtoRGBEffect.h"
Jim Van Verth8026ccc2018-10-04 13:10:39 -040016#include "SkBitmapCache.h"
17#include "SkImage_Gpu.h"
18#include "SkImage_GpuBase.h"
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040019#include "SkReadPixelsRec.h"
Jim Van Verth8026ccc2018-10-04 13:10:39 -040020
21SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrContext> context, int width, int height, uint32_t uniqueID,
22 SkAlphaType at, SkBudgeted budgeted, sk_sp<SkColorSpace> cs)
23 : INHERITED(width, height, uniqueID)
24 , fContext(std::move(context))
25 , fAlphaType(at)
26 , fBudgeted(budgeted)
27 , fColorSpace(std::move(cs)) {}
28
29SkImage_GpuBase::~SkImage_GpuBase() {}
30
31//////////////////////////////////////////////////////////////////////////////////////////////////
32
33bool SkImage_GpuBase::ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
34 GrPixelConfig* config, SkColorType ct, SkAlphaType at,
35 sk_sp<SkColorSpace> cs) {
36 if (!tex.isValid()) {
37 return false;
38 }
39 // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to
40 // create a fake image info here.
41 SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs);
42 if (!SkImageInfoIsValid(info)) {
43 return false;
44 }
Brian Salomonf391d0f2018-12-14 09:18:50 -050045 GrBackendFormat backendFormat = tex.getBackendFormat();
46 if (!backendFormat.isValid()) {
47 return false;
48 }
49 *config = ctx->contextPriv().caps()->getConfigFromBackendFormat(backendFormat, ct);
50 return *config != kUnknown_GrPixelConfig;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040051}
52
53//////////////////////////////////////////////////////////////////////////////////////////////////
54
Brian Osmane50cdf02018-10-19 13:02:14 -040055bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040056 if (!fContext->contextPriv().resourceProvider()) {
57 // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
58 return false;
59 }
60
Jim Van Verth8026ccc2018-10-04 13:10:39 -040061 const auto desc = SkBitmapCacheDesc::Make(this);
62 if (SkBitmapCache::Find(desc, dst)) {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040063 SkASSERT(dst->isImmutable());
64 SkASSERT(dst->getPixels());
65 return true;
66 }
67
68 SkBitmapCache::RecPtr rec = nullptr;
69 SkPixmap pmap;
70 if (kAllow_CachingHint == chint) {
71 rec = SkBitmapCache::Alloc(desc, this->onImageInfo(), &pmap);
72 if (!rec) {
73 return false;
74 }
75 } else {
76 if (!dst->tryAllocPixels(this->onImageInfo()) || !dst->peekPixels(&pmap)) {
77 return false;
78 }
79 }
80
81 sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
82 this->asTextureProxyRef(),
83 fColorSpace);
84 if (!sContext) {
85 return false;
86 }
87
88 if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), 0, 0)) {
89 return false;
90 }
91
92 if (rec) {
93 SkBitmapCache::Add(std::move(rec), dst);
94 this->notifyAddedToRasterCache();
95 }
96 return true;
97}
98
99sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(const SkIRect& subset) const {
100 sk_sp<GrSurfaceProxy> proxy = this->asTextureProxyRef();
101
102 GrSurfaceDesc desc;
103 desc.fWidth = subset.width();
104 desc.fHeight = subset.height();
105 desc.fConfig = proxy->config();
106
Greg Daniel4065d452018-11-16 15:43:41 -0500107 GrBackendFormat format = proxy->backendFormat().makeTexture2D();
108 if (!format.isValid()) {
109 return nullptr;
110 }
111
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400112 sk_sp<GrSurfaceContext> sContext(fContext->contextPriv().makeDeferredSurfaceContext(
Greg Daniel4065d452018-11-16 15:43:41 -0500113 format, desc, proxy->origin(), GrMipMapped::kNo, SkBackingFit::kExact, fBudgeted));
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400114 if (!sContext) {
115 return nullptr;
116 }
117
118 if (!sContext->copy(proxy.get(), subset, SkIPoint::Make(0, 0))) {
119 return nullptr;
120 }
121
122 // MDB: this call is okay bc we know 'sContext' was kExact
123 return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
124 fAlphaType, sContext->asTextureProxyRef(),
125 fColorSpace, fBudgeted);
126}
127
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400128static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
129 switch (info.colorType()) {
130 case kRGBA_8888_SkColorType:
131 case kBGRA_8888_SkColorType:
132 break;
133 default:
134 return; // nothing to do
135 }
136
137 // SkColor is not necesarily RGBA or BGRA, but it is one of them on little-endian,
138 // and in either case, the alpha-byte is always in the same place, so we can safely call
139 // SkPreMultiplyColor()
140 //
141 SkColor* row = (SkColor*)pixels;
142 for (int y = 0; y < info.height(); ++y) {
143 for (int x = 0; x < info.width(); ++x) {
144 row[x] = SkPreMultiplyColor(row[x]);
145 }
146 row = (SkColor*)((char*)(row)+rowBytes);
147 }
148}
149
150bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
151 int srcX, int srcY, CachingHint) const {
152 if (!fContext->contextPriv().resourceProvider()) {
153 // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
154 return false;
155 }
156
157 if (!SkImageInfoValidConversion(dstInfo, this->onImageInfo())) {
158 return false;
159 }
160
161 SkReadPixelsRec rec(dstInfo, dstPixels, dstRB, srcX, srcY);
162 if (!rec.trim(this->width(), this->height())) {
163 return false;
164 }
165
166 // TODO: this seems to duplicate code in GrTextureContext::onReadPixels and
167 // GrRenderTargetContext::onReadPixels
168 uint32_t flags = 0;
169 if (kUnpremul_SkAlphaType == rec.fInfo.alphaType() && kPremul_SkAlphaType == fAlphaType) {
170 // let the GPU perform this transformation for us
171 flags = GrContextPriv::kUnpremul_PixelOpsFlag;
172 }
173
174 sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
175 this->asTextureProxyRef(), fColorSpace);
176 if (!sContext) {
177 return false;
178 }
179
180 if (!sContext->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY, flags)) {
181 return false;
182 }
183
184 // do we have to manually fix-up the alpha channel?
185 // src dst
186 // unpremul premul fix manually
187 // premul unpremul done by kUnpremul_PixelOpsFlag
188 // all other combos need to change.
189 //
190 // Should this be handled by Ganesh? todo:?
191 //
192 if (kPremul_SkAlphaType == rec.fInfo.alphaType() && kUnpremul_SkAlphaType == fAlphaType) {
193 apply_premul(rec.fInfo, rec.fPixels, rec.fRowBytes);
194 }
195 return true;
196}
197
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400198sk_sp<GrTextureProxy> SkImage_GpuBase::asTextureProxyRef(GrContext* context,
199 const GrSamplerState& params,
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400200 SkScalar scaleAdjust[2]) const {
201 if (context->uniqueID() != fContext->uniqueID()) {
202 SkASSERT(0);
203 return nullptr;
204 }
205
206 GrTextureAdjuster adjuster(fContext.get(), this->asTextureProxyRef(), fAlphaType,
207 this->uniqueID(), fColorSpace.get());
Brian Osman6064e1c2018-10-19 14:27:54 -0400208 return adjuster.refTextureProxyForParams(params, scaleAdjust);
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400209}
210
211GrBackendTexture SkImage_GpuBase::onGetBackendTexture(bool flushPendingGrContextIO,
212 GrSurfaceOrigin* origin) const {
213 sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
214 SkASSERT(proxy);
215
216 if (!fContext->contextPriv().resourceProvider() && !proxy->isInstantiated()) {
217 // This image was created with a DDL context and cannot be instantiated.
218 return GrBackendTexture();
219}
220
221 if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) {
222 return GrBackendTexture(); // invalid
223 }
224
225 GrTexture* texture = proxy->peekTexture();
226
227 if (texture) {
228 if (flushPendingGrContextIO) {
229 fContext->contextPriv().prepareSurfaceForExternalIO(proxy.get());
230 }
231 if (origin) {
232 *origin = proxy->origin();
233 }
234 return texture->getBackendTexture();
235 }
236 return GrBackendTexture(); // invalid
237}
238
239GrTexture* SkImage_GpuBase::onGetTexture() const {
240 GrTextureProxy* proxy = this->peekProxy();
241 if (!proxy) {
242 return nullptr;
243 }
244
245 sk_sp<GrTextureProxy> proxyRef = this->asTextureProxyRef();
246 if (!fContext->contextPriv().resourceProvider() && !proxyRef->isInstantiated()) {
247 // This image was created with a DDL context and cannot be instantiated.
248 return nullptr;
249 }
250
251 if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) {
252 return nullptr;
253 }
254
255 return proxy->peekTexture();
256}
257
258sk_sp<SkImage> SkImage_GpuBase::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
Brian Osmanbe686f02018-10-12 11:18:02 -0400259 auto xform = GrColorSpaceXformEffect::Make(fColorSpace.get(), fAlphaType,
260 target.get(), fAlphaType);
Brian Osmanb4ae4992018-10-18 11:16:14 -0400261 SkASSERT(xform);
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400262
Brian Osman9c111352018-10-16 10:18:26 -0400263 sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
264
Greg Daniel4065d452018-11-16 15:43:41 -0500265 GrBackendFormat format = proxy->backendFormat().makeTexture2D();
266 if (!format.isValid()) {
267 return nullptr;
268 }
269
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400270 sk_sp<GrRenderTargetContext> renderTargetContext(
Brian Osman9c111352018-10-16 10:18:26 -0400271 fContext->contextPriv().makeDeferredRenderTargetContextWithFallback(
Greg Daniel4065d452018-11-16 15:43:41 -0500272 format, SkBackingFit::kExact, this->width(), this->height(),
273 proxy->config(), nullptr));
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400274 if (!renderTargetContext) {
275 return nullptr;
276 }
277
278 GrPaint paint;
279 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
Brian Osman9c111352018-10-16 10:18:26 -0400280 paint.addColorTextureProcessor(std::move(proxy), SkMatrix::I());
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400281 paint.addColorFragmentProcessor(std::move(xform));
282
Brian Osmanb4ae4992018-10-18 11:16:14 -0400283 renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
284 SkRect::MakeIWH(this->width(), this->height()));
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400285 if (!renderTargetContext->asTextureProxy()) {
286 return nullptr;
287 }
288
289 // MDB: this call is okay bc we know 'renderTargetContext' was exact
290 return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
Brian Osmanbe686f02018-10-12 11:18:02 -0400291 fAlphaType, renderTargetContext->asTextureProxyRef(),
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400292 std::move(target), fBudgeted);
293}
294
295bool SkImage_GpuBase::onIsValid(GrContext* context) const {
296 // The base class has already checked that context isn't abandoned (if it's not nullptr)
297 if (fContext->abandoned()) {
298 return false;
299 }
300
301 if (context && context != fContext.get()) {
302 return false;
303 }
304
305 return true;
306}
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400307
Jim Van Verth0e671942018-11-09 12:03:57 -0500308bool SkImage_GpuBase::MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
Jim Van Verth53275362018-11-09 15:42:35 -0500309 int numTextures, const SkYUVAIndex yuvaIndices[4],
310 GrSurfaceOrigin imageOrigin,
Jim Van Verth0e671942018-11-09 12:03:57 -0500311 sk_sp<GrTextureProxy> tempTextureProxies[4]) {
312 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
313
314 // We need to make a copy of the input backend textures because we need to preserve the result
315 // of validate_backend_texture.
316 GrBackendTexture yuvaTexturesCopy[4];
317 for (int textureIndex = 0; textureIndex < numTextures; ++textureIndex) {
318 yuvaTexturesCopy[textureIndex] = yuvaTextures[textureIndex];
Brian Salomonf391d0f2018-12-14 09:18:50 -0500319 GrBackendFormat backendFormat = yuvaTexturesCopy[textureIndex].getBackendFormat();
320 if (!backendFormat.isValid()) {
321 return false;
322 }
323 yuvaTexturesCopy[textureIndex].fConfig =
324 ctx->contextPriv().caps()->getYUVAConfigFromBackendFormat(backendFormat);
325 if (yuvaTexturesCopy[textureIndex].fConfig == kUnknown_GrPixelConfig) {
Jim Van Verth0e671942018-11-09 12:03:57 -0500326 return false;
327 }
328 SkASSERT(yuvaTexturesCopy[textureIndex].isValid());
329
330 tempTextureProxies[textureIndex] =
Brian Salomonc67c31c2018-12-06 10:00:03 -0500331 proxyProvider->wrapBackendTexture(yuvaTexturesCopy[textureIndex], imageOrigin,
332 kBorrow_GrWrapOwnership, kRead_GrIOType);
Jim Van Verth0e671942018-11-09 12:03:57 -0500333 if (!tempTextureProxies[textureIndex]) {
334 return false;
335 }
Jim Van Verth53275362018-11-09 15:42:35 -0500336
337 // Check that each texture contains the channel data for the corresponding YUVA index
338 GrPixelConfig config = yuvaTexturesCopy[textureIndex].fConfig;
339 for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) {
340 if (yuvaIndices[yuvaIndex].fIndex == textureIndex) {
341 switch (yuvaIndices[yuvaIndex].fChannel) {
342 case SkColorChannel::kR:
343 if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
344 return false;
345 }
346 break;
347 case SkColorChannel::kG:
348 case SkColorChannel::kB:
349 if (kAlpha_8_as_Alpha_GrPixelConfig == config ||
350 kAlpha_8_as_Red_GrPixelConfig == config) {
351 return false;
352 }
353 break;
354 case SkColorChannel::kA:
355 default:
356 if (kRGB_888_GrPixelConfig == config) {
357 return false;
358 }
359 break;
360 }
361 }
362 }
Jim Van Verth0e671942018-11-09 12:03:57 -0500363 }
364
365 return true;
366}
367
368bool SkImage_GpuBase::RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
369 const SkRect& rect, SkYUVColorSpace yuvColorSpace,
370 const sk_sp<GrTextureProxy> proxies[4],
371 const SkYUVAIndex yuvaIndices[4]) {
372 SkASSERT(renderTargetContext);
373 if (!renderTargetContext->asSurfaceProxy()) {
374 return false;
375 }
376
377 GrPaint paint;
378 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
379
Jim Van Verth0e671942018-11-09 12:03:57 -0500380 paint.addColorFragmentProcessor(GrYUVtoRGBEffect::Make(proxies, yuvaIndices,
381 yuvColorSpace,
382 GrSamplerState::Filter::kNearest));
383
384 renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), rect);
385
386 // DDL TODO: in the promise image version we must not flush here
387 ctx->contextPriv().flushSurfaceWrites(renderTargetContext->asSurfaceProxy());
388
389 return true;
390}
391
Brian Salomonbe5a0932018-12-10 10:03:26 -0500392sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
393 GrContext* context, int width, int height, GrSurfaceOrigin origin, GrPixelConfig config,
394 GrBackendFormat backendFormat, GrMipMapped mipMapped,
395 SkImage_GpuBase::TextureFulfillProc fulfillProc,
396 SkImage_GpuBase::TextureReleaseProc releaseProc, SkImage_GpuBase::PromiseDoneProc doneProc,
397 SkImage_GpuBase::TextureContext textureContext) {
398 SkASSERT(context);
399 SkASSERT(width > 0 && height > 0);
400 SkASSERT(doneProc);
Brian Salomonf391d0f2018-12-14 09:18:50 -0500401 SkASSERT(config != kUnknown_GrPixelConfig);
Brian Salomonbe5a0932018-12-10 10:03:26 -0500402
403 if (!fulfillProc || !releaseProc) {
404 doneProc(textureContext);
405 return nullptr;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400406 }
407
Brian Salomonbe5a0932018-12-10 10:03:26 -0500408 if (mipMapped == GrMipMapped::kYes &&
409 GrTextureTypeHasRestrictedSampling(backendFormat.textureType())) {
410 // It is invalid to have a GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE and have mips as
411 // well.
412 doneProc(textureContext);
413 return nullptr;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400414 }
Brian Salomonbe5a0932018-12-10 10:03:26 -0500415
416 /**
417 * This helper class manages the ref counting for the the ReleaseProc and DoneProc for promise
418 * images. It holds a weak ref on the ReleaseProc (hard refs are owned by GrTextures). The weak
419 * ref allows us to reuse an outstanding ReleaseProc (because we dropped our GrTexture but the
420 * GrTexture isn't done on the GPU) without needing to call FulfillProc again. It also holds a
421 * hard ref on the DoneProc. The idea is that after every flush we may call the ReleaseProc so
422 * that the client can free up their GPU memory if they want to. The life time of the DoneProc
423 * matches that of any outstanding ReleaseProc as well as the PromiseLazyInstantiateCallback.
424 * Thus we won't call the DoneProc until all ReleaseProcs are finished and we are finished with
425 * the PromiseImageHelper (i.e. won't call FulfillProc again).
426 */
427 class PromiseLazyInstantiateCallback {
428 public:
429 PromiseLazyInstantiateCallback(SkImage_GpuBase::TextureFulfillProc fulfillProc,
430 SkImage_GpuBase::TextureReleaseProc releaseProc,
431 SkImage_GpuBase::PromiseDoneProc doneProc,
432 SkImage_GpuBase::TextureContext context,
433 GrPixelConfig config)
434 : fFulfillProc(fulfillProc)
435 , fReleaseProc(releaseProc)
436 , fContext(context)
437 , fConfig(config) {
438 fDoneHelper.reset(new GrReleaseProcHelper(doneProc, context));
439 }
440
441 sk_sp<GrSurface> operator()(GrResourceProvider* resourceProvider) {
442 if (!resourceProvider) {
443 this->reset();
444 return sk_sp<GrTexture>();
445 }
446
447 // Releases the promise helper if there are no outstanding hard refs. This means that we
448 // don't have any ReleaseProcs waiting to be called so we will need to do a fulfill.
449 if (fReleaseHelper && fReleaseHelper->weak_expired()) {
450 this->resetReleaseHelper();
451 }
452
453 sk_sp<GrTexture> tex;
454 if (!fReleaseHelper) {
455 fFulfillProc(fContext, &fBackendTex);
456 fBackendTex.fConfig = fConfig;
457 if (!fBackendTex.isValid()) {
458 // Even though the GrBackendTexture is not valid, we must call the release
459 // proc to keep our contract of always calling Fulfill and Release in pairs.
460 fReleaseProc(fContext);
461 return sk_sp<GrTexture>();
462 }
463
464 tex = resourceProvider->wrapBackendTexture(fBackendTex, kBorrow_GrWrapOwnership,
465 kRead_GrIOType);
466 if (!tex) {
467 // Even though the GrBackendTexture is not valid, we must call the release
468 // proc to keep our contract of always calling Fulfill and Release in pairs.
469 fReleaseProc(fContext);
470 return sk_sp<GrTexture>();
471 }
472 fReleaseHelper =
473 new SkPromiseReleaseProcHelper(fReleaseProc, fContext, fDoneHelper);
474 // Take a weak ref
475 fReleaseHelper->weak_ref();
476 } else {
477 SkASSERT(fBackendTex.isValid());
478 tex = resourceProvider->wrapBackendTexture(fBackendTex, kBorrow_GrWrapOwnership,
479 kRead_GrIOType);
480 if (!tex) {
481 // We weren't able to make a texture here, but since we are in this branch
482 // of the calls (promiseHelper.fReleaseHelper is valid) there is already a
483 // texture out there which will call the release proc so we don't need to
484 // call it here.
485 return sk_sp<GrTexture>();
486 }
487
488 SkAssertResult(fReleaseHelper->try_ref());
489 }
490 SkASSERT(tex);
491 // Pass the hard ref off to the texture
492 tex->setRelease(sk_sp<GrReleaseProcHelper>(fReleaseHelper));
493 return std::move(tex);
494 }
495
496 private:
497 void reset() {
498 this->resetReleaseHelper();
499 fDoneHelper.reset();
500 }
501
502 // Weak unrefs fReleaseHelper and sets it to null
503 void resetReleaseHelper() {
504 if (fReleaseHelper) {
505 fReleaseHelper->weak_unref();
506 fReleaseHelper = nullptr;
507 }
508 }
509
510 SkImage_GpuBase::TextureFulfillProc fFulfillProc;
511 SkImage_GpuBase::TextureReleaseProc fReleaseProc;
512 SkImage_GpuBase::TextureContext fContext;
513
514 GrPixelConfig fConfig;
515 // We cache the GrBackendTexture so that if we deleted the GrTexture but the the release
516 // proc has yet not been called (this can happen on Vulkan), then we can create a new
517 // texture without needing to call the fulfill proc again.
518 GrBackendTexture fBackendTex;
519 // The fReleaseHelper is used to track a weak ref on the release proc. This helps us make
520 // sure we are always pairing fulfill and release proc calls correctly.
521 SkPromiseReleaseProcHelper* fReleaseHelper = nullptr;
522 // We don't want to call the fDoneHelper until we are done with the PromiseImageHelper and
523 // all ReleaseHelpers are finished. Thus we hold a hard ref here and we will pass a hard ref
524 // to each fReleaseHelper we make.
525 sk_sp<GrReleaseProcHelper> fDoneHelper;
526 } callback(fulfillProc, releaseProc, doneProc, textureContext, config);
527
528 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
529
530 GrSurfaceDesc desc;
531 desc.fWidth = width;
532 desc.fHeight = height;
533 desc.fConfig = config;
534
535 // We pass kReadOnly here since we should treat content of the client's texture as immutable.
536 return proxyProvider->createLazyProxy(std::move(callback), backendFormat, desc, origin,
537 mipMapped, GrInternalSurfaceFlags::kReadOnly,
538 SkBackingFit::kExact, SkBudgeted::kNo,
539 GrSurfaceProxy::LazyInstantiationType::kDeinstantiate);
Jim Van Verth8bbce0e2018-10-08 14:34:52 -0400540}