blob: 33cdd6830719907e513bc94b65b77e3469d7fe78 [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"
Robert Phillips5e1aa8b2021-07-09 09:10:02 -040017#include "src/gpu/GrClientMappedBufferManager.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 -0500149GrDrawingManager* GrSurfaceContext::drawingManager() {
150 return fContext->priv().drawingManager();
151}
152
153const GrDrawingManager* GrSurfaceContext::drawingManager() const {
154 return fContext->priv().drawingManager();
155}
156
157#ifdef SK_DEBUG
Brian Salomon70fe17e2020-11-30 14:33:58 -0500158GrSingleOwner* GrSurfaceContext::singleOwner() const { return fContext->priv().singleOwner(); }
Robert Phillips0d075de2019-03-04 11:08:13 -0500159#endif
Greg Daniel6eb8c242019-06-05 10:22:24 -0400160
Brian Salomondd4087d2020-12-23 20:36:44 -0500161static bool alpha_types_compatible(SkAlphaType srcAlphaType, SkAlphaType dstAlphaType) {
162 // If both alpha types are kUnknown things make sense. If not, it's too underspecified.
163 return (srcAlphaType == kUnknown_SkAlphaType) == (dstAlphaType == kUnknown_SkAlphaType);
164}
165
166bool GrSurfaceContext::readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoint pt) {
Brian Salomon1d435302019-07-01 13:05:28 -0400167 ASSERT_SINGLE_OWNER
168 RETURN_FALSE_IF_ABANDONED
169 SkDEBUGCODE(this->validate();)
Robert Phillipsa92913e2021-07-12 16:31:52 -0400170 GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "readPixels", fContext);
171
Adlai Hollerbcfc5542020-08-27 12:44:07 -0400172 if (!fContext->priv().matches(dContext)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400173 return false;
174 }
Brian Salomon46f63232021-01-25 10:13:35 -0500175
176 if (dst.colorType() == GrColorType::kUnknown) {
177 return false;
178 }
179
Brian Salomonc24c8ef2021-02-01 13:32:30 -0500180 if (dst.rowBytes() % dst.info().bpp()) {
181 return false;
182 }
183
Brian Salomondd4087d2020-12-23 20:36:44 -0500184 dst = dst.clip(this->dimensions(), &pt);
185 if (!dst.hasPixels()) {
Brian Salomon1d435302019-07-01 13:05:28 -0400186 return false;
187 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500188 if (!alpha_types_compatible(this->colorInfo().alphaType(), dst.alphaType())) {
Brian Salomon1d435302019-07-01 13:05:28 -0400189 return false;
190 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500191 // We allow unknown alpha types but only if both src and dst are unknown. Otherwise, it's too
192 // weird to reason about what should be expected.
Greg Daniel6eb8c242019-06-05 10:22:24 -0400193
Brian Salomon982127b2021-01-21 10:43:35 -0500194 sk_sp<GrSurfaceProxy> srcProxy = this->asSurfaceProxyRef();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400195
Stephen White3c0a50f2020-01-16 18:19:54 -0500196 if (srcProxy->framebufferOnly()) {
197 return false;
198 }
199
Greg Daniel6eb8c242019-06-05 10:22:24 -0400200 // MDB TODO: delay this instantiation until later in the method
Adlai Hollerc95b5892020-08-11 12:02:22 -0400201 if (!srcProxy->instantiate(dContext->priv().resourceProvider())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400202 return false;
203 }
204
205 GrSurface* srcSurface = srcProxy->peekSurface();
206
Brian Salomondd4087d2020-12-23 20:36:44 -0500207 SkColorSpaceXformSteps::Flags flags =
208 SkColorSpaceXformSteps{this->colorInfo(), dst.info()}.flags;
Mike Klein7321e6a2019-12-03 11:08:40 -0600209 bool unpremul = flags.unpremul,
210 needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
211 premul = flags.premul;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400212
Adlai Hollerc95b5892020-08-11 12:02:22 -0400213 const GrCaps* caps = dContext->priv().caps();
Robert Phillips07f0e412020-01-17 15:20:00 -0500214 bool srcIsCompressed = caps->isFormatCompressed(srcSurface->backendFormat());
Greg Daniel6eb8c242019-06-05 10:22:24 -0400215 // This is the getImageData equivalent to the canvas2D putImageData fast path. We probably don't
216 // care so much about getImageData performance. However, in order to ensure putImageData/
217 // getImageData in "legacy" mode are round-trippable we use the GPU to do the complementary
218 // unpremul step to writeSurfacePixels's premul step (which is determined empirically in
219 // fContext->vaildaPMUPMConversionExists()).
Greg Daniel0258c902019-08-01 13:08:33 -0400220 GrBackendFormat defaultRGBAFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
221 GrRenderable::kYes);
Greg Danielc71c7962020-01-14 16:44:18 -0500222 GrColorType srcColorType = this->colorInfo().colorType();
Brian Salomon1d435302019-07-01 13:05:28 -0400223 bool canvas2DFastPath = unpremul && !needColorConversion &&
Brian Salomondd4087d2020-12-23 20:36:44 -0500224 (GrColorType::kRGBA_8888 == dst.colorType() ||
225 GrColorType::kBGRA_8888 == dst.colorType()) &&
Brian Salomon1d435302019-07-01 13:05:28 -0400226 SkToBool(srcProxy->asTextureProxy()) &&
Greg Danielc71c7962020-01-14 16:44:18 -0500227 (srcColorType == GrColorType::kRGBA_8888 ||
228 srcColorType == GrColorType::kBGRA_8888) &&
Greg Daniel0258c902019-08-01 13:08:33 -0400229 defaultRGBAFormat.isValid() &&
Adlai Hollerc95b5892020-08-11 12:02:22 -0400230 dContext->priv().validPMUPMConversionExists();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400231
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400232 auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);
Brian Salomondc0710f2019-07-01 14:59:32 -0400233 if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400234 return false;
235 }
236
Brian Salomondc0710f2019-07-01 14:59:32 -0400237 if (readFlag == GrCaps::SurfaceReadPixelsSupport::kCopyToTexture2D || canvas2DFastPath) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400238 std::unique_ptr<GrSurfaceContext> tempCtx;
239 if (this->asTextureProxy()) {
240 GrColorType colorType = (canvas2DFastPath || srcIsCompressed)
241 ? GrColorType::kRGBA_8888
242 : this->colorInfo().colorType();
Brian Salomondd4087d2020-12-23 20:36:44 -0500243 SkAlphaType alphaType = canvas2DFastPath ? dst.alphaType()
Brian Salomon590f5672020-12-16 11:44:47 -0500244 : this->colorInfo().alphaType();
245 GrImageInfo tempInfo(colorType,
246 alphaType,
247 this->colorInfo().refColorSpace(),
Brian Salomondd4087d2020-12-23 20:36:44 -0500248 dst.dimensions());
Brian Salomon590f5672020-12-16 11:44:47 -0500249 auto sfc = GrSurfaceFillContext::Make(dContext, tempInfo, SkBackingFit::kApprox);
250 if (!sfc) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400251 return false;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400252 }
Brian Salomon72c7b982020-10-06 10:07:38 -0400253
254 std::unique_ptr<GrFragmentProcessor> fp;
255 if (canvas2DFastPath) {
256 fp = dContext->priv().createPMToUPMEffect(GrTextureEffect::Make(
257 this->readSurfaceView(), this->colorInfo().alphaType()));
Brian Salomondd4087d2020-12-23 20:36:44 -0500258 if (dst.colorType() == GrColorType::kBGRA_8888) {
Brian Salomon72c7b982020-10-06 10:07:38 -0400259 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
Brian Salomondd4087d2020-12-23 20:36:44 -0500260 dst = GrPixmap(dst.info().makeColorType(GrColorType::kRGBA_8888),
261 dst.addr(),
262 dst.rowBytes());
Brian Salomon72c7b982020-10-06 10:07:38 -0400263 }
Brian Salomon72c7b982020-10-06 10:07:38 -0400264 } else {
265 fp = GrTextureEffect::Make(this->readSurfaceView(), this->colorInfo().alphaType());
266 }
267 if (!fp) {
268 return false;
269 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500270 sfc->fillRectToRectWithFP(SkIRect::MakePtSize(pt, dst.dimensions()),
271 SkIRect::MakeSize(dst.dimensions()),
Brian Salomon590f5672020-12-16 11:44:47 -0500272 std::move(fp));
Brian Salomon72c7b982020-10-06 10:07:38 -0400273 pt = {0, 0};
Brian Salomon590f5672020-12-16 11:44:47 -0500274 tempCtx = std::move(sfc);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400275 } else {
Brian Salomon72c7b982020-10-06 10:07:38 -0400276 auto restrictions = this->caps()->getDstCopyRestrictions(this->asRenderTargetProxy(),
277 this->colorInfo().colorType());
278 sk_sp<GrSurfaceProxy> copy;
279 static constexpr auto kFit = SkBackingFit::kExact;
280 static constexpr auto kBudgeted = SkBudgeted::kYes;
281 static constexpr auto kMipMapped = GrMipMapped::kNo;
282 if (restrictions.fMustCopyWholeSrc) {
Brian Salomon982127b2021-01-21 10:43:35 -0500283 copy = GrSurfaceProxy::Copy(fContext,
284 std::move(srcProxy),
285 this->origin(),
286 kMipMapped,
287 kFit,
Brian Salomon72c7b982020-10-06 10:07:38 -0400288 kBudgeted);
289 } else {
Brian Salomondd4087d2020-12-23 20:36:44 -0500290 auto srcRect = SkIRect::MakePtSize(pt, dst.dimensions());
Brian Salomon982127b2021-01-21 10:43:35 -0500291 copy = GrSurfaceProxy::Copy(fContext,
292 std::move(srcProxy),
293 this->origin(),
294 kMipMapped,
295 srcRect,
296 kFit,
297 kBudgeted,
298 restrictions.fRectsMustMatch);
Brian Salomon72c7b982020-10-06 10:07:38 -0400299 pt = {0, 0};
300 }
301 if (!copy) {
302 return false;
303 }
304 GrSurfaceProxyView view{std::move(copy), this->origin(), this->readSwizzle()};
Brian Salomon14f99fc2020-12-07 12:19:47 -0500305 tempCtx = GrSurfaceContext::Make(dContext, std::move(view), this->colorInfo());
Brian Salomon72c7b982020-10-06 10:07:38 -0400306 SkASSERT(tempCtx);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400307 }
Brian Salomondd4087d2020-12-23 20:36:44 -0500308 return tempCtx->readPixels(dContext, dst, pt);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400309 }
310
Greg Danielb8d84f82020-02-13 14:25:00 -0500311 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400312
Brian Salomon1d435302019-07-01 13:05:28 -0400313 auto supportedRead = caps->supportedReadPixelsColorType(
Brian Salomondd4087d2020-12-23 20:36:44 -0500314 this->colorInfo().colorType(), srcProxy->backendFormat(), dst.colorType());
Brian Salomon1d435302019-07-01 13:05:28 -0400315
Brian Salomondd4087d2020-12-23 20:36:44 -0500316 bool makeTight =
317 !caps->readPixelsRowBytesSupport() && dst.rowBytes() != dst.info().minRowBytes();
Brian Salomon1047a492019-07-02 12:25:21 -0400318
319 bool convert = unpremul || premul || needColorConversion || flip || makeTight ||
Brian Salomondd4087d2020-12-23 20:36:44 -0500320 (dst.colorType() != supportedRead.fColorType);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400321
Brian Salomonf30b1c12019-06-20 12:25:02 -0400322 std::unique_ptr<char[]> tmpPixels;
Brian Salomondd4087d2020-12-23 20:36:44 -0500323 GrPixmap tmp;
324 void* readDst = dst.addr();
325 size_t readRB = dst.rowBytes();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400326 if (convert) {
Brian Salomondd4087d2020-12-23 20:36:44 -0500327 GrImageInfo tmpInfo(supportedRead.fColorType,
328 this->colorInfo().alphaType(),
329 this->colorInfo().refColorSpace(),
330 dst.dimensions());
Brian Salomon1d435302019-07-01 13:05:28 -0400331 size_t tmpRB = tmpInfo.minRowBytes();
332 size_t size = tmpRB * tmpInfo.height();
333 // Chrome MSAN bots require the data to be initialized (hence the ()).
John Stilesfbd050b2020-08-03 13:21:46 -0400334 tmpPixels = std::make_unique<char[]>(size);
Brian Salomondd4087d2020-12-23 20:36:44 -0500335 tmp = {tmpInfo, tmpPixels.get(), tmpRB};
Brian Salomonf30b1c12019-06-20 12:25:02 -0400336
Brian Salomonf30b1c12019-06-20 12:25:02 -0400337 readDst = tmpPixels.get();
Brian Salomon1d435302019-07-01 13:05:28 -0400338 readRB = tmpRB;
Brian Salomondd4087d2020-12-23 20:36:44 -0500339 pt.fY = flip ? srcSurface->height() - pt.fY - dst.height() : pt.fY;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400340 }
341
Brian Salomon982127b2021-01-21 10:43:35 -0500342 dContext->priv().flushSurface(srcProxy.get());
Adlai Hollerc95b5892020-08-11 12:02:22 -0400343 dContext->submit();
Brian Salomone2078f12021-05-24 12:40:46 -0400344 if (!dContext->priv().getGpu()->readPixels(srcSurface,
345 SkIRect::MakePtSize(pt, dst.dimensions()),
Brian Salomondd4087d2020-12-23 20:36:44 -0500346 this->colorInfo().colorType(),
Brian Salomone2078f12021-05-24 12:40:46 -0400347 supportedRead.fColorType,
348 readDst,
349 readRB)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400350 return false;
351 }
352
Brian Salomondd4087d2020-12-23 20:36:44 -0500353 if (tmp.hasPixels()) {
354 return GrConvertPixels(dst, tmp, flip);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400355 }
356 return true;
357}
Robert Phillips0d075de2019-03-04 11:08:13 -0500358
Brian Salomonea1d39b2021-04-01 17:06:52 -0400359bool GrSurfaceContext::writePixels(GrDirectContext* dContext,
360 GrCPixmap src,
Brian Salomon75ee7372021-04-06 15:04:35 -0400361 SkIPoint dstPt) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400362 ASSERT_SINGLE_OWNER
363 RETURN_FALSE_IF_ABANDONED
364 SkDEBUGCODE(this->validate();)
Brian Salomon2c673402021-04-02 14:36:58 -0400365
366 src = src.clip(this->dimensions(), &dstPt);
367 if (!src.hasPixels()) {
368 return false;
369 }
370 if (!src.info().bpp() || src.rowBytes() % src.info().bpp()) {
371 return false;
372 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400373 return this->internalWritePixels(dContext, &src, 1, dstPt);
Brian Salomon2c673402021-04-02 14:36:58 -0400374}
375
376bool GrSurfaceContext::writePixels(GrDirectContext* dContext,
377 const GrCPixmap src[],
Brian Salomon75ee7372021-04-06 15:04:35 -0400378 int numLevels) {
Brian Salomon2c673402021-04-02 14:36:58 -0400379 ASSERT_SINGLE_OWNER
380 RETURN_FALSE_IF_ABANDONED
381 SkDEBUGCODE(this->validate();)
382
383 SkASSERT(dContext);
384 SkASSERT(numLevels >= 1);
385 SkASSERT(src);
386
387 if (numLevels == 1) {
388 if (src->dimensions() != this->dimensions()) {
389 return false;
390 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400391 return this->writePixels(dContext, src[0], {0, 0});
Brian Salomon2c673402021-04-02 14:36:58 -0400392 }
393 if (!this->asTextureProxy() || this->asTextureProxy()->proxyMipmapped() == GrMipmapped::kNo) {
394 return false;
395 }
396
397 SkISize dims = this->dimensions();
398 if (numLevels != SkMipmap::ComputeLevelCount(dims) + 1) {
399 return false;
400 }
401 for (int i = 0; i < numLevels; ++i) {
402 if (src[i].colorInfo() != src[0].colorInfo()) {
403 return false;
404 }
405 if (dims != src[i].dimensions()) {
406 return false;
407 }
408 if (!src[i].info().bpp() || src[i].rowBytes() % src[i].info().bpp()) {
409 return false;
410 }
411 dims = {std::max(1, dims.width()/2), std::max(1, dims.height()/2)};
412 }
Brian Salomon75ee7372021-04-06 15:04:35 -0400413 return this->internalWritePixels(dContext, src, numLevels, {0, 0});
Brian Salomon2c673402021-04-02 14:36:58 -0400414}
415
416bool GrSurfaceContext::internalWritePixels(GrDirectContext* dContext,
417 const GrCPixmap src[],
418 int numLevels,
Brian Salomon75ee7372021-04-06 15:04:35 -0400419 SkIPoint pt) {
Robert Phillipsa92913e2021-07-12 16:31:52 -0400420 GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "internalWritePixels", fContext);
Brian Salomon2c673402021-04-02 14:36:58 -0400421
422 SkASSERT(numLevels >= 1);
423 SkASSERT(src);
424
425 // We can either write to a subset or write MIP levels, but not both.
426 SkASSERT((src[0].dimensions() == this->dimensions() && pt.isZero()) || numLevels == 1);
427 SkASSERT(numLevels == 1 ||
Brian Salomon7cde6c32021-04-02 15:53:42 -0400428 (this->asTextureProxy() && this->asTextureProxy()->mipmapped() == GrMipmapped::kYes));
Brian Salomon2c673402021-04-02 14:36:58 -0400429 // Our public caller should have clipped to the bounds of the surface already.
Brian Salomonea1d39b2021-04-01 17:06:52 -0400430 SkASSERT(SkIRect::MakeSize(this->dimensions()).contains(
431 SkIRect::MakePtSize(pt, src[0].dimensions())));
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400432
Adlai Hollerc95b5892020-08-11 12:02:22 -0400433 if (!dContext) {
Brian Salomonc320b152018-02-20 14:05:36 -0500434 return false;
435 }
Robert Phillips6a6de562019-02-15 15:19:15 -0500436
Brian Salomon1d435302019-07-01 13:05:28 -0400437 if (this->asSurfaceProxy()->readOnly()) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500438 return false;
439 }
440
Brian Salomon2c673402021-04-02 14:36:58 -0400441 if (src[0].colorType() == GrColorType::kUnknown) {
Brian Salomon46f63232021-01-25 10:13:35 -0500442 return false;
443 }
444
Brian Salomon2c673402021-04-02 14:36:58 -0400445 if (!alpha_types_compatible(src[0].alphaType(), this->colorInfo().alphaType())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400446 return false;
447 }
448
449 GrSurfaceProxy* dstProxy = this->asSurfaceProxy();
Stephen White3c0a50f2020-01-16 18:19:54 -0500450
451 if (dstProxy->framebufferOnly()) {
452 return false;
453 }
454
Adlai Hollerc95b5892020-08-11 12:02:22 -0400455 if (!dstProxy->instantiate(dContext->priv().resourceProvider())) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400456 return false;
457 }
458
459 GrSurface* dstSurface = dstProxy->peekSurface();
460
Brian Salomondd4087d2020-12-23 20:36:44 -0500461 SkColorSpaceXformSteps::Flags flags =
Brian Salomon2c673402021-04-02 14:36:58 -0400462 SkColorSpaceXformSteps{src[0].colorInfo(), this->colorInfo()}.flags;
Mike Klein7321e6a2019-12-03 11:08:40 -0600463 bool unpremul = flags.unpremul,
464 needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
465 premul = flags.premul;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400466
Adlai Hollerc95b5892020-08-11 12:02:22 -0400467 const GrCaps* caps = dContext->priv().caps();
Greg Daniel7bfc9132019-08-14 14:23:53 -0400468
469 auto rgbaDefaultFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
470 GrRenderable::kNo);
471
Greg Danielc71c7962020-01-14 16:44:18 -0500472 GrColorType dstColorType = this->colorInfo().colorType();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400473 // For canvas2D putImageData performance we have a special code path for unpremul RGBA_8888 srcs
474 // that are premultiplied on the GPU. This is kept as narrow as possible for now.
Brian Salomon1d435302019-07-01 13:05:28 -0400475 bool canvas2DFastPath = !caps->avoidWritePixelsFastPath() && premul && !needColorConversion &&
Brian Salomon2c673402021-04-02 14:36:58 -0400476 (src[0].colorType() == GrColorType::kRGBA_8888 ||
477 src[0].colorType() == GrColorType::kBGRA_8888) &&
Brian Salomon590f5672020-12-16 11:44:47 -0500478 this->asFillContext() &&
Greg Danielc71c7962020-01-14 16:44:18 -0500479 (dstColorType == GrColorType::kRGBA_8888 ||
480 dstColorType == GrColorType::kBGRA_8888) &&
Greg Daniel7bfc9132019-08-14 14:23:53 -0400481 rgbaDefaultFormat.isValid() &&
Adlai Hollerc95b5892020-08-11 12:02:22 -0400482 dContext->priv().validPMUPMConversionExists();
Brian Salomon2c673402021-04-02 14:36:58 -0400483 // Drawing code path doesn't support writing to levels and doesn't support inserting layout
484 // transitions.
Brian Salomon75ee7372021-04-06 15:04:35 -0400485 if ((!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) && numLevels == 1) {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500486 GrColorInfo tempColorInfo;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400487 GrBackendFormat format;
Greg Danielbfa19c42019-12-19 16:41:40 -0500488 GrSwizzle tempReadSwizzle;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400489 if (canvas2DFastPath) {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500490 tempColorInfo = {GrColorType::kRGBA_8888,
491 kUnpremul_SkAlphaType,
492 this->colorInfo().refColorSpace()};
Greg Daniel7bfc9132019-08-14 14:23:53 -0400493 format = rgbaDefaultFormat;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400494 } else {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500495 tempColorInfo = this->colorInfo();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400496 format = dstProxy->backendFormat().makeTexture2D();
497 if (!format.isValid()) {
498 return false;
499 }
Greg Danielbfa19c42019-12-19 16:41:40 -0500500 tempReadSwizzle = this->readSwizzle();
Greg Daniel6eb8c242019-06-05 10:22:24 -0400501 }
502
Greg Daniel2e52ad12019-06-13 10:04:16 -0400503 // It is more efficient for us to write pixels into a top left origin so we prefer that.
504 // However, if the final proxy isn't a render target then we must use a copy to move the
505 // data into it which requires the origins to match. If the final proxy is a render target
506 // we can use a draw instead which doesn't have this origin restriction. Thus for render
507 // targets we will use top left and otherwise we will make the origins match.
Brian Salomonf30b1c12019-06-20 12:25:02 -0400508 GrSurfaceOrigin tempOrigin =
Brian Salomon590f5672020-12-16 11:44:47 -0500509 this->asFillContext() ? kTopLeft_GrSurfaceOrigin : this->origin();
Brian Salomon2c673402021-04-02 14:36:58 -0400510 auto tempProxy = dContext->priv().proxyProvider()->createProxy(format,
511 src[0].dimensions(),
512 GrRenderable::kNo,
513 1,
514 GrMipmapped::kNo,
515 SkBackingFit::kApprox,
516 SkBudgeted::kYes,
517 GrProtected::kNo);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400518 if (!tempProxy) {
519 return false;
520 }
Greg Daniel3912a4b2020-01-14 09:56:04 -0500521 GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle);
Brian Salomon14f99fc2020-12-07 12:19:47 -0500522 GrSurfaceContext tempCtx(dContext, tempView, tempColorInfo);
Greg Daniel6eb8c242019-06-05 10:22:24 -0400523
524 // In the fast path we always write the srcData to the temp context as though it were RGBA.
525 // When the data is really BGRA the write will cause the R and B channels to be swapped in
526 // the intermediate surface which gets corrected by a swizzle effect when drawing to the
527 // dst.
Brian Salomon2c673402021-04-02 14:36:58 -0400528 GrCPixmap origSrcBase = src[0];
529 GrCPixmap srcBase = origSrcBase;
Brian Salomon1d435302019-07-01 13:05:28 -0400530 if (canvas2DFastPath) {
Brian Salomon2c673402021-04-02 14:36:58 -0400531 srcBase = GrCPixmap(origSrcBase.info().makeColorType(GrColorType::kRGBA_8888),
532 origSrcBase.addr(),
533 origSrcBase.rowBytes());
Brian Salomon1d435302019-07-01 13:05:28 -0400534 }
Brian Salomon2c673402021-04-02 14:36:58 -0400535 if (!tempCtx.writePixels(dContext, srcBase, {0, 0})) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400536 return false;
537 }
538
Brian Salomon590f5672020-12-16 11:44:47 -0500539 if (this->asFillContext()) {
Greg Daniel46cfbc62019-06-07 11:43:30 -0400540 std::unique_ptr<GrFragmentProcessor> fp;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400541 if (canvas2DFastPath) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400542 fp = dContext->priv().createUPMToPMEffect(
Brian Salomon14f99fc2020-12-07 12:19:47 -0500543 GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType()));
Brian Salomon1d435302019-07-01 13:05:28 -0400544 // Important: check the original src color type here!
Brian Salomon2c673402021-04-02 14:36:58 -0400545 if (origSrcBase.colorType() == GrColorType::kBGRA_8888) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400546 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
547 }
548 } else {
Brian Salomon14f99fc2020-12-07 12:19:47 -0500549 fp = GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType());
Greg Daniel6eb8c242019-06-05 10:22:24 -0400550 }
551 if (!fp) {
552 return false;
553 }
Brian Salomon2c673402021-04-02 14:36:58 -0400554 this->asFillContext()->fillRectToRectWithFP(
555 SkIRect::MakeSize(srcBase.dimensions()),
556 SkIRect::MakePtSize(pt, srcBase.dimensions()),
557 std::move(fp));
Greg Daniel6eb8c242019-06-05 10:22:24 -0400558 } else {
Brian Salomon2c673402021-04-02 14:36:58 -0400559 SkIRect srcRect = SkIRect::MakeSize(srcBase.dimensions());
Brian Salomon1d435302019-07-01 13:05:28 -0400560 SkIPoint dstPoint = SkIPoint::Make(pt.fX, pt.fY);
Brian Salomon982127b2021-01-21 10:43:35 -0500561 if (!this->copy(std::move(tempProxy), srcRect, dstPoint)) {
Greg Daniel6eb8c242019-06-05 10:22:24 -0400562 return false;
563 }
Greg Daniel6eb8c242019-06-05 10:22:24 -0400564 }
565 return true;
566 }
567
Brian Salomon2c673402021-04-02 14:36:58 -0400568 GrColorType srcColorType = src[0].colorType();
569 auto [allowedColorType, _] =
Brian Salomon4bc0c1f2019-09-30 15:12:27 -0400570 caps->supportedWritePixelsColorType(this->colorInfo().colorType(),
Brian Salomon01915c02019-08-02 09:57:21 -0400571 dstProxy->backendFormat(),
Brian Salomon2c673402021-04-02 14:36:58 -0400572 srcColorType);
Greg Danielb8d84f82020-02-13 14:25:00 -0500573 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Greg Daniel6eb8c242019-06-05 10:22:24 -0400574
Brian Salomon2c673402021-04-02 14:36:58 -0400575 bool convertAll = premul ||
576 unpremul ||
577 needColorConversion ||
578 flip ||
579 (srcColorType != allowedColorType);
580 bool mustBeTight = !caps->writePixelsRowBytesSupport();
581 size_t tmpSize = 0;
582 if (mustBeTight || convertAll) {
583 for (int i = 0; i < numLevels; ++i) {
584 if (convertAll || (mustBeTight && src[i].rowBytes() != src[i].info().minRowBytes())) {
585 tmpSize += src[i].info().makeColorType(allowedColorType).minRowBytes()*
586 src[i].height();
587 }
588 }
Greg Daniel6eb8c242019-06-05 10:22:24 -0400589 }
590
Brian Salomon2c673402021-04-02 14:36:58 -0400591 auto tmpData = tmpSize ? SkData::MakeUninitialized(tmpSize) : nullptr;
592 void* tmp = tmpSize ? tmpData->writable_data() : nullptr;
593 SkAutoSTArray<15, GrMipLevel> srcLevels(numLevels);
594 bool ownAllStorage = true;
595 for (int i = 0; i < numLevels; ++i) {
596 if (convertAll || (mustBeTight && src[i].rowBytes() != src[i].info().minRowBytes())) {
597 GrImageInfo tmpInfo(allowedColorType,
598 this->colorInfo().alphaType(),
599 this->colorInfo().refColorSpace(),
600 src[i].dimensions());
601 auto tmpRB = tmpInfo.minRowBytes();
602 GrPixmap tmpPM(tmpInfo, tmp, tmpRB);
603 SkAssertResult(GrConvertPixels(tmpPM, src[i], flip));
604 srcLevels[i] = {tmpPM.addr(), tmpPM.rowBytes(), tmpData};
605 tmp = SkTAddOffset<void>(tmp, tmpRB*tmpPM.height());
606 } else {
607 srcLevels[i] = {src[i].addr(), src[i].rowBytes(), src[i].pixelStorage()};
608 ownAllStorage &= src[i].ownsPixels();
609 }
610 }
611 pt.fY = flip ? dstSurface->height() - pt.fY - src[0].height() : pt.fY;
612
613 if (!dContext->priv().drawingManager()->newWritePixelsTask(
Brian Salomon974c8212021-04-05 16:24:00 -0400614 sk_ref_sp(dstProxy),
615 SkIRect::MakePtSize(pt, src[0].dimensions()),
616 allowedColorType,
617 this->colorInfo().colorType(),
618 srcLevels.begin(),
Brian Salomon75ee7372021-04-06 15:04:35 -0400619 numLevels)) {
Brian Salomon2c673402021-04-02 14:36:58 -0400620 return false;
621 }
622 if (numLevels > 1) {
623 dstProxy->asTextureProxy()->markMipmapsClean();
624 }
625 if (!ownAllStorage) {
626 // If any pixmap doesn't own its pixels then we must flush so that the pixels are pushed to
627 // the GPU before we return.
Brian Salomon24949422021-02-11 09:39:46 -0500628 dContext->priv().flushSurface(dstProxy);
629 }
Brian Salomon2c673402021-04-02 14:36:58 -0400630 return true;
Brian Osman45580d32016-11-23 09:37:01 -0500631}
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400632
Adlai Hollerc95b5892020-08-11 12:02:22 -0400633void GrSurfaceContext::asyncRescaleAndReadPixels(GrDirectContext* dContext,
634 const SkImageInfo& info,
Brian Salomon63a0a752020-06-26 13:32:09 -0400635 const SkIRect& srcRect,
636 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -0500637 RescaleMode rescaleMode,
Brian Salomon63a0a752020-06-26 13:32:09 -0400638 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400639 ReadPixelsContext callbackContext) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400640 if (!dContext) {
641 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400642 return;
643 }
644 auto rt = this->asRenderTargetProxy();
645 if (rt && rt->wrapsVkSecondaryCB()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400646 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400647 return;
648 }
649 if (rt && rt->framebufferOnly()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400650 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400651 return;
652 }
653 auto dstCT = SkColorTypeToGrColorType(info.colorType());
654 if (dstCT == GrColorType::kUnknown) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400655 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400656 return;
657 }
Brian Salomon827bb722021-05-06 16:24:21 -0400658 bool needsRescale = srcRect.size() != info.dimensions() ||
659 this->origin() == kBottomLeft_GrSurfaceOrigin ||
660 this->colorInfo().alphaType() != info.alphaType() ||
661 !SkColorSpace::Equals(this->colorInfo().colorSpace(), info.colorSpace());
Brian Salomon63a0a752020-06-26 13:32:09 -0400662 auto colorTypeOfFinalContext = this->colorInfo().colorType();
663 auto backendFormatOfFinalContext = this->asSurfaceProxy()->backendFormat();
664 if (needsRescale) {
665 colorTypeOfFinalContext = dstCT;
666 backendFormatOfFinalContext =
667 this->caps()->getDefaultBackendFormat(dstCT, GrRenderable::kYes);
668 }
669 auto readInfo = this->caps()->supportedReadPixelsColorType(colorTypeOfFinalContext,
Brian Salomonbacbb922021-01-21 19:48:00 -0500670 backendFormatOfFinalContext,
671 dstCT);
Brian Salomon63a0a752020-06-26 13:32:09 -0400672 // Fail if we can't read from the source surface's color type.
673 if (readInfo.fColorType == GrColorType::kUnknown) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400674 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400675 return;
676 }
677 // Fail if read color type does not have all of dstCT's color channels and those missing color
678 // channels are in the src.
679 uint32_t dstChannels = GrColorTypeChannelFlags(dstCT);
680 uint32_t legalReadChannels = GrColorTypeChannelFlags(readInfo.fColorType);
681 uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
682 if ((~legalReadChannels & dstChannels) & srcChannels) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400683 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400684 return;
685 }
686
Brian Salomonbacbb922021-01-21 19:48:00 -0500687 std::unique_ptr<GrSurfaceFillContext> tempFC;
Brian Salomon63a0a752020-06-26 13:32:09 -0400688 int x = srcRect.fLeft;
689 int y = srcRect.fTop;
690 if (needsRescale) {
Brian Salomonbacbb922021-01-21 19:48:00 -0500691 tempFC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma, rescaleMode);
692 if (!tempFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400693 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400694 return;
695 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500696 SkASSERT(SkColorSpace::Equals(tempFC->colorInfo().colorSpace(), info.colorSpace()));
697 SkASSERT(tempFC->origin() == kTopLeft_GrSurfaceOrigin);
Brian Salomon63a0a752020-06-26 13:32:09 -0400698 x = y = 0;
Brian Salomon63a0a752020-06-26 13:32:09 -0400699 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500700 auto srcCtx = tempFC ? tempFC.get() : this;
701 return srcCtx->asyncReadPixels(dContext,
702 SkIRect::MakePtSize({x, y}, info.dimensions()),
703 info.colorType(),
704 callback,
705 callbackContext);
Brian Salomon63a0a752020-06-26 13:32:09 -0400706}
707
708class GrSurfaceContext::AsyncReadResult : public SkImage::AsyncReadResult {
709public:
Robert Phillips82ad7af2021-03-11 16:00:10 -0500710 AsyncReadResult(GrDirectContext::DirectContextID intendedRecipient)
711 : fIntendedRecipient(intendedRecipient) {
712 }
713
Brian Salomon63a0a752020-06-26 13:32:09 -0400714 ~AsyncReadResult() override {
715 for (int i = 0; i < fPlanes.count(); ++i) {
Robert Phillips82ad7af2021-03-11 16:00:10 -0500716 fPlanes[i].releaseMappedBuffer(fIntendedRecipient);
Brian Salomon63a0a752020-06-26 13:32:09 -0400717 }
718 }
719
720 int count() const override { return fPlanes.count(); }
Brian Salomonbe1084b2021-01-26 13:29:30 -0500721 const void* data(int i) const override { return fPlanes[i].data(); }
722 size_t rowBytes(int i) const override { return fPlanes[i].rowBytes(); }
Brian Salomon63a0a752020-06-26 13:32:09 -0400723
724 bool addTransferResult(const PixelTransferResult& result,
725 SkISize dimensions,
726 size_t rowBytes,
727 GrClientMappedBufferManager* manager) {
728 SkASSERT(!result.fTransferBuffer->isMapped());
729 const void* mappedData = result.fTransferBuffer->map();
730 if (!mappedData) {
731 return false;
732 }
733 if (result.fPixelConverter) {
Brian Salomonbe1084b2021-01-26 13:29:30 -0500734 size_t size = rowBytes*dimensions.height();
735 sk_sp<SkData> data = SkData::MakeUninitialized(size);
736 result.fPixelConverter(data->writable_data(), mappedData);
737 this->addCpuPlane(std::move(data), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400738 result.fTransferBuffer->unmap();
739 } else {
740 manager->insert(result.fTransferBuffer);
741 this->addMappedPlane(mappedData, rowBytes, std::move(result.fTransferBuffer));
742 }
743 return true;
744 }
745
Brian Salomonbe1084b2021-01-26 13:29:30 -0500746 void addCpuPlane(sk_sp<SkData> data, size_t rowBytes) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400747 SkASSERT(data);
748 SkASSERT(rowBytes > 0);
Brian Salomonbe1084b2021-01-26 13:29:30 -0500749 fPlanes.emplace_back(std::move(data), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400750 }
751
752private:
753 void addMappedPlane(const void* data, size_t rowBytes, sk_sp<GrGpuBuffer> mappedBuffer) {
754 SkASSERT(data);
755 SkASSERT(rowBytes > 0);
756 SkASSERT(mappedBuffer);
757 SkASSERT(mappedBuffer->isMapped());
Brian Salomonbe1084b2021-01-26 13:29:30 -0500758 fPlanes.emplace_back(std::move(mappedBuffer), rowBytes);
Brian Salomon63a0a752020-06-26 13:32:09 -0400759 }
760
Brian Salomonbe1084b2021-01-26 13:29:30 -0500761 class Plane {
762 public:
763 Plane(sk_sp<GrGpuBuffer> buffer, size_t rowBytes)
764 : fMappedBuffer(std::move(buffer)), fRowBytes(rowBytes) {}
765 Plane(sk_sp<SkData> data, size_t rowBytes) : fData(std::move(data)), fRowBytes(rowBytes) {}
766
767 Plane(const Plane&) = delete;
768 Plane(Plane&&) = default;
769
770 ~Plane() { SkASSERT(!fMappedBuffer); }
771
772 Plane& operator=(const Plane&) = delete;
773 Plane& operator=(Plane&&) = default;
774
Robert Phillips82ad7af2021-03-11 16:00:10 -0500775 void releaseMappedBuffer(GrDirectContext::DirectContextID intendedRecipient) {
Brian Salomonbe1084b2021-01-26 13:29:30 -0500776 if (fMappedBuffer) {
777 GrClientMappedBufferManager::BufferFinishedMessageBus::Post(
Robert Phillips82ad7af2021-03-11 16:00:10 -0500778 {std::move(fMappedBuffer), intendedRecipient});
Brian Salomonbe1084b2021-01-26 13:29:30 -0500779 }
780 }
781
782 const void* data() const {
783 if (fMappedBuffer) {
784 SkASSERT(!fData);
785 SkASSERT(fMappedBuffer->isMapped());
786 return fMappedBuffer->map();
787 }
788 SkASSERT(fData);
789 return fData->data();
790 }
791
792 size_t rowBytes() const { return fRowBytes; }
793
794 private:
795 sk_sp<SkData> fData;
Brian Salomon1eea1ea2021-01-26 18:12:25 +0000796 sk_sp<GrGpuBuffer> fMappedBuffer;
Brian Salomonbe1084b2021-01-26 13:29:30 -0500797 size_t fRowBytes;
Brian Salomon63a0a752020-06-26 13:32:09 -0400798 };
799 SkSTArray<3, Plane> fPlanes;
Robert Phillips82ad7af2021-03-11 16:00:10 -0500800 GrDirectContext::DirectContextID fIntendedRecipient;
Brian Salomon63a0a752020-06-26 13:32:09 -0400801};
802
Adlai Hollerc95b5892020-08-11 12:02:22 -0400803void GrSurfaceContext::asyncReadPixels(GrDirectContext* dContext,
804 const SkIRect& rect,
Brian Salomon63a0a752020-06-26 13:32:09 -0400805 SkColorType colorType,
806 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400807 ReadPixelsContext callbackContext) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400808 SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
809 SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
810
Adlai Hollerc95b5892020-08-11 12:02:22 -0400811 if (!dContext || this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
812 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400813 return;
814 }
815
Adlai Hollerc95b5892020-08-11 12:02:22 -0400816 auto mappedBufferManager = dContext->priv().clientMappedBufferManager();
Brian Salomon63a0a752020-06-26 13:32:09 -0400817
818 auto transferResult = this->transferPixels(SkColorTypeToGrColorType(colorType), rect);
819
820 if (!transferResult.fTransferBuffer) {
821 auto ii = SkImageInfo::Make(rect.size(), colorType, this->colorInfo().alphaType(),
822 this->colorInfo().refColorSpace());
Robert Phillips82ad7af2021-03-11 16:00:10 -0500823 static const GrDirectContext::DirectContextID kInvalid;
824 auto result = std::make_unique<AsyncReadResult>(kInvalid);
Brian Salomonbe1084b2021-01-26 13:29:30 -0500825 GrPixmap pm = GrPixmap::Allocate(ii);
826 result->addCpuPlane(pm.pixelStorage(), pm.rowBytes());
Brian Salomon63a0a752020-06-26 13:32:09 -0400827
Adlai Hollerc95b5892020-08-11 12:02:22 -0400828 SkIPoint pt{rect.fLeft, rect.fTop};
Brian Salomondd4087d2020-12-23 20:36:44 -0500829 if (!this->readPixels(dContext, pm, pt)) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400830 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400831 return;
832 }
Adlai Hollerc95b5892020-08-11 12:02:22 -0400833 callback(callbackContext, std::move(result));
Brian Salomon63a0a752020-06-26 13:32:09 -0400834 return;
835 }
836
837 struct FinishContext {
838 ReadPixelsCallback* fClientCallback;
839 ReadPixelsContext fClientContext;
840 SkISize fSize;
841 SkColorType fColorType;
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400842 size_t fBufferAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -0400843 GrClientMappedBufferManager* fMappedBufferManager;
844 PixelTransferResult fTransferResult;
845 };
846 // Assumption is that the caller would like to flush. We could take a parameter or require an
847 // explicit flush from the caller. We'd have to have a way to defer attaching the finish
848 // callback to GrGpu until after the next flush that flushes our op list, though.
849 auto* finishContext = new FinishContext{callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400850 callbackContext,
Brian Salomon63a0a752020-06-26 13:32:09 -0400851 rect.size(),
852 colorType,
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400853 this->caps()->transferBufferAlignment(),
Brian Salomon63a0a752020-06-26 13:32:09 -0400854 mappedBufferManager,
855 std::move(transferResult)};
856 auto finishCallback = [](GrGpuFinishedContext c) {
857 const auto* context = reinterpret_cast<const FinishContext*>(c);
Robert Phillips82ad7af2021-03-11 16:00:10 -0500858 auto manager = context->fMappedBufferManager;
859 auto result = std::make_unique<AsyncReadResult>(manager->owningDirectContext());
Jim Van Vertha655f0d2021-05-18 15:03:27 -0400860 size_t rowBytes =
861 GrAlignTo(context->fSize.width() * SkColorTypeBytesPerPixel(context->fColorType),
862 context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -0400863 if (!result->addTransferResult(context->fTransferResult, context->fSize, rowBytes,
Robert Phillips82ad7af2021-03-11 16:00:10 -0500864 manager)) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400865 result.reset();
866 }
867 (*context->fClientCallback)(context->fClientContext, std::move(result));
868 delete context;
869 };
870 GrFlushInfo flushInfo;
871 flushInfo.fFinishedContext = finishContext;
872 flushInfo.fFinishedProc = finishCallback;
Robert Phillips80bfda82020-11-12 09:23:36 -0500873
874 dContext->priv().flushSurface(this->asSurfaceProxy(),
875 SkSurface::BackendSurfaceAccess::kNoAccess,
876 flushInfo);
Brian Salomon63a0a752020-06-26 13:32:09 -0400877}
878
Adlai Hollerc95b5892020-08-11 12:02:22 -0400879void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext,
880 SkYUVColorSpace yuvColorSpace,
Brian Salomon63a0a752020-06-26 13:32:09 -0400881 sk_sp<SkColorSpace> dstColorSpace,
882 const SkIRect& srcRect,
883 SkISize dstSize,
884 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -0500885 RescaleMode rescaleMode,
Brian Salomon63a0a752020-06-26 13:32:09 -0400886 ReadPixelsCallback callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -0400887 ReadPixelsContext callbackContext) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400888 SkASSERT(srcRect.fLeft >= 0 && srcRect.fRight <= this->width());
889 SkASSERT(srcRect.fTop >= 0 && srcRect.fBottom <= this->height());
890 SkASSERT(!dstSize.isZero());
891 SkASSERT((dstSize.width() % 2 == 0) && (dstSize.height() % 2 == 0));
892
Adlai Hollerc95b5892020-08-11 12:02:22 -0400893 if (!dContext) {
894 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400895 return;
896 }
897 auto rt = this->asRenderTargetProxy();
898 if (rt && rt->wrapsVkSecondaryCB()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400899 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400900 return;
901 }
902 if (rt && rt->framebufferOnly()) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400903 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400904 return;
905 }
906 if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400907 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400908 return;
909 }
910 int x = srcRect.fLeft;
911 int y = srcRect.fTop;
Brian Salomon827bb722021-05-06 16:24:21 -0400912 bool needsRescale = srcRect.size() != dstSize ||
913 !SkColorSpace::Equals(this->colorInfo().colorSpace(), dstColorSpace.get());
914 GrSurfaceProxyView srcView = this->readSurfaceView();
Brian Salomon63a0a752020-06-26 13:32:09 -0400915 if (needsRescale) {
Brian Salomon827bb722021-05-06 16:24:21 -0400916 auto info = SkImageInfo::Make(dstSize,
917 kRGBA_8888_SkColorType,
918 this->colorInfo().alphaType(),
919 dstColorSpace);
Brian Salomon63a0a752020-06-26 13:32:09 -0400920 // TODO: Incorporate the YUV conversion into last pass of rescaling.
Brian Salomonbacbb922021-01-21 19:48:00 -0500921 auto tempFC = this->rescale(info,
922 kTopLeft_GrSurfaceOrigin,
923 srcRect,
924 rescaleGamma,
925 rescaleMode);
926 if (!tempFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400927 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400928 return;
929 }
Brian Salomonbacbb922021-01-21 19:48:00 -0500930 SkASSERT(SkColorSpace::Equals(tempFC->colorInfo().colorSpace(), info.colorSpace()));
931 SkASSERT(tempFC->origin() == kTopLeft_GrSurfaceOrigin);
Brian Salomon63a0a752020-06-26 13:32:09 -0400932 x = y = 0;
Brian Salomonbacbb922021-01-21 19:48:00 -0500933 srcView = tempFC->readSurfaceView();
Brian Salomon827bb722021-05-06 16:24:21 -0400934 } else if (!srcView.asTextureProxy()) {
935 srcView = GrSurfaceProxyView::Copy(fContext,
936 std::move(srcView),
937 GrMipmapped::kNo,
938 srcRect,
939 SkBackingFit::kApprox,
940 SkBudgeted::kYes);
941 if (!srcView) {
942 // If we can't get a texture copy of the contents then give up.
943 callback(callbackContext, nullptr);
944 return;
Brian Salomon63a0a752020-06-26 13:32:09 -0400945 }
Brian Salomon827bb722021-05-06 16:24:21 -0400946 SkASSERT(srcView.asTextureProxy());
947 x = y = 0;
Brian Salomon63a0a752020-06-26 13:32:09 -0400948 }
949
Brian Salomonbacbb922021-01-21 19:48:00 -0500950 auto yInfo = SkImageInfo::MakeA8(dstSize);
951 auto yFC = GrSurfaceFillContext::MakeWithFallback(dContext, yInfo, SkBackingFit::kApprox);
952
953 auto uvInfo = yInfo.makeWH(yInfo.width()/2, yInfo.height()/2);
954 auto uFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
955 auto vFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
956
957 if (!yFC || !uFC || !vFC) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400958 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400959 return;
960 }
961
962 float baseM[20];
963 SkColorMatrix_RGB2YUV(yuvColorSpace, baseM);
964
965 // TODO: Use one transfer buffer for all three planes to reduce map/unmap cost?
966
967 auto texMatrix = SkMatrix::Translate(x, y);
968
Brian Salomoneac233a2021-06-24 11:56:50 -0400969 auto [readCT, offsetAlignment] =
970 this->caps()->supportedReadPixelsColorType(yFC->colorInfo().colorType(),
971 yFC->asSurfaceProxy()->backendFormat(),
972 GrColorType::kAlpha_8);
973 if (readCT == GrColorType::kUnknown) {
974 callback(callbackContext, nullptr);
975 return;
976 }
977 bool doSynchronousRead = !this->caps()->transferFromSurfaceToBufferSupport() ||
978 !offsetAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -0400979 PixelTransferResult yTransfer, uTransfer, vTransfer;
980
981 // This matrix generates (r,g,b,a) = (0, 0, 0, y)
982 float yM[20];
983 std::fill_n(yM, 15, 0.f);
984 std::copy_n(baseM + 0, 5, yM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -0500985
986 auto yFP = GrTextureEffect::Make(srcView, this->colorInfo().alphaType(), texMatrix);
Brian Osman48f83fd2021-06-23 15:51:26 +0000987 yFP = GrFragmentProcessor::ColorMatrix(std::move(yFP),
988 yM,
989 /*unpremulInput=*/false,
990 /*clampRGBOutput=*/true,
991 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -0500992 yFC->fillWithFP(std::move(yFP));
Brian Salomon63a0a752020-06-26 13:32:09 -0400993 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -0500994 yTransfer = yFC->transferPixels(GrColorType::kAlpha_8,
995 SkIRect::MakeSize(yFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -0400996 if (!yTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -0400997 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -0400998 return;
999 }
1000 }
1001
1002 texMatrix.preScale(2.f, 2.f);
1003 // This matrix generates (r,g,b,a) = (0, 0, 0, u)
1004 float uM[20];
1005 std::fill_n(uM, 15, 0.f);
1006 std::copy_n(baseM + 5, 5, uM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -05001007
1008 auto uFP = GrTextureEffect::Make(srcView,
1009 this->colorInfo().alphaType(),
1010 texMatrix,
1011 GrSamplerState::Filter::kLinear);
Brian Osman48f83fd2021-06-23 15:51:26 +00001012 uFP = GrFragmentProcessor::ColorMatrix(std::move(uFP),
1013 uM,
1014 /*unpremulInput=*/false,
1015 /*clampRGBOutput=*/true,
1016 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -05001017 uFC->fillWithFP(std::move(uFP));
Brian Salomon63a0a752020-06-26 13:32:09 -04001018 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001019 uTransfer = uFC->transferPixels(GrColorType::kAlpha_8,
1020 SkIRect::MakeSize(uFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -04001021 if (!uTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001022 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001023 return;
1024 }
1025 }
1026
1027 // This matrix generates (r,g,b,a) = (0, 0, 0, v)
1028 float vM[20];
1029 std::fill_n(vM, 15, 0.f);
1030 std::copy_n(baseM + 10, 5, vM + 15);
Brian Salomonbacbb922021-01-21 19:48:00 -05001031 auto vFP = GrTextureEffect::Make(std::move(srcView),
1032 this->colorInfo().alphaType(),
1033 texMatrix,
1034 GrSamplerState::Filter::kLinear);
Brian Osman48f83fd2021-06-23 15:51:26 +00001035 vFP = GrFragmentProcessor::ColorMatrix(std::move(vFP),
1036 vM,
1037 /*unpremulInput=*/false,
1038 /*clampRGBOutput=*/true,
1039 /*premulOutput=*/false);
Brian Salomonbacbb922021-01-21 19:48:00 -05001040 vFC->fillWithFP(std::move(vFP));
1041
Brian Salomon63a0a752020-06-26 13:32:09 -04001042 if (!doSynchronousRead) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001043 vTransfer = vFC->transferPixels(GrColorType::kAlpha_8,
1044 SkIRect::MakeSize(vFC->dimensions()));
Brian Salomon63a0a752020-06-26 13:32:09 -04001045 if (!vTransfer.fTransferBuffer) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001046 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001047 return;
1048 }
1049 }
1050
1051 if (doSynchronousRead) {
Brian Salomonbe1084b2021-01-26 13:29:30 -05001052 GrPixmap yPmp = GrPixmap::Allocate(yInfo);
1053 GrPixmap uPmp = GrPixmap::Allocate(uvInfo);
1054 GrPixmap vPmp = GrPixmap::Allocate(uvInfo);
Brian Salomonbacbb922021-01-21 19:48:00 -05001055 if (!yFC->readPixels(dContext, yPmp, {0, 0}) ||
1056 !uFC->readPixels(dContext, uPmp, {0, 0}) ||
1057 !vFC->readPixels(dContext, vPmp, {0, 0})) {
Adlai Hollerc95b5892020-08-11 12:02:22 -04001058 callback(callbackContext, nullptr);
Brian Salomon63a0a752020-06-26 13:32:09 -04001059 return;
1060 }
Robert Phillips82ad7af2021-03-11 16:00:10 -05001061 auto result = std::make_unique<AsyncReadResult>(dContext->directContextID());
Brian Salomonbe1084b2021-01-26 13:29:30 -05001062 result->addCpuPlane(yPmp.pixelStorage(), yPmp.rowBytes());
1063 result->addCpuPlane(uPmp.pixelStorage(), uPmp.rowBytes());
1064 result->addCpuPlane(vPmp.pixelStorage(), vPmp.rowBytes());
Adlai Hollerc95b5892020-08-11 12:02:22 -04001065 callback(callbackContext, std::move(result));
Brian Salomon63a0a752020-06-26 13:32:09 -04001066 return;
1067 }
1068
1069 struct FinishContext {
1070 ReadPixelsCallback* fClientCallback;
1071 ReadPixelsContext fClientContext;
1072 GrClientMappedBufferManager* fMappedBufferManager;
1073 SkISize fSize;
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001074 size_t fBufferAlignment;
Brian Salomon63a0a752020-06-26 13:32:09 -04001075 PixelTransferResult fYTransfer;
1076 PixelTransferResult fUTransfer;
1077 PixelTransferResult fVTransfer;
1078 };
1079 // Assumption is that the caller would like to flush. We could take a parameter or require an
1080 // explicit flush from the caller. We'd have to have a way to defer attaching the finish
1081 // callback to GrGpu until after the next flush that flushes our op list, though.
1082 auto* finishContext = new FinishContext{callback,
Adlai Hollerc95b5892020-08-11 12:02:22 -04001083 callbackContext,
1084 dContext->priv().clientMappedBufferManager(),
Brian Salomon63a0a752020-06-26 13:32:09 -04001085 dstSize,
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001086 this->caps()->transferBufferAlignment(),
Brian Salomon63a0a752020-06-26 13:32:09 -04001087 std::move(yTransfer),
1088 std::move(uTransfer),
1089 std::move(vTransfer)};
1090 auto finishCallback = [](GrGpuFinishedContext c) {
1091 const auto* context = reinterpret_cast<const FinishContext*>(c);
Brian Salomon63a0a752020-06-26 13:32:09 -04001092 auto manager = context->fMappedBufferManager;
Robert Phillips82ad7af2021-03-11 16:00:10 -05001093 auto result = std::make_unique<AsyncReadResult>(manager->owningDirectContext());
Brian Salomon63a0a752020-06-26 13:32:09 -04001094 size_t rowBytes = SkToSizeT(context->fSize.width());
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001095 rowBytes = GrAlignTo(rowBytes, context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -04001096 if (!result->addTransferResult(context->fYTransfer, context->fSize, rowBytes, manager)) {
1097 (*context->fClientCallback)(context->fClientContext, nullptr);
1098 delete context;
1099 return;
1100 }
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001101 rowBytes = SkToSizeT(context->fSize.width()) / 2;
1102 rowBytes = GrAlignTo(rowBytes, context->fBufferAlignment);
Brian Salomon63a0a752020-06-26 13:32:09 -04001103 SkISize uvSize = {context->fSize.width() / 2, context->fSize.height() / 2};
1104 if (!result->addTransferResult(context->fUTransfer, uvSize, rowBytes, manager)) {
1105 (*context->fClientCallback)(context->fClientContext, nullptr);
1106 delete context;
1107 return;
1108 }
1109 if (!result->addTransferResult(context->fVTransfer, uvSize, rowBytes, manager)) {
1110 (*context->fClientCallback)(context->fClientContext, nullptr);
1111 delete context;
1112 return;
1113 }
1114 (*context->fClientCallback)(context->fClientContext, std::move(result));
1115 delete context;
1116 };
1117 GrFlushInfo flushInfo;
1118 flushInfo.fFinishedContext = finishContext;
1119 flushInfo.fFinishedProc = finishCallback;
Robert Phillips80bfda82020-11-12 09:23:36 -05001120 dContext->priv().flushSurface(this->asSurfaceProxy(),
1121 SkSurface::BackendSurfaceAccess::kNoAccess,
1122 flushInfo);
Brian Salomon63a0a752020-06-26 13:32:09 -04001123}
1124
Brian Salomond63638b2021-03-05 14:00:07 -05001125sk_sp<GrRenderTask> GrSurfaceContext::copy(sk_sp<GrSurfaceProxy> src,
1126 SkIRect srcRect,
1127 SkIPoint dstPoint) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001128 ASSERT_SINGLE_OWNER
Brian Salomond63638b2021-03-05 14:00:07 -05001129 RETURN_NULLPTR_IF_ABANDONED
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001130 SkDEBUGCODE(this->validate();)
Robert Phillipsa92913e2021-07-12 16:31:52 -04001131 GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "copy", fContext);
Greg Daniel25af6712018-04-25 10:44:38 -04001132
Brian Salomon947efe22019-07-16 15:36:11 -04001133 const GrCaps* caps = fContext->priv().caps();
1134
Greg Daniel46cfbc62019-06-07 11:43:30 -04001135 SkASSERT(src->backendFormat().textureType() != GrTextureType::kExternal);
Greg Danielc71c7962020-01-14 16:44:18 -05001136 SkASSERT(src->backendFormat() == this->asSurfaceProxy()->backendFormat());
Greg Daniel46cfbc62019-06-07 11:43:30 -04001137
Stephen White3c0a50f2020-01-16 18:19:54 -05001138 if (this->asSurfaceProxy()->framebufferOnly()) {
Brian Salomond63638b2021-03-05 14:00:07 -05001139 return nullptr;
Stephen White3c0a50f2020-01-16 18:19:54 -05001140 }
1141
Brian Salomon982127b2021-01-21 10:43:35 -05001142 if (!caps->canCopySurface(this->asSurfaceProxy(), src.get(), srcRect, dstPoint)) {
Brian Salomond63638b2021-03-05 14:00:07 -05001143 return nullptr;
Greg Daniel25af6712018-04-25 10:44:38 -04001144 }
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001145
Brian Salomon982127b2021-01-21 10:43:35 -05001146 return this->drawingManager()->newCopyRenderTask(std::move(src),
1147 srcRect,
1148 this->asSurfaceProxyRef(),
Brian Salomon0f9f8002021-01-22 16:30:50 -05001149 dstPoint,
1150 this->origin());
Robert Phillips2de8cfa2017-06-28 10:33:41 -04001151}
Greg Daniel46cfbc62019-06-07 11:43:30 -04001152
Brian Salomonbacbb922021-01-21 19:48:00 -05001153std::unique_ptr<GrSurfaceFillContext> GrSurfaceContext::rescale(const GrImageInfo& info,
Brian Salomoneebe7352020-12-09 16:37:04 -05001154 GrSurfaceOrigin origin,
1155 SkIRect srcRect,
1156 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001157 RescaleMode rescaleMode) {
Brian Salomonbacbb922021-01-21 19:48:00 -05001158 auto sfc = GrSurfaceFillContext::MakeWithFallback(fContext,
1159 info,
Brian Salomon1c86b632020-12-11 12:36:01 -05001160 SkBackingFit::kExact,
Brian Salomon1c86b632020-12-11 12:36:01 -05001161 1,
1162 GrMipmapped::kNo,
1163 this->asSurfaceProxy()->isProtected(),
1164 origin);
Brian Salomonbacbb922021-01-21 19:48:00 -05001165 if (!sfc || !this->rescaleInto(sfc.get(),
1166 SkIRect::MakeSize(sfc->dimensions()),
Brian Salomon1c86b632020-12-11 12:36:01 -05001167 srcRect,
1168 rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001169 rescaleMode)) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001170 return nullptr;
1171 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001172 return sfc;
Brian Salomon1c86b632020-12-11 12:36:01 -05001173}
1174
Brian Salomonbacbb922021-01-21 19:48:00 -05001175bool GrSurfaceContext::rescaleInto(GrSurfaceFillContext* dst,
Brian Salomon1c86b632020-12-11 12:36:01 -05001176 SkIRect dstRect,
1177 SkIRect srcRect,
1178 RescaleGamma rescaleGamma,
Mike Reed1efa14d2021-01-02 21:44:59 -05001179 RescaleMode rescaleMode) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001180 SkASSERT(dst);
1181 if (!SkIRect::MakeSize(dst->dimensions()).contains((dstRect))) {
1182 return false;
1183 }
1184
Brian Salomone9ad9982019-07-22 16:17:41 -04001185 auto rtProxy = this->asRenderTargetProxy();
1186 if (rtProxy && rtProxy->wrapsVkSecondaryCB()) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001187 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001188 }
1189
Stephen White3c0a50f2020-01-16 18:19:54 -05001190 if (this->asSurfaceProxy()->framebufferOnly()) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001191 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001192 }
1193
Greg Daniel40903af2020-01-30 14:55:05 -05001194 GrSurfaceProxyView texView = this->readSurfaceView();
Greg Daniel40903af2020-01-30 14:55:05 -05001195 if (!texView.asTextureProxy()) {
Brian Salomon827bb722021-05-06 16:24:21 -04001196 // TODO: If copying supported specifying a renderable copy then we could return the copy
1197 // when there are no other conversions.
Brian Salomon7e67dca2020-07-21 09:27:25 -04001198 texView = GrSurfaceProxyView::Copy(fContext, std::move(texView), GrMipmapped::kNo, srcRect,
Brian Salomonc5243782020-04-02 12:50:34 -04001199 SkBackingFit::kApprox, SkBudgeted::kNo);
1200 if (!texView) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001201 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001202 }
Greg Daniel40903af2020-01-30 14:55:05 -05001203 SkASSERT(texView.asTextureProxy());
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001204 srcRect = SkIRect::MakeSize(srcRect.size());
Brian Salomone9ad9982019-07-22 16:17:41 -04001205 }
1206
Brian Salomon1c86b632020-12-11 12:36:01 -05001207 SkISize finalSize = dstRect.size();
Brian Salomon827bb722021-05-06 16:24:21 -04001208 if (finalSize == srcRect.size()) {
1209 rescaleGamma = RescaleGamma::kSrc;
1210 rescaleMode = RescaleMode::kNearest;
1211 }
Brian Salomon1c86b632020-12-11 12:36:01 -05001212
Brian Salomonbf6b9792019-08-21 09:38:10 -04001213 // Within a rescaling pass A is the input (if not null) and B is the output. At the end of the
1214 // 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 -05001215 std::unique_ptr<GrSurfaceFillContext> tempA;
1216 std::unique_ptr<GrSurfaceFillContext> tempB;
Brian Salomonbf6b9792019-08-21 09:38:10 -04001217
Brian Salomone9ad9982019-07-22 16:17:41 -04001218 // Assume we should ignore the rescale linear request if the surface has no color space since
1219 // it's unclear how we'd linearize from an unknown color space.
Brian Salomon63a0a752020-06-26 13:32:09 -04001220 if (rescaleGamma == RescaleGamma::kLinear && this->colorInfo().colorSpace() &&
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001221 !this->colorInfo().colorSpace()->gammaIsLinear()) {
1222 auto cs = this->colorInfo().colorSpace()->makeLinearGamma();
Brian Salomone9ad9982019-07-22 16:17:41 -04001223 // We'll fall back to kRGBA_8888 if half float not supported.
Brian Salomonbacbb922021-01-21 19:48:00 -05001224 GrImageInfo ii(GrColorType::kRGBA_F16,
1225 dst->colorInfo().alphaType(),
1226 std::move(cs),
1227 srcRect.size());
1228 auto linearRTC = GrSurfaceFillContext::MakeWithFallback(fContext,
1229 std::move(ii),
1230 SkBackingFit::kApprox,
1231 1,
1232 GrMipmapped::kNo,
1233 GrProtected::kNo,
1234 dst->origin());
Brian Salomone9ad9982019-07-22 16:17:41 -04001235 if (!linearRTC) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001236 return false;
Brian Salomone9ad9982019-07-22 16:17:41 -04001237 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001238 auto fp = GrTextureEffect::Make(std::move(texView),
1239 this->colorInfo().alphaType(),
1240 SkMatrix::Translate(srcRect.topLeft()),
1241 GrSamplerState::Filter::kNearest,
1242 GrSamplerState::MipmapMode::kNone);
1243 fp = GrColorSpaceXformEffect::Make(std::move(fp),
1244 this->colorInfo(),
1245 linearRTC->colorInfo());
1246 linearRTC->fillWithFP(std::move(fp));
Greg Daniel40903af2020-01-30 14:55:05 -05001247 texView = linearRTC->readSurfaceView();
1248 SkASSERT(texView.asTextureProxy());
Brian Salomonbf6b9792019-08-21 09:38:10 -04001249 tempA = std::move(linearRTC);
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001250 srcRect = SkIRect::MakeSize(srcRect.size());
Brian Salomone9ad9982019-07-22 16:17:41 -04001251 }
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001252
Brian Salomon827bb722021-05-06 16:24:21 -04001253 do {
Brian Salomon1c86b632020-12-11 12:36:01 -05001254 SkISize nextDims = finalSize;
Mike Reed1efa14d2021-01-02 21:44:59 -05001255 if (rescaleMode != RescaleMode::kNearest) {
Brian Salomon1c86b632020-12-11 12:36:01 -05001256 if (srcRect.width() > finalSize.width()) {
1257 nextDims.fWidth = std::max((srcRect.width() + 1)/2, finalSize.width());
1258 } else if (srcRect.width() < finalSize.width()) {
1259 nextDims.fWidth = std::min(srcRect.width()*2, finalSize.width());
Brian Salomon59f31b12020-06-04 17:27:15 -04001260 }
Brian Salomon1c86b632020-12-11 12:36:01 -05001261 if (srcRect.height() > finalSize.height()) {
1262 nextDims.fHeight = std::max((srcRect.height() + 1)/2, finalSize.height());
1263 } else if (srcRect.height() < finalSize.height()) {
1264 nextDims.fHeight = std::min(srcRect.height()*2, finalSize.height());
Brian Salomon59f31b12020-06-04 17:27:15 -04001265 }
1266 }
Brian Salomonbf6b9792019-08-21 09:38:10 -04001267 auto input = tempA ? tempA.get() : this;
Brian Salomone9ad9982019-07-22 16:17:41 -04001268 sk_sp<GrColorSpaceXform> xform;
Brian Salomonbacbb922021-01-21 19:48:00 -05001269 GrSurfaceFillContext* stepDst;
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001270 SkIRect stepDstRect;
Brian Salomon1c86b632020-12-11 12:36:01 -05001271 if (nextDims == finalSize) {
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001272 stepDst = dst;
1273 stepDstRect = dstRect;
Brian Salomonbacbb922021-01-21 19:48:00 -05001274 xform = GrColorSpaceXform::Make(input->colorInfo(), dst->colorInfo());
Brian Salomon1c86b632020-12-11 12:36:01 -05001275 } else {
Brian Salomonbacbb922021-01-21 19:48:00 -05001276 GrImageInfo nextInfo(input->colorInfo(), nextDims);
1277 tempB = GrSurfaceFillContext::MakeWithFallback(fContext,
1278 nextInfo,
1279 SkBackingFit::kApprox);
Brian Salomon1c86b632020-12-11 12:36:01 -05001280 if (!tempB) {
1281 return false;
1282 }
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001283 stepDst = tempB.get();
1284 stepDstRect = SkIRect::MakeSize(tempB->dimensions());
Brian Salomone9ad9982019-07-22 16:17:41 -04001285 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001286 std::unique_ptr<GrFragmentProcessor> fp;
Mike Reed1efa14d2021-01-02 21:44:59 -05001287 if (rescaleMode == RescaleMode::kRepeatedCubic) {
Brian Salomon59f31b12020-06-04 17:27:15 -04001288 auto dir = GrBicubicEffect::Direction::kXY;
1289 if (nextDims.width() == srcRect.width()) {
1290 dir = GrBicubicEffect::Direction::kY;
1291 } else if (nextDims.height() == srcRect.height()) {
1292 dir = GrBicubicEffect::Direction::kX;
Brian Salomone9ad9982019-07-22 16:17:41 -04001293 }
Brian Salomon1af72d12020-06-25 10:47:26 -04001294 static constexpr auto kWM = GrSamplerState::WrapMode::kClamp;
Mike Reed3867c702020-09-01 13:28:10 -04001295 static constexpr auto kKernel = GrBicubicEffect::gCatmullRom;
Brian Salomon1c86b632020-12-11 12:36:01 -05001296 fp = GrBicubicEffect::MakeSubset(std::move(texView),
1297 input->colorInfo().alphaType(),
Brian Salomonbacbb922021-01-21 19:48:00 -05001298 SkMatrix::I(),
Brian Salomon1c86b632020-12-11 12:36:01 -05001299 kWM,
1300 kWM,
1301 SkRect::Make(srcRect),
1302 kKernel,
1303 dir,
1304 *this->caps());
Brian Salomon59f31b12020-06-04 17:27:15 -04001305 } else {
Mike Reed1efa14d2021-01-02 21:44:59 -05001306 auto filter = rescaleMode == RescaleMode::kNearest ? GrSamplerState::Filter::kNearest
1307 : GrSamplerState::Filter::kLinear;
Brian Salomonbacbb922021-01-21 19:48:00 -05001308 auto srcRectF = SkRect::Make(srcRect);
1309 fp = GrTextureEffect::MakeSubset(std::move(texView),
1310 this->colorInfo().alphaType(),
1311 SkMatrix::I(),
1312 {filter, GrSamplerState::MipmapMode::kNone},
1313 srcRectF,
1314 srcRectF,
1315 *this->caps());
Brian Salomone9ad9982019-07-22 16:17:41 -04001316 }
Brian Salomonbacbb922021-01-21 19:48:00 -05001317 if (xform) {
1318 fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(xform));
1319 }
1320 stepDst->fillRectToRectWithFP(srcRect, stepDstRect, std::move(fp));
Brian Salomon4bd9fcc2020-12-11 13:52:03 -05001321 texView = stepDst->readSurfaceView();
Brian Salomonbf6b9792019-08-21 09:38:10 -04001322 tempA = std::move(tempB);
Brian Salomonafd8a6c2020-05-21 12:10:54 -04001323 srcRect = SkIRect::MakeSize(nextDims);
Brian Salomon827bb722021-05-06 16:24:21 -04001324 } while (srcRect.size() != finalSize);
Brian Salomon1c86b632020-12-11 12:36:01 -05001325 return true;
Brian Salomone9ad9982019-07-22 16:17:41 -04001326}
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001327
1328GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorType dstCT,
1329 const SkIRect& rect) {
1330 SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
1331 SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
Robert Phillipsf8f45d92020-07-01 11:11:18 -04001332 auto direct = fContext->asDirectContext();
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001333 if (!direct) {
1334 return {};
1335 }
1336 auto rtProxy = this->asRenderTargetProxy();
1337 if (rtProxy && rtProxy->wrapsVkSecondaryCB()) {
1338 return {};
1339 }
1340
1341 auto proxy = this->asSurfaceProxy();
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001342 auto supportedRead = this->caps()->supportedReadPixelsColorType(this->colorInfo().colorType(),
1343 proxy->backendFormat(), dstCT);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001344 // Fail if read color type does not have all of dstCT's color channels and those missing color
1345 // channels are in the src.
Brian Salomon2f23ae62020-03-26 16:17:56 -04001346 uint32_t dstChannels = GrColorTypeChannelFlags(dstCT);
1347 uint32_t legalReadChannels = GrColorTypeChannelFlags(supportedRead.fColorType);
1348 uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
1349 if ((~legalReadChannels & dstChannels) & srcChannels) {
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001350 return {};
1351 }
1352
Brian Salomonfb28c6f2020-01-10 13:04:45 -05001353 if (!this->caps()->transferFromSurfaceToBufferSupport() ||
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001354 !supportedRead.fOffsetAlignmentForTransferBuffer) {
1355 return {};
1356 }
1357
1358 size_t rowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * rect.width();
Jim Van Vertha655f0d2021-05-18 15:03:27 -04001359 rowBytes = GrAlignTo(rowBytes, this->caps()->transferBufferAlignment());
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001360 size_t size = rowBytes * rect.height();
Greg Daniel2e967df2021-02-08 10:38:31 -05001361 // By using kStream_GrAccessPattern here, we are not able to cache and reuse the buffer for
1362 // multiple reads. Switching to kDynamic_GrAccessPattern would allow for this, however doing
1363 // so causes a crash in a chromium test. See skbug.com/11297
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001364 auto buffer = direct->priv().resourceProvider()->createBuffer(
Greg Daniel393debc2021-02-06 03:37:20 +00001365 size, GrGpuBufferType::kXferGpuToCpu, GrAccessPattern::kStream_GrAccessPattern);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001366 if (!buffer) {
1367 return {};
1368 }
1369 auto srcRect = rect;
Greg Danielb8d84f82020-02-13 14:25:00 -05001370 bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001371 if (flip) {
1372 srcRect = SkIRect::MakeLTRB(rect.fLeft, this->height() - rect.fBottom, rect.fRight,
1373 this->height() - rect.fTop);
1374 }
Greg Danielbbfec9d2019-08-20 10:56:51 -04001375 this->drawingManager()->newTransferFromRenderTask(this->asSurfaceProxyRef(), srcRect,
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001376 this->colorInfo().colorType(),
Greg Danielbbfec9d2019-08-20 10:56:51 -04001377 supportedRead.fColorType, buffer, 0);
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001378 PixelTransferResult result;
1379 result.fTransferBuffer = std::move(buffer);
Brian Salomon4bc0c1f2019-09-30 15:12:27 -04001380 auto at = this->colorInfo().alphaType();
Brian Salomon8f8354a2019-07-31 20:12:02 -04001381 if (supportedRead.fColorType != dstCT || flip) {
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001382 result.fPixelConverter = [w = rect.width(), h = rect.height(), dstCT, supportedRead, at](
1383 void* dst, const void* src) {
Brian Salomonf2ebdd92019-09-30 12:15:30 -04001384 GrImageInfo srcInfo(supportedRead.fColorType, at, nullptr, w, h);
1385 GrImageInfo dstInfo(dstCT, at, nullptr, w, h);
Brian Salomon5392c942021-03-30 16:14:37 -04001386 GrConvertPixels( GrPixmap(dstInfo, dst, dstInfo.minRowBytes()),
1387 GrCPixmap(srcInfo, src, srcInfo.minRowBytes()));
Brian Salomon4d2d6f42019-07-26 14:15:11 -04001388 };
1389 }
1390 return result;
1391}
Greg Daniel46e366a2019-12-16 14:38:36 -05001392
1393#ifdef SK_DEBUG
1394void GrSurfaceContext::validate() const {
Greg Daniel3912a4b2020-01-14 09:56:04 -05001395 SkASSERT(fReadView.proxy());
1396 fReadView.proxy()->validate(fContext);
Brian Salomonc5243782020-04-02 12:50:34 -04001397 if (this->colorInfo().colorType() != GrColorType::kUnknown) {
1398 SkASSERT(fContext->priv().caps()->areColorTypeAndFormatCompatible(
1399 this->colorInfo().colorType(), fReadView.proxy()->backendFormat()));
1400 }
Greg Daniel46e366a2019-12-16 14:38:36 -05001401 this->onValidate();
1402}
1403#endif