robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrRenderTargetContext.h" |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkDrawable.h" |
Brian Osman | f5ecf51 | 2020-04-01 09:29:13 -0400 | [diff] [blame] | 11 | #include "include/core/SkVertices.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrBackendSemaphore.h" |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 13 | #include "include/private/GrImageContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/private/GrRecordingContext.h" |
| 15 | #include "include/private/SkShadowFlags.h" |
| 16 | #include "include/utils/SkShadowUtils.h" |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 17 | #include "src/core/SkAutoPixmapStorage.h" |
| 18 | #include "src/core/SkConvertPixels.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/core/SkDrawShadowInfo.h" |
| 20 | #include "src/core/SkGlyphRunPainter.h" |
| 21 | #include "src/core/SkLatticeIter.h" |
| 22 | #include "src/core/SkMatrixPriv.h" |
| 23 | #include "src/core/SkRRectPriv.h" |
| 24 | #include "src/core/SkSurfacePriv.h" |
Brian Osman | 28ba528 | 2019-10-30 14:18:07 -0400 | [diff] [blame] | 25 | #include "src/core/SkYUVMath.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/gpu/GrAppliedClip.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 27 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "src/gpu/GrBlurUtils.h" |
| 29 | #include "src/gpu/GrCaps.h" |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 30 | #include "src/gpu/GrClientMappedBufferManager.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 31 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 33 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/GrDrawingManager.h" |
| 35 | #include "src/gpu/GrFixedClip.h" |
| 36 | #include "src/gpu/GrGpuResourcePriv.h" |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 37 | #include "src/gpu/GrImageContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 38 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 39 | #include "src/gpu/GrMemoryPool.h" |
| 40 | #include "src/gpu/GrPathRenderer.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 41 | #include "src/gpu/GrProxyProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 42 | #include "src/gpu/GrRecordingContextPriv.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 43 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 44 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 45 | #include "src/gpu/GrResourceProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 46 | #include "src/gpu/GrStencilAttachment.h" |
| 47 | #include "src/gpu/GrStyle.h" |
| 48 | #include "src/gpu/GrTracing.h" |
| 49 | #include "src/gpu/SkGr.h" |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 50 | #include "src/gpu/effects/GrBicubicEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 51 | #include "src/gpu/effects/GrRRectEffect.h" |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 52 | #include "src/gpu/effects/generated/GrColorMatrixFragmentProcessor.h" |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 53 | #include "src/gpu/geometry/GrQuad.h" |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 54 | #include "src/gpu/geometry/GrQuadUtils.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 55 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 56 | #include "src/gpu/ops/GrAtlasTextOp.h" |
| 57 | #include "src/gpu/ops/GrClearOp.h" |
| 58 | #include "src/gpu/ops/GrClearStencilClipOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 59 | #include "src/gpu/ops/GrDrawAtlasOp.h" |
| 60 | #include "src/gpu/ops/GrDrawOp.h" |
| 61 | #include "src/gpu/ops/GrDrawVerticesOp.h" |
| 62 | #include "src/gpu/ops/GrDrawableOp.h" |
| 63 | #include "src/gpu/ops/GrFillRRectOp.h" |
| 64 | #include "src/gpu/ops/GrFillRectOp.h" |
| 65 | #include "src/gpu/ops/GrLatticeOp.h" |
| 66 | #include "src/gpu/ops/GrOp.h" |
| 67 | #include "src/gpu/ops/GrOvalOpFactory.h" |
| 68 | #include "src/gpu/ops/GrRegionOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 69 | #include "src/gpu/ops/GrShadowRRectOp.h" |
| 70 | #include "src/gpu/ops/GrStencilPathOp.h" |
| 71 | #include "src/gpu/ops/GrStrokeRectOp.h" |
| 72 | #include "src/gpu/ops/GrTextureOp.h" |
| 73 | #include "src/gpu/text/GrTextContext.h" |
| 74 | #include "src/gpu/text/GrTextTarget.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 75 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 76 | class GrRenderTargetContext::TextTarget : public GrTextTarget { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 77 | public: |
| 78 | TextTarget(GrRenderTargetContext* renderTargetContext) |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 79 | : GrTextTarget(renderTargetContext->width(), renderTargetContext->height(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 80 | renderTargetContext->colorInfo()) |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 81 | , fRenderTargetContext(renderTargetContext) |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 82 | , fGlyphPainter{*renderTargetContext} {} |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 83 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 84 | void addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) override { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 85 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 86 | } |
| 87 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 88 | void drawShape(const GrClip& clip, |
| 89 | const SkPaint& paint, |
| 90 | const SkMatrixProvider& matrixProvider, |
| 91 | const GrStyledShape& shape) override { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 92 | GrBlurUtils::drawShapeWithMaskFilter(fRenderTargetContext->fContext, fRenderTargetContext, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 93 | clip, paint, matrixProvider, shape); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 96 | void makeGrPaint(GrMaskFormat maskFormat, |
| 97 | const SkPaint& skPaint, |
| 98 | const SkMatrixProvider& matrixProvider, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 99 | GrPaint* grPaint) override { |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 100 | auto context = fRenderTargetContext->fContext; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 101 | const GrColorInfo& colorInfo = fRenderTargetContext->colorInfo(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 102 | if (kARGB_GrMaskFormat == maskFormat) { |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 103 | SkPaintToGrPaintWithPrimitiveColor(context, colorInfo, skPaint, matrixProvider, |
| 104 | grPaint); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 105 | } else { |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 106 | SkPaintToGrPaint(context, colorInfo, skPaint, matrixProvider, grPaint); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 110 | GrRecordingContext* getContext() override { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 111 | return fRenderTargetContext->fContext; |
| 112 | } |
| 113 | |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 114 | SkGlyphRunListPainter* glyphPainter() override { |
| 115 | return &fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 118 | private: |
| 119 | GrRenderTargetContext* fRenderTargetContext; |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 120 | SkGlyphRunListPainter fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 121 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 122 | }; |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 123 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 124 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 125 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 126 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 127 | #define ASSERT_SINGLE_OWNER_PRIV \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 128 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 129 | #define RETURN_IF_ABANDONED if (fContext->priv().abandoned()) { return; } |
| 130 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return; } |
| 131 | #define RETURN_FALSE_IF_ABANDONED if (fContext->priv().abandoned()) { return false; } |
| 132 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return false; } |
| 133 | #define RETURN_NULL_IF_ABANDONED if (fContext->priv().abandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 134 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 135 | ////////////////////////////////////////////////////////////////////////////// |
| 136 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 137 | class AutoCheckFlush { |
| 138 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 139 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 140 | SkASSERT(fDrawingManager); |
| 141 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 142 | ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 143 | |
| 144 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 145 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 148 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make( |
| 149 | GrRecordingContext* context, |
| 150 | GrColorType colorType, |
| 151 | sk_sp<SkColorSpace> colorSpace, |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 152 | sk_sp<GrSurfaceProxy> proxy, |
| 153 | GrSurfaceOrigin origin, |
| 154 | const SkSurfaceProps* surfaceProps, |
| 155 | bool managedOps) { |
| 156 | if (!proxy) { |
| 157 | return nullptr; |
| 158 | } |
| 159 | |
| 160 | const GrBackendFormat& format = proxy->backendFormat(); |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 161 | GrSwizzle readSwizzle, writeSwizzle; |
| 162 | if (colorType != GrColorType::kUnknown) { |
| 163 | readSwizzle = context->priv().caps()->getReadSwizzle(format, colorType); |
| 164 | writeSwizzle = context->priv().caps()->getWriteSwizzle(format, colorType); |
| 165 | } |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 166 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 167 | GrSurfaceProxyView readView(proxy, origin, readSwizzle); |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 168 | GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 169 | |
| 170 | return std::make_unique<GrRenderTargetContext>(context, std::move(readView), |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 171 | std::move(writeView), colorType, |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 172 | std::move(colorSpace), surfaceProps, managedOps); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make( |
| 176 | GrRecordingContext* context, |
| 177 | GrColorType colorType, |
| 178 | sk_sp<SkColorSpace> colorSpace, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 179 | SkBackingFit fit, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 180 | SkISize dimensions, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 181 | const GrBackendFormat& format, |
| 182 | int sampleCnt, |
| 183 | GrMipMapped mipMapped, |
| 184 | GrProtected isProtected, |
| 185 | GrSurfaceOrigin origin, |
| 186 | SkBudgeted budgeted, |
| 187 | const SkSurfaceProps* surfaceProps) { |
| 188 | // It is probably not necessary to check if the context is abandoned here since uses of the |
| 189 | // GrRenderTargetContext which need the context will mostly likely fail later on without an |
| 190 | // issue. However having this hear adds some reassurance in case there is a path doesn't handle |
| 191 | // an abandoned context correctly. It also lets us early out of some extra work. |
| 192 | if (context->priv().abandoned()) { |
| 193 | return nullptr; |
| 194 | } |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 195 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 196 | sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 197 | format, dimensions, GrRenderable::kYes, sampleCnt, mipMapped, fit, budgeted, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 198 | isProtected); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 199 | if (!proxy) { |
| 200 | return nullptr; |
| 201 | } |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 202 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 203 | auto rtc = GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), |
| 204 | std::move(proxy), origin, surfaceProps, true); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 205 | if (!rtc) { |
| 206 | return nullptr; |
| 207 | } |
| 208 | rtc->discard(); |
| 209 | return rtc; |
| 210 | } |
| 211 | |
| 212 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make( |
| 213 | GrRecordingContext* context, |
| 214 | GrColorType colorType, |
| 215 | sk_sp<SkColorSpace> colorSpace, |
| 216 | SkBackingFit fit, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 217 | SkISize dimensions, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 218 | int sampleCnt, |
| 219 | GrMipMapped mipMapped, |
| 220 | GrProtected isProtected, |
| 221 | GrSurfaceOrigin origin, |
| 222 | SkBudgeted budgeted, |
| 223 | const SkSurfaceProps* surfaceProps) { |
| 224 | auto format = context->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes); |
| 225 | if (!format.isValid()) { |
| 226 | return nullptr; |
| 227 | } |
| 228 | |
| 229 | return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), fit, dimensions, |
| 230 | format, sampleCnt, mipMapped, isProtected, origin, budgeted, |
| 231 | surfaceProps); |
| 232 | } |
| 233 | |
| 234 | static inline GrColorType color_type_fallback(GrColorType ct) { |
| 235 | switch (ct) { |
| 236 | // kRGBA_8888 is our default fallback for many color types that may not have renderable |
| 237 | // backend formats. |
| 238 | case GrColorType::kAlpha_8: |
| 239 | case GrColorType::kBGR_565: |
| 240 | case GrColorType::kABGR_4444: |
| 241 | case GrColorType::kBGRA_8888: |
| 242 | case GrColorType::kRGBA_1010102: |
| 243 | case GrColorType::kRGBA_F16: |
| 244 | case GrColorType::kRGBA_F16_Clamped: |
| 245 | return GrColorType::kRGBA_8888; |
| 246 | case GrColorType::kAlpha_F16: |
| 247 | return GrColorType::kRGBA_F16; |
| 248 | case GrColorType::kGray_8: |
| 249 | return GrColorType::kRGB_888x; |
| 250 | default: |
| 251 | return GrColorType::kUnknown; |
| 252 | } |
| 253 | } |
| 254 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 255 | std::tuple<GrColorType, GrBackendFormat> GrRenderTargetContext::GetFallbackColorTypeAndFormat( |
Brian Salomon | 0029db0 | 2020-04-03 10:41:24 -0400 | [diff] [blame] | 256 | GrImageContext* context, GrColorType colorType, int sampleCnt) { |
| 257 | auto caps = context->priv().caps(); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 258 | do { |
Brian Salomon | 0029db0 | 2020-04-03 10:41:24 -0400 | [diff] [blame] | 259 | auto format = caps->getDefaultBackendFormat(colorType, GrRenderable::kYes); |
| 260 | // We continue to the fallback color type if there no default renderable format or we |
| 261 | // requested msaa and the format doesn't support msaa. |
| 262 | if (format.isValid() && caps->isFormatRenderable(format, sampleCnt)) { |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 263 | return {colorType, format}; |
| 264 | } |
| 265 | colorType = color_type_fallback(colorType); |
| 266 | } while (colorType != GrColorType::kUnknown); |
| 267 | return {GrColorType::kUnknown, {}}; |
| 268 | } |
| 269 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 270 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeWithFallback( |
| 271 | GrRecordingContext* context, |
| 272 | GrColorType colorType, |
| 273 | sk_sp<SkColorSpace> colorSpace, |
| 274 | SkBackingFit fit, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 275 | SkISize dimensions, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 276 | int sampleCnt, |
| 277 | GrMipMapped mipMapped, |
| 278 | GrProtected isProtected, |
| 279 | GrSurfaceOrigin origin, |
| 280 | SkBudgeted budgeted, |
| 281 | const SkSurfaceProps* surfaceProps) { |
Brian Salomon | 0029db0 | 2020-04-03 10:41:24 -0400 | [diff] [blame] | 282 | auto [ct, format] = GetFallbackColorTypeAndFormat(context, colorType, sampleCnt); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 283 | if (ct == GrColorType::kUnknown) { |
| 284 | return nullptr; |
| 285 | } |
| 286 | return GrRenderTargetContext::Make(context, ct, colorSpace, fit, dimensions, sampleCnt, |
| 287 | mipMapped, isProtected, origin, budgeted, surfaceProps); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 290 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTexture( |
| 291 | GrRecordingContext* context, |
| 292 | GrColorType colorType, |
| 293 | sk_sp<SkColorSpace> colorSpace, |
| 294 | const GrBackendTexture& tex, |
| 295 | int sampleCnt, |
| 296 | GrSurfaceOrigin origin, |
| 297 | const SkSurfaceProps* surfaceProps, |
| 298 | ReleaseProc releaseProc, |
| 299 | ReleaseContext releaseCtx) { |
| 300 | SkASSERT(sampleCnt > 0); |
| 301 | sk_sp<GrTextureProxy> proxy(context->priv().proxyProvider()->wrapRenderableBackendTexture( |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 302 | tex, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, releaseProc, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 303 | releaseCtx)); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 304 | if (!proxy) { |
| 305 | return nullptr; |
| 306 | } |
| 307 | |
| 308 | return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), std::move(proxy), |
| 309 | origin, surfaceProps); |
| 310 | } |
| 311 | |
| 312 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTextureAsRenderTarget( |
| 313 | GrRecordingContext* context, |
| 314 | GrColorType colorType, |
| 315 | sk_sp<SkColorSpace> colorSpace, |
| 316 | const GrBackendTexture& tex, |
| 317 | int sampleCnt, |
| 318 | GrSurfaceOrigin origin, |
| 319 | const SkSurfaceProps* surfaceProps) { |
| 320 | SkASSERT(sampleCnt > 0); |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 321 | sk_sp<GrSurfaceProxy> proxy( |
| 322 | context->priv().proxyProvider()->wrapBackendTextureAsRenderTarget(tex, sampleCnt)); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 323 | if (!proxy) { |
| 324 | return nullptr; |
| 325 | } |
| 326 | |
| 327 | return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), std::move(proxy), |
| 328 | origin, surfaceProps); |
| 329 | } |
| 330 | |
| 331 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendRenderTarget( |
| 332 | GrRecordingContext* context, |
| 333 | GrColorType colorType, |
| 334 | sk_sp<SkColorSpace> colorSpace, |
| 335 | const GrBackendRenderTarget& rt, |
| 336 | GrSurfaceOrigin origin, |
| 337 | const SkSurfaceProps* surfaceProps, |
| 338 | ReleaseProc releaseProc, |
| 339 | ReleaseContext releaseCtx) { |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 340 | sk_sp<GrSurfaceProxy> proxy( |
| 341 | context->priv().proxyProvider()->wrapBackendRenderTarget(rt, releaseProc, releaseCtx)); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 342 | if (!proxy) { |
| 343 | return nullptr; |
| 344 | } |
| 345 | |
| 346 | return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), std::move(proxy), |
| 347 | origin, surfaceProps); |
| 348 | } |
| 349 | |
| 350 | std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromVulkanSecondaryCB( |
| 351 | GrRecordingContext* context, |
| 352 | const SkImageInfo& imageInfo, |
| 353 | const GrVkDrawableInfo& vkInfo, |
| 354 | const SkSurfaceProps* props) { |
| 355 | sk_sp<GrSurfaceProxy> proxy( |
| 356 | context->priv().proxyProvider()->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, |
| 357 | vkInfo)); |
| 358 | if (!proxy) { |
| 359 | return nullptr; |
| 360 | } |
| 361 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 362 | return GrRenderTargetContext::Make(context, SkColorTypeToGrColorType(imageInfo.colorType()), |
| 363 | imageInfo.refColorSpace(), std::move(proxy), |
| 364 | kTopLeft_GrSurfaceOrigin, props); |
| 365 | } |
| 366 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 367 | // In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress |
| 368 | // GrOpsTask to be picked up and added to by renderTargetContexts lower in the call |
| 369 | // stack. When this occurs with a closed GrOpsTask, a new one will be allocated |
| 370 | // when the renderTargetContext attempts to use it (via getOpsTask). |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 371 | GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 372 | GrSurfaceProxyView readView, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 373 | GrSurfaceProxyView writeView, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 374 | GrColorType colorType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 375 | sk_sp<SkColorSpace> colorSpace, |
| 376 | const SkSurfaceProps* surfaceProps, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 377 | bool managedOpsTask) |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 378 | : GrSurfaceContext(context, std::move(readView), colorType, kPremul_SkAlphaType, |
| 379 | std::move(colorSpace)) |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 380 | , fWriteView(std::move(writeView)) |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 381 | , fOpsTask(sk_ref_sp(this->asSurfaceProxy()->getLastOpsTask())) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 382 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 383 | , fManagedOpsTask(managedOpsTask) { |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 384 | SkASSERT(this->asSurfaceProxy() == fWriteView.proxy()); |
| 385 | SkASSERT(this->origin() == fWriteView.origin()); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 386 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 387 | fTextTarget.reset(new TextTarget(this)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 388 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 389 | } |
| 390 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 391 | #ifdef SK_DEBUG |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 392 | void GrRenderTargetContext::onValidate() const { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 393 | if (fOpsTask && !fOpsTask->isClosed()) { |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 394 | SkASSERT(fWriteView.proxy()->getLastRenderTask() == fOpsTask.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 395 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 396 | } |
| 397 | #endif |
| 398 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 399 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 400 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 403 | inline GrAAType GrRenderTargetContext::chooseAAType(GrAA aa) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 404 | if (GrAA::kNo == aa) { |
| 405 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type reflect |
| 406 | // that. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 407 | if (this->numSamples() > 1 && !this->caps()->multisampleDisableSupport()) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 408 | return GrAAType::kMSAA; |
| 409 | } |
| 410 | return GrAAType::kNone; |
| 411 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 412 | return (this->numSamples() > 1) ? GrAAType::kMSAA : GrAAType::kCoverage; |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 413 | } |
| 414 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 415 | GrMipMapped GrRenderTargetContext::mipMapped() const { |
| 416 | if (const GrTextureProxy* proxy = this->asTextureProxy()) { |
| 417 | return proxy->mipMapped(); |
| 418 | } |
| 419 | return GrMipMapped::kNo; |
| 420 | } |
| 421 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 422 | GrOpsTask* GrRenderTargetContext::getOpsTask() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 423 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 424 | SkDEBUGCODE(this->validate();) |
| 425 | |
Brian Salomon | 777f239 | 2020-04-21 16:38:05 +0000 | [diff] [blame^] | 426 | if (!fOpsTask || fOpsTask->isClosed()) { |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 427 | sk_sp<GrOpsTask> newOpsTask = |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 428 | this->drawingManager()->newOpsTask(this->writeSurfaceView(), fManagedOpsTask); |
Chris Dalton | dec74f3 | 2019-10-02 02:32:37 -0600 | [diff] [blame] | 429 | if (fOpsTask && fNumStencilSamples > 0) { |
| 430 | // Store the stencil values in memory upon completion of fOpsTask. |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 431 | fOpsTask->setMustPreserveStencil(); |
| 432 | // Reload the stencil buffer content at the beginning of newOpsTask. |
| 433 | // FIXME: Could the topo sort insert a task between these two that modifies the stencil |
| 434 | // values? |
| 435 | newOpsTask->setInitialStencilContent(GrOpsTask::StencilContent::kPreserved); |
| 436 | } |
| 437 | fOpsTask = std::move(newOpsTask); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 438 | } |
Brian Salomon | 777f239 | 2020-04-21 16:38:05 +0000 | [diff] [blame^] | 439 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 440 | return fOpsTask.get(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 443 | void GrRenderTargetContext::drawGlyphRunList(const GrClip& clip, |
| 444 | const SkMatrixProvider& matrixProvider, |
| 445 | const SkGlyphRunList& blob) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 446 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 447 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 448 | SkDEBUGCODE(this->validate();) |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 449 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawGlyphRunList", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 450 | |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 451 | // Drawing text can cause us to do inline uploads. This is not supported for wrapped vulkan |
| 452 | // secondary command buffers because it would require stopping and starting a render pass which |
| 453 | // we don't have access to. |
| 454 | if (this->wrapsVkSecondaryCB()) { |
| 455 | return; |
| 456 | } |
| 457 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 458 | GrTextContext* atlasTextContext = this->drawingManager()->getTextContext(); |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 459 | atlasTextContext->drawGlyphRunList(fContext, fTextTarget.get(), clip, matrixProvider, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 460 | fSurfaceProps, blob); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 463 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 464 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 465 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 466 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 467 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "discard", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 468 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 469 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 470 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 471 | this->getOpsTask()->discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 474 | void GrRenderTargetContext::clear(const SkIRect* rect, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 475 | const SkPMColor4f& color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 476 | CanClearFullscreen canClearFullscreen) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 477 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 478 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 479 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 480 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "clear", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 481 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 482 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 483 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, |
| 484 | canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 485 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 486 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 487 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 488 | const SkPMColor4f& color, |
| 489 | CanClearFullscreen canClearFullscreen) { |
| 490 | ASSERT_SINGLE_OWNER_PRIV |
| 491 | RETURN_IF_ABANDONED_PRIV |
| 492 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 493 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clear", |
| 494 | fRenderTargetContext->fContext); |
| 495 | |
| 496 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
| 497 | fRenderTargetContext->internalClear(clip, color, canClearFullscreen); |
| 498 | } |
| 499 | |
| 500 | static void clear_to_grpaint(const SkPMColor4f& color, GrPaint* paint) { |
| 501 | paint->setColor4f(color); |
| 502 | if (color.isOpaque()) { |
| 503 | // Can just rely on the src-over blend mode to do the right thing |
| 504 | paint->setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
| 505 | } else { |
| 506 | // A clear overwrites the prior color, so even if it's transparent, it behaves as if it |
| 507 | // were src blended |
| 508 | paint->setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 513 | const SkPMColor4f& color, |
| 514 | CanClearFullscreen canClearFullscreen) { |
| 515 | bool isFull = false; |
| 516 | if (!clip.hasWindowRectangles()) { |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 517 | // TODO: wrt the shouldInitializeTextures path, it would be more performant to |
| 518 | // only clear the entire target if we knew it had not been cleared before. As |
| 519 | // is this could end up doing a lot of redundant clears. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 520 | isFull = !clip.scissorEnabled() || |
| 521 | (CanClearFullscreen::kYes == canClearFullscreen && |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 522 | (this->caps()->preferFullscreenClears() || this->caps()->shouldInitializeTextures())) || |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 523 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 524 | } |
| 525 | |
| 526 | if (isFull) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 527 | GrOpsTask* opsTask = this->getOpsTask(); |
| 528 | if (opsTask->resetForFullscreenClear(this->canDiscardPreviousOpsOnFullClear()) && |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 529 | !this->caps()->performColorClearsAsDraws()) { |
| 530 | // The op list was emptied and native clears are allowed, so just use the load op |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 531 | opsTask->setColorLoadOp(GrLoadOp::kClear, color); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 532 | return; |
| 533 | } else { |
| 534 | // Will use an op for the clear, reset the load op to discard since the op will |
| 535 | // blow away the color buffer contents |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 536 | opsTask->setColorLoadOp(GrLoadOp::kDiscard); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // Must add an op to the list (either because we couldn't use a load op, or because the |
| 540 | // clear load op isn't supported) |
| 541 | if (this->caps()->performColorClearsAsDraws()) { |
| 542 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 543 | GrPaint paint; |
| 544 | clear_to_grpaint(color, &paint); |
| 545 | this->addDrawOp(GrFixedClip::Disabled(), |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 546 | GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(), |
| 547 | rtRect)); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 548 | } else { |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 549 | this->addOp(GrClearOp::Make( |
| 550 | fContext, SkIRect::MakeEmpty(), color, /* fullscreen */ true)); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 551 | } |
| 552 | } else { |
| 553 | if (this->caps()->performPartialClearsAsDraws()) { |
| 554 | // performPartialClearsAsDraws() also returns true if any clear has to be a draw. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 555 | GrPaint paint; |
| 556 | clear_to_grpaint(color, &paint); |
| 557 | |
Michael Ludwig | 64b28a7 | 2019-05-28 12:02:00 -0400 | [diff] [blame] | 558 | this->addDrawOp(clip, |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 559 | GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(), |
| 560 | SkRect::Make(clip.scissorRect()))); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 561 | } else { |
| 562 | std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip, color, |
| 563 | this->asSurfaceProxy())); |
| 564 | // This version of the clear op factory can return null if the clip doesn't intersect |
| 565 | // with the surface proxy's boundary |
| 566 | if (!op) { |
| 567 | return; |
| 568 | } |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 569 | this->addOp(std::move(op)); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 574 | void GrRenderTargetContext::drawPaint(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 575 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 576 | const SkMatrix& viewMatrix) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 577 | // Start with the render target, since that is the maximum content we could possibly fill. |
| 578 | // drawFilledQuad() will automatically restrict it to clip bounds for us if possible. |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 579 | SkRect r = this->asSurfaceProxy()->getBoundsRect(); |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 580 | if (!paint.numTotalFragmentProcessors()) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 581 | // The paint is trivial so we won't need to use local coordinates, so skip calculating the |
| 582 | // inverse view matrix. |
| 583 | this->fillRectToRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), r, r); |
| 584 | } else { |
| 585 | // Use the inverse view matrix to arrive at appropriate local coordinates for the paint. |
| 586 | SkMatrix localMatrix; |
| 587 | if (!viewMatrix.invert(&localMatrix)) { |
| 588 | return; |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 589 | } |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 590 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), r, |
| 591 | localMatrix); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 592 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 595 | enum class GrRenderTargetContext::QuadOptimization { |
| 596 | // The rect to draw doesn't intersect clip or render target, so no draw op should be added |
| 597 | kDiscarded, |
| 598 | // The rect to draw was converted to some other op and appended to the oplist, so no additional |
| 599 | // op is necessary. Currently this can convert it to a clear op or a rrect op. Only valid if |
| 600 | // a constColor is provided. |
| 601 | kSubmitted, |
| 602 | // The clip was folded into the device quad, with updated edge flags and local coords, and |
| 603 | // caller is responsible for adding an appropriate op. |
| 604 | kClipApplied, |
| 605 | // No change to clip, but quad updated to better fit clip/render target, and caller is |
| 606 | // responsible for adding an appropriate op. |
| 607 | kCropped |
| 608 | }; |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 609 | |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 610 | static bool make_vertex_finite(float* value) { |
| 611 | if (SkScalarIsNaN(*value)) { |
| 612 | return false; |
| 613 | } |
| 614 | |
| 615 | if (!SkScalarIsFinite(*value)) { |
| 616 | // +/- infinity at this point. Don't use exactly SK_ScalarMax so that we have some precision |
| 617 | // left when calculating crops. |
| 618 | static constexpr float kNearInfinity = SK_ScalarMax / 4.f; |
| 619 | *value = *value < 0.f ? -kNearInfinity : kNearInfinity; |
| 620 | } |
| 621 | |
| 622 | return true; |
| 623 | } |
| 624 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 625 | GrRenderTargetContext::QuadOptimization GrRenderTargetContext::attemptQuadOptimization( |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 626 | const GrClip& clip, const SkPMColor4f* constColor, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 627 | const GrUserStencilSettings* stencilSettings, GrAA* aa, DrawQuad* quad) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 628 | // Optimization requirements: |
| 629 | // 1. kDiscard applies when clip bounds and quad bounds do not intersect |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 630 | // 2a. kSubmitted applies when constColor and final geom is pixel aligned rect; |
| 631 | // pixel aligned rect requires rect clip and (rect quad or quad covers clip) OR |
| 632 | // 2b. kSubmitted applies when constColor and rrect clip and quad covers clip |
| 633 | // 4. kClipApplied applies when rect clip and (rect quad or quad covers clip) |
| 634 | // 5. kCropped in all other scenarios (although a crop may be a no-op) |
| 635 | |
| 636 | // Save the old AA flags since CropToRect will modify 'quad' and if kCropped is returned, it's |
| 637 | // better to just keep the old flags instead of introducing mixed edge flags. |
| 638 | GrQuadAAFlags oldFlags = quad->fEdgeFlags; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 639 | |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 640 | SkRect rtRect; |
| 641 | if (stencilSettings) { |
Robert Phillips | e9462dd | 2019-10-23 12:41:29 -0400 | [diff] [blame] | 642 | // Must use size at which the rendertarget will ultimately be allocated so that stencil |
| 643 | // buffer updates on approximately sized render targets don't get corrupted. |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 644 | rtRect = this->asSurfaceProxy()->backingStoreBoundsRect(); |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 645 | } else { |
| 646 | // Use the logical size of the render target, which allows for "fullscreen" clears even if |
| 647 | // the render target has an approximate backing fit |
| 648 | rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 649 | } |
| 650 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 651 | SkRect drawBounds = quad->fDevice.bounds(); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 652 | if (constColor) { |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 653 | // If the device quad is not finite, coerce into a finite quad. This is acceptable since it |
| 654 | // will be cropped to the finite 'clip' or render target and there is no local space mapping |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 655 | if (!quad->fDevice.isFinite()) { |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 656 | for (int i = 0; i < 4; ++i) { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 657 | if (!make_vertex_finite(quad->fDevice.xs() + i) || |
| 658 | !make_vertex_finite(quad->fDevice.ys() + i) || |
| 659 | !make_vertex_finite(quad->fDevice.ws() + i)) { |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 660 | // Discard if we see a nan |
| 661 | return QuadOptimization::kDiscarded; |
| 662 | } |
| 663 | } |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 664 | SkASSERT(quad->fDevice.isFinite()); |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 665 | } |
| 666 | } else { |
| 667 | // CropToRect requires the quads to be finite. If they are not finite and we have local |
| 668 | // coordinates, the mapping from local space to device space is poorly defined so drop it |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 669 | if (!quad->fDevice.isFinite()) { |
Michael Ludwig | ed71b7e | 2019-06-21 13:47:02 -0400 | [diff] [blame] | 670 | return QuadOptimization::kDiscarded; |
| 671 | } |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 674 | // If the quad is entirely off screen, it doesn't matter what the clip does |
| 675 | if (!rtRect.intersects(drawBounds)) { |
| 676 | return QuadOptimization::kDiscarded; |
| 677 | } |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 678 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 679 | // Check if clip can be represented as a rounded rect (initialize as if clip fully contained |
| 680 | // the render target). |
| 681 | SkRRect clipRRect = SkRRect::MakeRect(rtRect); |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 682 | // We initialize clipAA to *aa when there are stencil settings so that we don't artificially |
| 683 | // encounter mixed-aa edges (not allowed for stencil), but we want to start as non-AA for |
| 684 | // regular draws so that if we fully cover the render target, that can stop being anti-aliased. |
| 685 | GrAA clipAA = stencilSettings ? *aa : GrAA::kNo; |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 686 | bool axisAlignedClip = true; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 687 | if (!clip.quickContains(rtRect)) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 688 | if (!clip.isRRect(rtRect, &clipRRect, &clipAA)) { |
| 689 | axisAlignedClip = false; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 690 | } |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 693 | // If the clip rrect is valid (i.e. axis-aligned), we can potentially combine it with the |
| 694 | // draw geometry so that no clip is needed when drawing. |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 695 | if (axisAlignedClip && (!stencilSettings || clipAA == *aa)) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 696 | // Tighten clip bounds (if clipRRect.isRect() is true, clipBounds now holds the intersection |
| 697 | // of the render target and the clip rect) |
| 698 | SkRect clipBounds = rtRect; |
| 699 | if (!clipBounds.intersect(clipRRect.rect()) || !clipBounds.intersects(drawBounds)) { |
| 700 | return QuadOptimization::kDiscarded; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 703 | if (clipRRect.isRect()) { |
| 704 | // No rounded corners, so the kClear and kExplicitClip optimizations are possible |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 705 | if (GrQuadUtils::CropToRect(clipBounds, clipAA, quad, /*compute local*/ !constColor)) { |
Chris Dalton | bc3307c | 2020-02-04 13:21:03 -0700 | [diff] [blame] | 706 | if (!stencilSettings && constColor && |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 707 | quad->fDevice.quadType() == GrQuad::Type::kAxisAligned) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 708 | // Clear optimization is possible |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 709 | drawBounds = quad->fDevice.bounds(); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 710 | if (drawBounds.contains(rtRect)) { |
| 711 | // Fullscreen clear |
| 712 | this->clear(nullptr, *constColor, CanClearFullscreen::kYes); |
| 713 | return QuadOptimization::kSubmitted; |
| 714 | } else if (GrClip::IsPixelAligned(drawBounds) && |
| 715 | drawBounds.width() > 256 && drawBounds.height() > 256) { |
| 716 | // Scissor + clear (round shouldn't do anything since we are pixel aligned) |
| 717 | SkIRect scissorRect; |
| 718 | drawBounds.round(&scissorRect); |
| 719 | this->clear(&scissorRect, *constColor, CanClearFullscreen::kNo); |
| 720 | return QuadOptimization::kSubmitted; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // Update overall AA setting. |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 725 | if (*aa == GrAA::kNo && clipAA == GrAA::kYes && |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 726 | quad->fEdgeFlags != GrQuadAAFlags::kNone) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 727 | // The clip was anti-aliased and now the draw needs to be upgraded to AA to |
| 728 | // properly reflect the smooth edge of the clip. |
| 729 | *aa = GrAA::kYes; |
| 730 | } |
| 731 | // We intentionally do not downgrade AA here because we don't know if we need to |
| 732 | // preserve MSAA (see GrQuadAAFlags docs). But later in the pipeline, the ops can |
| 733 | // use GrResolveAATypeForQuad() to turn off coverage AA when all flags are off. |
| 734 | |
| 735 | // deviceQuad is exactly the intersection of original quad and clip, so it can be |
| 736 | // drawn with no clip (submitted by caller) |
| 737 | return QuadOptimization::kClipApplied; |
| 738 | } else { |
| 739 | // The quads have been updated to better fit the clip bounds, but can't get rid of |
| 740 | // the clip entirely |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 741 | quad->fEdgeFlags = oldFlags; |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 742 | return QuadOptimization::kCropped; |
| 743 | } |
Chris Dalton | bc3307c | 2020-02-04 13:21:03 -0700 | [diff] [blame] | 744 | } else if (!stencilSettings && constColor) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 745 | // Rounded corners and constant filled color (limit ourselves to solid colors because |
| 746 | // there is no way to use custom local coordinates with drawRRect). |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 747 | if (GrQuadUtils::CropToRect(clipBounds, clipAA, quad, /* compute local */ false) && |
| 748 | quad->fDevice.quadType() == GrQuad::Type::kAxisAligned && |
| 749 | quad->fDevice.bounds().contains(clipBounds)) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 750 | // Since the cropped quad became a rectangle which covered the bounds of the rrect, |
| 751 | // we can draw the rrect directly and ignore the edge flags |
| 752 | GrPaint paint; |
| 753 | clear_to_grpaint(*constColor, &paint); |
| 754 | this->drawRRect(GrFixedClip::Disabled(), std::move(paint), clipAA, SkMatrix::I(), |
| 755 | clipRRect, GrStyle::SimpleFill()); |
| 756 | return QuadOptimization::kSubmitted; |
| 757 | } else { |
| 758 | // The quad has been updated to better fit clip bounds, but can't remove the clip |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 759 | quad->fEdgeFlags = oldFlags; |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 760 | return QuadOptimization::kCropped; |
| 761 | } |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 762 | } |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 765 | // Crop the quad to the conservative bounds of the clip. |
| 766 | SkIRect clipDevBounds; |
| 767 | clip.getConservativeBounds(rtRect.width(), rtRect.height(), &clipDevBounds); |
| 768 | SkRect clipBounds = SkRect::Make(clipDevBounds); |
| 769 | |
| 770 | // One final check for discarding, since we may have gone here directly due to a complex clip |
| 771 | if (!clipBounds.intersects(drawBounds)) { |
| 772 | return QuadOptimization::kDiscarded; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 775 | // Even if this were to return true, the crop rect does not exactly match the clip, so can not |
| 776 | // report explicit-clip. Since these edges aren't visible, don't update the final edge flags. |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 777 | GrQuadUtils::CropToRect(clipBounds, clipAA, quad, /* compute local */ !constColor); |
| 778 | quad->fEdgeFlags = oldFlags; |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 779 | |
| 780 | return QuadOptimization::kCropped; |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 783 | void GrRenderTargetContext::drawFilledQuad(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 784 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 785 | GrAA aa, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 786 | DrawQuad* quad, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 787 | const GrUserStencilSettings* ss) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 788 | ASSERT_SINGLE_OWNER |
| 789 | RETURN_IF_ABANDONED |
| 790 | SkDEBUGCODE(this->validate();) |
| 791 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFilledQuad", fContext); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 792 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 793 | AutoCheckFlush acf(this->drawingManager()); |
| 794 | |
| 795 | SkPMColor4f* constColor = nullptr; |
| 796 | SkPMColor4f paintColor; |
| 797 | if (!ss && !paint.numCoverageFragmentProcessors() && |
| 798 | paint.isConstantBlendedColor(&paintColor)) { |
| 799 | // Only consider clears/rrects when it's easy to guarantee 100% fill with single color |
| 800 | constColor = &paintColor; |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 801 | } |
| 802 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 803 | QuadOptimization opt = this->attemptQuadOptimization(clip, constColor, ss, &aa, quad); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 804 | if (opt >= QuadOptimization::kClipApplied) { |
| 805 | // These optimizations require caller to add an op themselves |
| 806 | const GrClip& finalClip = opt == QuadOptimization::kClipApplied ? GrFixedClip::Disabled() |
| 807 | : clip; |
| 808 | GrAAType aaType = ss ? (aa == GrAA::kYes ? GrAAType::kMSAA : GrAAType::kNone) |
| 809 | : this->chooseAAType(aa); |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 810 | this->addDrawOp(finalClip, GrFillRectOp::Make(fContext, std::move(paint), aaType, |
| 811 | quad, ss)); |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 812 | } |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 813 | // All other optimization levels were completely handled inside attempt(), so no extra op needed |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 816 | void GrRenderTargetContext::drawTexturedQuad(const GrClip& clip, |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 817 | GrSurfaceProxyView proxyView, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 818 | SkAlphaType srcAlphaType, |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 819 | sk_sp<GrColorSpaceXform> textureXform, |
| 820 | GrSamplerState::Filter filter, |
| 821 | const SkPMColor4f& color, |
| 822 | SkBlendMode blendMode, |
| 823 | GrAA aa, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 824 | DrawQuad* quad, |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 825 | const SkRect* domain) { |
| 826 | ASSERT_SINGLE_OWNER |
| 827 | RETURN_IF_ABANDONED |
| 828 | SkDEBUGCODE(this->validate();) |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 829 | SkASSERT(proxyView.asTextureProxy()); |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 830 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexturedQuad", fContext); |
| 831 | |
| 832 | AutoCheckFlush acf(this->drawingManager()); |
| 833 | |
| 834 | // Functionally this is very similar to drawFilledQuad except that there's no constColor to |
| 835 | // enable the kSubmitted optimizations, no stencil settings support, and its a GrTextureOp. |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 836 | QuadOptimization opt = this->attemptQuadOptimization(clip, nullptr, nullptr, &aa, quad); |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 837 | |
| 838 | SkASSERT(opt != QuadOptimization::kSubmitted); |
| 839 | if (opt != QuadOptimization::kDiscarded) { |
| 840 | // And the texture op if not discarded |
| 841 | const GrClip& finalClip = opt == QuadOptimization::kClipApplied ? GrFixedClip::Disabled() |
| 842 | : clip; |
| 843 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 844 | auto clampType = GrColorTypeClampType(this->colorInfo().colorType()); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 845 | auto saturate = clampType == GrClampType::kManual ? GrTextureOp::Saturate::kYes |
| 846 | : GrTextureOp::Saturate::kNo; |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 847 | // Use the provided domain, although hypothetically we could detect that the cropped local |
| 848 | // quad is sufficiently inside the domain and the constraint could be dropped. |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 849 | this->addDrawOp(finalClip, |
| 850 | GrTextureOp::Make(fContext, std::move(proxyView), srcAlphaType, |
| 851 | std::move(textureXform), filter, color, saturate, |
| 852 | blendMode, aaType, quad, domain)); |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 856 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 857 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 858 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 859 | const SkMatrix& viewMatrix, |
| 860 | const SkRect& rect, |
| 861 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 862 | if (!style) { |
| 863 | style = &GrStyle::SimpleFill(); |
| 864 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 865 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 866 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 867 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 868 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRect", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 869 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 870 | // Path effects should've been devolved to a path in SkGpuDevice |
| 871 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 872 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 873 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 874 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 875 | const SkStrokeRec& stroke = style->strokeRec(); |
Robert Phillips | 8c8b046 | 2018-08-24 16:18:03 -0400 | [diff] [blame] | 876 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 877 | // Fills the rect, using rect as its own local coordinates |
| 878 | this->fillRectToRect(clip, std::move(paint), aa, viewMatrix, rect, rect); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 879 | return; |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 880 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 881 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 882 | if ((!rect.width() || !rect.height()) && |
| 883 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 884 | SkScalar r = stroke.getWidth() / 2; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 885 | // TODO: Move these stroke->fill fallbacks to GrStyledShape? |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 886 | switch (stroke.getJoin()) { |
| 887 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 888 | this->drawRect( |
| 889 | clip, std::move(paint), aa, viewMatrix, |
| 890 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 891 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 892 | return; |
| 893 | case SkPaint::kRound_Join: |
| 894 | // Raster draws nothing when both dimensions are empty. |
| 895 | if (rect.width() || rect.height()){ |
| 896 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 897 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 898 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 899 | return; |
| 900 | } |
| 901 | case SkPaint::kBevel_Join: |
| 902 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 903 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 904 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 905 | &GrStyle::SimpleFill()); |
| 906 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 907 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 908 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 909 | &GrStyle::SimpleFill()); |
| 910 | } |
| 911 | return; |
| 912 | } |
| 913 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 914 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 915 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 916 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 917 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 918 | op = GrStrokeRectOp::Make(fContext, std::move(paint), aaType, viewMatrix, rect, stroke); |
| 919 | // op may be null if the stroke is not supported or if using coverage aa and the view matrix |
| 920 | // does not preserve rectangles. |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 921 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 922 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 923 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 924 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 925 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 926 | assert_alive(paint); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 927 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, |
| 928 | GrStyledShape(rect, *style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 931 | void GrRenderTargetContext::drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 932 | const SkMatrix& viewMatrix, const QuadSetEntry quads[], |
| 933 | int cnt) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 934 | GrAAType aaType = this->chooseAAType(aa); |
Robert Phillips | 438d986 | 2019-11-14 12:46:05 -0500 | [diff] [blame] | 935 | |
| 936 | GrFillRectOp::AddFillRectOps(this, clip, fContext, std::move(paint), aaType, viewMatrix, |
| 937 | quads, cnt); |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 938 | } |
| 939 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 940 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 941 | return fRenderTargetContext->asRenderTargetProxy()->maxWindowRectangles( |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 942 | *fRenderTargetContext->caps()); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 943 | } |
| 944 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 945 | GrOpsTask::CanDiscardPreviousOps GrRenderTargetContext::canDiscardPreviousOpsOnFullClear( |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 946 | ) const { |
| 947 | #if GR_TEST_UTILS |
| 948 | if (fPreserveOpsOnFullClear_TestingOnly) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 949 | return GrOpsTask::CanDiscardPreviousOps::kNo; |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 950 | } |
| 951 | #endif |
| 952 | // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops |
| 953 | // would normally be overwritten. The one exception is if the render target context is marked as |
| 954 | // needing a stencil buffer then there may be a prior op that writes to the stencil buffer. |
| 955 | // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get |
| 956 | // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond |
| 957 | // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002). |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 958 | return GrOpsTask::CanDiscardPreviousOps(!fNumStencilSamples); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 959 | } |
| 960 | |
Chris Dalton | 858cf23 | 2019-10-14 16:20:00 -0600 | [diff] [blame] | 961 | void GrRenderTargetContext::setNeedsStencil(bool useMixedSamplesIfNotMSAA) { |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 962 | // Don't clear stencil until after we've changed fNumStencilSamples. This ensures we don't loop |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 963 | // forever in the event that there are driver bugs and we need to clear as a draw. |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 964 | bool hasInitializedStencil = fNumStencilSamples > 0; |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 965 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 966 | int numRequiredSamples = this->numSamples(); |
Chris Dalton | 858cf23 | 2019-10-14 16:20:00 -0600 | [diff] [blame] | 967 | if (useMixedSamplesIfNotMSAA && 1 == numRequiredSamples) { |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 968 | SkASSERT(this->asRenderTargetProxy()->canUseMixedSamples(*this->caps())); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 969 | numRequiredSamples = this->caps()->internalMultisampleCount( |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 970 | this->asSurfaceProxy()->backendFormat()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 971 | } |
| 972 | SkASSERT(numRequiredSamples > 0); |
| 973 | |
| 974 | if (numRequiredSamples > fNumStencilSamples) { |
| 975 | fNumStencilSamples = numRequiredSamples; |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 976 | this->asRenderTargetProxy()->setNeedsStencil(fNumStencilSamples); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 977 | } |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 978 | |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 979 | if (!hasInitializedStencil) { |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 980 | if (this->caps()->performStencilClearsAsDraws()) { |
| 981 | // There is a driver bug with clearing stencil. We must use an op to manually clear the |
| 982 | // stencil buffer before the op that required 'setNeedsStencil'. |
| 983 | this->internalStencilClear(GrFixedClip::Disabled(), /* inside mask */ false); |
| 984 | } else { |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 985 | this->getOpsTask()->setInitialStencilContent( |
| 986 | GrOpsTask::StencilContent::kUserBitsCleared); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 991 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 992 | ASSERT_SINGLE_OWNER_PRIV |
| 993 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 994 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 995 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clearStencilClip", |
| 996 | fRenderTargetContext->fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 997 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 998 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 999 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1000 | fRenderTargetContext->internalStencilClear(clip, insideStencilMask); |
| 1001 | } |
| 1002 | |
| 1003 | void GrRenderTargetContext::internalStencilClear(const GrFixedClip& clip, bool insideStencilMask) { |
Chris Dalton | 858cf23 | 2019-10-14 16:20:00 -0600 | [diff] [blame] | 1004 | this->setNeedsStencil(/* useMixedSamplesIfNotMSAA = */ false); |
| 1005 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1006 | if (this->caps()->performStencilClearsAsDraws()) { |
| 1007 | const GrUserStencilSettings* ss = GrStencilSettings::SetClipBitSettings(insideStencilMask); |
| 1008 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 1009 | |
| 1010 | // Configure the paint to have no impact on the color buffer |
| 1011 | GrPaint paint; |
Michael Ludwig | 0cb2fde | 2019-05-28 13:14:41 -0400 | [diff] [blame] | 1012 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 1013 | this->addDrawOp(clip, GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(), |
| 1014 | rtRect, ss)); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1015 | } else { |
| 1016 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(fContext, clip, insideStencilMask, |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 1017 | this->asRenderTargetProxy())); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1018 | if (!op) { |
| 1019 | return; |
| 1020 | } |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 1021 | this->addOp(std::move(op)); |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 1022 | } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 1025 | void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1026 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1027 | const SkMatrix& viewMatrix, |
Robert Phillips | e1efd38 | 2019-08-21 10:07:10 -0400 | [diff] [blame] | 1028 | sk_sp<const GrPath> path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1029 | ASSERT_SINGLE_OWNER_PRIV |
| 1030 | RETURN_IF_ABANDONED_PRIV |
| 1031 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1032 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilPath", |
| 1033 | fRenderTargetContext->fContext); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1034 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1035 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 1036 | SkASSERT(path); |
| 1037 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 1038 | |
| 1039 | // FIXME: Use path bounds instead of this WAR once |
| 1040 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 1041 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 1042 | |
| 1043 | // Setup clip |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 1044 | GrAppliedHardClip appliedClip; |
| 1045 | if (!clip.apply(fRenderTargetContext->width(), fRenderTargetContext->height(), &appliedClip, |
| 1046 | &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1047 | return; |
| 1048 | } |
| 1049 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1050 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(fRenderTargetContext->fContext, |
| 1051 | viewMatrix, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1052 | GrAA::kYes == doStencilMSAA, |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1053 | appliedClip.hasStencilClip(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1054 | appliedClip.scissorState(), |
Robert Phillips | e1efd38 | 2019-08-21 10:07:10 -0400 | [diff] [blame] | 1055 | std::move(path)); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 1056 | if (!op) { |
| 1057 | return; |
| 1058 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1059 | op->setClippedBounds(bounds); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 1060 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 1061 | fRenderTargetContext->setNeedsStencil(GrAA::kYes == doStencilMSAA); |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 1062 | fRenderTargetContext->addOp(std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1065 | void GrRenderTargetContext::drawTextureSet(const GrClip& clip, TextureSetEntry set[], |
| 1066 | int cnt, int proxyRunCnt, |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1067 | GrSamplerState::Filter filter, SkBlendMode mode, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1068 | GrAA aa, SkCanvas::SrcRectConstraint constraint, |
| 1069 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 1070 | sk_sp<GrColorSpaceXform> texXform) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1071 | ASSERT_SINGLE_OWNER |
| 1072 | RETURN_IF_ABANDONED |
| 1073 | SkDEBUGCODE(this->validate();) |
| 1074 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureSet", fContext); |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1075 | |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1076 | // Create the minimum number of GrTextureOps needed to draw this set. Individual |
| 1077 | // GrTextureOps can rebind the texture between draws thus avoiding GrPaint (re)creation. |
| 1078 | AutoCheckFlush acf(this->drawingManager()); |
| 1079 | GrAAType aaType = this->chooseAAType(aa); |
| 1080 | auto clampType = GrColorTypeClampType(this->colorInfo().colorType()); |
| 1081 | auto saturate = clampType == GrClampType::kManual ? GrTextureOp::Saturate::kYes |
| 1082 | : GrTextureOp::Saturate::kNo; |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1083 | GrTextureOp::AddTextureSetOps(this, clip, fContext, set, cnt, proxyRunCnt, filter, saturate, |
| 1084 | mode, aaType, constraint, viewMatrix, std::move(texXform)); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1087 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1088 | GrPaint&& paint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 1089 | const SkMatrixProvider& matrixProvider, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1090 | sk_sp<SkVertices> vertices, |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 1091 | GrPrimitiveType* overridePrimType, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 1092 | const SkRuntimeEffect* effect) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1093 | ASSERT_SINGLE_OWNER |
| 1094 | RETURN_IF_ABANDONED |
| 1095 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1096 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawVertices", fContext); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1097 | |
| 1098 | AutoCheckFlush acf(this->drawingManager()); |
| 1099 | |
| 1100 | SkASSERT(vertices); |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1101 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 1102 | std::unique_ptr<GrDrawOp> op = |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 1103 | GrDrawVerticesOp::Make(fContext, std::move(paint), std::move(vertices), matrixProvider, |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 1104 | aaType, this->colorInfo().refColorSpaceXformFromSRGB(), |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 1105 | overridePrimType, effect); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 1106 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /////////////////////////////////////////////////////////////////////////////// |
| 1110 | |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1111 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
| 1112 | GrPaint&& paint, |
| 1113 | const SkMatrix& viewMatrix, |
| 1114 | int spriteCount, |
| 1115 | const SkRSXform xform[], |
| 1116 | const SkRect texRect[], |
| 1117 | const SkColor colors[]) { |
| 1118 | ASSERT_SINGLE_OWNER |
| 1119 | RETURN_IF_ABANDONED |
| 1120 | SkDEBUGCODE(this->validate();) |
| 1121 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawAtlas", fContext); |
| 1122 | |
| 1123 | AutoCheckFlush acf(this->drawingManager()); |
| 1124 | |
| 1125 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
| 1126 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(fContext, std::move(paint), viewMatrix, |
| 1127 | aaType, spriteCount, xform, texRect, colors); |
| 1128 | this->addDrawOp(clip, std::move(op)); |
| 1129 | } |
| 1130 | |
| 1131 | /////////////////////////////////////////////////////////////////////////////// |
| 1132 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1133 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1134 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1135 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1136 | const SkMatrix& viewMatrix, |
| 1137 | const SkRRect& rrect, |
| 1138 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1139 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1140 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1141 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1142 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRRect", fContext); |
Robert Phillips | 8529080 | 2018-07-02 13:14:28 -0400 | [diff] [blame] | 1143 | |
| 1144 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1145 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1146 | return; |
| 1147 | } |
| 1148 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1149 | GrNoClip noclip; |
| 1150 | const GrClip* clip = &origClip; |
| 1151 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 1152 | // The Android framework frequently clips rrects to themselves where the clip is non-aa and the |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1153 | // draw is aa. Since our lower level clip code works from op bounds, which are SkRects, it |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1154 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 1155 | // attempts to mitigate the stencil clip cost but will only help when the entire clip stack |
Michael Ludwig | 2839884 | 2019-03-25 10:24:24 -0400 | [diff] [blame] | 1156 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. This |
| 1157 | // only works for filled rrects since the stroke width outsets beyond the rrect itself. |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1158 | SkRRect devRRect; |
Michael Ludwig | 2839884 | 2019-03-25 10:24:24 -0400 | [diff] [blame] | 1159 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.transform(viewMatrix, &devRRect) && |
| 1160 | clip->quickContains(devRRect)) { |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1161 | clip = &noclip; |
| 1162 | } |
| 1163 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1164 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 1165 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1166 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1167 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1168 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 1169 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1170 | std::unique_ptr<GrDrawOp> op; |
Jim Van Verth | 64b8589 | 2019-06-17 12:01:46 -0400 | [diff] [blame] | 1171 | if (GrAAType::kCoverage == aaType && rrect.isSimple() && |
| 1172 | rrect.getSimpleRadii().fX == rrect.getSimpleRadii().fY && |
| 1173 | viewMatrix.rectStaysRect() && viewMatrix.isSimilarity()) { |
| 1174 | // In coverage mode, we draw axis-aligned circular roundrects with the GrOvalOpFactory |
| 1175 | // to avoid perf regressions on some platforms. |
| 1176 | assert_alive(paint); |
| 1177 | op = GrOvalOpFactory::MakeCircularRRectOp( |
| 1178 | fContext, std::move(paint), viewMatrix, rrect, stroke, this->caps()->shaderCaps()); |
| 1179 | } |
| 1180 | if (!op && style.isSimpleFill()) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1181 | assert_alive(paint); |
Robert Phillips | 360ec18 | 2020-03-26 13:29:50 -0400 | [diff] [blame] | 1182 | op = GrFillRRectOp::Make(fContext, std::move(paint), viewMatrix, rrect, aaType); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1183 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1184 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1185 | assert_alive(paint); |
| 1186 | op = GrOvalOpFactory::MakeRRectOp( |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1187 | fContext, std::move(paint), viewMatrix, rrect, stroke, this->caps()->shaderCaps()); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1188 | } |
| 1189 | if (op) { |
| 1190 | this->addDrawOp(*clip, std::move(op)); |
| 1191 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1192 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1193 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1194 | assert_alive(paint); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1195 | this->drawShapeUsingPathRenderer(*clip, std::move(paint), aa, viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1196 | GrStyledShape(rrect, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1199 | /////////////////////////////////////////////////////////////////////////////// |
| 1200 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1201 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 1202 | SkPoint3 result; |
| 1203 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 1204 | result.fZ = pt.fZ; |
| 1205 | return result; |
| 1206 | } |
| 1207 | |
| 1208 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1209 | const SkMatrix& viewMatrix, |
| 1210 | const SkPath& path, |
| 1211 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1212 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1213 | if (fContext->priv().abandoned()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1214 | return true; |
| 1215 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1216 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1217 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFastShadow", fContext); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1218 | |
| 1219 | // check z plane |
| 1220 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 1221 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 1222 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 1223 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 1224 | return false; |
| 1225 | } |
| 1226 | |
| 1227 | SkRRect rrect; |
| 1228 | SkRect rect; |
| 1229 | // we can only handle rects, circles, and rrects with circular corners |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1230 | bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsSimpleCircular(rrect) && |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1231 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 1232 | if (!isRRect && |
| 1233 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 1234 | rect.width() > SK_ScalarNearlyZero) { |
| 1235 | rrect.setOval(rect); |
| 1236 | isRRect = true; |
| 1237 | } |
| 1238 | if (!isRRect && path.isRect(&rect)) { |
| 1239 | rrect.setRect(rect); |
| 1240 | isRRect = true; |
| 1241 | } |
| 1242 | |
| 1243 | if (!isRRect) { |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1247 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1248 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1249 | } |
| 1250 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1251 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1252 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1253 | // transform light |
| 1254 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 1255 | |
| 1256 | // 1/scale |
| 1257 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
Jim Van Verth | eda9a55 | 2019-07-24 14:46:53 -0400 | [diff] [blame] | 1258 | SkScalarInvert(SkScalarAbs(viewMatrix[SkMatrix::kMScaleX])) : |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1259 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 1260 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1261 | |
| 1262 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1263 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
| 1264 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1265 | if (SkColorGetA(rec.fAmbientColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1266 | SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight); |
| 1267 | const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight); |
| 1268 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1269 | |
| 1270 | // Outset the shadow rrect to the border of the penumbra |
| 1271 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1272 | SkRRect ambientRRect; |
| 1273 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1274 | // If the rrect was an oval then its outset will also be one. |
| 1275 | // We set it explicitly to avoid errors. |
| 1276 | if (rrect.isOval()) { |
| 1277 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1278 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1279 | SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1280 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1281 | } |
| 1282 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1283 | GrColor ambientColor = SkColorToPremulGrColor(rec.fAmbientColor); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1284 | if (transparent) { |
| 1285 | // set a large inset to force a fill |
| 1286 | devSpaceInsetWidth = ambientRRect.width(); |
| 1287 | } |
Jim Van Verth | 39e7165 | 2018-04-23 18:08:45 +0000 | [diff] [blame] | 1288 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1289 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1290 | ambientColor, |
| 1291 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1292 | ambientRRect, |
| 1293 | devSpaceAmbientBlur, |
Jim Van Verth | fb18639 | 2018-09-11 11:37:46 -0400 | [diff] [blame] | 1294 | devSpaceInsetWidth); |
Robert Phillips | e576378 | 2019-04-17 14:38:24 -0400 | [diff] [blame] | 1295 | if (op) { |
| 1296 | this->addDrawOp(clip, std::move(op)); |
| 1297 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1298 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1299 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1300 | if (SkColorGetA(rec.fSpotColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1301 | SkScalar devSpaceSpotBlur; |
| 1302 | SkScalar spotScale; |
| 1303 | SkVector spotOffset; |
| 1304 | SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY, |
| 1305 | devLightPos.fZ, rec.fLightRadius, |
| 1306 | &devSpaceSpotBlur, &spotScale, &spotOffset); |
| 1307 | // handle scale of radius due to CTM |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1308 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1309 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1310 | // Adjust translate for the effect of the scale. |
| 1311 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1312 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1313 | // This offset is in dev space, need to transform it into source space. |
| 1314 | SkMatrix ctmInverse; |
| 1315 | if (viewMatrix.invert(&ctmInverse)) { |
| 1316 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1317 | } else { |
| 1318 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1319 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1320 | SkASSERT(false); |
| 1321 | } |
| 1322 | |
| 1323 | // Compute the transformed shadow rrect |
| 1324 | SkRRect spotShadowRRect; |
| 1325 | SkMatrix shadowTransform; |
| 1326 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1327 | rrect.transform(shadowTransform, &spotShadowRRect); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1328 | SkScalar spotRadius = SkRRectPriv::GetSimpleRadii(spotShadowRRect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1329 | |
| 1330 | // Compute the insetWidth |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1331 | SkScalar blurOutset = srcSpaceSpotBlur; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1332 | SkScalar insetWidth = blurOutset; |
| 1333 | if (transparent) { |
| 1334 | // If transparent, just do a fill |
| 1335 | insetWidth += spotShadowRRect.width(); |
| 1336 | } else { |
| 1337 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1338 | // border. We want to extend this inset area so that it meets up with the caster |
| 1339 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1340 | // |
| 1341 | // We compare the min and max corners inset by the radius between the original |
| 1342 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1343 | // between the scaled radius and the original radius gives the distance from the |
| 1344 | // transformed shadow shape to the original shape in that corner. The max |
| 1345 | // of these gives the maximum distance we need to cover. |
| 1346 | // |
| 1347 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1348 | // that to get the full insetWidth. |
| 1349 | SkScalar maxOffset; |
| 1350 | if (rrect.isRect()) { |
| 1351 | // Manhattan distance works better for rects |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1352 | maxOffset = std::max(std::max(SkTAbs(spotShadowRRect.rect().fLeft - |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1353 | rrect.rect().fLeft), |
| 1354 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1355 | rrect.rect().fTop)), |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1356 | std::max(SkTAbs(spotShadowRRect.rect().fRight - |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1357 | rrect.rect().fRight), |
| 1358 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1359 | rrect.rect().fBottom))); |
| 1360 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1361 | SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1362 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1363 | rrect.rect().fLeft + dr, |
| 1364 | spotShadowRRect.rect().fTop - |
| 1365 | rrect.rect().fTop + dr); |
| 1366 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1367 | rrect.rect().fRight - dr, |
| 1368 | spotShadowRRect.rect().fBottom - |
| 1369 | rrect.rect().fBottom - dr); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1370 | maxOffset = SkScalarSqrt(std::max(SkPointPriv::LengthSqd(upperLeftOffset), |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 1371 | SkPointPriv::LengthSqd(lowerRightOffset))) + dr; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1372 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1373 | insetWidth += std::max(blurOutset, maxOffset); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | // Outset the shadow rrect to the border of the penumbra |
| 1377 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1378 | if (spotShadowRRect.isOval()) { |
| 1379 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1380 | } else { |
| 1381 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1382 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1383 | } |
| 1384 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1385 | GrColor spotColor = SkColorToPremulGrColor(rec.fSpotColor); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1386 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1387 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1388 | spotColor, |
| 1389 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1390 | spotShadowRRect, |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1391 | 2.0f * devSpaceSpotBlur, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1392 | insetWidth); |
Robert Phillips | e576378 | 2019-04-17 14:38:24 -0400 | [diff] [blame] | 1393 | if (op) { |
| 1394 | this->addDrawOp(clip, std::move(op)); |
| 1395 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /////////////////////////////////////////////////////////////////////////////// |
| 1402 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1403 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1404 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1405 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1406 | const SkMatrix& viewMatrix, |
| 1407 | const SkRRect& origOuter, |
| 1408 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1409 | SkASSERT(!origInner.isEmpty()); |
| 1410 | SkASSERT(!origOuter.isEmpty()); |
| 1411 | |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1412 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1413 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1414 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 45839f9 | 2017-12-04 09:02:35 -0500 | [diff] [blame] | 1415 | |
| 1416 | if (GrAAType::kMSAA == aaType) { |
| 1417 | return false; |
| 1418 | } |
| 1419 | |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1420 | if (GrAAType::kCoverage == aaType && SkRRectPriv::IsCircle(*inner) |
| 1421 | && SkRRectPriv::IsCircle(*outer)) { |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1422 | auto outerR = outer->width() / 2.f; |
| 1423 | auto innerR = inner->width() / 2.f; |
| 1424 | auto cx = outer->getBounds().fLeft + outerR; |
| 1425 | auto cy = outer->getBounds().fTop + outerR; |
| 1426 | if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && |
| 1427 | SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { |
| 1428 | auto avgR = (innerR + outerR) / 2.f; |
| 1429 | auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); |
| 1430 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1431 | stroke.setStrokeStyle(outerR - innerR); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1432 | auto op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1433 | circleBounds, GrStyle(stroke, nullptr), |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1434 | this->caps()->shaderCaps()); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1435 | if (op) { |
| 1436 | this->addDrawOp(clip, std::move(op)); |
| 1437 | return true; |
| 1438 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1439 | assert_alive(paint); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1440 | } |
| 1441 | } |
| 1442 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 1443 | GrClipEdgeType innerEdgeType, outerEdgeType; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1444 | if (GrAAType::kCoverage == aaType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1445 | innerEdgeType = GrClipEdgeType::kInverseFillAA; |
| 1446 | outerEdgeType = GrClipEdgeType::kFillAA; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1447 | } else { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1448 | innerEdgeType = GrClipEdgeType::kInverseFillBW; |
| 1449 | outerEdgeType = GrClipEdgeType::kFillBW; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1450 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1451 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1452 | SkMatrix inverseVM; |
| 1453 | if (!viewMatrix.isIdentity()) { |
| 1454 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1455 | return false; |
| 1456 | } |
| 1457 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1458 | return false; |
| 1459 | } |
| 1460 | if (!viewMatrix.invert(&inverseVM)) { |
| 1461 | return false; |
| 1462 | } |
| 1463 | } else { |
| 1464 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1465 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1466 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1467 | const auto& caps = *this->caps()->shaderCaps(); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1468 | // TODO these need to be a geometry processors |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1469 | auto innerEffect = GrRRectEffect::Make(innerEdgeType, *inner, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1470 | if (!innerEffect) { |
| 1471 | return false; |
| 1472 | } |
| 1473 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1474 | auto outerEffect = GrRRectEffect::Make(outerEdgeType, *outer, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1475 | if (!outerEffect) { |
| 1476 | return false; |
| 1477 | } |
| 1478 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1479 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1480 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1481 | |
| 1482 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1483 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1484 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1485 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1486 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1487 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1488 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1489 | return true; |
| 1490 | } |
| 1491 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1492 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1493 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1494 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1495 | const SkMatrix& viewMatrix, |
| 1496 | const SkRRect& outer, |
| 1497 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1498 | ASSERT_SINGLE_OWNER |
| 1499 | RETURN_IF_ABANDONED |
| 1500 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1501 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawDRRect", fContext); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1502 | |
| 1503 | SkASSERT(!outer.isEmpty()); |
| 1504 | SkASSERT(!inner.isEmpty()); |
| 1505 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1506 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1507 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1508 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1509 | return; |
| 1510 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1511 | assert_alive(paint); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1512 | |
| 1513 | SkPath path; |
| 1514 | path.setIsVolatile(true); |
| 1515 | path.addRRect(inner); |
| 1516 | path.addRRect(outer); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1517 | path.setFillType(SkPathFillType::kEvenOdd); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1518 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrStyledShape(path)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1521 | /////////////////////////////////////////////////////////////////////////////// |
| 1522 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1523 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1524 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1525 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1526 | const SkMatrix& viewMatrix, |
| 1527 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1528 | const GrStyle& style, |
| 1529 | const GrUserStencilSettings* ss) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1530 | ASSERT_SINGLE_OWNER |
| 1531 | RETURN_IF_ABANDONED |
| 1532 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1533 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRegion", fContext); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1534 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1535 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1536 | // GrRegionOp performs no antialiasing but is much faster, so here we check the matrix |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1537 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1538 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1539 | SkScalarIsInt(viewMatrix.getTranslateX()) && |
| 1540 | SkScalarIsInt(viewMatrix.getTranslateY())) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1541 | aa = GrAA::kNo; |
| 1542 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1543 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1544 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1545 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1546 | SkPath path; |
| 1547 | region.getBoundaryPath(&path); |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 1548 | path.setIsVolatile(true); |
| 1549 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1550 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1553 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1554 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(fContext, std::move(paint), viewMatrix, region, |
| 1555 | aaType, ss); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1556 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1559 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1560 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1561 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1562 | const SkMatrix& viewMatrix, |
| 1563 | const SkRect& oval, |
| 1564 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1565 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1566 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1567 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1568 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawOval", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1569 | |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1570 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1571 | |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1572 | if (oval.isEmpty() && !style.pathEffect()) { |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1573 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
| 1574 | return; |
| 1575 | } |
| 1576 | |
| 1577 | this->drawRect(clip, std::move(paint), aa, viewMatrix, oval, &style); |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1578 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1581 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1582 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1583 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1584 | |
| 1585 | std::unique_ptr<GrDrawOp> op; |
Jim Van Verth | d7871cc | 2019-06-27 13:08:04 -0400 | [diff] [blame] | 1586 | if (GrAAType::kCoverage == aaType && oval.width() > SK_ScalarNearlyZero && |
| 1587 | oval.width() == oval.height() && viewMatrix.isSimilarity()) { |
Jim Van Verth | 64b8589 | 2019-06-17 12:01:46 -0400 | [diff] [blame] | 1588 | // We don't draw true circles as round rects in coverage mode, because it can |
| 1589 | // cause perf regressions on some platforms as compared to the dedicated circle Op. |
| 1590 | assert_alive(paint); |
| 1591 | op = GrOvalOpFactory::MakeCircleOp(fContext, std::move(paint), viewMatrix, oval, style, |
| 1592 | this->caps()->shaderCaps()); |
| 1593 | } |
| 1594 | if (!op && style.isSimpleFill()) { |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 1595 | // GrFillRRectOp has special geometry and a fragment-shader branch to conditionally evaluate |
| 1596 | // the arc equation. This same special geometry and fragment branch also turn out to be a |
| 1597 | // substantial optimization for drawing ovals (namely, by not evaluating the arc equation |
| 1598 | // inside the oval's inner diamond). Given these optimizations, it's a clear win to draw |
| 1599 | // ovals the exact same way we do round rects. |
Jim Van Verth | 64b8589 | 2019-06-17 12:01:46 -0400 | [diff] [blame] | 1600 | assert_alive(paint); |
Robert Phillips | 360ec18 | 2020-03-26 13:29:50 -0400 | [diff] [blame] | 1601 | op = GrFillRRectOp::Make(fContext, std::move(paint), viewMatrix, SkRRect::MakeOval(oval), |
| 1602 | aaType); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1603 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1604 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1605 | assert_alive(paint); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1606 | op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, oval, style, |
| 1607 | this->caps()->shaderCaps()); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1608 | } |
| 1609 | if (op) { |
| 1610 | this->addDrawOp(clip, std::move(op)); |
| 1611 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1612 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1613 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1614 | assert_alive(paint); |
Brian Salomon | 5209d7f | 2018-04-20 16:52:42 -0400 | [diff] [blame] | 1615 | this->drawShapeUsingPathRenderer( |
| 1616 | clip, std::move(paint), aa, viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1617 | GrStyledShape(SkRRect::MakeOval(oval), SkPathDirection::kCW, 2, false, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1620 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1621 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1622 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1623 | const SkMatrix& viewMatrix, |
| 1624 | const SkRect& oval, |
| 1625 | SkScalar startAngle, |
| 1626 | SkScalar sweepAngle, |
| 1627 | bool useCenter, |
| 1628 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1629 | ASSERT_SINGLE_OWNER |
| 1630 | RETURN_IF_ABANDONED |
| 1631 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1632 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawArc", fContext); |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1633 | |
| 1634 | AutoCheckFlush acf(this->drawingManager()); |
| 1635 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1636 | GrAAType aaType = this->chooseAAType(aa); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1637 | if (GrAAType::kCoverage == aaType) { |
| 1638 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
| 1639 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(fContext, |
| 1640 | std::move(paint), |
| 1641 | viewMatrix, |
| 1642 | oval, |
| 1643 | startAngle, |
| 1644 | sweepAngle, |
| 1645 | useCenter, |
| 1646 | style, |
| 1647 | shaderCaps); |
| 1648 | if (op) { |
| 1649 | this->addDrawOp(clip, std::move(op)); |
| 1650 | return; |
| 1651 | } |
| 1652 | assert_alive(paint); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1653 | } |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 1654 | this->drawShapeUsingPathRenderer( |
| 1655 | clip, std::move(paint), aa, viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1656 | GrStyledShape::MakeArc(oval, startAngle, sweepAngle, useCenter, style)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1659 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1660 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1661 | const SkMatrix& viewMatrix, |
Greg Daniel | ed96bca | 2019-12-05 15:05:54 -0500 | [diff] [blame] | 1662 | GrSurfaceProxyView view, |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 1663 | SkAlphaType alphaType, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1664 | sk_sp<GrColorSpaceXform> csxf, |
| 1665 | GrSamplerState::Filter filter, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1666 | std::unique_ptr<SkLatticeIter> iter, |
| 1667 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1668 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1669 | RETURN_IF_ABANDONED |
| 1670 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1671 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawImageLattice", fContext); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1672 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1673 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1674 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1675 | std::unique_ptr<GrDrawOp> op = |
Greg Daniel | ed96bca | 2019-12-05 15:05:54 -0500 | [diff] [blame] | 1676 | GrLatticeOp::MakeNonAA(fContext, std::move(paint), viewMatrix, std::move(view), |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 1677 | alphaType, std::move(csxf), filter, std::move(iter), dst); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1678 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1681 | void GrRenderTargetContext::drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable, |
| 1682 | const SkRect& bounds) { |
| 1683 | std::unique_ptr<GrOp> op(GrDrawableOp::Make(fContext, std::move(drawable), bounds)); |
| 1684 | SkASSERT(op); |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 1685 | this->addOp(std::move(op)); |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1688 | void GrRenderTargetContext::asyncRescaleAndReadPixels( |
| 1689 | const SkImageInfo& info, const SkIRect& srcRect, SkSurface::RescaleGamma rescaleGamma, |
| 1690 | SkFilterQuality rescaleQuality, ReadPixelsCallback callback, ReadPixelsContext context) { |
| 1691 | auto direct = fContext->priv().asDirectContext(); |
| 1692 | if (!direct) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1693 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1694 | return; |
| 1695 | } |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 1696 | if (this->asRenderTargetProxy()->wrapsVkSecondaryCB()) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1697 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1698 | return; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1699 | } |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 1700 | if (this->asRenderTargetProxy()->framebufferOnly()) { |
| 1701 | callback(context, nullptr); |
| 1702 | return; |
| 1703 | } |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1704 | auto dstCT = SkColorTypeToGrColorType(info.colorType()); |
Brian Salomon | b3bd864 | 2019-11-04 16:59:29 -0500 | [diff] [blame] | 1705 | if (dstCT == GrColorType::kUnknown) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1706 | callback(context, nullptr); |
Brian Salomon | 5dd7746 | 2019-09-26 16:57:09 -0400 | [diff] [blame] | 1707 | return; |
| 1708 | } |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1709 | bool needsRescale = srcRect.width() != info.width() || srcRect.height() != info.height(); |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1710 | auto colorTypeOfFinalContext = this->colorInfo().colorType(); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 1711 | auto backendFormatOfFinalContext = this->asSurfaceProxy()->backendFormat(); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1712 | if (needsRescale) { |
Greg Daniel | c6dc5cf | 2019-07-17 16:02:00 -0400 | [diff] [blame] | 1713 | colorTypeOfFinalContext = dstCT; |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1714 | backendFormatOfFinalContext = this->caps()->getDefaultBackendFormat(dstCT, |
| 1715 | GrRenderable::kYes); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1716 | } |
Greg Daniel | c6dc5cf | 2019-07-17 16:02:00 -0400 | [diff] [blame] | 1717 | auto readInfo = this->caps()->supportedReadPixelsColorType(colorTypeOfFinalContext, |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 1718 | backendFormatOfFinalContext, dstCT); |
| 1719 | // Fail if we can't read from the source surface's color type. |
| 1720 | if (readInfo.fColorType == GrColorType::kUnknown) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1721 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1722 | return; |
| 1723 | } |
Brian Salomon | 624f906 | 2019-07-02 14:23:00 -0400 | [diff] [blame] | 1724 | // Fail if read color type does not have all of dstCT's color channels and those missing color |
| 1725 | // channels are in the src. |
Brian Salomon | 2f23ae6 | 2020-03-26 16:17:56 -0400 | [diff] [blame] | 1726 | uint32_t dstChannels = GrColorTypeChannelFlags(dstCT); |
| 1727 | uint32_t legalReadChannels = GrColorTypeChannelFlags(readInfo.fColorType); |
| 1728 | uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType()); |
| 1729 | if ((~legalReadChannels & dstChannels) & srcChannels) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1730 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1731 | return; |
| 1732 | } |
| 1733 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1734 | std::unique_ptr<GrRenderTargetContext> tempRTC; |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1735 | int x = srcRect.fLeft; |
| 1736 | int y = srcRect.fTop; |
| 1737 | if (needsRescale) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1738 | tempRTC = this->rescale(info, srcRect, rescaleGamma, rescaleQuality); |
| 1739 | if (!tempRTC) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1740 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1741 | return; |
| 1742 | } |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1743 | SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace())); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1744 | SkASSERT(tempRTC->origin() == kTopLeft_GrSurfaceOrigin); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1745 | x = y = 0; |
| 1746 | } else { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1747 | sk_sp<GrColorSpaceXform> xform = GrColorSpaceXform::Make(this->colorInfo().colorSpace(), |
| 1748 | this->colorInfo().alphaType(), |
| 1749 | info.colorSpace(), |
| 1750 | info.alphaType()); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1751 | // Insert a draw to a temporary surface if we need to do a y-flip or color space conversion. |
| 1752 | if (this->origin() == kBottomLeft_GrSurfaceOrigin || xform) { |
Brian Salomon | 4d03689 | 2019-07-02 15:10:58 -0400 | [diff] [blame] | 1753 | // We flip or color convert by drawing and we don't currently support drawing to |
| 1754 | // kPremul. |
| 1755 | if (info.alphaType() == kUnpremul_SkAlphaType) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1756 | callback(context, nullptr); |
Brian Salomon | 4d03689 | 2019-07-02 15:10:58 -0400 | [diff] [blame] | 1757 | return; |
| 1758 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1759 | GrSurfaceProxyView texProxyView = this->readSurfaceView(); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1760 | SkRect srcRectToDraw = SkRect::Make(srcRect); |
| 1761 | // If the src is not texturable first try to make a copy to a texture. |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1762 | if (!texProxyView.asTextureProxy()) { |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 1763 | texProxyView = |
| 1764 | GrSurfaceProxyView::Copy(fContext, texProxyView, GrMipMapped::kNo, srcRect, |
| 1765 | SkBackingFit::kApprox, SkBudgeted::kNo); |
| 1766 | if (!texProxyView) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1767 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1768 | return; |
| 1769 | } |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 1770 | SkASSERT(texProxyView.asTextureProxy()); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1771 | srcRectToDraw = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 1772 | } |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 1773 | tempRTC = GrRenderTargetContext::Make( |
| 1774 | direct, this->colorInfo().colorType(), info.refColorSpace(), |
| 1775 | SkBackingFit::kApprox, srcRect.size(), 1, GrMipMapped::kNo, GrProtected::kNo, |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 1776 | kTopLeft_GrSurfaceOrigin); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1777 | if (!tempRTC) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1778 | callback(context, nullptr); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1779 | return; |
| 1780 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1781 | tempRTC->drawTexture(GrNoClip(), std::move(texProxyView), this->colorInfo().alphaType(), |
| 1782 | GrSamplerState::Filter::kNearest, SkBlendMode::kSrc, |
| 1783 | SK_PMColor4fWHITE, srcRectToDraw, |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1784 | SkRect::MakeWH(srcRect.width(), srcRect.height()), GrAA::kNo, |
| 1785 | GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint, |
| 1786 | SkMatrix::I(), std::move(xform)); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1787 | x = y = 0; |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1788 | } |
| 1789 | } |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1790 | auto rtc = tempRTC ? tempRTC.get() : this; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1791 | return rtc->asyncReadPixels(SkIRect::MakeXYWH(x, y, info.width(), info.height()), |
| 1792 | info.colorType(), callback, context); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1795 | class GrRenderTargetContext::AsyncReadResult : public SkSurface::AsyncReadResult { |
| 1796 | public: |
| 1797 | AsyncReadResult(uint32_t inboxID) : fInboxID(inboxID) {} |
| 1798 | ~AsyncReadResult() override { |
| 1799 | for (int i = 0; i < fPlanes.count(); ++i) { |
| 1800 | if (!fPlanes[i].fMappedBuffer) { |
| 1801 | delete[] static_cast<const char*>(fPlanes[i].fData); |
| 1802 | } else { |
| 1803 | GrClientMappedBufferManager::BufferFinishedMessageBus::Post( |
| 1804 | {std::move(fPlanes[i].fMappedBuffer), fInboxID}); |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | int count() const override { return fPlanes.count(); } |
| 1810 | const void* data(int i) const override { return fPlanes[i].fData; } |
| 1811 | size_t rowBytes(int i) const override { return fPlanes[i].fRowBytes; } |
| 1812 | |
| 1813 | bool addTransferResult(const PixelTransferResult& result, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 1814 | SkISize dimensions, |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1815 | size_t rowBytes, |
| 1816 | GrClientMappedBufferManager* manager) { |
| 1817 | SkASSERT(!result.fTransferBuffer->isMapped()); |
| 1818 | const void* mappedData = result.fTransferBuffer->map(); |
| 1819 | if (!mappedData) { |
| 1820 | return false; |
| 1821 | } |
| 1822 | if (result.fPixelConverter) { |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 1823 | std::unique_ptr<char[]> convertedData(new char[rowBytes * dimensions.height()]); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1824 | result.fPixelConverter(convertedData.get(), mappedData); |
| 1825 | this->addCpuPlane(std::move(convertedData), rowBytes); |
| 1826 | result.fTransferBuffer->unmap(); |
| 1827 | } else { |
| 1828 | manager->insert(result.fTransferBuffer); |
| 1829 | this->addMappedPlane(mappedData, rowBytes, std::move(result.fTransferBuffer)); |
| 1830 | } |
| 1831 | return true; |
| 1832 | } |
| 1833 | |
| 1834 | void addCpuPlane(std::unique_ptr<const char[]> data, size_t rowBytes) { |
| 1835 | SkASSERT(data); |
| 1836 | SkASSERT(rowBytes > 0); |
| 1837 | fPlanes.emplace_back(data.release(), rowBytes, nullptr); |
| 1838 | } |
| 1839 | |
| 1840 | private: |
| 1841 | void addMappedPlane(const void* data, size_t rowBytes, sk_sp<GrGpuBuffer> mappedBuffer) { |
| 1842 | SkASSERT(data); |
| 1843 | SkASSERT(rowBytes > 0); |
| 1844 | SkASSERT(mappedBuffer); |
| 1845 | SkASSERT(mappedBuffer->isMapped()); |
| 1846 | fPlanes.emplace_back(data, rowBytes, std::move(mappedBuffer)); |
| 1847 | } |
| 1848 | |
| 1849 | struct Plane { |
| 1850 | Plane(const void* data, size_t rowBytes, sk_sp<GrGpuBuffer> buffer) |
| 1851 | : fData(data), fRowBytes(rowBytes), fMappedBuffer(std::move(buffer)) {} |
| 1852 | const void* fData; |
| 1853 | size_t fRowBytes; |
| 1854 | // If this is null then fData is heap alloc and must be delete[]ed as const char[]. |
| 1855 | sk_sp<GrGpuBuffer> fMappedBuffer; |
| 1856 | }; |
| 1857 | SkSTArray<3, Plane> fPlanes; |
| 1858 | uint32_t fInboxID; |
| 1859 | }; |
| 1860 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1861 | void GrRenderTargetContext::asyncReadPixels(const SkIRect& rect, SkColorType colorType, |
| 1862 | ReadPixelsCallback callback, |
| 1863 | ReadPixelsContext context) { |
| 1864 | SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width()); |
| 1865 | SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height()); |
| 1866 | |
Greg Daniel | ca9dbe2 | 2020-01-02 13:44:30 -0500 | [diff] [blame] | 1867 | if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) { |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 1868 | callback(context, nullptr); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1872 | auto directContext = fContext->priv().asDirectContext(); |
| 1873 | SkASSERT(directContext); |
| 1874 | auto mappedBufferManager = directContext->priv().clientMappedBufferManager(); |
| 1875 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1876 | auto transferResult = this->transferPixels(SkColorTypeToGrColorType(colorType), rect); |
| 1877 | |
| 1878 | if (!transferResult.fTransferBuffer) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1879 | auto ii = SkImageInfo::Make(rect.size(), colorType, |
| 1880 | this->colorInfo().alphaType(), |
| 1881 | this->colorInfo().refColorSpace()); |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 1882 | auto result = std::make_unique<AsyncReadResult>(0); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1883 | std::unique_ptr<char[]> data(new char[ii.computeMinByteSize()]); |
| 1884 | SkPixmap pm(ii, data.get(), ii.minRowBytes()); |
| 1885 | result->addCpuPlane(std::move(data), pm.rowBytes()); |
| 1886 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 1887 | if (!this->readPixels(ii, pm.writable_addr(), pm.rowBytes(), {rect.fLeft, rect.fTop})) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1888 | callback(context, nullptr); |
Brian Salomon | 4bb5026 | 2020-02-06 16:11:31 -0500 | [diff] [blame] | 1889 | return; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1890 | } |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1891 | callback(context, std::move(result)); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 1892 | return; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1893 | } |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1894 | |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1895 | struct FinishContext { |
| 1896 | ReadPixelsCallback* fClientCallback; |
| 1897 | ReadPixelsContext fClientContext; |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1898 | SkISize fSize; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1899 | SkColorType fColorType; |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1900 | GrClientMappedBufferManager* fMappedBufferManager; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1901 | PixelTransferResult fTransferResult; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1902 | }; |
| 1903 | // Assumption is that the caller would like to flush. We could take a parameter or require an |
| 1904 | // explicit flush from the caller. We'd have to have a way to defer attaching the finish |
| 1905 | // callback to GrGpu until after the next flush that flushes our op list, though. |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1906 | auto* finishContext = new FinishContext{callback, |
| 1907 | context, |
| 1908 | rect.size(), |
| 1909 | colorType, |
| 1910 | mappedBufferManager, |
| 1911 | std::move(transferResult)}; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1912 | auto finishCallback = [](GrGpuFinishedContext c) { |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1913 | const auto* context = reinterpret_cast<const FinishContext*>(c); |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 1914 | auto result = std::make_unique<AsyncReadResult>(context->fMappedBufferManager->inboxID()); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1915 | size_t rowBytes = context->fSize.width() * SkColorTypeBytesPerPixel(context->fColorType); |
| 1916 | if (!result->addTransferResult(context->fTransferResult, context->fSize, rowBytes, |
| 1917 | context->fMappedBufferManager)) { |
| 1918 | result.reset(); |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1919 | } |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1920 | (*context->fClientCallback)(context->fClientContext, std::move(result)); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1921 | delete context; |
| 1922 | }; |
| 1923 | GrFlushInfo flushInfo; |
| 1924 | flushInfo.fFinishedContext = finishContext; |
| 1925 | flushInfo.fFinishedProc = finishCallback; |
| 1926 | this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo); |
| 1927 | } |
| 1928 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1929 | void GrRenderTargetContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, |
| 1930 | sk_sp<SkColorSpace> dstColorSpace, |
| 1931 | const SkIRect& srcRect, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1932 | SkISize dstSize, |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1933 | RescaleGamma rescaleGamma, |
| 1934 | SkFilterQuality rescaleQuality, |
| 1935 | ReadPixelsCallback callback, |
| 1936 | ReadPixelsContext context) { |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1937 | SkASSERT(srcRect.fLeft >= 0 && srcRect.fRight <= this->width()); |
| 1938 | SkASSERT(srcRect.fTop >= 0 && srcRect.fBottom <= this->height()); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1939 | SkASSERT(!dstSize.isZero()); |
| 1940 | SkASSERT((dstSize.width() % 2 == 0) && (dstSize.height() % 2 == 0)); |
| 1941 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1942 | auto direct = fContext->priv().asDirectContext(); |
| 1943 | if (!direct) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1944 | callback(context, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1945 | return; |
| 1946 | } |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 1947 | if (this->asRenderTargetProxy()->wrapsVkSecondaryCB()) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1948 | callback(context, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1949 | return; |
| 1950 | } |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 1951 | if (this->asRenderTargetProxy()->framebufferOnly()) { |
| 1952 | callback(context, nullptr); |
| 1953 | return; |
| 1954 | } |
Greg Daniel | ca9dbe2 | 2020-01-02 13:44:30 -0500 | [diff] [blame] | 1955 | if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) { |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 1956 | callback(context, nullptr); |
| 1957 | return; |
| 1958 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1959 | int x = srcRect.fLeft; |
| 1960 | int y = srcRect.fTop; |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1961 | bool needsRescale = srcRect.size() != dstSize; |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1962 | GrSurfaceProxyView srcView; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1963 | if (needsRescale) { |
Brian Salomon | 4d03689 | 2019-07-02 15:10:58 -0400 | [diff] [blame] | 1964 | // We assume the caller wants kPremul. There is no way to indicate a preference. |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1965 | auto info = SkImageInfo::Make(dstSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1966 | dstColorSpace); |
| 1967 | // TODO: Incorporate the YUV conversion into last pass of rescaling. |
Brian Salomon | a7e5c7c | 2020-01-27 15:41:40 -0500 | [diff] [blame] | 1968 | auto tempRTC = this->rescale(info, srcRect, rescaleGamma, rescaleQuality); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1969 | if (!tempRTC) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 1970 | callback(context, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1971 | return; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1972 | } |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1973 | SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace())); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1974 | SkASSERT(tempRTC->origin() == kTopLeft_GrSurfaceOrigin); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1975 | x = y = 0; |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1976 | srcView = tempRTC->readSurfaceView(); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1977 | } else { |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 1978 | srcView = this->readSurfaceView(); |
| 1979 | if (!srcView.asTextureProxy()) { |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 1980 | srcView = GrSurfaceProxyView::Copy(fContext, std::move(srcView), GrMipMapped::kNo, |
| 1981 | srcRect, SkBackingFit::kApprox, SkBudgeted::kYes); |
| 1982 | if (!srcView) { |
Brian Salomon | a7e5c7c | 2020-01-27 15:41:40 -0500 | [diff] [blame] | 1983 | // If we can't get a texture copy of the contents then give up. |
| 1984 | callback(context, nullptr); |
| 1985 | return; |
| 1986 | } |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 1987 | SkASSERT(srcView.asTextureProxy()); |
Brian Salomon | a7e5c7c | 2020-01-27 15:41:40 -0500 | [diff] [blame] | 1988 | x = y = 0; |
| 1989 | } |
Brian Salomon | 4d03689 | 2019-07-02 15:10:58 -0400 | [diff] [blame] | 1990 | // We assume the caller wants kPremul. There is no way to indicate a preference. |
| 1991 | sk_sp<GrColorSpaceXform> xform = GrColorSpaceXform::Make( |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1992 | this->colorInfo().colorSpace(), this->colorInfo().alphaType(), dstColorSpace.get(), |
| 1993 | kPremul_SkAlphaType); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 1994 | if (xform) { |
Brian Salomon | a7e5c7c | 2020-01-27 15:41:40 -0500 | [diff] [blame] | 1995 | SkRect srcRectToDraw = SkRect::MakeXYWH(x, y, srcRect.width(), srcRect.height()); |
| 1996 | auto tempRTC = GrRenderTargetContext::Make( |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 1997 | direct, this->colorInfo().colorType(), dstColorSpace, SkBackingFit::kApprox, |
| 1998 | dstSize, 1, GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1999 | if (!tempRTC) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2000 | callback(context, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2001 | return; |
| 2002 | } |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 2003 | tempRTC->drawTexture(GrNoClip(), std::move(srcView), this->colorInfo().alphaType(), |
| 2004 | GrSamplerState::Filter::kNearest, SkBlendMode::kSrc, |
| 2005 | SK_PMColor4fWHITE, srcRectToDraw, SkRect::Make(srcRect.size()), |
| 2006 | GrAA::kNo, GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint, |
| 2007 | SkMatrix::I(), std::move(xform)); |
| 2008 | srcView = tempRTC->readSurfaceView(); |
| 2009 | SkASSERT(srcView.asTextureProxy()); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2010 | x = y = 0; |
| 2011 | } |
| 2012 | } |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 2013 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 2014 | auto yRTC = GrRenderTargetContext::MakeWithFallback( |
| 2015 | direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, dstSize, 1, |
| 2016 | GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2017 | int halfW = dstSize.width()/2; |
| 2018 | int halfH = dstSize.height()/2; |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 2019 | auto uRTC = GrRenderTargetContext::MakeWithFallback( |
| 2020 | direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1, |
| 2021 | GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
| 2022 | auto vRTC = GrRenderTargetContext::MakeWithFallback( |
| 2023 | direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1, |
| 2024 | GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2025 | if (!yRTC || !uRTC || !vRTC) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2026 | callback(context, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2027 | return; |
| 2028 | } |
| 2029 | |
Brian Osman | 28ba528 | 2019-10-30 14:18:07 -0400 | [diff] [blame] | 2030 | float baseM[20]; |
| 2031 | SkColorMatrix_RGB2YUV(yuvColorSpace, baseM); |
| 2032 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2033 | // TODO: Use one transfer buffer for all three planes to reduce map/unmap cost? |
| 2034 | |
| 2035 | auto texMatrix = SkMatrix::MakeTrans(x, y); |
| 2036 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2037 | SkRect dstRectY = SkRect::Make(dstSize); |
| 2038 | SkRect dstRectUV = SkRect::MakeWH(halfW, halfH); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 2039 | |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2040 | bool doSynchronousRead = !this->caps()->transferFromSurfaceToBufferSupport(); |
| 2041 | PixelTransferResult yTransfer, uTransfer, vTransfer; |
| 2042 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2043 | // This matrix generates (r,g,b,a) = (0, 0, 0, y) |
| 2044 | float yM[20]; |
Brian Salomon | df586b7 | 2019-06-11 13:26:37 -0400 | [diff] [blame] | 2045 | std::fill_n(yM, 15, 0.f); |
Brian Osman | 28ba528 | 2019-10-30 14:18:07 -0400 | [diff] [blame] | 2046 | std::copy_n(baseM + 0, 5, yM + 15); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2047 | GrPaint yPaint; |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 2048 | yPaint.addColorFragmentProcessor( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 2049 | GrTextureEffect::Make(srcView, this->colorInfo().alphaType(), texMatrix)); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2050 | auto yFP = GrColorMatrixFragmentProcessor::Make(yM, false, true, false); |
| 2051 | yPaint.addColorFragmentProcessor(std::move(yFP)); |
| 2052 | yPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 2053 | yRTC->fillRectToRect(GrNoClip(), std::move(yPaint), GrAA::kNo, SkMatrix::I(), |
| 2054 | dstRectY, dstRectY); |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2055 | if (!doSynchronousRead) { |
| 2056 | yTransfer = yRTC->transferPixels(GrColorType::kAlpha_8, |
| 2057 | SkIRect::MakeWH(yRTC->width(), yRTC->height())); |
| 2058 | if (!yTransfer.fTransferBuffer) { |
| 2059 | callback(context, nullptr); |
| 2060 | return; |
| 2061 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | texMatrix.preScale(2.f, 2.f); |
| 2065 | // This matrix generates (r,g,b,a) = (0, 0, 0, u) |
| 2066 | float uM[20]; |
Brian Salomon | df586b7 | 2019-06-11 13:26:37 -0400 | [diff] [blame] | 2067 | std::fill_n(uM, 15, 0.f); |
Brian Osman | 28ba528 | 2019-10-30 14:18:07 -0400 | [diff] [blame] | 2068 | std::copy_n(baseM + 5, 5, uM + 15); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2069 | GrPaint uPaint; |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 2070 | uPaint.addColorFragmentProcessor(GrTextureEffect::Make( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 2071 | srcView, this->colorInfo().alphaType(), texMatrix, GrSamplerState::Filter::kBilerp)); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2072 | auto uFP = GrColorMatrixFragmentProcessor::Make(uM, false, true, false); |
| 2073 | uPaint.addColorFragmentProcessor(std::move(uFP)); |
| 2074 | uPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 2075 | uRTC->fillRectToRect(GrNoClip(), std::move(uPaint), GrAA::kNo, SkMatrix::I(), |
| 2076 | dstRectUV, dstRectUV); |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2077 | if (!doSynchronousRead) { |
| 2078 | uTransfer = uRTC->transferPixels(GrColorType::kAlpha_8, |
| 2079 | SkIRect::MakeWH(uRTC->width(), uRTC->height())); |
| 2080 | if (!uTransfer.fTransferBuffer) { |
| 2081 | callback(context, nullptr); |
| 2082 | return; |
| 2083 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | // This matrix generates (r,g,b,a) = (0, 0, 0, v) |
| 2087 | float vM[20]; |
Brian Salomon | df586b7 | 2019-06-11 13:26:37 -0400 | [diff] [blame] | 2088 | std::fill_n(vM, 15, 0.f); |
Brian Osman | 28ba528 | 2019-10-30 14:18:07 -0400 | [diff] [blame] | 2089 | std::copy_n(baseM + 10, 5, vM + 15); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2090 | GrPaint vPaint; |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 2091 | vPaint.addColorFragmentProcessor(GrTextureEffect::Make(std::move(srcView), |
| 2092 | this->colorInfo().alphaType(), texMatrix, |
| 2093 | GrSamplerState::Filter::kBilerp)); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2094 | auto vFP = GrColorMatrixFragmentProcessor::Make(vM, false, true, false); |
| 2095 | vPaint.addColorFragmentProcessor(std::move(vFP)); |
| 2096 | vPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 2097 | vRTC->fillRectToRect(GrNoClip(), std::move(vPaint), GrAA::kNo, SkMatrix::I(), |
| 2098 | dstRectUV, dstRectUV); |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2099 | if (!doSynchronousRead) { |
| 2100 | vTransfer = vRTC->transferPixels(GrColorType::kAlpha_8, |
| 2101 | SkIRect::MakeWH(vRTC->width(), vRTC->height())); |
| 2102 | if (!vTransfer.fTransferBuffer) { |
| 2103 | callback(context, nullptr); |
| 2104 | return; |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | if (doSynchronousRead) { |
Brian Salomon | 2ea69aa | 2020-01-28 16:05:22 -0500 | [diff] [blame] | 2109 | GrImageInfo yInfo(GrColorType::kAlpha_8, kPremul_SkAlphaType, nullptr, dstSize); |
| 2110 | GrImageInfo uvInfo = yInfo.makeWH(halfW, halfH); |
| 2111 | size_t yRB = yInfo.minRowBytes(); |
| 2112 | size_t uvRB = uvInfo.minRowBytes(); |
| 2113 | std::unique_ptr<char[]> y(new char[yRB * yInfo.height()]); |
| 2114 | std::unique_ptr<char[]> u(new char[uvRB*uvInfo.height()]); |
| 2115 | std::unique_ptr<char[]> v(new char[uvRB*uvInfo.height()]); |
| 2116 | if (!yRTC->readPixels(yInfo, y.get(), yRB, {0, 0}, direct) || |
| 2117 | !uRTC->readPixels(uvInfo, u.get(), uvRB, {0, 0}, direct) || |
| 2118 | !vRTC->readPixels(uvInfo, v.get(), uvRB, {0, 0}, direct)) { |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2119 | callback(context, nullptr); |
| 2120 | return; |
| 2121 | } |
| 2122 | auto result = std::make_unique<AsyncReadResult>(direct->priv().contextID()); |
Brian Salomon | 2ea69aa | 2020-01-28 16:05:22 -0500 | [diff] [blame] | 2123 | result->addCpuPlane(std::move(y), yRB ); |
| 2124 | result->addCpuPlane(std::move(u), uvRB); |
| 2125 | result->addCpuPlane(std::move(v), uvRB); |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 2126 | callback(context, std::move(result)); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2127 | return; |
| 2128 | } |
| 2129 | |
| 2130 | struct FinishContext { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2131 | ReadPixelsCallback* fClientCallback; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2132 | ReadPixelsContext fClientContext; |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2133 | GrClientMappedBufferManager* fMappedBufferManager; |
| 2134 | SkISize fSize; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2135 | PixelTransferResult fYTransfer; |
| 2136 | PixelTransferResult fUTransfer; |
| 2137 | PixelTransferResult fVTransfer; |
| 2138 | }; |
| 2139 | // Assumption is that the caller would like to flush. We could take a parameter or require an |
| 2140 | // explicit flush from the caller. We'd have to have a way to defer attaching the finish |
| 2141 | // callback to GrGpu until after the next flush that flushes our op list, though. |
| 2142 | auto* finishContext = new FinishContext{callback, |
| 2143 | context, |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2144 | direct->priv().clientMappedBufferManager(), |
| 2145 | dstSize, |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2146 | std::move(yTransfer), |
| 2147 | std::move(uTransfer), |
| 2148 | std::move(vTransfer)}; |
| 2149 | auto finishCallback = [](GrGpuFinishedContext c) { |
| 2150 | const auto* context = reinterpret_cast<const FinishContext*>(c); |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 2151 | auto result = std::make_unique<AsyncReadResult>(context->fMappedBufferManager->inboxID()); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2152 | auto manager = context->fMappedBufferManager; |
| 2153 | size_t rowBytes = SkToSizeT(context->fSize.width()); |
| 2154 | if (!result->addTransferResult(context->fYTransfer, context->fSize, rowBytes, manager)) { |
| 2155 | (*context->fClientCallback)(context->fClientContext, nullptr); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2156 | delete context; |
| 2157 | return; |
| 2158 | } |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2159 | rowBytes /= 2; |
| 2160 | SkISize uvSize = {context->fSize.width()/2, context->fSize.height()/2}; |
| 2161 | if (!result->addTransferResult(context->fUTransfer, uvSize, rowBytes, manager)) { |
| 2162 | (*context->fClientCallback)(context->fClientContext, nullptr); |
| 2163 | delete context; |
| 2164 | return; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2165 | } |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2166 | if (!result->addTransferResult(context->fVTransfer, uvSize, rowBytes, manager)) { |
| 2167 | (*context->fClientCallback)(context->fClientContext, nullptr); |
| 2168 | delete context; |
| 2169 | return; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 2170 | } |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 2171 | (*context->fClientCallback)(context->fClientContext, std::move(result)); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 2172 | delete context; |
| 2173 | }; |
| 2174 | GrFlushInfo flushInfo; |
| 2175 | flushInfo.fFinishedContext = finishContext; |
| 2176 | flushInfo.fFinishedProc = finishCallback; |
| 2177 | this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 2178 | } |
| 2179 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 2180 | GrSemaphoresSubmitted GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess access, |
| 2181 | const GrFlushInfo& info) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 2182 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 2183 | if (fContext->priv().abandoned()) { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 2184 | return GrSemaphoresSubmitted::kNo; |
| 2185 | } |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 2186 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 15c9142 | 2019-05-07 16:54:48 -0400 | [diff] [blame] | 2187 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 2188 | |
Greg Daniel | 55f040b | 2020-02-13 15:38:32 +0000 | [diff] [blame] | 2189 | return this->drawingManager()->flushSurface(this->asSurfaceProxy(), access, info); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2190 | } |
| 2191 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 2192 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 2193 | const GrBackendSemaphore waitSemaphores[]) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2194 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 2195 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2196 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2197 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "waitOnSemaphores", fContext); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2198 | |
| 2199 | AutoCheckFlush acf(this->drawingManager()); |
| 2200 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 2201 | if (numSemaphores && !this->caps()->semaphoreSupport()) { |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 2202 | return false; |
| 2203 | } |
| 2204 | |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 2205 | auto direct = fContext->priv().asDirectContext(); |
| 2206 | if (!direct) { |
| 2207 | return false; |
| 2208 | } |
| 2209 | |
| 2210 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 2211 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 2212 | std::unique_ptr<std::unique_ptr<GrSemaphore>[]> grSemaphores( |
| 2213 | new std::unique_ptr<GrSemaphore>[numSemaphores]); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2214 | for (int i = 0; i < numSemaphores; ++i) { |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 2215 | grSemaphores[i] = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 2216 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 2217 | kAdopt_GrWrapOwnership); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 2218 | } |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 2219 | this->drawingManager()->newWaitRenderTask(this->asSurfaceProxyRef(), std::move(grSemaphores), |
| 2220 | numSemaphores); |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 2221 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 2222 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 2223 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2224 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2225 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2226 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2227 | const SkMatrix& viewMatrix, |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 2228 | const SkPath& path, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2229 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2230 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2231 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 2232 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 2233 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPath", fContext); |
| 2234 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2235 | GrStyledShape shape(path, style); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 2236 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 2237 | this->drawShape(clip, std::move(paint), aa, viewMatrix, shape); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | void GrRenderTargetContext::drawShape(const GrClip& clip, |
| 2241 | GrPaint&& paint, |
| 2242 | GrAA aa, |
| 2243 | const SkMatrix& viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2244 | const GrStyledShape& shape) { |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 2245 | ASSERT_SINGLE_OWNER |
| 2246 | RETURN_IF_ABANDONED |
| 2247 | SkDEBUGCODE(this->validate();) |
| 2248 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawShape", fContext); |
| 2249 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2250 | if (shape.isEmpty()) { |
| 2251 | if (shape.inverseFilled()) { |
| 2252 | this->drawPaint(clip, std::move(paint), viewMatrix); |
| 2253 | } |
| 2254 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2257 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2258 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2259 | if (!shape.style().hasPathEffect()) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 2260 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2261 | SkRRect rrect; |
| 2262 | // We can ignore the starting point and direction since there is no path effect. |
| 2263 | bool inverted; |
| 2264 | if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) { |
| 2265 | if (rrect.isRect()) { |
| 2266 | this->drawRect(clip, std::move(paint), aa, viewMatrix, rrect.rect(), |
| 2267 | &shape.style()); |
| 2268 | return; |
| 2269 | } else if (rrect.isOval()) { |
| 2270 | this->drawOval(clip, std::move(paint), aa, viewMatrix, rrect.rect(), shape.style()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2271 | return; |
| 2272 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2273 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, shape.style()); |
| 2274 | return; |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 2275 | } else if (GrAAType::kCoverage == aaType && shape.style().isSimpleFill() && |
| 2276 | viewMatrix.rectStaysRect()) { |
| 2277 | // TODO: the rectStaysRect restriction could be lifted if we were willing to apply |
| 2278 | // the matrix to all the points individually rather than just to the rect |
| 2279 | SkRect rects[2]; |
| 2280 | if (shape.asNestedRects(rects)) { |
| 2281 | // Concave AA paths are expensive - try to avoid them for special cases |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 2282 | std::unique_ptr<GrDrawOp> op = GrStrokeRectOp::MakeNested( |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 2283 | fContext, std::move(paint), viewMatrix, rects); |
| 2284 | if (op) { |
| 2285 | this->addDrawOp(clip, std::move(op)); |
| 2286 | } |
| 2287 | // Returning here indicates that there is nothing to draw in this case. |
| 2288 | return; |
| 2289 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2290 | } |
| 2291 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 2292 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2293 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, shape); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 2296 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2297 | const GrUserStencilSettings* ss, |
| 2298 | SkRegion::Op op, |
| 2299 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2300 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2301 | const SkMatrix& viewMatrix, |
| 2302 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2303 | ASSERT_SINGLE_OWNER_PRIV |
| 2304 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2305 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2306 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilPath", |
| 2307 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2308 | |
| 2309 | if (path.isEmpty() && path.isInverseFillType()) { |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 2310 | GrPaint paint; |
| 2311 | paint.setCoverageSetOpXPFactory(op, invert); |
| 2312 | this->stencilRect(clip, ss, std::move(paint), GrAA::kNo, SkMatrix::I(), |
| 2313 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 2314 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2315 | return true; |
| 2316 | } |
| 2317 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2318 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2319 | |
| 2320 | // An Assumption here is that path renderer would use some form of tweaking |
| 2321 | // the src color (either the input alpha or in the frag shader) to implement |
| 2322 | // aa. If we have some future driver-mojo path AA that can do the right |
| 2323 | // thing WRT to the blend then we'll need some query on the PR. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2324 | GrAAType aaType = fRenderTargetContext->chooseAAType(aa); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 2325 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2326 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2327 | SkIRect clipConservativeBounds; |
| 2328 | clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 2329 | &clipConservativeBounds, nullptr); |
| 2330 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2331 | GrStyledShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2332 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 2333 | canDrawArgs.fCaps = fRenderTargetContext->caps(); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2334 | canDrawArgs.fProxy = fRenderTargetContext->asRenderTargetProxy(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2335 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2336 | canDrawArgs.fShape = &shape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2337 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2338 | canDrawArgs.fAAType = aaType; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2339 | SkASSERT(!fRenderTargetContext->wrapsVkSecondaryCB()); |
| 2340 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = false; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2341 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2342 | |
| 2343 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2344 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 2345 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2346 | if (!pr) { |
| 2347 | return false; |
| 2348 | } |
| 2349 | |
| 2350 | GrPaint paint; |
| 2351 | paint.setCoverageSetOpXPFactory(op, invert); |
| 2352 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 2353 | GrPathRenderer::DrawPathArgs args{fRenderTargetContext->drawingManager()->getContext(), |
| 2354 | std::move(paint), |
| 2355 | ss, |
| 2356 | fRenderTargetContext, |
| 2357 | &clip, |
| 2358 | &clipConservativeBounds, |
| 2359 | &viewMatrix, |
| 2360 | &shape, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2361 | aaType, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 2362 | fRenderTargetContext->colorInfo().isLinearlyBlended()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2363 | pr->drawPath(args); |
| 2364 | return true; |
| 2365 | } |
| 2366 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2367 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2368 | ASSERT_SINGLE_OWNER_PRIV |
| 2369 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 2370 | if (fRenderTargetContext->fContext->priv().abandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2371 | return SkBudgeted::kNo; |
| 2372 | } |
| 2373 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2374 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2375 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 2376 | return fRenderTargetContext->asSurfaceProxy()->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2379 | void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, |
| 2380 | GrPaint&& paint, |
| 2381 | GrAA aa, |
| 2382 | const SkMatrix& viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2383 | const GrStyledShape& originalShape) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2384 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2385 | RETURN_IF_ABANDONED |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2386 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "internalDrawPath", fContext); |
| 2387 | |
Jim Van Verth | f86073a | 2018-10-02 13:05:38 -0400 | [diff] [blame] | 2388 | if (!viewMatrix.isFinite() || !originalShape.bounds().isFinite()) { |
| 2389 | return; |
| 2390 | } |
| 2391 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2392 | SkIRect clipConservativeBounds; |
| 2393 | clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr); |
| 2394 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2395 | GrStyledShape tempShape; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2396 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2397 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2398 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 2399 | canDrawArgs.fCaps = this->caps(); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2400 | canDrawArgs.fProxy = this->asRenderTargetProxy(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2401 | canDrawArgs.fViewMatrix = &viewMatrix; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2402 | canDrawArgs.fShape = &originalShape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2403 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2404 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = this->wrapsVkSecondaryCB(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2405 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2406 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2407 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 2408 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2409 | if (originalShape.isEmpty() && !originalShape.inverseFilled()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2410 | return; |
| 2411 | } |
| 2412 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2413 | canDrawArgs.fAAType = aaType; |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2414 | |
| 2415 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
| 2416 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
| 2417 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 2418 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2419 | if (!pr && originalShape.style().pathEffect()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2420 | // It didn't work above, so try again with the path effect applied. |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2421 | tempShape = originalShape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 2422 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2423 | return; |
| 2424 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2425 | canDrawArgs.fShape = &tempShape; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2426 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2427 | } |
| 2428 | if (!pr) { |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2429 | if (canDrawArgs.fShape->style().applies()) { |
| 2430 | tempShape = canDrawArgs.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, |
| 2431 | styleScale); |
| 2432 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2433 | return; |
| 2434 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2435 | canDrawArgs.fShape = &tempShape; |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 2436 | // This time, allow SW renderer |
| 2437 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
| 2438 | } else { |
| 2439 | pr = this->drawingManager()->getSoftwarePathRenderer(); |
Robert Phillips | d81379d | 2020-04-21 10:39:02 -0400 | [diff] [blame] | 2440 | #if GR_PATH_RENDERER_SPEW |
| 2441 | SkDebugf("falling back to: %s\n", pr->name()); |
| 2442 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 2443 | } |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2444 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2445 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2446 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2447 | #ifdef SK_DEBUG |
| 2448 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 2449 | #endif |
| 2450 | return; |
| 2451 | } |
| 2452 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 2453 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2454 | std::move(paint), |
| 2455 | &GrUserStencilSettings::kUnused, |
| 2456 | this, |
| 2457 | &clip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2458 | &clipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2459 | &viewMatrix, |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2460 | canDrawArgs.fShape, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2461 | aaType, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 2462 | this->colorInfo().isLinearlyBlended()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 2463 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2466 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 2467 | *bounds = op->bounds(); |
| 2468 | if (op->hasZeroArea()) { |
| 2469 | if (op->hasAABloat()) { |
| 2470 | bounds->outset(0.5f, 0.5f); |
| 2471 | } else { |
| 2472 | // We don't know which way the particular GPU will snap lines or points at integer |
| 2473 | // coords. So we ensure that the bounds is large enough for either snap. |
| 2474 | SkRect before = *bounds; |
| 2475 | bounds->roundOut(bounds); |
| 2476 | if (bounds->fLeft == before.fLeft) { |
| 2477 | bounds->fLeft -= 1; |
| 2478 | } |
| 2479 | if (bounds->fTop == before.fTop) { |
| 2480 | bounds->fTop -= 1; |
| 2481 | } |
| 2482 | if (bounds->fRight == before.fRight) { |
| 2483 | bounds->fRight += 1; |
| 2484 | } |
| 2485 | if (bounds->fBottom == before.fBottom) { |
| 2486 | bounds->fBottom += 1; |
| 2487 | } |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 2492 | void GrRenderTargetContext::addOp(std::unique_ptr<GrOp> op) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 2493 | this->getOpsTask()->addOp( |
Chris Dalton | 0875512 | 2019-08-05 16:13:47 -0600 | [diff] [blame] | 2494 | std::move(op), GrTextureResolveManager(this->drawingManager()), *this->caps()); |
| 2495 | } |
| 2496 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2497 | void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op, |
| 2498 | const std::function<WillAddOpFn>& willAddFn) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2499 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 2500 | if (fContext->priv().abandoned()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2501 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2502 | return; |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 2503 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 2504 | SkDEBUGCODE(this->validate();) |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 2505 | SkDEBUGCODE(op->fAddDrawOpCalled = true;) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2506 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "addDrawOp", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 2507 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2508 | // Setup clip |
| 2509 | SkRect bounds; |
| 2510 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 2511 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2512 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 2513 | bool usesHWAA = fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA; |
Chris Dalton | 9acf682 | 2019-11-12 11:52:40 -0700 | [diff] [blame] | 2514 | bool usesUserStencilBits = fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil; |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 2515 | |
Chris Dalton | 9acf682 | 2019-11-12 11:52:40 -0700 | [diff] [blame] | 2516 | if (usesUserStencilBits) { // Stencil clipping will call setNeedsStencil on its own, if needed. |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 2517 | this->setNeedsStencil(usesHWAA); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 2518 | } |
| 2519 | |
Chris Dalton | 9acf682 | 2019-11-12 11:52:40 -0700 | [diff] [blame] | 2520 | if (!clip.apply(fContext, this, usesHWAA, usesUserStencilBits, &appliedClip, &bounds)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2521 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2522 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2523 | } |
| 2524 | |
Chris Dalton | 9acf682 | 2019-11-12 11:52:40 -0700 | [diff] [blame] | 2525 | bool willUseStencil = usesUserStencilBits || appliedClip.hasStencilClip(); |
| 2526 | SkASSERT(!willUseStencil || fNumStencilSamples > 0); |
| 2527 | |
| 2528 | // If stencil is enabled and the framebuffer is mixed sampled, then the graphics pipeline will |
| 2529 | // have mixed sampled coverage, regardless of whether HWAA is enabled. (e.g., a non-aa draw |
| 2530 | // that uses a stencil test when the stencil buffer is multisampled.) |
| 2531 | bool hasMixedSampledCoverage = ( |
| 2532 | willUseStencil && fNumStencilSamples > this->numSamples()); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2533 | SkASSERT(!hasMixedSampledCoverage || |
| 2534 | this->asRenderTargetProxy()->canUseMixedSamples(*this->caps())); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2535 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 2536 | GrClampType clampType = GrColorTypeClampType(this->colorInfo().colorType()); |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 2537 | GrProcessorSet::Analysis analysis = op->finalize( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2538 | *this->caps(), &appliedClip, hasMixedSampledCoverage, clampType); |
| 2539 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2540 | GrXferProcessor::DstProxyView dstProxyView; |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 2541 | if (analysis.requiresDstTexture()) { |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2542 | if (!this->setupDstProxyView(clip, *op, &dstProxyView)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2543 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2544 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | op->setClippedBounds(bounds); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 2549 | auto opsTask = this->getOpsTask(); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2550 | if (willAddFn) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 2551 | willAddFn(op.get(), opsTask->uniqueID()); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2552 | } |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2553 | opsTask->addDrawOp(std::move(op), analysis, std::move(appliedClip), dstProxyView, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 2554 | GrTextureResolveManager(this->drawingManager()), *this->caps()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2557 | bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op, |
| 2558 | GrXferProcessor::DstProxyView* dstProxyView) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2559 | // If we are wrapping a vulkan secondary command buffer, we can't make a dst copy because we |
| 2560 | // don't actually have a VkImage to make a copy of. Additionally we don't have the power to |
| 2561 | // start and stop the render pass in order to make the copy. |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2562 | if (this->asRenderTargetProxy()->wrapsVkSecondaryCB()) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2563 | return false; |
| 2564 | } |
| 2565 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 2566 | if (this->caps()->textureBarrierSupport() && |
| 2567 | !this->asSurfaceProxy()->requiresManualMSAAResolve()) { |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2568 | if (this->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2569 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 2570 | // will be responsible to detect this situation and request a texture barrier. |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2571 | dstProxyView->setProxyView(this->readSurfaceView()); |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2572 | dstProxyView->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2573 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 2577 | SkIRect copyRect = SkIRect::MakeSize(this->asSurfaceProxy()->dimensions()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2578 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2579 | SkIRect clippedRect; |
Chris Dalton | 2243c7b | 2019-08-21 14:46:35 -0600 | [diff] [blame] | 2580 | clip.getConservativeBounds( |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 2581 | this->width(), this->height(), &clippedRect); |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2582 | SkRect opBounds = op.bounds(); |
| 2583 | // If the op has aa bloating or is a infinitely thin geometry (hairline) outset the bounds by |
| 2584 | // 0.5 pixels. |
| 2585 | if (op.hasAABloat() || op.hasZeroArea()) { |
| 2586 | opBounds.outset(0.5f, 0.5f); |
| 2587 | // An antialiased/hairline draw can sometimes bleed outside of the clips bounds. For |
| 2588 | // performance we may ignore the clip when the draw is entirely inside the clip is float |
| 2589 | // space but will hit pixels just outside the clip when actually rasterizing. |
| 2590 | clippedRect.outset(1, 1); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 2591 | clippedRect.intersect(SkIRect::MakeSize(this->asSurfaceProxy()->dimensions())); |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2592 | } |
| 2593 | SkIRect opIBounds; |
| 2594 | opBounds.roundOut(&opIBounds); |
| 2595 | if (!clippedRect.intersect(opIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2596 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2597 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2598 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2599 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2600 | } |
| 2601 | |
Greg Daniel | 3155f7f | 2020-01-16 16:54:26 -0500 | [diff] [blame] | 2602 | GrColorType colorType = this->colorInfo().colorType(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2603 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 2604 | // have per-sample dst values by making the copy multisampled. |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 2605 | GrCaps::DstCopyRestrictions restrictions = this->caps()->getDstCopyRestrictions( |
Greg Daniel | 3155f7f | 2020-01-16 16:54:26 -0500 | [diff] [blame] | 2606 | this->asRenderTargetProxy(), colorType); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2607 | |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 2608 | if (!restrictions.fMustCopyWholeSrc) { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2609 | copyRect = clippedRect; |
| 2610 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2611 | |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 2612 | SkIPoint dstOffset; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2613 | SkBackingFit fit; |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 2614 | if (restrictions.fRectsMustMatch == GrSurfaceProxy::RectsMustMatch::kYes) { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2615 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2616 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2617 | } else { |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2618 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2619 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2620 | } |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 2621 | auto copy = |
| 2622 | GrSurfaceProxy::Copy(fContext, this->asSurfaceProxy(), this->origin(), GrMipMapped::kNo, |
| 2623 | copyRect, fit, SkBudgeted::kYes, restrictions.fRectsMustMatch); |
| 2624 | SkASSERT(copy); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2625 | |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 2626 | dstProxyView->setProxyView({std::move(copy), this->origin(), this->readSwizzle()}); |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 2627 | dstProxyView->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2628 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 2629 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2630 | |
Greg Daniel | 573312e | 2020-02-07 17:22:35 -0500 | [diff] [blame] | 2631 | bool GrRenderTargetContext::blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 2632 | const SkIPoint& dstPoint) { |
Greg Daniel | 573312e | 2020-02-07 17:22:35 -0500 | [diff] [blame] | 2633 | SkASSERT(view.asTextureProxy()); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2634 | SkIRect clippedSrcRect; |
| 2635 | SkIPoint clippedDstPoint; |
Greg Daniel | 573312e | 2020-02-07 17:22:35 -0500 | [diff] [blame] | 2636 | if (!GrClipSrcRectAndDstPoint(this->asSurfaceProxy()->dimensions(), view.proxy()->dimensions(), |
| 2637 | srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2638 | return false; |
| 2639 | } |
| 2640 | |
| 2641 | GrPaint paint; |
| 2642 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 2643 | |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 2644 | auto fp = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2645 | if (!fp) { |
| 2646 | return false; |
| 2647 | } |
| 2648 | paint.addColorFragmentProcessor(std::move(fp)); |
| 2649 | |
| 2650 | this->fillRectToRect( |
| 2651 | GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), |
| 2652 | SkRect::MakeXYWH(clippedDstPoint.fX, clippedDstPoint.fY, clippedSrcRect.width(), |
| 2653 | clippedSrcRect.height()), |
| 2654 | SkRect::Make(clippedSrcRect)); |
| 2655 | return true; |
| 2656 | } |