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