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