blob: 4dde34b3bd7700c3d921bf4eb8e83cfc4202f087 [file] [log] [blame]
Brian Osman45580d32016-11-23 09:37:01 -05001/*
2 * Copyright 2016 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 Daniel46cfbc62019-06-07 11:43:30 -04008#include "src/gpu/GrSurfaceContext.h"
9
John Stilesfbd050b2020-08-03 13:21:46 -040010#include <memory>
11
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040012#include "include/gpu/GrDirectContext.h"
13#include "include/gpu/GrRecordingContext.h"
Greg Daniel6eb8c242019-06-05 10:22:24 -040014#include "src/core/SkAutoPixmapStorage.h"
Brian Salomon2c673402021-04-02 14:36:58 -040015#include "src/core/SkMipmap.h"
Brian Salomon63a0a752020-06-26 13:32:09 -040016#include "src/core/SkYUVMath.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040017#include "src/gpu/GrAuditTrail.h"
Brian Salomon1c86b632020-12-11 12:36:01 -050018#include "src/gpu/GrColorSpaceXform.h"
Brian Salomonf30b1c12019-06-20 12:25:02 -040019#include "src/gpu/GrDataUtils.h"
Adlai Hollera0693042020-10-14 11:23:11 -040020#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrDrawingManager.h"
Greg Daniel6eb8c242019-06-05 10:22:24 -040022#include "src/gpu/GrGpu.h"
Brian Salomonf2ebdd92019-09-30 12:15:30 -040023#include "src/gpu/GrImageInfo.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040024#include "src/gpu/GrProxyProvider.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrRecordingContextPriv.h"
Robert Phillips1a82a4e2021-07-01 10:27:44 -040026#include "src/gpu/GrResourceProvider.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050027#include "src/gpu/GrSurfaceDrawContext.h"
Brian Salomonbacbb922021-01-21 19:48:00 -050028#include "src/gpu/GrSurfaceFillContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "src/gpu/SkGr.h"
Brian Salomone9ad9982019-07-22 16:17:41 -040030#include "src/gpu/effects/GrBicubicEffect.h"
Robert Phillips550de7f2021-07-06 16:28:52 -040031#include "src/gpu/effects/GrTextureEffect.h"
Brian Osman45580d32016-11-23 09:37:01 -050032
Brian Salomond63638b2021-03-05 14:00:07 -050033#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
34#define RETURN_FALSE_IF_ABANDONED if (this->fContext->abandoned()) { return false; }
35#define RETURN_NULLPTR_IF_ABANDONED if (this->fContext->abandoned()) { return nullptr; }
Brian Osman45580d32016-11-23 09:37:01 -050036
Greg Danielbfa19c42019-12-19 16:41:40 -050037std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
Greg Daniel3912a4b2020-01-14 09:56:04 -050038 GrSurfaceProxyView readView,
Brian Salomon14f99fc2020-12-07 12:19:47 -050039 const GrColorInfo& info) {
Greg Daniele20fcad2020-01-08 11:52:34 -050040 // It is probably not necessary to check if the context is abandoned here since uses of the
41 // GrSurfaceContext which need the context will mostly likely fail later on without an issue.
42 // However having this hear adds some reassurance in case there is a path doesn't handle an
43 // abandoned context correctly. It also lets us early out of some extra work.
Robert Phillips9eb00022020-06-30 15:30:12 -040044 if (context->abandoned()) {
Greg Daniele20fcad2020-01-08 11:52:34 -050045 return nullptr;
46 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050047 GrSurfaceProxy* proxy = readView.proxy();
Greg Danielbfa19c42019-12-19 16:41:40 -050048 SkASSERT(proxy && proxy->asTextureProxy());
49
Greg Danielbfa19c42019-12-19 16:41:40 -050050 std::unique_ptr<GrSurfaceContext> surfaceContext;
Greg Daniel3912a4b2020-01-14 09:56:04 -050051 if (proxy->asRenderTargetProxy()) {
Brian Salomon8afde5f2020-04-01 16:22:00 -040052 // Will we ever want a swizzle that is not the default write swizzle for the format and
Greg Danielbfa19c42019-12-19 16:41:40 -050053 // colorType here? If so we will need to manually pass that in.
Brian Salomonc5243782020-04-02 12:50:34 -040054 GrSwizzle writeSwizzle;
Brian Salomon14f99fc2020-12-07 12:19:47 -050055 if (info.colorType() != GrColorType::kUnknown) {
56 writeSwizzle = context->priv().caps()->getWriteSwizzle(proxy->backendFormat(),
57 info.colorType());
Brian Salomonc5243782020-04-02 12:50:34 -040058 }
Brian Salomon8afde5f2020-04-01 16:22:00 -040059 GrSurfaceProxyView writeView(readView.refProxy(), readView.origin(), writeSwizzle);
Brian Salomon590f5672020-12-16 11:44:47 -050060 if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
61 surfaceContext = std::make_unique<GrSurfaceDrawContext>(context,
62 std::move(readView),
63 std::move(writeView),
64 info.colorType(),
65 info.refColorSpace(),
Chris Daltonf5b87f92021-04-19 17:27:09 -060066 SkSurfaceProps());
Brian Salomon590f5672020-12-16 11:44:47 -050067 } else {
68 surfaceContext = std::make_unique<GrSurfaceFillContext>(context,
69 std::move(readView),
70 std::move(writeView),
71 info);
72 }
Greg Danielbfa19c42019-12-19 16:41:40 -050073 } else {
Brian Salomon14f99fc2020-12-07 12:19:47 -050074 surfaceContext = std::make_unique<GrSurfaceContext>(context, std::move(readView), info);
Greg Danielbfa19c42019-12-19 16:41:40 -050075 }
Robert Phillips07f0e412020-01-17 15:20:00 -050076 SkDEBUGCODE(surfaceContext->validate();)
Greg Danielbfa19c42019-12-19 16:41:40 -050077 return surfaceContext;
78}
79
Brian Salomona56a7462020-02-07 14:17:25 -050080std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
Brian Salomon14f99fc2020-12-07 12:19:47 -050081 const GrImageInfo& info,
Brian Salomona56a7462020-02-07 14:17:25 -050082 const GrBackendFormat& format,
Brian Salomona56a7462020-02-07 14:17:25 -050083 SkBackingFit fit,
Brian Salomon14f99fc2020-12-07 12:19:47 -050084 GrSurfaceOrigin origin,
85 GrRenderable renderable,
86 int sampleCount,
87 GrMipmapped mipmapped,
88 GrProtected isProtected,
Brian Salomona56a7462020-02-07 14:17:25 -050089 SkBudgeted budgeted) {
Brian Salomon14f99fc2020-12-07 12:19:47 -050090 SkASSERT(context);
91 SkASSERT(renderable == GrRenderable::kYes || sampleCount == 1);
92 if (context->abandoned()) {
93 return nullptr;
Brian Salomond005b692020-04-01 15:47:05 -040094 }
Brian Salomon14f99fc2020-12-07 12:19:47 -050095 sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(format,
96 info.dimensions(),
97 renderable,
98 sampleCount,
99 mipmapped,
100 fit,
101 budgeted,
102 isProtected);
Greg Danielbfa19c42019-12-19 16:41:40 -0500103 if (!proxy) {
104 return nullptr;
105 }
106
Brian Salomon14f99fc2020-12-07 12:19:47 -0500107 GrSwizzle swizzle;
108 if (info.colorType() != GrColorType::kUnknown &&
109 !context->priv().caps()->isFormatCompressed(format)) {
110 swizzle = context->priv().caps()->getReadSwizzle(format, info.colorType());
111 }
112
Greg Daniel3912a4b2020-01-14 09:56:04 -0500113 GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
Brian Salomon14f99fc2020-12-07 12:19:47 -0500114 return GrSurfaceContext::Make(context, std::move(view), info.colorInfo());
115}
116
117std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
118 const GrImageInfo& info,
119 SkBackingFit fit,
120 GrSurfaceOrigin origin,
121 GrRenderable renderable,
122 int sampleCount,
123 GrMipmapped mipmapped,
124 GrProtected isProtected,
125 SkBudgeted budgeted) {
126 GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat(info.colorType(),
127 renderable);
128 return Make(context,
129 info,
130 format,
131 fit,
132 origin,
133 renderable,
134 sampleCount,
135 mipmapped,
136 isProtected,
137 budgeted);
Greg Danielbfa19c42019-12-19 16:41:40 -0500138}
139
Robert Phillips69893702019-02-22 11:16:30 -0500140GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context,
Greg Daniel3912a4b2020-01-14 09:56:04 -0500141 GrSurfaceProxyView readView,
Brian Salomon14f99fc2020-12-07 12:19:47 -0500142 const GrColorInfo& info)
143 : fContext(context), fReadView(std::move(readView)), fColorInfo(info) {
Robert Phillips9eb00022020-06-30 15:30:12 -0400144 SkASSERT(!context->abandoned());
Greg Daniele20fcad2020-01-08 11:52:34 -0500145}
Robert Phillipsa90aa2b2017-04-10 08:19:26 -0400146
Brian Salomon4d2d6f42019-07-26 14:15:11 -0400147const GrCaps* GrSurfaceContext::caps() const { return fContext->priv().caps(); }
148
Robert Phillips0d075de2019-03-04 11:08:13 -0500149GrAuditTrail* GrSurfaceContext::auditTrail() {
150 return fContext->priv().auditTrail();
151}
152
153GrDrawingManager* GrSurfaceContext::drawingManager() {
154 return fContext->priv().drawingManager();
155}
156
157const GrDrawingManager* GrSurfaceContext::drawingManager() const {
158 return fContext->priv().drawingManager();
159}
160
161#ifdef SK_DEBUG
Brian Salomon70fe17e2020-11-30 14:33:58 -0500162GrSingleOwner* GrSurfaceContext::singleOwner() const { return fContext->priv().singleOwner(); }
Robert Phillips0d075de2019-03-04 11:08:13 -0500163#endif
Greg Daniel6eb8c242019-06-05 10:22:24 -0400164
Brian Salomondd4087d2020-12-23 20:36:44 -0500165static bool alpha_types_compatible(SkAlphaType srcAlphaType, SkAlphaType dstAlphaType) {
166 // If both alpha types are kUnknown things make sense. If not, it's too underspecified.
167 return (srcAlphaType == kUnknown_SkAlphaType) == (dstAlphaType == kUnknown_SkAlphaType);
168}
169
170bool GrSurfaceContext::readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoint pt) {
Brian Salomon1d435302019-07-01 13:05:28 -0400171 ASSERT_SINGLE_OWNER
172 RETURN_FALSE_IF_ABANDONED
173 SkDEBUGCODE(this->validate();)
174 GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels");
Adlai Hollerbcfc5542020-08-27 12:44:07 -0400175 if (!fContext->priv().matches(dContext)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400176 return false;
177 }
Brian Salomon46f63232021-01-25 10:13:35 -0500178
179 if (dst.colorType() == GrColorType::kUnknown) {
180 return false;
181 }
182
Brian Salomonc24c8ef2021-02-01 13:32:30 -0500183 if (dst.rowBytes() % dst.info().bpp()) {
184 return false;
185 }
186
Brian Salomondd4087d2020-12-23 20:36:44 -0500187 dst = dst.clip(this->dimensions(), &pt);
188 if (!dst.hasPixels()) {
Brian Salomon1d435302019-07-01 13:05:28 -0400189 return false;
190 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500191 if (!alpha_types_compatible(this->colorInfo().alphaType(), dst.alphaType())) {
Brian Salomon1d435302019-07-01 13:05:28 -0400192 return false;
193 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500194 // We allow unknown alpha types but only if both src and dst are unknown. Otherwise, it's too
195 // weird to reason about what should be expected.
Greg Daniel6eb8c242019-06-05 10:22:24 -0400196
Brian Salomon982127b2021-01-21 10:43:35 -0500197 sk_sp<GrSurfaceProxy> srcProxy = this->asSurfaceProxyRef();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400198
Stephen White3c0a50f2020-01-16 18:19:54 -0500199 if (srcProxy->framebufferOnly()) {
200 return false;
201 }
202
Greg Daniel6eb8c242019-06-05 10:22:24 -0400203 // MDB TODO: delay this instantiation until later in the method
Adlai Hollerc95b5892020-08-11 12:02:22 -0400204 if (!srcProxy->instantiate(dContext->priv().resourceProvider())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400205 return false;
206 }
207
208 GrSurface* srcSurface = srcProxy->peekSurface();
209
Brian Salomondd4087d2020-12-23 20:36:44 -0500210 SkColorSpaceXformSteps::Flags flags =
211 SkColorSpaceXformSteps{this->colorInfo(), dst.info()}.flags;
Mike Klein7321e6a2019-12-03 11:08:40 -0600212 bool unpremul = flags.unpremul,
213 needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
214 premul = flags.premul;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400215
Adlai Hollerc95b5892020-08-11 12:02:22 -0400216 const GrCaps* caps = dContext->priv().caps();
Robert Phillips07f0e412020-01-17 15:20:00 -0500217 bool srcIsCompressed = caps->isFormatCompressed(srcSurface->backendFormat());
Greg Daniel6eb8c242019-06-05 10:22:24 -0400218 // This is the getImageData equivalent to the canvas2D putImageData fast path. We probably don't
219 // care so much about getImageData performance. However, in order to ensure putImageData/
220 // getImageData in "legacy" mode are round-trippable we use the GPU to do the complementary
221 // unpremul step to writeSurfacePixels's premul step (which is determined empirically in
222 // fContext->vaildaPMUPMConversionExists()).
Greg Daniel0258c902019-08-01 13:08:33 -0400223 GrBackendFormat defaultRGBAFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
224 GrRenderable::kYes);
Greg Danielc71c7962020-01-14 16:44:18 -0500225 GrColorType srcColorType = this->colorInfo().colorType();
Brian Salomon1d435302019-07-01 13:05:28 -0400226 bool canvas2DFastPath = unpremul && !needColorConversion &&
Brian Salomondd4087d2020-12-23 20:36:44 -0500227 (GrColorType::kRGBA_8888 == dst.colorType() ||
228 GrColorType::kBGRA_8888 == dst.colorType()) &&
Brian Salomon1d435302019-07-01 13:05:28 -0400229 SkToBool(srcProxy->asTextureProxy()) &&
Greg Danielc71c7962020-01-14 16:44:18 -0500230 (srcColorType == GrColorType::kRGBA_8888 ||
231 srcColorType == GrColorType::kBGRA_8888) &&
Greg Daniel0258c902019-08-01 13:08:33 -0400232 defaultRGBAFormat.isValid() &&
Adlai Hollerc95b5892020-08-11 12:02:22 -0400233 dContext->priv().validPMUPMConversionExists();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400234
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400235 auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);
Brian Salomondc0710f2019-07-01 14:59:32 -0400236 if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400237 return false;
238 }
239
Brian Salomondc0710f2019-07-01 14:59:32 -0400240 if (readFlag == GrCaps::SurfaceReadPixelsSupport::kCopyToTexture2D || canvas2DFastPath) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400241 std::unique_ptr<GrSurfaceContext> tempCtx;
242 if (this->asTextureProxy()) {
243 GrColorType colorType = (canvas2DFastPath || srcIsCompressed)
244 ? GrColorType::kRGBA_8888
245 : this->colorInfo().colorType();
Brian Salomondd4087d2020-12-23 20:36:44 -0500246 SkAlphaType alphaType = canvas2DFastPath ? dst.alphaType()
Brian Salomon590f5672020-12-16 11:44:47 -0500247 : this->colorInfo().alphaType();
248 GrImageInfo tempInfo(colorType,
249 alphaType,
250 this->colorInfo().refColorSpace(),
Brian Salomondd4087d2020-12-23 20:36:44 -0500251 dst.dimensions());
Brian Salomon590f5672020-12-16 11:44:47 -0500252 auto sfc = GrSurfaceFillContext::Make(dContext, tempInfo, SkBackingFit::kApprox);
253 if (!sfc) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400254 return false;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400255 }
Brian Salomon72c7b982020-10-06 10:07:38 -0400256
257 std::unique_ptr<GrFragmentProcessor> fp;
258 if (canvas2DFastPath) {
259 fp = dContext->priv().createPMToUPMEffect(GrTextureEffect::Make(
260 this->readSurfaceView(), this->colorInfo().alphaType()));
Brian Salomondd4087d2020-12-23 20:36:44 -0500261 if (dst.colorType() == GrColorType::kBGRA_8888) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400262 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
Brian Salomondd4087d2020-12-23 20:36:44 -0500263 dst = GrPixmap(dst.info().makeColorType(GrColorType::kRGBA_8888),
264 dst.addr(),
265 dst.rowBytes());
Brian Salomon72c7b982020-10-06 10:07:38 -0400266 }
Brian Salomon72c7b982020-10-06 10:07:38 -0400267 } else {
268 fp = GrTextureEffect::Make(this->readSurfaceView(), this->colorInfo().alphaType());
269 }
270 if (!fp) {
271 return false;
272 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500273 sfc->fillRectToRectWithFP(SkIRect::MakePtSize(pt, dst.dimensions()),
274 SkIRect::MakeSize(dst.dimensions()),
Brian Salomon590f5672020-12-16 11:44:47 -0500275 std::move(fp));
Brian Salomon72c7b982020-10-06 10:07:38 -0400276 pt = {0, 0};
Brian Salomon590f5672020-12-16 11:44:47 -0500277 tempCtx = std::move(sfc);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400278 } else {
Brian Salomon72c7b982020-10-06 10:07:38 -0400279 auto restrictions = this->caps()->getDstCopyRestrictions(this->asRenderTargetProxy(),
280 this->colorInfo().colorType());
281 sk_sp<GrSurfaceProxy> copy;
282 static constexpr auto kFit = SkBackingFit::kExact;
283 static constexpr auto kBudgeted = SkBudgeted::kYes;
284 static constexpr auto kMipMapped = GrMipMapped::kNo;
285 if (restrictions.fMustCopyWholeSrc) {
Brian Salomon982127b2021-01-21 10:43:35 -0500286 copy = GrSurfaceProxy::Copy(fContext,
287 std::move(srcProxy),
288 this->origin(),
289 kMipMapped,
290 kFit,
Brian Salomon72c7b982020-10-06 10:07:38 -0400291 kBudgeted);
292 } else {
Brian Salomondd4087d2020-12-23 20:36:44 -0500293 auto srcRect = SkIRect::MakePtSize(pt, dst.dimensions());
Brian Salomon982127b2021-01-21 10:43:35 -0500294 copy = GrSurfaceProxy::Copy(fContext,
295 std::move(srcProxy),
296 this->origin(),
297 kMipMapped,
298 srcRect,
299 kFit,
300 kBudgeted,
301 restrictions.fRectsMustMatch);
Brian Salomon72c7b982020-10-06 10:07:38 -0400302 pt = {0, 0};
303 }
304 if (!copy) {
305 return false;
306 }
307 GrSurfaceProxyView view{std::move(copy), this->origin(), this->readSwizzle()};
Brian Salomon14f99fc2020-12-07 12:19:47 -0500308 tempCtx = GrSurfaceContext::Make(dContext, std::move(view), this->colorInfo());
Brian Salomon72c7b982020-10-06 10:07:38 -0400309 SkASSERT(tempCtx);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400310 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500311 return tempCtx->readPixels(dContext, dst, pt);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400312 }
313
Greg Danielb8d84f82020-02-13 14:25:00 -0500314 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400315
Brian Salomon1d435302019-07-01 13:05:28 -0400316 auto supportedRead = caps->supportedReadPixelsColorType(
Brian Salomondd4087d2020-12-23 20:36:44 -0500317 this->colorInfo().colorType(), srcProxy->backendFormat(), dst.colorType());
Brian Salomon1d435302019-07-01 13:05:28 -0400318
Brian Salomondd4087d2020-12-23 20:36:44 -0500319 bool makeTight =
320 !caps->readPixelsRowBytesSupport() && dst.rowBytes() != dst.info().minRowBytes();
Brian Salomon1047a492019-07-02 12:25:21 -0400321
322 bool convert = unpremul || premul || needColorConversion || flip || makeTight ||
Brian Salomondd4087d2020-12-23 20:36:44 -0500323 (dst.colorType() != supportedRead.fColorType);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400324
Brian Salomonf30b1c12019-06-20 12:25:02 -0400325 std::unique_ptr<char[]> tmpPixels;
Brian Salomondd4087d2020-12-23 20:36:44 -0500326 GrPixmap tmp;
327 void* readDst = dst.addr();
328 size_t readRB = dst.rowBytes();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400329 if (convert) {
Brian Salomondd4087d2020-12-23 20:36:44 -0500330 GrImageInfo tmpInfo(supportedRead.fColorType,
331 this->colorInfo().alphaType(),
332 this->colorInfo().refColorSpace(),
333 dst.dimensions());
Brian Salomon1d435302019-07-01 13:05:28 -0400334 size_t tmpRB = tmpInfo.minRowBytes();
335 size_t size = tmpRB * tmpInfo.height();
336 // Chrome MSAN bots require the data to be initialized (hence the ()).
John Stilesfbd050b2020-08-03 13:21:46 -0400337 tmpPixels = std::make_unique<char[]>(size);
Brian Salomondd4087d2020-12-23 20:36:44 -0500338 tmp = {tmpInfo, tmpPixels.get(), tmpRB};
Brian Salomonf30b1c12019-06-20 12:25:02 -0400339
Brian Salomonf30b1c12019-06-20 12:25:02 -0400340 readDst = tmpPixels.get();
Brian Salomon1d435302019-07-01 13:05:28 -0400341 readRB = tmpRB;
Brian Salomondd4087d2020-12-23 20:36:44 -0500342 pt.fY = flip ? srcSurface->height() - pt.fY - dst.height() : pt.fY;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400343 }
344
Brian Salomon982127b2021-01-21 10:43:35 -0500345 dContext->priv().flushSurface(srcProxy.get());
Adlai Hollerc95b5892020-08-11 12:02:22 -0400346 dContext->submit();
Brian Salomone2078f12021-05-24 12:40:46 -0400347 if (!dContext->priv().getGpu()->readPixels(srcSurface,
348 SkIRect::MakePtSize(pt, dst.dimensions()),
Brian Salomondd4087d2020-12-23 20:36:44 -0500349 this->colorInfo().colorType(),
Brian Salomone2078f12021-05-24 12:40:46 -0400350 supportedRead.fColorType,
351 readDst,
352 readRB)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400353 return false;
354 }
355
Brian Salomondd4087d2020-12-23 20:36:44 -0500356 if (tmp.hasPixels()) {
357 return GrConvertPixels(dst, tmp, flip);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400358 }
359 return true;
360}
Robert Phillips0d075de2019-03-04 11:08:13 -0500361
Brian Salomonea1d39b2021-04-01 17:06:52 -0400362bool GrSurfaceContext::writePixels(GrDirectContext* dContext,
363 GrCPixmap src,
Brian Salomon75ee7372021-04-06 15:04:35 -0400364 SkIPoint dstPt) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400365 ASSERT_SINGLE_OWNER
366 RETURN_FALSE_IF_ABANDONED
367 SkDEBUGCODE(this->validate();)
Brian Salomon2c673402021-04-02 14:36:58 -0400368
369 src = src.clip(this->dimensions(), &dstPt);
370 if (!src.hasPixels()) {
371 return false;
372 }
373 if (!src.info().bpp() || src.rowBytes() % src.info().bpp()) {
374 return false;
375 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400376 return this->internalWritePixels(dContext, &src, 1, dstPt);
Brian Salomon2c673402021-04-02 14:36:58 -0400377}
378
379bool GrSurfaceContext::writePixels(GrDirectContext* dContext,
380 const GrCPixmap src[],
Brian Salomon75ee7372021-04-06 15:04:35 -0400381 int numLevels) {
Brian Salomon2c673402021-04-02 14:36:58 -0400382 ASSERT_SINGLE_OWNER
383 RETURN_FALSE_IF_ABANDONED
384 SkDEBUGCODE(this->validate();)
385
386 SkASSERT(dContext);
387 SkASSERT(numLevels >= 1);
388 SkASSERT(src);
389
390 if (numLevels == 1) {
391 if (src->dimensions() != this->dimensions()) {
392 return false;
393 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400394 return this->writePixels(dContext, src[0], {0, 0});
Brian Salomon2c673402021-04-02 14:36:58 -0400395 }
396 if (!this->asTextureProxy() || this->asTextureProxy()->proxyMipmapped() == GrMipmapped::kNo) {
397 return false;
398 }
399
400 SkISize dims = this->dimensions();
401 if (numLevels != SkMipmap::ComputeLevelCount(dims) + 1) {
402 return false;
403 }
404 for (int i = 0; i < numLevels; ++i) {
405 if (src[i].colorInfo() != src[0].colorInfo()) {
406 return false;
407 }
408 if (dims != src[i].dimensions()) {
409 return false;
410 }
411 if (!src[i].info().bpp() || src[i].rowBytes() % src[i].info().bpp()) {
412 return false;
413 }
414 dims = {std::max(1, dims.width()/2), std::max(1, dims.height()/2)};
415 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400416 return this->internalWritePixels(dContext, src, numLevels, {0, 0});
Brian Salomon2c673402021-04-02 14:36:58 -0400417}
418
419bool GrSurfaceContext::internalWritePixels(GrDirectContext* dContext,
420 const GrCPixmap src[],
421 int numLevels,
Brian Salomon75ee7372021-04-06 15:04:35 -0400422 SkIPoint pt) {
Brian Salomon2c673402021-04-02 14:36:58 -0400423 GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::internalWritePixels");
424
425 SkASSERT(numLevels >= 1);
426 SkASSERT(src);
427
428 // We can either write to a subset or write MIP levels, but not both.
429 SkASSERT((src[0].dimensions() == this->dimensions() && pt.isZero()) || numLevels == 1);
430 SkASSERT(numLevels == 1 ||
Brian Salomon7cde6c32021-04-02 15:53:42 -0400431 (this->asTextureProxy() && this->asTextureProxy()->mipmapped() == GrMipmapped::kYes));
Brian Salomon2c673402021-04-02 14:36:58 -0400432 // Our public caller should have clipped to the bounds of the surface already.
Brian Salomonea1d39b2021-04-01 17:06:52 -0400433 SkASSERT(SkIRect::MakeSize(this->dimensions()).contains(
434 SkIRect::MakePtSize(pt, src[0].dimensions())));
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400435
Adlai Hollerc95b5892020-08-11 12:02:22 -0400436 if (!dContext) {
Brian Salomonc320b152018-02-20 14:05:36 -0500437 return false;
438 }
Robert Phillips6a6de562019-02-15 15:19:15 -0500439
Brian Salomon1d435302019-07-01 13:05:28 -0400440 if (this->asSurfaceProxy()->readOnly()) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500441 return false;
442 }
443
Brian Salomon2c673402021-04-02 14:36:58 -0400444 if (src[0].colorType() == GrColorType::kUnknown) {
Brian Salomon46f63232021-01-25 10:13:35 -0500445 return false;
446 }
447
Brian Salomon2c673402021-04-02 14:36:58 -0400448 if (!alpha_types_compatible(src[0].alphaType(), this->colorInfo().alphaType())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400449 return false;
450 }
451
452 GrSurfaceProxy* dstProxy = this->asSurfaceProxy();
Stephen White3c0a50f2020-01-16 18:19:54 -0500453
454 if (dstProxy->framebufferOnly()) {
455 return false;
456 }
457
Adlai Hollerc95b5892020-08-11 12:02:22 -0400458 if (!dstProxy->instantiate(dContext->priv().resourceProvider())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400459 return false;
460 }
461
462 GrSurface* dstSurface = dstProxy->peekSurface();
463
Brian Salomondd4087d2020-12-23 20:36:44 -0500464 SkColorSpaceXformSteps::Flags flags =
Brian Salomon2c673402021-04-02 14:36:58 -0400465 SkColorSpaceXformSteps{src[0].colorInfo(), this->colorInfo()}.flags;
Mike Klein7321e6a2019-12-03 11:08:40 -0600466 bool unpremul = flags.unpremul,
467 needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
468 premul = flags.premul;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400469
Adlai Hollerc95b5892020-08-11 12:02:22 -0400470 const GrCaps* caps = dContext->priv().caps();
Greg Daniel7bfc9132019-08-14 14:23:53 -0400471
472 auto rgbaDefaultFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
473 GrRenderable::kNo);
474
Greg Danielc71c7962020-01-14 16:44:18 -0500475 GrColorType dstColorType = this->colorInfo().colorType();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400476 // For canvas2D putImageData performance we have a special code path for unpremul RGBA_8888 srcs
477 // that are premultiplied on the GPU. This is kept as narrow as possible for now.
Brian Salomon1d435302019-07-01 13:05:28 -0400478 bool canvas2DFastPath = !caps->avoidWritePixelsFastPath() && premul && !needColorConversion &&
Brian Salomon2c673402021-04-02 14:36:58 -0400479 (src[0].colorType() == GrColorType::kRGBA_8888 ||
480 src[0].colorType() == GrColorType::kBGRA_8888) &&
Brian Salomon590f5672020-12-16 11:44:47 -0500481 this->asFillContext() &&
Greg Danielc71c7962020-01-14 16:44:18 -0500482 (dstColorType == GrColorType::kRGBA_8888 ||
483 dstColorType == GrColorType::kBGRA_8888) &&
Greg Daniel7bfc9132019-08-14 14:23:53 -0400484 rgbaDefaultFormat.isValid() &&
Adlai Hollerc95b5892020-08-11 12:02:22 -0400485 dContext->priv().validPMUPMConversionExists();
Brian Salomon2c673402021-04-02 14:36:58 -0400486 // Drawing code path doesn't support writing to levels and doesn't support inserting layout
487 // transitions.
Brian Salomon75ee7372021-04-06 15:04:35 -0400488 if ((!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) && numLevels == 1) {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500489 GrColorInfo tempColorInfo;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400490 GrBackendFormat format;
Greg Danielbfa19c42019-12-19 16:41:40 -0500491 GrSwizzle tempReadSwizzle;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400492 if (canvas2DFastPath) {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500493 tempColorInfo = {GrColorType::kRGBA_8888,
494 kUnpremul_SkAlphaType,
495 this->colorInfo().refColorSpace()};
Greg Daniel7bfc9132019-08-14 14:23:53 -0400496 format = rgbaDefaultFormat;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400497 } else {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500498 tempColorInfo = this->colorInfo();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400499 format = dstProxy->backendFormat().makeTexture2D();
500 if (!format.isValid()) {
501 return false;
502 }
Greg Danielbfa19c42019-12-19 16:41:40 -0500503 tempReadSwizzle = this->readSwizzle();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400504 }
505
Greg Daniel2e52ad12019-06-13 10:04:16 -0400506 // It is more efficient for us to write pixels into a top left origin so we prefer that.
507 // However, if the final proxy isn't a render target then we must use a copy to move the
508 // data into it which requires the origins to match. If the final proxy is a render target
509 // we can use a draw instead which doesn't have this origin restriction. Thus for render
510 // targets we will use top left and otherwise we will make the origins match.
Brian Salomonf30b1c12019-06-20 12:25:02 -0400511 GrSurfaceOrigin tempOrigin =
Brian Salomon590f5672020-12-16 11:44:47 -0500512 this->asFillContext() ? kTopLeft_GrSurfaceOrigin : this->origin();
Brian Salomon2c673402021-04-02 14:36:58 -0400513 auto tempProxy = dContext->priv().proxyProvider()->createProxy(format,
514 src[0].dimensions(),
515 GrRenderable::kNo,
516 1,
517 GrMipmapped::kNo,
518 SkBackingFit::kApprox,
519 SkBudgeted::kYes,
520 GrProtected::kNo);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400521 if (!tempProxy) {
522 return false;
523 }
Greg Daniel3912a4b2020-01-14 09:56:04 -0500524 GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle);
Brian Salomon14f99fc2020-12-07 12:19:47 -0500525 GrSurfaceContext tempCtx(dContext, tempView, tempColorInfo);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400526
527 // In the fast path we always write the srcData to the temp context as though it were RGBA.
528 // When the data is really BGRA the write will cause the R and B channels to be swapped in
529 // the intermediate surface which gets corrected by a swizzle effect when drawing to the
530 // dst.
Brian Salomon2c673402021-04-02 14:36:58 -0400531 GrCPixmap origSrcBase = src[0];
532 GrCPixmap srcBase = origSrcBase;
Brian Salomon1d435302019-07-01 13:05:28 -0400533 if (canvas2DFastPath) {
Brian Salomon2c673402021-04-02 14:36:58 -0400534 srcBase = GrCPixmap(origSrcBase.info().makeColorType(GrColorType::kRGBA_8888),
535 origSrcBase.addr(),
536 origSrcBase.rowBytes());
Brian Salomon1d435302019-07-01 13:05:28 -0400537 }
Brian Salomon2c673402021-04-02 14:36:58 -0400538 if (!tempCtx.writePixels(dContext, srcBase, {0, 0})) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400539 return false;
540 }
541
Brian Salomon590f5672020-12-16 11:44:47 -0500542 if (this->asFillContext()) {
Greg Daniel46cfbc62019-06-07 11:43:30 -0400543 std::unique_ptr<GrFragmentProcessor> fp;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400544 if (canvas2DFastPath) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400545 fp = dContext->priv().createUPMToPMEffect(
Brian Salomon14f99fc2020-12-07 12:19:47 -0500546 GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType()));
Brian Salomon1d435302019-07-01 13:05:28 -0400547 // Important: check the original src color type here!
Brian Salomon2c673402021-04-02 14:36:58 -0400548 if (origSrcBase.colorType() == GrColorType::kBGRA_8888) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400549 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
550 }
551 } else {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500552 fp = GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType());
Greg Daniel6eb8c242019-06-05 10:22:24 -0400553 }
554 if (!fp) {
555 return false;
556 }
Brian Salomon2c673402021-04-02 14:36:58 -0400557 this->asFillContext()->fillRectToRectWithFP(
558 SkIRect::MakeSize(srcBase.dimensions()),
559 SkIRect::MakePtSize(pt, srcBase.dimensions()),
560 std::move(fp));
Greg Daniel6eb8c242019-06-05 10:22:24 -0400561 } else {
Brian Salomon2c673402021-04-02 14:36:58 -0400562 SkIRect srcRect = SkIRect::MakeSize(srcBase.dimensions());
Brian Salomon1d435302019-07-01 13:05:28 -0400563 SkIPoint dstPoint = SkIPoint::Make(pt.fX, pt.fY);
Brian Salomon982127b2021-01-21 10:43:35 -0500564 if (!this->copy(std::move(tempProxy), srcRect, dstPoint)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400565 return false;
566 }
Greg Daniel6eb8c242019-06-05 10:22:24 -0400567 }
568 return true;
569 }
570
Brian Salomon2c673402021-04-02 14:36:58 -0400571 GrColorType srcColorType = src[0].colorType();
572 auto [allowedColorType, _] =
Brian Salomon4bc0c1f2019-09-30 15:12:27 -0400573 caps->supportedWritePixelsColorType(this->colorInfo().colorType(),
Brian Salomon01915c02019-08-02 09:57:21 -0400574 dstProxy->backendFormat(),
Brian Salomon2c673402021-04-02 14:36:58 -0400575 srcColorType);
Greg Danielb8d84f82020-02-13 14:25:00 -0500576 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400577
Brian Salomon2c673402021-04-02 14:36:58 -0400578 bool convertAll = premul ||
579 unpremul ||
580 needColorConversion ||
581 flip ||
582 (srcColorType != allowedColorType);
583 bool mustBeTight = !caps->writePixelsRowBytesSupport();
584 size_t tmpSize = 0;
585 if (mustBeTight || convertAll) {
586 for (int i = 0; i < numLevels; ++i) {
587 if (convertAll || (mustBeTight && src[i].rowBytes() != src[i].info().minRowBytes())) {
588 tmpSize += src[i].info().makeColorType(allowedColorType).minRowBytes()*
589 src[i].height();
590 }
591 }
Greg Daniel6eb8c242019-06-05 10:22:24 -0400592 }
593
Brian Salomon2c673402021-04-02 14:36:58 -0400594 auto tmpData = tmpSize ? SkData::MakeUninitialized(tmpSize) : nullptr;
595 void* tmp = tmpSize ? tmpData->writable_data() : nullptr;
596 SkAutoSTArray<15, GrMipLevel> srcLevels(numLevels);
597 bool ownAllStorage = true;
598 for (int i = 0; i < numLevels; ++i) {
599 if (convertAll || (mustBeTight && src[i].rowBytes() != src[i].info().minRowBytes())) {
600 GrImageInfo tmpInfo(allowedColorType,
601 this->colorInfo().alphaType(),
602 this->colorInfo().refColorSpace(),
603 src[i].dimensions());
604 auto tmpRB = tmpInfo.minRowBytes();
605 GrPixmap tmpPM(tmpInfo, tmp, tmpRB);
606 SkAssertResult(GrConvertPixels(tmpPM, src[i], flip));
607 srcLevels[i] = {tmpPM.addr(), tmpPM.rowBytes(), tmpData};
608 tmp = SkTAddOffset<void>(tmp, tmpRB*tmpPM.height());
609 } else {
610 srcLevels[i] = {src[i].addr(), src[i].rowBytes(), src[i].pixelStorage()};
611 ownAllStorage &= src[i].ownsPixels();
612 }
613 }
614 pt.fY = flip ? dstSurface->height() - pt.fY - src[0].height() : pt.fY;
615
616 if (!dContext->priv().drawingManager()->newWritePixelsTask(
Brian Salomon974c8212021-04-05 16:24:00 -0400617 sk_ref_sp(dstProxy),
618 SkIRect::MakePtSize(pt, src[0].dimensions()),
619 allowedColorType,
620 this->colorInfo().colorType(),
621 srcLevels.begin(),
Brian Salomon75ee7372021-04-06 15:04:35 -0400622 numLevels)) {
Brian Salomon2c673402021-04-02 14:36:58 -0400623 return false;
624 }
625 if (numLevels > 1) {
626 dstProxy->asTextureProxy()->markMipmapsClean();
627 }
628 if (!ownAllStorage) {
629 // If any pixmap doesn't own its pixels then we must flush so that the pixels are pushed to
630 // the GPU before we return.
Brian Salomon24949422021-02-11 09:39:46 -0500631 dContext->priv().flushSurface(dstProxy);
632 }
Brian Salomon2c673402021-04-02 14:36:58 -0400633 return true;
Brian Osman45580d32016-11-23 09:37:01 -0500634}
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400635
Adlai Hollerc95b5892020-08-11 12:02:22 -0400636void GrSurfaceContext::asyncRescaleAndReadPixels(GrDirectContext* dContext,
637 const SkImageInfo& info,
Brian Salomon63a0a752020-06-26 13:32:09 -0400638 const SkIRect& srcRect,
639 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -0500640 RescaleMode rescaleMode,
Brian Salomon63a0a752020-06-26 13:32:09 -0400641 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400642 ReadPixelsContext callbackContext) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400643 if (!dContext) {
644 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400645 return;
646 }
647 auto rt = this->asRenderTargetProxy();
648 if (rt && rt->wrapsVkSecondaryCB()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400649 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400650 return;
651 }
652 if (rt && rt->framebufferOnly()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400653 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400654 return;
655 }
656 auto dstCT = SkColorTypeToGrColorType(info.colorType());
657 if (dstCT == GrColorType::kUnknown) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400658 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400659 return;
660 }
Brian Salomon827bb722021-05-06 16:24:21 -0400661 bool needsRescale = srcRect.size() != info.dimensions() ||
662 this->origin() == kBottomLeft_GrSurfaceOrigin ||
663 this->colorInfo().alphaType() != info.alphaType() ||
664 !SkColorSpace::Equals(this->colorInfo().colorSpace(), info.colorSpace());
Brian Salomon63a0a752020-06-26 13:32:09 -0400665 auto colorTypeOfFinalContext = this->colorInfo().colorType();
666 auto backendFormatOfFinalContext = this->asSurfaceProxy()->backendFormat();
667 if (needsRescale) {
668 colorTypeOfFinalContext = dstCT;
669 backendFormatOfFinalContext =
670 this->caps()->getDefaultBackendFormat(dstCT, GrRenderable::kYes);
671 }
672 auto readInfo = this->caps()->supportedReadPixelsColorType(colorTypeOfFinalContext,
Brian Salomonbacbb922021-01-21 19:48:00 -0500673 backendFormatOfFinalContext,
674 dstCT);
Brian Salomon63a0a752020-06-26 13:32:09 -0400675 // Fail if we can't read from the source surface's color type.
676 if (readInfo.fColorType == GrColorType::kUnknown) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400677 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400678 return;
679 }
680 // Fail if read color type does not have all of dstCT's color channels and those missing color
681 // channels are in the src.
682 uint32_t dstChannels = GrColorTypeChannelFlags(dstCT);
683 uint32_t legalReadChannels = GrColorTypeChannelFlags(readInfo.fColorType);
684 uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
685 if ((~legalReadChannels & dstChannels) & srcChannels) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400686 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400687 return;
688 }
689
Brian Salomonbacbb922021-01-21 19:48:00 -0500690 std::unique_ptr<GrSurfaceFillContext> tempFC;
Brian Salomon63a0a752020-06-26 13:32:09 -0400691 int x = srcRect.fLeft;
692 int y = srcRect.fTop;
693 if (needsRescale) {
Brian Salomonbacbb922021-01-21 19:48:00 -0500694 tempFC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma, rescaleMode);
695 if (!tempFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400696 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400697 return;
698 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500699 SkASSERT(SkColorSpace::Equals(tempFC->colorInfo().colorSpace(), info.colorSpace()));
700 SkASSERT(tempFC->origin() == kTopLeft_GrSurfaceOrigin);
Brian Salomon63a0a752020-06-26 13:32:09 -0400701 x = y = 0;
Brian Salomon63a0a752020-06-26 13:32:09 -0400702 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500703 auto srcCtx = tempFC ? tempFC.get() : this;
704 return srcCtx->asyncReadPixels(dContext,
705 SkIRect::MakePtSize({x, y}, info.dimensions()),
706 info.colorType(),
707 callback,
708 callbackContext);
Brian Salomon63a0a752020-06-26 13:32:09 -0400709}
710
711class GrSurfaceContext::AsyncReadResult : public SkImage::AsyncReadResult {
712public:
Robert Phillips82ad7af2021-03-11 16:00:10 -0500713 AsyncReadResult(GrDirectContext::DirectContextID intendedRecipient)
714 : fIntendedRecipient(intendedRecipient) {
715 }
716
Brian Salomon63a0a752020-06-26 13:32:09 -0400717 ~AsyncReadResult() override {
718 for (int i = 0; i < fPlanes.count(); ++i) {
Robert Phillips82ad7af2021-03-11 16:00:10 -0500719 fPlanes[i].releaseMappedBuffer(fIntendedRecipient);
Brian Salomon63a0a752020-06-26 13:32:09 -0400720 }
721 }
722
723 int count() const override { return fPlanes.count(); }
Brian Salomonbe1084b2021-01-26 13:29:30 -0500724 const void* data(int i) const override { return fPlanes[i].data(); }
725 size_t rowBytes(int i) const override { return fPlanes[i].rowBytes(); }
Brian Salomon63a0a752020-06-26 13:32:09 -0400726
727 bool addTransferResult(const PixelTransferResult& result,
728 SkISize dimensions,
729 size_t rowBytes,
730 GrClientMappedBufferManager* manager) {
731 SkASSERT(!result.fTransferBuffer->isMapped());
732 const void* mappedData = result.fTransferBuffer->map();
733 if (!mappedData) {
734 return false;
735 }
736 if (result.fPixelConverter) {
Brian Salomonbe1084b2021-01-26 13:29:30 -0500737 size_t size = rowBytes*dimensions.height();
738 sk_sp<SkData> data = SkData::MakeUninitialized(size);
739 result.fPixelConverter(data->writable_data(), mappedData);
740 this->addCpuPlane(std::move(data), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400741 result.fTransferBuffer->unmap();
742 } else {
743 manager->insert(result.fTransferBuffer);
744 this->addMappedPlane(mappedData, rowBytes, std::move(result.fTransferBuffer));
745 }
746 return true;
747 }
748
Brian Salomonbe1084b2021-01-26 13:29:30 -0500749 void addCpuPlane(sk_sp<SkData> data, size_t rowBytes) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400750 SkASSERT(data);
751 SkASSERT(rowBytes > 0);
Brian Salomonbe1084b2021-01-26 13:29:30 -0500752 fPlanes.emplace_back(std::move(data), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400753 }
754
755private:
756 void addMappedPlane(const void* data, size_t rowBytes, sk_sp<GrGpuBuffer> mappedBuffer) {
757 SkASSERT(data);
758 SkASSERT(rowBytes > 0);
759 SkASSERT(mappedBuffer);
760 SkASSERT(mappedBuffer->isMapped());
Brian Salomonbe1084b2021-01-26 13:29:30 -0500761 fPlanes.emplace_back(std::move(mappedBuffer), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400762 }
763
Brian Salomonbe1084b2021-01-26 13:29:30 -0500764 class Plane {
765 public:
766 Plane(sk_sp<GrGpuBuffer> buffer, size_t rowBytes)
767 : fMappedBuffer(std::move(buffer)), fRowBytes(rowBytes) {}
768 Plane(sk_sp<SkData> data, size_t rowBytes) : fData(std::move(data)), fRowBytes(rowBytes) {}
769
770 Plane(const Plane&) = delete;
771 Plane(Plane&&) = default;
772
773 ~Plane() { SkASSERT(!fMappedBuffer); }
774
775 Plane& operator=(const Plane&) = delete;
776 Plane& operator=(Plane&&) = default;
777
Robert Phillips82ad7af2021-03-11 16:00:10 -0500778 void releaseMappedBuffer(GrDirectContext::DirectContextID intendedRecipient) {
Brian Salomonbe1084b2021-01-26 13:29:30 -0500779 if (fMappedBuffer) {
780 GrClientMappedBufferManager::BufferFinishedMessageBus::Post(
Robert Phillips82ad7af2021-03-11 16:00:10 -0500781 {std::move(fMappedBuffer), intendedRecipient});
Brian Salomonbe1084b2021-01-26 13:29:30 -0500782 }
783 }
784
785 const void* data() const {
786 if (fMappedBuffer) {
787 SkASSERT(!fData);
788 SkASSERT(fMappedBuffer->isMapped());
789 return fMappedBuffer->map();
790 }
791 SkASSERT(fData);
792 return fData->data();
793 }
794
795 size_t rowBytes() const { return fRowBytes; }
796
797 private:
798 sk_sp<SkData> fData;
Brian Salomon1eea1ea2021-01-26 18:12:25 +0000799 sk_sp<GrGpuBuffer> fMappedBuffer;
Brian Salomonbe1084b2021-01-26 13:29:30 -0500800 size_t fRowBytes;
Brian Salomon63a0a752020-06-26 13:32:09 -0400801 };
802 SkSTArray<3, Plane> fPlanes;
Robert Phillips82ad7af2021-03-11 16:00:10 -0500803 GrDirectContext::DirectContextID fIntendedRecipient;
Brian Salomon63a0a752020-06-26 13:32:09 -0400804};
805
Adlai Hollerc95b5892020-08-11 12:02:22 -0400806void GrSurfaceContext::asyncReadPixels(GrDirectContext* dContext,
807 const SkIRect& rect,
Brian Salomon63a0a752020-06-26 13:32:09 -0400808 SkColorType colorType,
809 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400810 ReadPixelsContext callbackContext) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400811 SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
812 SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
813
Adlai Hollerc95b5892020-08-11 12:02:22 -0400814 if (!dContext || this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
815 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400816 return;
817 }
818
Adlai Hollerc95b5892020-08-11 12:02:22 -0400819 auto mappedBufferManager = dContext->priv().clientMappedBufferManager();
Brian Salomon63a0a752020-06-26 13:32:09 -0400820
821 auto transferResult = this->transferPixels(SkColorTypeToGrColorType(colorType), rect);
822
823 if (!transferResult.fTransferBuffer) {
824 auto ii = SkImageInfo::Make(rect.size(), colorType, this->colorInfo().alphaType(),
825 this->colorInfo().refColorSpace());
Robert Phillips82ad7af2021-03-11 16:00:10 -0500826 static const GrDirectContext::DirectContextID kInvalid;
827 auto result = std::make_unique<AsyncReadResult>(kInvalid);
Brian Salomonbe1084b2021-01-26 13:29:30 -0500828 GrPixmap pm = GrPixmap::Allocate(ii);
829 result->addCpuPlane(pm.pixelStorage(), pm.rowBytes());
Brian Salomon63a0a752020-06-26 13:32:09 -0400830
Adlai Hollerc95b5892020-08-11 12:02:22 -0400831 SkIPoint pt{rect.fLeft, rect.fTop};
Brian Salomondd4087d2020-12-23 20:36:44 -0500832 if (!this->readPixels(dContext, pm, pt)) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400833 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400834 return;
835 }
Adlai Hollerc95b5892020-08-11 12:02:22 -0400836 callback(callbackContext, std::move(result));
Brian Salomon63a0a752020-06-26 13:32:09 -0400837 return;
838 }
839
840 struct FinishContext {
841 ReadPixelsCallback* fClientCallback;
842 ReadPixelsContext fClientContext;
843 SkISize fSize;
844 SkColorType fColorType;
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400845 size_t fBufferAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -0400846 GrClientMappedBufferManager* fMappedBufferManager;
847 PixelTransferResult fTransferResult;
848 };
849 // Assumption is that the caller would like to flush. We could take a parameter or require an
850 // explicit flush from the caller. We'd have to have a way to defer attaching the finish
851 // callback to GrGpu until after the next flush that flushes our op list, though.
852 auto* finishContext = new FinishContext{callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400853 callbackContext,
Brian Salomon63a0a752020-06-26 13:32:09 -0400854 rect.size(),
855 colorType,
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400856 this->caps()->transferBufferAlignment(),
Brian Salomon63a0a752020-06-26 13:32:09 -0400857 mappedBufferManager,
858 std::move(transferResult)};
859 auto finishCallback = [](GrGpuFinishedContext c) {
860 const auto* context = reinterpret_cast<const FinishContext*>(c);
Robert Phillips82ad7af2021-03-11 16:00:10 -0500861 auto manager = context->fMappedBufferManager;
862 auto result = std::make_unique<AsyncReadResult>(manager->owningDirectContext());
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400863 size_t rowBytes =
864 GrAlignTo(context->fSize.width() * SkColorTypeBytesPerPixel(context->fColorType),
865 context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -0400866 if (!result->addTransferResult(context->fTransferResult, context->fSize, rowBytes,
Robert Phillips82ad7af2021-03-11 16:00:10 -0500867 manager)) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400868 result.reset();
869 }
870 (*context->fClientCallback)(context->fClientContext, std::move(result));
871 delete context;
872 };
873 GrFlushInfo flushInfo;
874 flushInfo.fFinishedContext = finishContext;
875 flushInfo.fFinishedProc = finishCallback;
Robert Phillips80bfda82020-11-12 09:23:36 -0500876
877 dContext->priv().flushSurface(this->asSurfaceProxy(),
878 SkSurface::BackendSurfaceAccess::kNoAccess,
879 flushInfo);
Brian Salomon63a0a752020-06-26 13:32:09 -0400880}
881
Adlai Hollerc95b5892020-08-11 12:02:22 -0400882void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext,
883 SkYUVColorSpace yuvColorSpace,
Brian Salomon63a0a752020-06-26 13:32:09 -0400884 sk_sp<SkColorSpace> dstColorSpace,
885 const SkIRect& srcRect,
886 SkISize dstSize,
887 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -0500888 RescaleMode rescaleMode,
Brian Salomon63a0a752020-06-26 13:32:09 -0400889 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400890 ReadPixelsContext callbackContext) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400891 SkASSERT(srcRect.fLeft >= 0 && srcRect.fRight <= this->width());
892 SkASSERT(srcRect.fTop >= 0 && srcRect.fBottom <= this->height());
893 SkASSERT(!dstSize.isZero());
894 SkASSERT((dstSize.width() % 2 == 0) && (dstSize.height() % 2 == 0));
895
Adlai Hollerc95b5892020-08-11 12:02:22 -0400896 if (!dContext) {
897 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400898 return;
899 }
900 auto rt = this->asRenderTargetProxy();
901 if (rt && rt->wrapsVkSecondaryCB()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400902 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400903 return;
904 }
905 if (rt && rt->framebufferOnly()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400906 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400907 return;
908 }
909 if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400910 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400911 return;
912 }
913 int x = srcRect.fLeft;
914 int y = srcRect.fTop;
Brian Salomon827bb722021-05-06 16:24:21 -0400915 bool needsRescale = srcRect.size() != dstSize ||
916 !SkColorSpace::Equals(this->colorInfo().colorSpace(), dstColorSpace.get());
917 GrSurfaceProxyView srcView = this->readSurfaceView();
Brian Salomon63a0a752020-06-26 13:32:09 -0400918 if (needsRescale) {
Brian Salomon827bb722021-05-06 16:24:21 -0400919 auto info = SkImageInfo::Make(dstSize,
920 kRGBA_8888_SkColorType,
921 this->colorInfo().alphaType(),
922 dstColorSpace);
Brian Salomon63a0a752020-06-26 13:32:09 -0400923 // TODO: Incorporate the YUV conversion into last pass of rescaling.
Brian Salomonbacbb922021-01-21 19:48:00 -0500924 auto tempFC = this->rescale(info,
925 kTopLeft_GrSurfaceOrigin,
926 srcRect,
927 rescaleGamma,
928 rescaleMode);
929 if (!tempFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400930 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400931 return;
932 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500933 SkASSERT(SkColorSpace::Equals(tempFC->colorInfo().colorSpace(), info.colorSpace()));
934 SkASSERT(tempFC->origin() == kTopLeft_GrSurfaceOrigin);
Brian Salomon63a0a752020-06-26 13:32:09 -0400935 x = y = 0;
Brian Salomonbacbb922021-01-21 19:48:00 -0500936 srcView = tempFC->readSurfaceView();
Brian Salomon827bb722021-05-06 16:24:21 -0400937 } else if (!srcView.asTextureProxy()) {
938 srcView = GrSurfaceProxyView::Copy(fContext,
939 std::move(srcView),
940 GrMipmapped::kNo,
941 srcRect,
942 SkBackingFit::kApprox,
943 SkBudgeted::kYes);
944 if (!srcView) {
945 // If we can't get a texture copy of the contents then give up.
946 callback(callbackContext, nullptr);
947 return;
Brian Salomon63a0a752020-06-26 13:32:09 -0400948 }
Brian Salomon827bb722021-05-06 16:24:21 -0400949 SkASSERT(srcView.asTextureProxy());
950 x = y = 0;
Brian Salomon63a0a752020-06-26 13:32:09 -0400951 }
952
Brian Salomonbacbb922021-01-21 19:48:00 -0500953 auto yInfo = SkImageInfo::MakeA8(dstSize);
954 auto yFC = GrSurfaceFillContext::MakeWithFallback(dContext, yInfo, SkBackingFit::kApprox);
955
956 auto uvInfo = yInfo.makeWH(yInfo.width()/2, yInfo.height()/2);
957 auto uFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
958 auto vFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
959
960 if (!yFC || !uFC || !vFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400961 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400962 return;
963 }
964
965 float baseM[20];
966 SkColorMatrix_RGB2YUV(yuvColorSpace, baseM);
967
968 // TODO: Use one transfer buffer for all three planes to reduce map/unmap cost?
969
970 auto texMatrix = SkMatrix::Translate(x, y);
971
Brian Salomoneac233a2021-06-24 11:56:50 -0400972 auto [readCT, offsetAlignment] =
973 this->caps()->supportedReadPixelsColorType(yFC->colorInfo().colorType(),
974 yFC->asSurfaceProxy()->backendFormat(),
975 GrColorType::kAlpha_8);
976 if (readCT == GrColorType::kUnknown) {
977 callback(callbackContext, nullptr);
978 return;
979 }
980 bool doSynchronousRead = !this->caps()->transferFromSurfaceToBufferSupport() ||
981 !offsetAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -0400982 PixelTransferResult yTransfer, uTransfer, vTransfer;
983
984 // This matrix generates (r,g,b,a) = (0, 0, 0, y)
985 float yM[20];
986 std::fill_n(yM, 15, 0.f);
987 std::copy_n(baseM + 0, 5, yM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -0500988
989 auto yFP = GrTextureEffect::Make(srcView, this->colorInfo().alphaType(), texMatrix);
Brian Osman48f83fd2021-06-23 15:51:26 +0000990 yFP = GrFragmentProcessor::ColorMatrix(std::move(yFP),
991 yM,
992 /*unpremulInput=*/false,
993 /*clampRGBOutput=*/true,
994 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -0500995 yFC->fillWithFP(std::move(yFP));
Brian Salomon63a0a752020-06-26 13:32:09 -0400996 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -0500997 yTransfer = yFC->transferPixels(GrColorType::kAlpha_8,
998 SkIRect::MakeSize(yFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -0400999 if (!yTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001000 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001001 return;
1002 }
1003 }
1004
1005 texMatrix.preScale(2.f, 2.f);
1006 // This matrix generates (r,g,b,a) = (0, 0, 0, u)
1007 float uM[20];
1008 std::fill_n(uM, 15, 0.f);
1009 std::copy_n(baseM + 5, 5, uM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -05001010
1011 auto uFP = GrTextureEffect::Make(srcView,
1012 this->colorInfo().alphaType(),
1013 texMatrix,
1014 GrSamplerState::Filter::kLinear);
Brian Osman48f83fd2021-06-23 15:51:26 +00001015 uFP = GrFragmentProcessor::ColorMatrix(std::move(uFP),
1016 uM,
1017 /*unpremulInput=*/false,
1018 /*clampRGBOutput=*/true,
1019 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -05001020 uFC->fillWithFP(std::move(uFP));
Brian Salomon63a0a752020-06-26 13:32:09 -04001021 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001022 uTransfer = uFC->transferPixels(GrColorType::kAlpha_8,
1023 SkIRect::MakeSize(uFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -04001024 if (!uTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001025 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001026 return;
1027 }
1028 }
1029
1030 // This matrix generates (r,g,b,a) = (0, 0, 0, v)
1031 float vM[20];
1032 std::fill_n(vM, 15, 0.f);
1033 std::copy_n(baseM + 10, 5, vM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -05001034 auto vFP = GrTextureEffect::Make(std::move(srcView),
1035 this->colorInfo().alphaType(),
1036 texMatrix,
1037 GrSamplerState::Filter::kLinear);
Brian Osman48f83fd2021-06-23 15:51:26 +00001038 vFP = GrFragmentProcessor::ColorMatrix(std::move(vFP),
1039 vM,
1040 /*unpremulInput=*/false,
1041 /*clampRGBOutput=*/true,
1042 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -05001043 vFC->fillWithFP(std::move(vFP));
1044
Brian Salomon63a0a752020-06-26 13:32:09 -04001045 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001046 vTransfer = vFC->transferPixels(GrColorType::kAlpha_8,
1047 SkIRect::MakeSize(vFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -04001048 if (!vTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001049 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001050 return;
1051 }
1052 }
1053
1054 if (doSynchronousRead) {
Brian Salomonbe1084b2021-01-26 13:29:30 -05001055 GrPixmap yPmp = GrPixmap::Allocate(yInfo);
1056 GrPixmap uPmp = GrPixmap::Allocate(uvInfo);
1057 GrPixmap vPmp = GrPixmap::Allocate(uvInfo);
Brian Salomonbacbb922021-01-21 19:48:00 -05001058 if (!yFC->readPixels(dContext, yPmp, {0, 0}) ||
1059 !uFC->readPixels(dContext, uPmp, {0, 0}) ||
1060 !vFC->readPixels(dContext, vPmp, {0, 0})) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001061 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001062 return;
1063 }
Robert Phillips82ad7af2021-03-11 16:00:10 -05001064 auto result = std::make_unique<AsyncReadResult>(dContext->directContextID());
Brian Salomonbe1084b2021-01-26 13:29:30 -05001065 result->addCpuPlane(yPmp.pixelStorage(), yPmp.rowBytes());
1066 result->addCpuPlane(uPmp.pixelStorage(), uPmp.rowBytes());
1067 result->addCpuPlane(vPmp.pixelStorage(), vPmp.rowBytes());
Adlai Hollerc95b5892020-08-11 12:02:22 -04001068 callback(callbackContext, std::move(result));
Brian Salomon63a0a752020-06-26 13:32:09 -04001069 return;
1070 }
1071
1072 struct FinishContext {
1073 ReadPixelsCallback* fClientCallback;
1074 ReadPixelsContext fClientContext;
1075 GrClientMappedBufferManager* fMappedBufferManager;
1076 SkISize fSize;
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001077 size_t fBufferAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -04001078 PixelTransferResult fYTransfer;
1079 PixelTransferResult fUTransfer;
1080 PixelTransferResult fVTransfer;
1081 };
1082 // Assumption is that the caller would like to flush. We could take a parameter or require an
1083 // explicit flush from the caller. We'd have to have a way to defer attaching the finish
1084 // callback to GrGpu until after the next flush that flushes our op list, though.
1085 auto* finishContext = new FinishContext{callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -04001086 callbackContext,
1087 dContext->priv().clientMappedBufferManager(),
Brian Salomon63a0a752020-06-26 13:32:09 -04001088 dstSize,
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001089 this->caps()->transferBufferAlignment(),
Brian Salomon63a0a752020-06-26 13:32:09 -04001090 std::move(yTransfer),
1091 std::move(uTransfer),
1092 std::move(vTransfer)};
1093 auto finishCallback = [](GrGpuFinishedContext c) {
1094 const auto* context = reinterpret_cast<const FinishContext*>(c);
Brian Salomon63a0a752020-06-26 13:32:09 -04001095 auto manager = context->fMappedBufferManager;
Robert Phillips82ad7af2021-03-11 16:00:10 -05001096 auto result = std::make_unique<AsyncReadResult>(manager->owningDirectContext());
Brian Salomon63a0a752020-06-26 13:32:09 -04001097 size_t rowBytes = SkToSizeT(context->fSize.width());
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001098 rowBytes = GrAlignTo(rowBytes, context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -04001099 if (!result->addTransferResult(context->fYTransfer, context->fSize, rowBytes, manager)) {
1100 (*context->fClientCallback)(context->fClientContext, nullptr);
1101 delete context;
1102 return;
1103 }
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001104 rowBytes = SkToSizeT(context->fSize.width()) / 2;
1105 rowBytes = GrAlignTo(rowBytes, context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -04001106 SkISize uvSize = {context->fSize.width() / 2, context->fSize.height() / 2};
1107 if (!result->addTransferResult(context->fUTransfer, uvSize, rowBytes, manager)) {
1108 (*context->fClientCallback)(context->fClientContext, nullptr);
1109 delete context;
1110 return;
1111 }
1112 if (!result->addTransferResult(context->fVTransfer, uvSize, rowBytes, manager)) {
1113 (*context->fClientCallback)(context->fClientContext, nullptr);
1114 delete context;
1115 return;
1116 }
1117 (*context->fClientCallback)(context->fClientContext, std::move(result));
1118 delete context;
1119 };
1120 GrFlushInfo flushInfo;
1121 flushInfo.fFinishedContext = finishContext;
1122 flushInfo.fFinishedProc = finishCallback;
Robert Phillips80bfda82020-11-12 09:23:36 -05001123 dContext->priv().flushSurface(this->asSurfaceProxy(),
1124 SkSurface::BackendSurfaceAccess::kNoAccess,
1125 flushInfo);
Brian Salomon63a0a752020-06-26 13:32:09 -04001126}
1127
Brian Salomond63638b2021-03-05 14:00:07 -05001128sk_sp<GrRenderTask> GrSurfaceContext::copy(sk_sp<GrSurfaceProxy> src,
1129 SkIRect srcRect,
1130 SkIPoint dstPoint) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001131 ASSERT_SINGLE_OWNER
Brian Salomond63638b2021-03-05 14:00:07 -05001132 RETURN_NULLPTR_IF_ABANDONED
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001133 SkDEBUGCODE(this->validate();)
Greg Daniel46cfbc62019-06-07 11:43:30 -04001134 GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContextPriv::copy");
Greg Daniel25af6712018-04-25 10:44:38 -04001135
Brian Salomon947efe22019-07-16 15:36:11 -04001136 const GrCaps* caps = fContext->priv().caps();
1137
Greg Daniel46cfbc62019-06-07 11:43:30 -04001138 SkASSERT(src->backendFormat().textureType() != GrTextureType::kExternal);
Greg Danielc71c7962020-01-14 16:44:18 -05001139 SkASSERT(src->backendFormat() == this->asSurfaceProxy()->backendFormat());
Greg Daniel46cfbc62019-06-07 11:43:30 -04001140
Stephen White3c0a50f2020-01-16 18:19:54 -05001141 if (this->asSurfaceProxy()->framebufferOnly()) {
Brian Salomond63638b2021-03-05 14:00:07 -05001142 return nullptr;
Stephen White3c0a50f2020-01-16 18:19:54 -05001143 }
1144
Brian Salomon982127b2021-01-21 10:43:35 -05001145 if (!caps->canCopySurface(this->asSurfaceProxy(), src.get(), srcRect, dstPoint)) {
Brian Salomond63638b2021-03-05 14:00:07 -05001146 return nullptr;
Greg Daniel25af6712018-04-25 10:44:38 -04001147 }
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001148
Brian Salomon982127b2021-01-21 10:43:35 -05001149 return this->drawingManager()->newCopyRenderTask(std::move(src),
1150 srcRect,
1151 this->asSurfaceProxyRef(),
Brian Salomon0f9f8002021-01-22 16:30:50 -05001152 dstPoint,
1153 this->origin());
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001154}
Greg Daniel46cfbc62019-06-07 11:43:30 -04001155
Brian Salomonbacbb922021-01-21 19:48:00 -05001156std::unique_ptr<GrSurfaceFillContext> GrSurfaceContext::rescale(const GrImageInfo& info,
Brian Salomoneebe7352020-12-09 16:37:04 -05001157 GrSurfaceOrigin origin,
1158 SkIRect srcRect,
1159 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001160 RescaleMode rescaleMode) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001161 auto sfc = GrSurfaceFillContext::MakeWithFallback(fContext,
1162 info,
Brian Salomon1c86b632020-12-11 12:36:01 -05001163 SkBackingFit::kExact,
Brian Salomon1c86b632020-12-11 12:36:01 -05001164 1,
1165 GrMipmapped::kNo,
1166 this->asSurfaceProxy()->isProtected(),
1167 origin);
Brian Salomonbacbb922021-01-21 19:48:00 -05001168 if (!sfc || !this->rescaleInto(sfc.get(),
1169 SkIRect::MakeSize(sfc->dimensions()),
Brian Salomon1c86b632020-12-11 12:36:01 -05001170 srcRect,
1171 rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001172 rescaleMode)) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001173 return nullptr;
1174 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001175 return sfc;
Brian Salomon1c86b632020-12-11 12:36:01 -05001176}
1177
Brian Salomonbacbb922021-01-21 19:48:00 -05001178bool GrSurfaceContext::rescaleInto(GrSurfaceFillContext* dst,
Brian Salomon1c86b632020-12-11 12:36:01 -05001179 SkIRect dstRect,
1180 SkIRect srcRect,
1181 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001182 RescaleMode rescaleMode) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001183 SkASSERT(dst);
1184 if (!SkIRect::MakeSize(dst->dimensions()).contains((dstRect))) {
1185 return false;
1186 }
1187
Brian Salomone9ad9982019-07-22 16:17:41 -04001188 auto rtProxy = this->asRenderTargetProxy();
1189 if (rtProxy && rtProxy->wrapsVkSecondaryCB()) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001190 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001191 }
1192
Stephen White3c0a50f2020-01-16 18:19:54 -05001193 if (this->asSurfaceProxy()->framebufferOnly()) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001194 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001195 }
1196
Greg Daniel40903af2020-01-30 14:55:05 -05001197 GrSurfaceProxyView texView = this->readSurfaceView();
Greg Daniel40903af2020-01-30 14:55:05 -05001198 if (!texView.asTextureProxy()) {
Brian Salomon827bb722021-05-06 16:24:21 -04001199 // TODO: If copying supported specifying a renderable copy then we could return the copy
1200 // when there are no other conversions.
Brian Salomon7e67dca2020-07-21 09:27:25 -04001201 texView = GrSurfaceProxyView::Copy(fContext, std::move(texView), GrMipmapped::kNo, srcRect,
Brian Salomonc5243782020-04-02 12:50:34 -04001202 SkBackingFit::kApprox, SkBudgeted::kNo);
1203 if (!texView) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001204 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001205 }
Greg Daniel40903af2020-01-30 14:55:05 -05001206 SkASSERT(texView.asTextureProxy());
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001207 srcRect = SkIRect::MakeSize(srcRect.size());
Brian Salomone9ad9982019-07-22 16:17:41 -04001208 }
1209
Brian Salomon1c86b632020-12-11 12:36:01 -05001210 SkISize finalSize = dstRect.size();
Brian Salomon827bb722021-05-06 16:24:21 -04001211 if (finalSize == srcRect.size()) {
1212 rescaleGamma = RescaleGamma::kSrc;
1213 rescaleMode = RescaleMode::kNearest;
1214 }
Brian Salomon1c86b632020-12-11 12:36:01 -05001215
Brian Salomonbf6b9792019-08-21 09:38:10 -04001216 // Within a rescaling pass A is the input (if not null) and B is the output. At the end of the
1217 // pass B is moved to A. If 'this' is the input on the first pass then tempA is null.
Brian Salomonbacbb922021-01-21 19:48:00 -05001218 std::unique_ptr<GrSurfaceFillContext> tempA;
1219 std::unique_ptr<GrSurfaceFillContext> tempB;
Brian Salomonbf6b9792019-08-21 09:38:10 -04001220
Brian Salomone9ad9982019-07-22 16:17:41 -04001221 // Assume we should ignore the rescale linear request if the surface has no color space since
1222 // it's unclear how we'd linearize from an unknown color space.
Brian Salomon63a0a752020-06-26 13:32:09 -04001223 if (rescaleGamma == RescaleGamma::kLinear && this->colorInfo().colorSpace() &&
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001224 !this->colorInfo().colorSpace()->gammaIsLinear()) {
1225 auto cs = this->colorInfo().colorSpace()->makeLinearGamma();
Brian Salomone9ad9982019-07-22 16:17:41 -04001226 // We'll fall back to kRGBA_8888 if half float not supported.
Brian Salomonbacbb922021-01-21 19:48:00 -05001227 GrImageInfo ii(GrColorType::kRGBA_F16,
1228 dst->colorInfo().alphaType(),
1229 std::move(cs),
1230 srcRect.size());
1231 auto linearRTC = GrSurfaceFillContext::MakeWithFallback(fContext,
1232 std::move(ii),
1233 SkBackingFit::kApprox,
1234 1,
1235 GrMipmapped::kNo,
1236 GrProtected::kNo,
1237 dst->origin());
Brian Salomone9ad9982019-07-22 16:17:41 -04001238 if (!linearRTC) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001239 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001240 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001241 auto fp = GrTextureEffect::Make(std::move(texView),
1242 this->colorInfo().alphaType(),
1243 SkMatrix::Translate(srcRect.topLeft()),
1244 GrSamplerState::Filter::kNearest,
1245 GrSamplerState::MipmapMode::kNone);
1246 fp = GrColorSpaceXformEffect::Make(std::move(fp),
1247 this->colorInfo(),
1248 linearRTC->colorInfo());
1249 linearRTC->fillWithFP(std::move(fp));
Greg Daniel40903af2020-01-30 14:55:05 -05001250 texView = linearRTC->readSurfaceView();
1251 SkASSERT(texView.asTextureProxy());
Brian Salomonbf6b9792019-08-21 09:38:10 -04001252 tempA = std::move(linearRTC);
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001253 srcRect = SkIRect::MakeSize(srcRect.size());
Brian Salomone9ad9982019-07-22 16:17:41 -04001254 }
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001255
Brian Salomon827bb722021-05-06 16:24:21 -04001256 do {
Brian Salomon1c86b632020-12-11 12:36:01 -05001257 SkISize nextDims = finalSize;
Mike Reed1efa14d2021-01-02 21:44:59 -05001258 if (rescaleMode != RescaleMode::kNearest) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001259 if (srcRect.width() > finalSize.width()) {
1260 nextDims.fWidth = std::max((srcRect.width() + 1)/2, finalSize.width());
1261 } else if (srcRect.width() < finalSize.width()) {
1262 nextDims.fWidth = std::min(srcRect.width()*2, finalSize.width());
Brian Salomon59f31b12020-06-04 17:27:15 -04001263 }
Brian Salomon1c86b632020-12-11 12:36:01 -05001264 if (srcRect.height() > finalSize.height()) {
1265 nextDims.fHeight = std::max((srcRect.height() + 1)/2, finalSize.height());
1266 } else if (srcRect.height() < finalSize.height()) {
1267 nextDims.fHeight = std::min(srcRect.height()*2, finalSize.height());
Brian Salomon59f31b12020-06-04 17:27:15 -04001268 }
1269 }
Brian Salomonbf6b9792019-08-21 09:38:10 -04001270 auto input = tempA ? tempA.get() : this;
Brian Salomone9ad9982019-07-22 16:17:41 -04001271 sk_sp<GrColorSpaceXform> xform;
Brian Salomonbacbb922021-01-21 19:48:00 -05001272 GrSurfaceFillContext* stepDst;
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001273 SkIRect stepDstRect;
Brian Salomon1c86b632020-12-11 12:36:01 -05001274 if (nextDims == finalSize) {
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001275 stepDst = dst;
1276 stepDstRect = dstRect;
Brian Salomonbacbb922021-01-21 19:48:00 -05001277 xform = GrColorSpaceXform::Make(input->colorInfo(), dst->colorInfo());
Brian Salomon1c86b632020-12-11 12:36:01 -05001278 } else {
Brian Salomonbacbb922021-01-21 19:48:00 -05001279 GrImageInfo nextInfo(input->colorInfo(), nextDims);
1280 tempB = GrSurfaceFillContext::MakeWithFallback(fContext,
1281 nextInfo,
1282 SkBackingFit::kApprox);
Brian Salomon1c86b632020-12-11 12:36:01 -05001283 if (!tempB) {
1284 return false;
1285 }
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001286 stepDst = tempB.get();
1287 stepDstRect = SkIRect::MakeSize(tempB->dimensions());
Brian Salomone9ad9982019-07-22 16:17:41 -04001288 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001289 std::unique_ptr<GrFragmentProcessor> fp;
Mike Reed1efa14d2021-01-02 21:44:59 -05001290 if (rescaleMode == RescaleMode::kRepeatedCubic) {
Brian Salomon59f31b12020-06-04 17:27:15 -04001291 auto dir = GrBicubicEffect::Direction::kXY;
1292 if (nextDims.width() == srcRect.width()) {
1293 dir = GrBicubicEffect::Direction::kY;
1294 } else if (nextDims.height() == srcRect.height()) {
1295 dir = GrBicubicEffect::Direction::kX;
Brian Salomone9ad9982019-07-22 16:17:41 -04001296 }
Brian Salomon1af72d12020-06-25 10:47:26 -04001297 static constexpr auto kWM = GrSamplerState::WrapMode::kClamp;
Mike Reed3867c702020-09-01 13:28:10 -04001298 static constexpr auto kKernel = GrBicubicEffect::gCatmullRom;
Brian Salomon1c86b632020-12-11 12:36:01 -05001299 fp = GrBicubicEffect::MakeSubset(std::move(texView),
1300 input->colorInfo().alphaType(),
Brian Salomonbacbb922021-01-21 19:48:00 -05001301 SkMatrix::I(),
Brian Salomon1c86b632020-12-11 12:36:01 -05001302 kWM,
1303 kWM,
1304 SkRect::Make(srcRect),
1305 kKernel,
1306 dir,
1307 *this->caps());
Brian Salomon59f31b12020-06-04 17:27:15 -04001308 } else {
Mike Reed1efa14d2021-01-02 21:44:59 -05001309 auto filter = rescaleMode == RescaleMode::kNearest ? GrSamplerState::Filter::kNearest
1310 : GrSamplerState::Filter::kLinear;
Brian Salomonbacbb922021-01-21 19:48:00 -05001311 auto srcRectF = SkRect::Make(srcRect);
1312 fp = GrTextureEffect::MakeSubset(std::move(texView),
1313 this->colorInfo().alphaType(),
1314 SkMatrix::I(),
1315 {filter, GrSamplerState::MipmapMode::kNone},
1316 srcRectF,
1317 srcRectF,
1318 *this->caps());
Brian Salomone9ad9982019-07-22 16:17:41 -04001319 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001320 if (xform) {
1321 fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(xform));
1322 }
1323 stepDst->fillRectToRectWithFP(srcRect, stepDstRect, std::move(fp));
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001324 texView = stepDst->readSurfaceView();
Brian Salomonbf6b9792019-08-21 09:38:10 -04001325 tempA = std::move(tempB);
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001326 srcRect = SkIRect::MakeSize(nextDims);
Brian Salomon827bb722021-05-06 16:24:21 -04001327 } while (srcRect.size() != finalSize);
Brian Salomon1c86b632020-12-11 12:36:01 -05001328 return true;
Brian Salomone9ad9982019-07-22 16:17:41 -04001329}
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001330
1331GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorType dstCT,
1332 const SkIRect& rect) {
1333 SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
1334 SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
Robert Phillipsf8f45d92020-07-01 11:11:18 -04001335 auto direct = fContext->asDirectContext();
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001336 if (!direct) {
1337 return {};
1338 }
1339 auto rtProxy = this->asRenderTargetProxy();
1340 if (rtProxy && rtProxy->wrapsVkSecondaryCB()) {
1341 return {};
1342 }
1343
1344 auto proxy = this->asSurfaceProxy();
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001345 auto supportedRead = this->caps()->supportedReadPixelsColorType(this->colorInfo().colorType(),
1346 proxy->backendFormat(), dstCT);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001347 // Fail if read color type does not have all of dstCT's color channels and those missing color
1348 // channels are in the src.
Brian Salomon2f23ae62020-03-26 16:17:56 -04001349 uint32_t dstChannels = GrColorTypeChannelFlags(dstCT);
1350 uint32_t legalReadChannels = GrColorTypeChannelFlags(supportedRead.fColorType);
1351 uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
1352 if ((~legalReadChannels & dstChannels) & srcChannels) {
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001353 return {};
1354 }
1355
Brian Salomonfb28c6f2020-01-10 13:04:45 -05001356 if (!this->caps()->transferFromSurfaceToBufferSupport() ||
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001357 !supportedRead.fOffsetAlignmentForTransferBuffer) {
1358 return {};
1359 }
1360
1361 size_t rowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * rect.width();
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001362 rowBytes = GrAlignTo(rowBytes, this->caps()->transferBufferAlignment());
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001363 size_t size = rowBytes * rect.height();
Greg Daniel2e967df2021-02-08 10:38:31 -05001364 // By using kStream_GrAccessPattern here, we are not able to cache and reuse the buffer for
1365 // multiple reads. Switching to kDynamic_GrAccessPattern would allow for this, however doing
1366 // so causes a crash in a chromium test. See skbug.com/11297
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001367 auto buffer = direct->priv().resourceProvider()->createBuffer(
Greg Daniel393debc2021-02-06 03:37:20 +00001368 size, GrGpuBufferType::kXferGpuToCpu, GrAccessPattern::kStream_GrAccessPattern);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001369 if (!buffer) {
1370 return {};
1371 }
1372 auto srcRect = rect;
Greg Danielb8d84f82020-02-13 14:25:00 -05001373 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001374 if (flip) {
1375 srcRect = SkIRect::MakeLTRB(rect.fLeft, this->height() - rect.fBottom, rect.fRight,
1376 this->height() - rect.fTop);
1377 }
Greg Danielbbfec9d2019-08-20 10:56:51 -04001378 this->drawingManager()->newTransferFromRenderTask(this->asSurfaceProxyRef(), srcRect,
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001379 this->colorInfo().colorType(),
Greg Danielbbfec9d2019-08-20 10:56:51 -04001380 supportedRead.fColorType, buffer, 0);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001381 PixelTransferResult result;
1382 result.fTransferBuffer = std::move(buffer);
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001383 auto at = this->colorInfo().alphaType();
Brian Salomon8f8354a2019-07-31 20:12:02 -04001384 if (supportedRead.fColorType != dstCT || flip) {
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001385 result.fPixelConverter = [w = rect.width(), h = rect.height(), dstCT, supportedRead, at](
1386 void* dst, const void* src) {
Brian Salomonf2ebdd92019-09-30 12:15:30 -04001387 GrImageInfo srcInfo(supportedRead.fColorType, at, nullptr, w, h);
1388 GrImageInfo dstInfo(dstCT, at, nullptr, w, h);
Brian Salomon5392c942021-03-30 16:14:37 -04001389 GrConvertPixels( GrPixmap(dstInfo, dst, dstInfo.minRowBytes()),
1390 GrCPixmap(srcInfo, src, srcInfo.minRowBytes()));
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001391 };
1392 }
1393 return result;
1394}
Greg Daniel46e366a2019-12-16 14:38:36 -05001395
1396#ifdef SK_DEBUG
1397void GrSurfaceContext::validate() const {
Greg Daniel3912a4b2020-01-14 09:56:04 -05001398 SkASSERT(fReadView.proxy());
1399 fReadView.proxy()->validate(fContext);
Brian Salomonc5243782020-04-02 12:50:34 -04001400 if (this->colorInfo().colorType() != GrColorType::kUnknown) {
1401 SkASSERT(fContext->priv().caps()->areColorTypeAndFormatCompatible(
1402 this->colorInfo().colorType(), fReadView.proxy()->backendFormat()));
1403 }
Greg Daniel46e366a2019-12-16 14:38:36 -05001404 this->onValidate();
1405}
1406#endif