Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 1 | /* |
| 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 Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrSurfaceContext.h" |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/GrRecordingContext.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 11 | #include "src/core/SkAutoPixmapStorage.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrAuditTrail.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrClip.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrDrawingManager.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrGpu.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceContextPriv.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrSurfacePriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/SkGr.h" |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 24 | #include "src/gpu/effects/GrBicubicEffect.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 25 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 26 | #define ASSERT_SINGLE_OWNER \ |
| 27 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 28 | #define RETURN_FALSE_IF_ABANDONED if (this->fContext->priv().abandoned()) { return false; } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 29 | |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 30 | std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context, |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 31 | GrSurfaceProxyView readView, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 32 | GrColorType colorType, |
| 33 | SkAlphaType alphaType, |
| 34 | sk_sp<SkColorSpace> colorSpace) { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 35 | // It is probably not necessary to check if the context is abandoned here since uses of the |
| 36 | // GrSurfaceContext which need the context will mostly likely fail later on without an issue. |
| 37 | // However having this hear adds some reassurance in case there is a path doesn't handle an |
| 38 | // abandoned context correctly. It also lets us early out of some extra work. |
| 39 | if (context->priv().abandoned()) { |
| 40 | return nullptr; |
| 41 | } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 42 | GrSurfaceProxy* proxy = readView.proxy(); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 43 | SkASSERT(proxy && proxy->asTextureProxy()); |
| 44 | |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 45 | std::unique_ptr<GrSurfaceContext> surfaceContext; |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 46 | if (proxy->asRenderTargetProxy()) { |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 47 | SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType); |
| 48 | // Will we ever want a swizzle that is not the default output swizzle for the format and |
| 49 | // colorType here? If so we will need to manually pass that in. |
| 50 | GrSwizzle outSwizzle = context->priv().caps()->getOutputSwizzle(proxy->backendFormat(), |
| 51 | colorType); |
Greg Daniel | c61d7e3 | 2020-02-04 14:27:45 -0500 | [diff] [blame^] | 52 | GrSurfaceProxyView outputView(readView.refProxy(), readView.origin(), outSwizzle); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 53 | surfaceContext.reset(new GrRenderTargetContext(context, std::move(readView), |
| 54 | std::move(outputView), colorType, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 55 | std::move(colorSpace), nullptr)); |
| 56 | } else { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 57 | surfaceContext.reset(new GrSurfaceContext(context, std::move(readView), colorType, |
| 58 | alphaType, std::move(colorSpace))); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 59 | } |
Robert Phillips | 07f0e41 | 2020-01-17 15:20:00 -0500 | [diff] [blame] | 60 | SkDEBUGCODE(surfaceContext->validate();) |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 61 | return surfaceContext; |
| 62 | } |
| 63 | |
| 64 | std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make( |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 65 | GrRecordingContext* context, |
| 66 | const SkISize& dimensions, |
| 67 | const GrBackendFormat& format, |
| 68 | GrRenderable renderable, |
| 69 | int renderTargetSampleCnt, |
| 70 | GrMipMapped mipMapped, |
| 71 | GrProtected isProtected, |
| 72 | GrSurfaceOrigin origin, |
| 73 | GrColorType colorType, |
| 74 | SkAlphaType alphaType, |
| 75 | sk_sp<SkColorSpace> colorSpace, |
| 76 | SkBackingFit fit, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 77 | SkBudgeted budgeted) { |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 78 | GrSurfaceDesc desc; |
| 79 | desc.fWidth = dimensions.width(); |
| 80 | desc.fHeight = dimensions.height(); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 81 | |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 82 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, colorType); |
| 83 | |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 84 | sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy( |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 85 | format, desc, swizzle, renderable, renderTargetSampleCnt, origin, mipMapped, fit, |
| 86 | budgeted, isProtected); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 87 | if (!proxy) { |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 91 | GrSurfaceProxyView view(std::move(proxy), origin, swizzle); |
| 92 | return GrSurfaceContext::Make(context, std::move(view), colorType, alphaType, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 93 | std::move(colorSpace)); |
| 94 | } |
| 95 | |
| 96 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 97 | // In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress |
| 98 | // GrOpsTasks to be picked up and added to by renderTargetContexts lower in the call |
| 99 | // stack. When this occurs with a closed GrOpsTask, a new one will be allocated |
| 100 | // when the renderTargetContext attempts to use it (via getOpsTask). |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 101 | GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context, |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 102 | GrSurfaceProxyView readView, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 103 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 104 | SkAlphaType alphaType, |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 105 | sk_sp<SkColorSpace> colorSpace) |
Greg Daniel | 901b98e | 2019-10-22 09:54:02 -0400 | [diff] [blame] | 106 | : fContext(context) |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 107 | , fReadView(std::move(readView)) |
| 108 | , fColorInfo(colorType, alphaType, std::move(colorSpace)) { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 109 | SkASSERT(!context->priv().abandoned()); |
| 110 | } |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 111 | |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 112 | const GrCaps* GrSurfaceContext::caps() const { return fContext->priv().caps(); } |
| 113 | |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 114 | GrAuditTrail* GrSurfaceContext::auditTrail() { |
| 115 | return fContext->priv().auditTrail(); |
| 116 | } |
| 117 | |
| 118 | GrDrawingManager* GrSurfaceContext::drawingManager() { |
| 119 | return fContext->priv().drawingManager(); |
| 120 | } |
| 121 | |
| 122 | const GrDrawingManager* GrSurfaceContext::drawingManager() const { |
| 123 | return fContext->priv().drawingManager(); |
| 124 | } |
| 125 | |
| 126 | #ifdef SK_DEBUG |
| 127 | GrSingleOwner* GrSurfaceContext::singleOwner() { |
| 128 | return fContext->priv().singleOwner(); |
| 129 | } |
| 130 | #endif |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 131 | |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 132 | bool GrSurfaceContext::readPixels(const GrImageInfo& origDstInfo, void* dst, size_t rowBytes, |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 133 | SkIPoint pt, GrContext* direct) { |
| 134 | ASSERT_SINGLE_OWNER |
| 135 | RETURN_FALSE_IF_ABANDONED |
| 136 | SkDEBUGCODE(this->validate();) |
| 137 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels"); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 138 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 139 | if (!direct && !(direct = fContext->priv().asDirectContext())) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 140 | return false; |
| 141 | } |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 142 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 143 | if (!dst) { |
| 144 | return false; |
| 145 | } |
| 146 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 147 | size_t tightRowBytes = origDstInfo.minRowBytes(); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 148 | if (!rowBytes) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 149 | rowBytes = tightRowBytes; |
| 150 | } else if (rowBytes < tightRowBytes) { |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (!origDstInfo.isValid()) { |
| 155 | return false; |
| 156 | } |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 157 | |
| 158 | GrSurfaceProxy* srcProxy = this->asSurfaceProxy(); |
| 159 | |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 160 | if (srcProxy->framebufferOnly()) { |
| 161 | return false; |
| 162 | } |
| 163 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 164 | // MDB TODO: delay this instantiation until later in the method |
| 165 | if (!srcProxy->instantiate(direct->priv().resourceProvider())) { |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | GrSurface* srcSurface = srcProxy->peekSurface(); |
| 170 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 171 | auto dstInfo = origDstInfo; |
| 172 | if (!dstInfo.clip(this->width(), this->height(), &pt, &dst, rowBytes)) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 173 | return false; |
| 174 | } |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 175 | // Our tight row bytes may have been changed by clipping. |
| 176 | tightRowBytes = dstInfo.minRowBytes(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 177 | |
Mike Klein | 7321e6a | 2019-12-03 11:08:40 -0600 | [diff] [blame] | 178 | SkColorSpaceXformSteps::Flags flags = SkColorSpaceXformSteps{this->colorInfo(), dstInfo}.flags; |
| 179 | bool unpremul = flags.unpremul, |
| 180 | needColorConversion = flags.linearize || flags.gamut_transform || flags.encode, |
| 181 | premul = flags.premul; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 182 | |
| 183 | const GrCaps* caps = direct->priv().caps(); |
Robert Phillips | 07f0e41 | 2020-01-17 15:20:00 -0500 | [diff] [blame] | 184 | bool srcIsCompressed = caps->isFormatCompressed(srcSurface->backendFormat()); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 185 | // This is the getImageData equivalent to the canvas2D putImageData fast path. We probably don't |
| 186 | // care so much about getImageData performance. However, in order to ensure putImageData/ |
| 187 | // getImageData in "legacy" mode are round-trippable we use the GPU to do the complementary |
| 188 | // unpremul step to writeSurfacePixels's premul step (which is determined empirically in |
| 189 | // fContext->vaildaPMUPMConversionExists()). |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 190 | GrBackendFormat defaultRGBAFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 191 | GrRenderable::kYes); |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 192 | GrColorType srcColorType = this->colorInfo().colorType(); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 193 | bool canvas2DFastPath = unpremul && !needColorConversion && |
| 194 | (GrColorType::kRGBA_8888 == dstInfo.colorType() || |
| 195 | GrColorType::kBGRA_8888 == dstInfo.colorType()) && |
| 196 | SkToBool(srcProxy->asTextureProxy()) && |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 197 | (srcColorType == GrColorType::kRGBA_8888 || |
| 198 | srcColorType == GrColorType::kBGRA_8888) && |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 199 | defaultRGBAFormat.isValid() && |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 200 | direct->priv().validPMUPMConversionExists(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 201 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 202 | auto readFlag = caps->surfaceSupportsReadPixels(srcSurface); |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 203 | if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 207 | if (readFlag == GrCaps::SurfaceReadPixelsSupport::kCopyToTexture2D || canvas2DFastPath) { |
Robert Phillips | 07f0e41 | 2020-01-17 15:20:00 -0500 | [diff] [blame] | 208 | GrColorType colorType = (canvas2DFastPath || srcIsCompressed) |
| 209 | ? GrColorType::kRGBA_8888 : this->colorInfo().colorType(); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 210 | sk_sp<SkColorSpace> cs = canvas2DFastPath ? nullptr : this->colorInfo().refColorSpace(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 211 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 212 | auto tempCtx = GrRenderTargetContext::Make( |
| 213 | direct, colorType, std::move(cs), SkBackingFit::kApprox, dstInfo.dimensions(), |
| 214 | 1, GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 215 | if (!tempCtx) { |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | std::unique_ptr<GrFragmentProcessor> fp; |
| 220 | if (canvas2DFastPath) { |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 221 | fp = direct->priv().createPMToUPMEffect(GrTextureEffect::Make( |
| 222 | sk_ref_sp(srcProxy->asTextureProxy()), this->colorInfo().alphaType())); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 223 | if (dstInfo.colorType() == GrColorType::kBGRA_8888) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 224 | fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA()); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 225 | dstInfo = dstInfo.makeColorType(GrColorType::kRGBA_8888); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 226 | } |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 227 | // The render target context is incorrectly tagged as kPremul even though we're writing |
| 228 | // unpremul data thanks to the PMToUPM effect. Fake out the dst alpha type so we don't |
| 229 | // double unpremul. |
| 230 | dstInfo = dstInfo.makeAlphaType(kPremul_SkAlphaType); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 231 | } else { |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 232 | fp = GrTextureEffect::Make(sk_ref_sp(srcProxy->asTextureProxy()), |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 233 | this->colorInfo().alphaType()); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 234 | } |
| 235 | if (!fp) { |
| 236 | return false; |
| 237 | } |
| 238 | GrPaint paint; |
| 239 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 240 | paint.addColorFragmentProcessor(std::move(fp)); |
| 241 | |
| 242 | tempCtx->asRenderTargetContext()->fillRectToRect( |
| 243 | GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 244 | SkRect::MakeWH(dstInfo.width(), dstInfo.height()), |
| 245 | SkRect::MakeXYWH(pt.fX, pt.fY, dstInfo.width(), dstInfo.height())); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 246 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 247 | return tempCtx->readPixels(dstInfo, dst, rowBytes, {0, 0}, direct); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 248 | } |
| 249 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 250 | bool flip = srcProxy->origin() == kBottomLeft_GrSurfaceOrigin; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 251 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 252 | auto supportedRead = caps->supportedReadPixelsColorType( |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 253 | this->colorInfo().colorType(), srcProxy->backendFormat(), dstInfo.colorType()); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 254 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 255 | bool makeTight = !caps->readPixelsRowBytesSupport() && tightRowBytes != rowBytes; |
| 256 | |
| 257 | bool convert = unpremul || premul || needColorConversion || flip || makeTight || |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 258 | (dstInfo.colorType() != supportedRead.fColorType); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 259 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 260 | std::unique_ptr<char[]> tmpPixels; |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 261 | GrImageInfo tmpInfo; |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 262 | void* readDst = dst; |
| 263 | size_t readRB = rowBytes; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 264 | if (convert) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 265 | tmpInfo = {supportedRead.fColorType, this->colorInfo().alphaType(), |
| 266 | this->colorInfo().refColorSpace(), dstInfo.width(), dstInfo.height()}; |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 267 | size_t tmpRB = tmpInfo.minRowBytes(); |
| 268 | size_t size = tmpRB * tmpInfo.height(); |
| 269 | // Chrome MSAN bots require the data to be initialized (hence the ()). |
| 270 | tmpPixels.reset(new char[size]()); |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 271 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 272 | readDst = tmpPixels.get(); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 273 | readRB = tmpRB; |
| 274 | pt.fY = flip ? srcSurface->height() - pt.fY - dstInfo.height() : pt.fY; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | direct->priv().flushSurface(srcProxy); |
| 278 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 279 | if (!direct->priv().getGpu()->readPixels(srcSurface, pt.fX, pt.fY, dstInfo.width(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 280 | dstInfo.height(), this->colorInfo().colorType(), |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 281 | supportedRead.fColorType, readDst, readRB)) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 282 | return false; |
| 283 | } |
| 284 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 285 | if (convert) { |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 286 | return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, readDst, readRB, flip); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 287 | } |
| 288 | return true; |
| 289 | } |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 290 | |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 291 | bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* src, size_t rowBytes, |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 292 | SkIPoint pt, GrContext* direct) { |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 293 | ASSERT_SINGLE_OWNER |
| 294 | RETURN_FALSE_IF_ABANDONED |
| 295 | SkDEBUGCODE(this->validate();) |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 296 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::writePixels"); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 297 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 298 | if (!direct && !(direct = fContext->priv().asDirectContext())) { |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 299 | return false; |
| 300 | } |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 301 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 302 | if (this->asSurfaceProxy()->readOnly()) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 303 | return false; |
| 304 | } |
| 305 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 306 | if (!src) { |
| 307 | return false; |
| 308 | } |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 309 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 310 | size_t tightRowBytes = origSrcInfo.minRowBytes(); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 311 | if (!rowBytes) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 312 | rowBytes = tightRowBytes; |
| 313 | } else if (rowBytes < tightRowBytes) { |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 314 | return false; |
| 315 | } |
| 316 | |
| 317 | if (!origSrcInfo.isValid()) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | |
| 321 | GrSurfaceProxy* dstProxy = this->asSurfaceProxy(); |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 322 | |
| 323 | if (dstProxy->framebufferOnly()) { |
| 324 | return false; |
| 325 | } |
| 326 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 327 | if (!dstProxy->instantiate(direct->priv().resourceProvider())) { |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | GrSurface* dstSurface = dstProxy->peekSurface(); |
| 332 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 333 | auto srcInfo = origSrcInfo; |
| 334 | if (!srcInfo.clip(this->width(), this->height(), &pt, &src, rowBytes)) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 335 | return false; |
| 336 | } |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 337 | // Our tight row bytes may have been changed by clipping. |
| 338 | tightRowBytes = srcInfo.minRowBytes(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 339 | |
Mike Klein | 7321e6a | 2019-12-03 11:08:40 -0600 | [diff] [blame] | 340 | SkColorSpaceXformSteps::Flags flags = SkColorSpaceXformSteps{srcInfo, this->colorInfo()}.flags; |
| 341 | bool unpremul = flags.unpremul, |
| 342 | needColorConversion = flags.linearize || flags.gamut_transform || flags.encode, |
| 343 | premul = flags.premul; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 344 | |
| 345 | const GrCaps* caps = direct->priv().caps(); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 346 | |
| 347 | auto rgbaDefaultFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 348 | GrRenderable::kNo); |
| 349 | |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 350 | GrColorType dstColorType = this->colorInfo().colorType(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 351 | // For canvas2D putImageData performance we have a special code path for unpremul RGBA_8888 srcs |
| 352 | // that are premultiplied on the GPU. This is kept as narrow as possible for now. |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 353 | bool canvas2DFastPath = !caps->avoidWritePixelsFastPath() && premul && !needColorConversion && |
| 354 | (srcInfo.colorType() == GrColorType::kRGBA_8888 || |
| 355 | srcInfo.colorType() == GrColorType::kBGRA_8888) && |
| 356 | SkToBool(this->asRenderTargetContext()) && |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 357 | (dstColorType == GrColorType::kRGBA_8888 || |
| 358 | dstColorType == GrColorType::kBGRA_8888) && |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 359 | rgbaDefaultFormat.isValid() && |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 360 | direct->priv().validPMUPMConversionExists(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 361 | |
| 362 | if (!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) { |
| 363 | GrSurfaceDesc desc; |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 364 | desc.fWidth = srcInfo.width(); |
| 365 | desc.fHeight = srcInfo.height(); |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 366 | GrColorType colorType; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 367 | |
| 368 | GrBackendFormat format; |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 369 | SkAlphaType alphaType; |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 370 | GrSwizzle tempReadSwizzle; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 371 | if (canvas2DFastPath) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 372 | colorType = GrColorType::kRGBA_8888; |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 373 | format = rgbaDefaultFormat; |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 374 | alphaType = kUnpremul_SkAlphaType; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 375 | } else { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 376 | colorType = this->colorInfo().colorType(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 377 | format = dstProxy->backendFormat().makeTexture2D(); |
| 378 | if (!format.isValid()) { |
| 379 | return false; |
| 380 | } |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 381 | alphaType = this->colorInfo().alphaType(); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 382 | tempReadSwizzle = this->readSwizzle(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Greg Daniel | 2e52ad1 | 2019-06-13 10:04:16 -0400 | [diff] [blame] | 385 | // It is more efficient for us to write pixels into a top left origin so we prefer that. |
| 386 | // However, if the final proxy isn't a render target then we must use a copy to move the |
| 387 | // data into it which requires the origins to match. If the final proxy is a render target |
| 388 | // we can use a draw instead which doesn't have this origin restriction. Thus for render |
| 389 | // targets we will use top left and otherwise we will make the origins match. |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 390 | GrSurfaceOrigin tempOrigin = |
| 391 | this->asRenderTargetContext() ? kTopLeft_GrSurfaceOrigin : dstProxy->origin(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 392 | auto tempProxy = direct->priv().proxyProvider()->createProxy( |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 393 | format, desc, tempReadSwizzle, GrRenderable::kNo, 1, tempOrigin, GrMipMapped::kNo, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 394 | SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 395 | if (!tempProxy) { |
| 396 | return false; |
| 397 | } |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 398 | SkASSERT(tempProxy->textureSwizzle() == tempReadSwizzle); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 399 | GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle); |
| 400 | GrSurfaceContext tempCtx(direct, std::move(tempView), colorType, alphaType, |
| 401 | this->colorInfo().refColorSpace()); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 402 | |
| 403 | // In the fast path we always write the srcData to the temp context as though it were RGBA. |
| 404 | // When the data is really BGRA the write will cause the R and B channels to be swapped in |
| 405 | // the intermediate surface which gets corrected by a swizzle effect when drawing to the |
| 406 | // dst. |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 407 | if (canvas2DFastPath) { |
| 408 | srcInfo = srcInfo.makeColorType(GrColorType::kRGBA_8888); |
| 409 | } |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 410 | if (!tempCtx.writePixels(srcInfo, src, rowBytes, {0, 0}, direct)) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 411 | return false; |
| 412 | } |
| 413 | |
| 414 | if (this->asRenderTargetContext()) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 415 | std::unique_ptr<GrFragmentProcessor> fp; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 416 | if (canvas2DFastPath) { |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 417 | fp = direct->priv().createUPMToPMEffect( |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 418 | GrTextureEffect::Make(std::move(tempProxy), alphaType)); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 419 | // Important: check the original src color type here! |
| 420 | if (origSrcInfo.colorType() == GrColorType::kBGRA_8888) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 421 | fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA()); |
| 422 | } |
| 423 | } else { |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 424 | fp = GrTextureEffect::Make(std::move(tempProxy), alphaType); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 425 | } |
| 426 | if (!fp) { |
| 427 | return false; |
| 428 | } |
| 429 | GrPaint paint; |
| 430 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 431 | paint.addColorFragmentProcessor(std::move(fp)); |
| 432 | this->asRenderTargetContext()->fillRectToRect( |
| 433 | GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 434 | SkRect::MakeXYWH(pt.fX, pt.fY, srcInfo.width(), srcInfo.height()), |
| 435 | SkRect::MakeWH(srcInfo.width(), srcInfo.height())); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 436 | } else { |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 437 | SkIRect srcRect = SkIRect::MakeWH(srcInfo.width(), srcInfo.height()); |
| 438 | SkIPoint dstPoint = SkIPoint::Make(pt.fX, pt.fY); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 439 | if (!this->copy(tempProxy.get(), srcRect, dstPoint)) { |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 440 | return false; |
| 441 | } |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 442 | } |
| 443 | return true; |
| 444 | } |
| 445 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 446 | GrColorType allowedColorType = |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 447 | caps->supportedWritePixelsColorType(this->colorInfo().colorType(), |
Brian Salomon | 01915c0 | 2019-08-02 09:57:21 -0400 | [diff] [blame] | 448 | dstProxy->backendFormat(), |
| 449 | srcInfo.colorType()).fColorType; |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 450 | bool flip = dstProxy->origin() == kBottomLeft_GrSurfaceOrigin; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 451 | bool makeTight = !caps->writePixelsRowBytesSupport() && rowBytes != tightRowBytes; |
| 452 | bool convert = premul || unpremul || needColorConversion || makeTight || |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 453 | (srcInfo.colorType() != allowedColorType) || flip; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 454 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 455 | std::unique_ptr<char[]> tmpPixels; |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 456 | GrColorType srcColorType = srcInfo.colorType(); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 457 | if (convert) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 458 | GrImageInfo tmpInfo(allowedColorType, this->colorInfo().alphaType(), |
| 459 | this->colorInfo().refColorSpace(), srcInfo.width(), srcInfo.height()); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 460 | auto tmpRB = tmpInfo.minRowBytes(); |
| 461 | tmpPixels.reset(new char[tmpRB * tmpInfo.height()]); |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 462 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 463 | GrConvertPixels(tmpInfo, tmpPixels.get(), tmpRB, srcInfo, src, rowBytes, flip); |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 464 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 465 | srcColorType = tmpInfo.colorType(); |
| 466 | rowBytes = tmpRB; |
| 467 | src = tmpPixels.get(); |
| 468 | pt.fY = flip ? dstSurface->height() - pt.fY - tmpInfo.height() : pt.fY; |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // On platforms that prefer flushes over VRAM use (i.e., ANGLE) we're better off forcing a |
| 472 | // complete flush here. On platforms that prefer VRAM use over flushes we're better off |
| 473 | // giving the drawing manager the chance of skipping the flush (i.e., by passing in the |
| 474 | // destination proxy) |
| 475 | // TODO: should this policy decision just be moved into the drawing manager? |
| 476 | direct->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr); |
| 477 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 478 | return direct->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(), |
| 479 | srcInfo.height(), this->colorInfo().colorType(), |
| 480 | srcColorType, src, rowBytes); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 481 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 482 | |
| 483 | bool GrSurfaceContext::copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
| 484 | ASSERT_SINGLE_OWNER |
| 485 | RETURN_FALSE_IF_ABANDONED |
| 486 | SkDEBUGCODE(this->validate();) |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 487 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContextPriv::copy"); |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 488 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 489 | const GrCaps* caps = fContext->priv().caps(); |
| 490 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 491 | SkASSERT(src->backendFormat().textureType() != GrTextureType::kExternal); |
| 492 | SkASSERT(src->origin() == this->asSurfaceProxy()->origin()); |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 493 | SkASSERT(src->textureSwizzle() == this->asSurfaceProxy()->textureSwizzle()); |
| 494 | SkASSERT(src->backendFormat() == this->asSurfaceProxy()->backendFormat()); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 495 | |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 496 | if (this->asSurfaceProxy()->framebufferOnly()) { |
| 497 | return false; |
| 498 | } |
| 499 | |
Chris Dalton | f8e5aad | 2019-08-02 12:55:23 -0600 | [diff] [blame] | 500 | if (!caps->canCopySurface(this->asSurfaceProxy(), src, srcRect, dstPoint)) { |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 501 | return false; |
| 502 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 503 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 504 | // The swizzle doesn't matter for copies and it is not used. |
| 505 | return this->drawingManager()->newCopyRenderTask( |
| 506 | GrSurfaceProxyView(sk_ref_sp(src), src->origin(), GrSwizzle()), srcRect, |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 507 | this->readSurfaceView(), dstPoint); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 508 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 509 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 510 | std::unique_ptr<GrRenderTargetContext> GrSurfaceContext::rescale( |
| 511 | const SkImageInfo& info, |
| 512 | const SkIRect& srcRect, |
| 513 | SkSurface::RescaleGamma rescaleGamma, |
| 514 | SkFilterQuality rescaleQuality) { |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 515 | auto direct = fContext->priv().asDirectContext(); |
| 516 | if (!direct) { |
| 517 | return nullptr; |
| 518 | } |
| 519 | auto rtProxy = this->asRenderTargetProxy(); |
| 520 | if (rtProxy && rtProxy->wrapsVkSecondaryCB()) { |
| 521 | return nullptr; |
| 522 | } |
| 523 | |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 524 | if (this->asSurfaceProxy()->framebufferOnly()) { |
| 525 | return nullptr; |
| 526 | } |
| 527 | |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 528 | // We rescale by drawing and don't currently support drawing to a kUnpremul destination. |
| 529 | if (info.alphaType() == kUnpremul_SkAlphaType) { |
| 530 | return nullptr; |
| 531 | } |
| 532 | |
| 533 | int srcW = srcRect.width(); |
| 534 | int srcH = srcRect.height(); |
| 535 | int srcX = srcRect.fLeft; |
| 536 | int srcY = srcRect.fTop; |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 537 | GrSurfaceProxyView texView = this->readSurfaceView(); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 538 | SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint; |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 539 | GrColorType srcColorType = this->colorInfo().colorType(); |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 540 | SkAlphaType srcAlphaType = this->colorInfo().alphaType(); |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 541 | if (!texView.asTextureProxy()) { |
| 542 | texView = GrSurfaceProxy::Copy(fContext, this->asSurfaceProxy(), this->origin(), |
| 543 | srcColorType, GrMipMapped::kNo, srcRect, |
| 544 | SkBackingFit::kApprox, SkBudgeted::kNo); |
| 545 | if (!texView.proxy()) { |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 546 | return nullptr; |
| 547 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 548 | SkASSERT(texView.asTextureProxy()); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 549 | srcX = 0; |
| 550 | srcY = 0; |
| 551 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 552 | } |
| 553 | |
| 554 | float sx = (float)info.width() / srcW; |
| 555 | float sy = (float)info.height() / srcH; |
| 556 | |
| 557 | // How many bilerp/bicubic steps to do in X and Y. + means upscaling, - means downscaling. |
| 558 | int stepsX; |
| 559 | int stepsY; |
| 560 | if (rescaleQuality > kNone_SkFilterQuality) { |
| 561 | stepsX = static_cast<int>((sx > 1.f) ? ceil(log2f(sx)) : floor(log2f(sx))); |
| 562 | stepsY = static_cast<int>((sy > 1.f) ? ceil(log2f(sy)) : floor(log2f(sy))); |
| 563 | } else { |
| 564 | stepsX = sx != 1.f; |
| 565 | stepsY = sy != 1.f; |
| 566 | } |
| 567 | SkASSERT(stepsX || stepsY); |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 568 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 569 | // Within a rescaling pass A is the input (if not null) and B is the output. At the end of the |
| 570 | // pass B is moved to A. If 'this' is the input on the first pass then tempA is null. |
| 571 | std::unique_ptr<GrRenderTargetContext> tempA; |
| 572 | std::unique_ptr<GrRenderTargetContext> tempB; |
| 573 | |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 574 | // Assume we should ignore the rescale linear request if the surface has no color space since |
| 575 | // it's unclear how we'd linearize from an unknown color space. |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 576 | if (rescaleGamma == SkSurface::kLinear && this->colorInfo().colorSpace() && |
| 577 | !this->colorInfo().colorSpace()->gammaIsLinear()) { |
| 578 | auto cs = this->colorInfo().colorSpace()->makeLinearGamma(); |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 579 | auto xform = GrColorSpaceXform::Make(this->colorInfo().colorSpace(), srcAlphaType, cs.get(), |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 580 | kPremul_SkAlphaType); |
| 581 | // We'll fall back to kRGBA_8888 if half float not supported. |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 582 | auto linearRTC = GrRenderTargetContext::MakeWithFallback( |
| 583 | fContext, GrColorType::kRGBA_F16, cs, SkBackingFit::kExact, {srcW, srcH}, 1, |
| 584 | GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 585 | if (!linearRTC) { |
| 586 | return nullptr; |
| 587 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 588 | linearRTC->drawTexture(GrNoClip(), std::move(texView), srcAlphaType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 589 | GrSamplerState::Filter::kNearest, SkBlendMode::kSrc, |
| 590 | SK_PMColor4fWHITE, SkRect::Make(srcRect), SkRect::MakeWH(srcW, srcH), |
| 591 | GrAA::kNo, GrQuadAAFlags::kNone, constraint, SkMatrix::I(), |
| 592 | std::move(xform)); |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 593 | texView = linearRTC->readSurfaceView(); |
| 594 | SkASSERT(texView.asTextureProxy()); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 595 | tempA = std::move(linearRTC); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 596 | srcX = 0; |
| 597 | srcY = 0; |
| 598 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 599 | } |
| 600 | while (stepsX || stepsY) { |
| 601 | int nextW = info.width(); |
| 602 | int nextH = info.height(); |
| 603 | if (stepsX < 0) { |
| 604 | nextW = info.width() << (-stepsX - 1); |
| 605 | stepsX++; |
| 606 | } else if (stepsX != 0) { |
| 607 | if (stepsX > 1) { |
| 608 | nextW = srcW * 2; |
| 609 | } |
| 610 | --stepsX; |
| 611 | } |
| 612 | if (stepsY < 0) { |
| 613 | nextH = info.height() << (-stepsY - 1); |
| 614 | stepsY++; |
| 615 | } else if (stepsY != 0) { |
| 616 | if (stepsY > 1) { |
| 617 | nextH = srcH * 2; |
| 618 | } |
| 619 | --stepsY; |
| 620 | } |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 621 | auto input = tempA ? tempA.get() : this; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 622 | GrColorType colorType = input->colorInfo().colorType(); |
| 623 | auto cs = input->colorInfo().refColorSpace(); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 624 | sk_sp<GrColorSpaceXform> xform; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 625 | auto prevAlphaType = input->colorInfo().alphaType(); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 626 | if (!stepsX && !stepsY) { |
| 627 | // Might as well fold conversion to final info in the last step. |
| 628 | cs = info.refColorSpace(); |
| 629 | colorType = SkColorTypeToGrColorType(info.colorType()); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 630 | xform = GrColorSpaceXform::Make(input->colorInfo().colorSpace(), |
| 631 | input->colorInfo().alphaType(), cs.get(), |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 632 | info.alphaType()); |
| 633 | } |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 634 | tempB = GrRenderTargetContext::MakeWithFallback( |
| 635 | fContext, colorType, std::move(cs), SkBackingFit::kExact, {nextW, nextH}, 1, |
| 636 | GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 637 | if (!tempB) { |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 638 | return nullptr; |
| 639 | } |
| 640 | auto dstRect = SkRect::MakeWH(nextW, nextH); |
| 641 | if (rescaleQuality == kHigh_SkFilterQuality) { |
| 642 | SkMatrix matrix; |
| 643 | matrix.setScaleTranslate((float)srcW / nextW, (float)srcH / nextH, srcX, srcY); |
| 644 | std::unique_ptr<GrFragmentProcessor> fp; |
| 645 | auto dir = GrBicubicEffect::Direction::kXY; |
| 646 | if (nextW == srcW) { |
| 647 | dir = GrBicubicEffect::Direction::kY; |
| 648 | } else if (nextH == srcH) { |
| 649 | dir = GrBicubicEffect::Direction::kX; |
| 650 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 651 | if (srcW != texView.proxy()->width() || srcH != texView.proxy()->height()) { |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 652 | auto domain = GrTextureDomain::MakeTexelDomain( |
| 653 | SkIRect::MakeXYWH(srcX, srcY, srcW, srcH), GrTextureDomain::kClamp_Mode); |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 654 | fp = GrBicubicEffect::Make(texView.detachProxy(), matrix, domain, dir, |
| 655 | prevAlphaType); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 656 | } else { |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 657 | fp = GrBicubicEffect::Make(texView.detachProxy(), matrix, dir, prevAlphaType); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 658 | } |
| 659 | if (xform) { |
| 660 | fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(xform)); |
| 661 | } |
| 662 | GrPaint paint; |
| 663 | paint.addColorFragmentProcessor(std::move(fp)); |
| 664 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 665 | tempB->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect, |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 666 | dstRect); |
| 667 | } else { |
| 668 | auto filter = rescaleQuality == kNone_SkFilterQuality ? GrSamplerState::Filter::kNearest |
| 669 | : GrSamplerState::Filter::kBilerp; |
| 670 | auto srcSubset = SkRect::MakeXYWH(srcX, srcY, srcW, srcH); |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 671 | tempB->drawTexture(GrNoClip(), std::move(texView), srcAlphaType, filter, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 672 | SkBlendMode::kSrc, SK_PMColor4fWHITE, srcSubset, dstRect, GrAA::kNo, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 673 | GrQuadAAFlags::kNone, constraint, SkMatrix::I(), std::move(xform)); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 674 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 675 | texView = tempB->readSurfaceView(); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 676 | tempA = std::move(tempB); |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 677 | srcX = srcY = 0; |
| 678 | srcW = nextW; |
| 679 | srcH = nextH; |
| 680 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 681 | } |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 682 | SkASSERT(tempA); |
| 683 | return tempA; |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 684 | } |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 685 | |
| 686 | GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorType dstCT, |
| 687 | const SkIRect& rect) { |
| 688 | SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width()); |
| 689 | SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height()); |
| 690 | auto direct = fContext->priv().asDirectContext(); |
| 691 | if (!direct) { |
| 692 | return {}; |
| 693 | } |
| 694 | auto rtProxy = this->asRenderTargetProxy(); |
| 695 | if (rtProxy && rtProxy->wrapsVkSecondaryCB()) { |
| 696 | return {}; |
| 697 | } |
| 698 | |
| 699 | auto proxy = this->asSurfaceProxy(); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 700 | auto supportedRead = this->caps()->supportedReadPixelsColorType(this->colorInfo().colorType(), |
| 701 | proxy->backendFormat(), dstCT); |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 702 | // Fail if read color type does not have all of dstCT's color channels and those missing color |
| 703 | // channels are in the src. |
| 704 | uint32_t dstComponents = GrColorTypeComponentFlags(dstCT); |
| 705 | uint32_t legalReadComponents = GrColorTypeComponentFlags(supportedRead.fColorType); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 706 | uint32_t srcComponents = GrColorTypeComponentFlags(this->colorInfo().colorType()); |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 707 | if ((~legalReadComponents & dstComponents) & srcComponents) { |
| 708 | return {}; |
| 709 | } |
| 710 | |
Brian Salomon | fb28c6f | 2020-01-10 13:04:45 -0500 | [diff] [blame] | 711 | if (!this->caps()->transferFromSurfaceToBufferSupport() || |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 712 | !supportedRead.fOffsetAlignmentForTransferBuffer) { |
| 713 | return {}; |
| 714 | } |
| 715 | |
| 716 | size_t rowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * rect.width(); |
| 717 | size_t size = rowBytes * rect.height(); |
| 718 | auto buffer = direct->priv().resourceProvider()->createBuffer( |
| 719 | size, GrGpuBufferType::kXferGpuToCpu, GrAccessPattern::kStream_GrAccessPattern); |
| 720 | if (!buffer) { |
| 721 | return {}; |
| 722 | } |
| 723 | auto srcRect = rect; |
| 724 | bool flip = proxy->origin() == kBottomLeft_GrSurfaceOrigin; |
| 725 | if (flip) { |
| 726 | srcRect = SkIRect::MakeLTRB(rect.fLeft, this->height() - rect.fBottom, rect.fRight, |
| 727 | this->height() - rect.fTop); |
| 728 | } |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 729 | this->drawingManager()->newTransferFromRenderTask(this->asSurfaceProxyRef(), srcRect, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 730 | this->colorInfo().colorType(), |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 731 | supportedRead.fColorType, buffer, 0); |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 732 | PixelTransferResult result; |
| 733 | result.fTransferBuffer = std::move(buffer); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 734 | auto at = this->colorInfo().alphaType(); |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 735 | if (supportedRead.fColorType != dstCT || flip) { |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 736 | result.fPixelConverter = [w = rect.width(), h = rect.height(), dstCT, supportedRead, at]( |
| 737 | void* dst, const void* src) { |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 738 | GrImageInfo srcInfo(supportedRead.fColorType, at, nullptr, w, h); |
| 739 | GrImageInfo dstInfo(dstCT, at, nullptr, w, h); |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 740 | GrConvertPixels(dstInfo, dst, dstInfo.minRowBytes(), |
| 741 | srcInfo, src, srcInfo.minRowBytes(), |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 742 | /* flipY = */ false); |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 743 | }; |
| 744 | } |
| 745 | return result; |
| 746 | } |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 747 | |
| 748 | #ifdef SK_DEBUG |
| 749 | void GrSurfaceContext::validate() const { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 750 | SkASSERT(fReadView.proxy()); |
| 751 | fReadView.proxy()->validate(fContext); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 752 | SkASSERT(fContext->priv().caps()->areColorTypeAndFormatCompatible( |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 753 | this->colorInfo().colorType(), fReadView.proxy()->backendFormat())); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 754 | |
| 755 | this->onValidate(); |
| 756 | } |
| 757 | #endif |
| 758 | |