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 Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 8 | #include "GrRenderTargetContext.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 9 | #include "../private/GrAuditTrail.h" |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 10 | #include "../private/SkShadowFlags.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 11 | #include "GrAppliedClip.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 12 | #include "GrBackendSemaphore.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 13 | #include "GrBlurUtils.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 14 | #include "GrCaps.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 15 | #include "GrColor.h" |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 16 | #include "GrContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 17 | #include "GrDrawingManager.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 18 | #include "GrFixedClip.h" |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 19 | #include "GrGpuResourcePriv.h" |
Robert Phillips | b6e9d3c | 2019-02-11 14:29:34 -0500 | [diff] [blame] | 20 | #include "GrMemoryPool.h" |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 21 | #include "GrOpList.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 22 | #include "GrPathRenderer.h" |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 23 | #include "GrQuad.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 24 | #include "GrRecordingContext.h" |
| 25 | #include "GrRecordingContextPriv.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 26 | #include "GrRenderTarget.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 27 | #include "GrRenderTargetContextPriv.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 28 | #include "GrResourceProvider.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 29 | #include "GrShape.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 30 | #include "GrStencilAttachment.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 31 | #include "GrStyle.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 32 | #include "GrTracing.h" |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 33 | #include "SkDrawable.h" |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 34 | #include "SkDrawShadowInfo.h" |
Herb Derby | 8378dfb | 2018-08-30 14:50:04 -0400 | [diff] [blame] | 35 | #include "SkGlyphRunPainter.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 36 | #include "SkGr.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 37 | #include "SkLatticeIter.h" |
| 38 | #include "SkMatrixPriv.h" |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 39 | #include "SkRRectPriv.h" |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 40 | #include "SkShadowUtils.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 41 | #include "SkSurfacePriv.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 42 | #include "effects/GrRRectEffect.h" |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 43 | #include "effects/GrTextureDomain.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 44 | #include "ops/GrAtlasTextOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 45 | #include "ops/GrClearOp.h" |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 46 | #include "ops/GrClearStencilClipOp.h" |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 47 | #include "ops/GrDebugMarkerOp.h" |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 48 | #include "ops/GrDrawableOp.h" |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 49 | #include "ops/GrDrawAtlasOp.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 50 | #include "ops/GrDrawOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 51 | #include "ops/GrDrawVerticesOp.h" |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 52 | #include "ops/GrFillRectOp.h" |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 53 | #include "ops/GrFillRRectOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 54 | #include "ops/GrLatticeOp.h" |
| 55 | #include "ops/GrOp.h" |
| 56 | #include "ops/GrOvalOpFactory.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 57 | #include "ops/GrRegionOp.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 58 | #include "ops/GrSemaphoreOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 59 | #include "ops/GrShadowRRectOp.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 60 | #include "ops/GrStencilPathOp.h" |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 61 | #include "ops/GrStrokeRectOp.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 62 | #include "ops/GrTextureOp.h" |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 63 | #include "text/GrTextContext.h" |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 64 | #include "text/GrTextTarget.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 65 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 66 | class GrRenderTargetContext::TextTarget : public GrTextTarget { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 67 | public: |
| 68 | TextTarget(GrRenderTargetContext* renderTargetContext) |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 69 | : GrTextTarget(renderTargetContext->width(), renderTargetContext->height(), |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame] | 70 | renderTargetContext->colorSpaceInfo()) |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 71 | , fRenderTargetContext(renderTargetContext) |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 72 | , fGlyphPainter{*renderTargetContext}{} |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 73 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 74 | void addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) override { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 75 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 76 | } |
| 77 | |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 78 | void drawShape(const GrClip& clip, const SkPaint& paint, |
| 79 | const SkMatrix& viewMatrix, const GrShape& shape) override { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 80 | GrBlurUtils::drawShapeWithMaskFilter(fRenderTargetContext->fContext, fRenderTargetContext, |
| 81 | clip, paint, viewMatrix, shape); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void makeGrPaint(GrMaskFormat maskFormat, const SkPaint& skPaint, const SkMatrix& viewMatrix, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 85 | GrPaint* grPaint) override { |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 86 | auto context = fRenderTargetContext->fContext; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 87 | const GrColorSpaceInfo& colorSpaceInfo = fRenderTargetContext->colorSpaceInfo(); |
| 88 | if (kARGB_GrMaskFormat == maskFormat) { |
| 89 | SkPaintToGrPaintWithPrimitiveColor(context, colorSpaceInfo, skPaint, grPaint); |
| 90 | } else { |
| 91 | SkPaintToGrPaint(context, colorSpaceInfo, skPaint, viewMatrix, grPaint); |
| 92 | } |
| 93 | } |
| 94 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 95 | GrRecordingContext* getContext() override { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 96 | return fRenderTargetContext->fContext; |
| 97 | } |
| 98 | |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 99 | SkGlyphRunListPainter* glyphPainter() override { |
| 100 | return &fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 103 | private: |
| 104 | GrRenderTargetContext* fRenderTargetContext; |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 105 | SkGlyphRunListPainter fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 106 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 107 | }; |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 108 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 109 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 110 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 111 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 112 | #define ASSERT_SINGLE_OWNER_PRIV \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 113 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 114 | #define RETURN_IF_ABANDONED if (fContext->priv().abandoned()) { return; } |
| 115 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return; } |
| 116 | #define RETURN_FALSE_IF_ABANDONED if (fContext->priv().abandoned()) { return false; } |
| 117 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return false; } |
| 118 | #define RETURN_NULL_IF_ABANDONED if (fContext->priv().abandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 119 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 120 | ////////////////////////////////////////////////////////////////////////////// |
| 121 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 122 | class AutoCheckFlush { |
| 123 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 124 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 125 | SkASSERT(fDrawingManager); |
| 126 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 127 | ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 128 | |
| 129 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 130 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 133 | // In MDB mode the reffing of the 'getLastOpList' call's result allows in-progress |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 134 | // GrOpLists to be picked up and added to by renderTargetContexts lower in the call |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 135 | // stack. When this occurs with a closed GrOpList, a new one will be allocated |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 136 | // when the renderTargetContext attempts to use it (via getOpList). |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 137 | GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 138 | sk_sp<GrRenderTargetProxy> rtp, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 139 | sk_sp<SkColorSpace> colorSpace, |
| 140 | const SkSurfaceProps* surfaceProps, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 141 | bool managedOpList) |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 142 | : GrSurfaceContext(context, rtp->config(), std::move(colorSpace)) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 143 | , fRenderTargetProxy(std::move(rtp)) |
| 144 | , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 145 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
| 146 | , fManagedOpList(managedOpList) { |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame] | 147 | if (!context->priv().explicitlyAllocateGPUResources()) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 148 | // MDB TODO: to ensure all resources still get allocated in the correct order in the hybrid |
| 149 | // world we need to get the correct opList here so that it, in turn, can grab and hold |
| 150 | // its rendertarget. |
| 151 | this->getRTOpList(); |
| 152 | } |
| 153 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 154 | fTextTarget.reset(new TextTarget(this)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 155 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 156 | } |
| 157 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 158 | #ifdef SK_DEBUG |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 159 | void GrRenderTargetContext::validate() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 160 | SkASSERT(fRenderTargetProxy); |
| 161 | fRenderTargetProxy->validate(fContext); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 162 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 163 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 164 | SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 165 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 166 | } |
| 167 | #endif |
| 168 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 169 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 170 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 173 | inline GrAAType GrRenderTargetContext::chooseAAType(GrAA aa) { |
| 174 | auto fsaaType = this->fsaaType(); |
| 175 | if (GrAA::kNo == aa) { |
| 176 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type reflect |
| 177 | // that. |
| 178 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !this->caps()->multisampleDisableSupport()) { |
| 179 | return GrAAType::kMSAA; |
| 180 | } |
| 181 | return GrAAType::kNone; |
| 182 | } |
| 183 | switch (fsaaType) { |
| 184 | case GrFSAAType::kNone: |
| 185 | case GrFSAAType::kMixedSamples: |
| 186 | return GrAAType::kCoverage; |
| 187 | case GrFSAAType::kUnifiedMSAA: |
| 188 | return GrAAType::kMSAA; |
| 189 | } |
| 190 | SK_ABORT("Unexpected fsaa type"); |
| 191 | return GrAAType::kNone; |
| 192 | } |
| 193 | |
| 194 | static inline GrPathRenderer::AATypeFlags choose_path_aa_type_flags( |
| 195 | GrAA aa, GrFSAAType fsaaType, const GrCaps& caps) { |
| 196 | using AATypeFlags = GrPathRenderer::AATypeFlags; |
| 197 | if (GrAA::kNo == aa) { |
| 198 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type flags |
| 199 | // reflect that. |
| 200 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !caps.multisampleDisableSupport()) { |
| 201 | return AATypeFlags::kMSAA; |
| 202 | } |
| 203 | return AATypeFlags::kNone; |
| 204 | } |
| 205 | switch (fsaaType) { |
| 206 | case GrFSAAType::kNone: |
| 207 | return AATypeFlags::kCoverage; |
| 208 | case GrFSAAType::kMixedSamples: |
| 209 | return AATypeFlags::kCoverage | AATypeFlags::kMixedSampledStencilThenCover; |
| 210 | case GrFSAAType::kUnifiedMSAA: |
| 211 | return AATypeFlags::kMSAA; |
| 212 | } |
| 213 | SK_ABORT("Invalid GrFSAAType."); |
| 214 | return AATypeFlags::kNone; |
| 215 | } |
| 216 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 217 | GrTextureProxy* GrRenderTargetContext::asTextureProxy() { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 218 | return fRenderTargetProxy->asTextureProxy(); |
| 219 | } |
| 220 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 221 | const GrTextureProxy* GrRenderTargetContext::asTextureProxy() const { |
| 222 | return fRenderTargetProxy->asTextureProxy(); |
| 223 | } |
| 224 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 225 | sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() { |
| 226 | return sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 227 | } |
| 228 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 229 | GrMipMapped GrRenderTargetContext::mipMapped() const { |
| 230 | if (const GrTextureProxy* proxy = this->asTextureProxy()) { |
| 231 | return proxy->mipMapped(); |
| 232 | } |
| 233 | return GrMipMapped::kNo; |
| 234 | } |
| 235 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 236 | GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 237 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 238 | SkDEBUGCODE(this->validate();) |
| 239 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 240 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 241 | fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy.get(), fManagedOpList); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 244 | return fOpList.get(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 247 | GrOpList* GrRenderTargetContext::getOpList() { |
| 248 | return this->getRTOpList(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 251 | void GrRenderTargetContext::drawGlyphRunList( |
| 252 | const GrClip& clip, const SkMatrix& viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 253 | const SkGlyphRunList& blob) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 254 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 255 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 256 | SkDEBUGCODE(this->validate();) |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 257 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawGlyphRunList", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 258 | |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 259 | // Drawing text can cause us to do inline uploads. This is not supported for wrapped vulkan |
| 260 | // secondary command buffers because it would require stopping and starting a render pass which |
| 261 | // we don't have access to. |
| 262 | if (this->wrapsVkSecondaryCB()) { |
| 263 | return; |
| 264 | } |
| 265 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 266 | GrTextContext* atlasTextContext = this->drawingManager()->getTextContext(); |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 267 | atlasTextContext->drawGlyphRunList(fContext, fTextTarget.get(), clip, viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 268 | fSurfaceProps, blob); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 271 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 272 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 273 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 274 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 275 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "discard", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 276 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 277 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 278 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 279 | this->getRTOpList()->discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 282 | void GrRenderTargetContext::clear(const SkIRect* rect, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 283 | const SkPMColor4f& color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 284 | CanClearFullscreen canClearFullscreen) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 285 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 286 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 287 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 288 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "clear", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 289 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 290 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 291 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, |
| 292 | canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 293 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 294 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 295 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 296 | const SkPMColor4f& color, |
| 297 | CanClearFullscreen canClearFullscreen) { |
| 298 | ASSERT_SINGLE_OWNER_PRIV |
| 299 | RETURN_IF_ABANDONED_PRIV |
| 300 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 301 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clear", |
| 302 | fRenderTargetContext->fContext); |
| 303 | |
| 304 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
| 305 | fRenderTargetContext->internalClear(clip, color, canClearFullscreen); |
| 306 | } |
| 307 | |
| 308 | static void clear_to_grpaint(const SkPMColor4f& color, GrPaint* paint) { |
| 309 | paint->setColor4f(color); |
| 310 | if (color.isOpaque()) { |
| 311 | // Can just rely on the src-over blend mode to do the right thing |
| 312 | paint->setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
| 313 | } else { |
| 314 | // A clear overwrites the prior color, so even if it's transparent, it behaves as if it |
| 315 | // were src blended |
| 316 | paint->setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 321 | const SkPMColor4f& color, |
| 322 | CanClearFullscreen canClearFullscreen) { |
| 323 | bool isFull = false; |
| 324 | if (!clip.hasWindowRectangles()) { |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 325 | // TODO: wrt the shouldInitializeTextures path, it would be more performant to |
| 326 | // only clear the entire target if we knew it had not been cleared before. As |
| 327 | // is this could end up doing a lot of redundant clears. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 328 | isFull = !clip.scissorEnabled() || |
| 329 | (CanClearFullscreen::kYes == canClearFullscreen && |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 330 | (this->caps()->preferFullscreenClears() || this->caps()->shouldInitializeTextures())) || |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 331 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 332 | } |
| 333 | |
| 334 | if (isFull) { |
| 335 | if (this->getRTOpList()->resetForFullscreenClear() && |
| 336 | !this->caps()->performColorClearsAsDraws()) { |
| 337 | // The op list was emptied and native clears are allowed, so just use the load op |
| 338 | this->getRTOpList()->setColorLoadOp(GrLoadOp::kClear, color); |
| 339 | return; |
| 340 | } else { |
| 341 | // Will use an op for the clear, reset the load op to discard since the op will |
| 342 | // blow away the color buffer contents |
| 343 | this->getRTOpList()->setColorLoadOp(GrLoadOp::kDiscard); |
| 344 | } |
| 345 | |
| 346 | // Must add an op to the list (either because we couldn't use a load op, or because the |
| 347 | // clear load op isn't supported) |
| 348 | if (this->caps()->performColorClearsAsDraws()) { |
| 349 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 350 | GrPaint paint; |
| 351 | clear_to_grpaint(color, &paint); |
| 352 | this->addDrawOp(GrFixedClip::Disabled(), |
| 353 | GrFillRectOp::Make(fContext, std::move(paint), |
| 354 | GrAAType::kNone, SkMatrix::I(), rtRect)); |
| 355 | } else { |
| 356 | this->getRTOpList()->addOp(GrClearOp::Make(fContext, SkIRect::MakeEmpty(), color, |
| 357 | /* fullscreen */ true), *this->caps()); |
| 358 | } |
| 359 | } else { |
| 360 | if (this->caps()->performPartialClearsAsDraws()) { |
| 361 | // performPartialClearsAsDraws() also returns true if any clear has to be a draw. |
| 362 | SkRect scissor = SkRect::Make(clip.scissorRect()); |
| 363 | GrPaint paint; |
| 364 | clear_to_grpaint(color, &paint); |
| 365 | |
| 366 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), GrAAType::kNone, |
| 367 | SkMatrix::I(), scissor)); |
| 368 | } else { |
| 369 | std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip, color, |
| 370 | this->asSurfaceProxy())); |
| 371 | // This version of the clear op factory can return null if the clip doesn't intersect |
| 372 | // with the surface proxy's boundary |
| 373 | if (!op) { |
| 374 | return; |
| 375 | } |
| 376 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 381 | void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const SkPMColor4f& color) { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 382 | ASSERT_SINGLE_OWNER_PRIV |
| 383 | RETURN_IF_ABANDONED_PRIV |
| 384 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 385 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "absClear", |
| 386 | fRenderTargetContext->fContext); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 387 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 388 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 389 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 390 | SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(), |
| 391 | fRenderTargetContext->fRenderTargetProxy->worstCaseHeight()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 392 | |
| 393 | if (clearRect) { |
| 394 | if (clearRect->contains(rtRect)) { |
| 395 | clearRect = nullptr; // full screen |
| 396 | } else { |
| 397 | if (!rtRect.intersect(*clearRect)) { |
| 398 | return; |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // TODO: in a post-MDB world this should be handled at the OpList level. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 404 | // This makes sure to always add an op to the list, instead of marking the clear as a load op. |
| 405 | // This code follows very similar logic to internalClear() below, but critical differences are |
| 406 | // highlighted in line related to absClear()'s unique behavior. |
| 407 | if (clearRect) { |
| 408 | if (fRenderTargetContext->caps()->performPartialClearsAsDraws()) { |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 409 | GrPaint paint; |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 410 | clear_to_grpaint(color, &paint); |
| 411 | |
| 412 | // Use the disabled clip; the rect geometry already matches the clear rectangle and |
| 413 | // if it were added to a scissor, that would be intersected with the logical surface |
| 414 | // bounds and not the worst case dimensions required here. |
| 415 | fRenderTargetContext->addDrawOp(GrFixedClip::Disabled(), |
| 416 | GrFillRectOp::Make(fRenderTargetContext->fContext, |
| 417 | std::move(paint), |
| 418 | GrAAType::kNone, |
| 419 | SkMatrix::I(), |
| 420 | SkRect::Make(rtRect))); |
| 421 | } else { |
| 422 | // Must use the ClearOp factory that takes a boolean (false) instead of a surface |
| 423 | // proxy. The surface proxy variant would intersect the clip rect with its logical |
| 424 | // bounds, which is not desired in this special case. |
| 425 | fRenderTargetContext->getRTOpList()->addOp( |
| 426 | GrClearOp::Make(fRenderTargetContext->fContext, rtRect, color, |
| 427 | /* fullscreen */ false), |
| 428 | *fRenderTargetContext->caps()); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 429 | } |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 430 | } else { |
| 431 | // Reset the oplist like in internalClear(), but do not rely on a load op for the clear |
| 432 | fRenderTargetContext->getRTOpList()->resetForFullscreenClear(); |
| 433 | fRenderTargetContext->getRTOpList()->setColorLoadOp(GrLoadOp::kDiscard); |
| 434 | |
| 435 | if (fRenderTargetContext->caps()->performColorClearsAsDraws()) { |
| 436 | // This draws a quad covering the worst case dimensions instead of just the logical |
| 437 | // width and height like in internalClear(). |
| 438 | GrPaint paint; |
| 439 | clear_to_grpaint(color, &paint); |
| 440 | fRenderTargetContext->addDrawOp(GrFixedClip::Disabled(), |
| 441 | GrFillRectOp::Make(fRenderTargetContext->fContext, |
| 442 | std::move(paint), |
| 443 | GrAAType::kNone, |
| 444 | SkMatrix::I(), |
| 445 | SkRect::Make(rtRect))); |
| 446 | } else { |
| 447 | // Nothing special about this path in absClear compared to internalClear() |
| 448 | fRenderTargetContext->getRTOpList()->addOp( |
| 449 | GrClearOp::Make(fRenderTargetContext->fContext, SkIRect::MakeEmpty(), color, |
| 450 | /* fullscreen */ true), |
| 451 | *fRenderTargetContext->caps()); |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 452 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 453 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 456 | void GrRenderTargetContext::drawPaint(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 457 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 458 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 459 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 460 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 461 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 462 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPaint", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 463 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 464 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 465 | // don't overflow fixed-point implementations |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 466 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 467 | SkRect r = fRenderTargetProxy->getBoundsRect(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 468 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 469 | // Check if we can optimize a clipped drawPaint(). We only do the transformation when there are |
| 470 | // no fragment processors because they may depend on having correct local coords and this path |
| 471 | // draws in device space without a local matrix. It currently handles converting clipRRect() |
| 472 | // to drawRRect() and solid colors to screen-filling drawRects() (which are then converted into |
| 473 | // clears if possible in drawRect). |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 474 | if (!paint.numTotalFragmentProcessors()) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 475 | SkRRect rrect; |
| 476 | GrAA aa = GrAA::kNo; |
| 477 | if (clip.isRRect(r, &rrect, &aa)) { |
| 478 | if (rrect.isRect()) { |
| 479 | // Use drawFilledRect() with no clip and the reduced rectangle |
| 480 | this->drawFilledRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect.rect()); |
| 481 | } else { |
| 482 | // Use drawRRect() with no clip |
| 483 | this->drawRRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect, |
| 484 | GrStyle::SimpleFill()); |
| 485 | } |
| 486 | } else { |
| 487 | // Use drawFilledRect() with no view matrix to draw a fullscreen quad, but preserve |
| 488 | // the clip. Since the paint has no FPs we can drop the view matrix without worrying |
| 489 | // about local coordinates. If the clip is simple, drawFilledRect() will turn this into |
| 490 | // a clear or a scissored clear. |
| 491 | this->drawFilledRect(clip, std::move(paint), aa, SkMatrix::I(), r); |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 492 | } |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 493 | return; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 496 | // Since the paint is not trivial, there's no way at this point drawRect() could have converted |
| 497 | // this drawPaint() into an optimized clear. drawRect() would then use GrFillRectOp without |
| 498 | // a local matrix, so we can simplify things and use the local matrix variant to draw a screen |
| 499 | // filling rect with the inverse view matrix for local coords, which works for all matrix |
| 500 | // conditions. |
| 501 | SkMatrix localMatrix; |
| 502 | if (!viewMatrix.invert(&localMatrix)) { |
| 503 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 504 | } |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 505 | |
| 506 | AutoCheckFlush acf(this->drawingManager()); |
| 507 | std::unique_ptr<GrDrawOp> op = GrFillRectOp::MakeWithLocalMatrix( |
| 508 | fContext, std::move(paint), GrAAType::kNone, SkMatrix::I(), localMatrix, r); |
| 509 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 510 | } |
| 511 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 512 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 513 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 514 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 515 | } |
| 516 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 517 | // Attempts to crop a rect and optional local rect to the clip boundaries. |
| 518 | // Returns false if the draw can be skipped entirely. |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 519 | static bool crop_filled_rect(int width, int height, const GrClip& clip, |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 520 | const SkMatrix& viewMatrix, SkRect* rect, |
| 521 | SkRect* localRect = nullptr) { |
| 522 | if (!viewMatrix.rectStaysRect()) { |
| 523 | return true; |
| 524 | } |
| 525 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 526 | SkIRect clipDevBounds; |
| 527 | SkRect clipBounds; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 528 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 529 | clip.getConservativeBounds(width, height, &clipDevBounds); |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 530 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) { |
| 531 | return false; |
| 532 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 533 | |
| 534 | if (localRect) { |
| 535 | if (!rect->intersects(clipBounds)) { |
| 536 | return false; |
| 537 | } |
| 538 | const SkScalar dx = localRect->width() / rect->width(); |
| 539 | const SkScalar dy = localRect->height() / rect->height(); |
| 540 | if (clipBounds.fLeft > rect->fLeft) { |
| 541 | localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx; |
| 542 | rect->fLeft = clipBounds.fLeft; |
| 543 | } |
| 544 | if (clipBounds.fTop > rect->fTop) { |
| 545 | localRect->fTop += (clipBounds.fTop - rect->fTop) * dy; |
| 546 | rect->fTop = clipBounds.fTop; |
| 547 | } |
| 548 | if (clipBounds.fRight < rect->fRight) { |
| 549 | localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx; |
| 550 | rect->fRight = clipBounds.fRight; |
| 551 | } |
| 552 | if (clipBounds.fBottom < rect->fBottom) { |
| 553 | localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy; |
| 554 | rect->fBottom = clipBounds.fBottom; |
| 555 | } |
| 556 | return true; |
| 557 | } |
| 558 | |
| 559 | return rect->intersect(clipBounds); |
| 560 | } |
| 561 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 562 | bool GrRenderTargetContext::drawFilledRectAsClear(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 563 | const SkMatrix& viewMatrix, const SkRect& rect) { |
| 564 | // Rules for a filled rect to become a clear [+scissor]: |
| 565 | // 1. The paint is a constant blend color with no other FPs |
| 566 | // 2. The view matrix maps rectangles to rectangles, or the transformed quad fully covers |
| 567 | // the render target (or clear region in #3). |
| 568 | // 3. The clip is an intersection of rectangles, so the clear region will be the |
| 569 | // intersection of the clip and the provided rect. |
| 570 | // 4. The clear region aligns with pixel bounds |
| 571 | // 5. There are no user stencil settings (and since the clip was IOR, the clip won't need |
| 572 | // to use the stencil either). |
| 573 | // If all conditions pass, the filled rect can either be a fullscreen clear (if it's big |
| 574 | // enough), or the rectangle geometry will be used as the scissor clip on the clear. |
| 575 | // If everything passes but rule #4, this submits a simplified fill rect op instead so that the |
| 576 | // rounding differences between clip and draws don't fight each other. |
| 577 | // NOTE: we route draws into clear() regardless of performColorClearsAsDraws() since the |
| 578 | // clear call is allowed to reset the oplist even when it also happens to use a GrFillRectOp. |
| 579 | |
| 580 | SkPMColor4f clearColor; |
| 581 | if (paint.numCoverageFragmentProcessors() > 0 || !paint.isConstantBlendedColor(&clearColor)) { |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | const SkRect rtRect = fRenderTargetProxy->getBoundsRect(); |
| 586 | // Will be the intersection of render target, clip, and quad |
| 587 | SkRect combinedRect = rtRect; |
| 588 | |
| 589 | SkRRect clipRRect; |
| 590 | GrAA clipAA; |
| 591 | if (!clip.quickContains(rtRect)) { |
| 592 | // If the clip is an rrect with no rounding, then it can replace the full RT bounds as the |
| 593 | // limiting region, although we will have to worry about AA. If the clip is anything |
| 594 | // more complicated, just punt to the regular fill rect op. |
| 595 | if (!clip.isRRect(rtRect, &clipRRect, &clipAA) || !clipRRect.isRect()) { |
| 596 | return false; |
| 597 | } |
| 598 | combinedRect = clipRRect.rect(); |
| 599 | } else { |
| 600 | // The clip is outside the render target, so the clip can be ignored |
| 601 | clipAA = GrAA::kNo; |
| 602 | } |
| 603 | |
| 604 | if (viewMatrix.rectStaysRect()) { |
| 605 | // Skip the extra overhead of inverting the view matrix to see if rtRect is contained in the |
| 606 | // drawn rectangle, and instead just intersect rtRect with the transformed rect. It will be |
| 607 | // the new clear region. |
| 608 | if (!combinedRect.intersect(viewMatrix.mapRect(rect))) { |
| 609 | // No intersection means nothing should be drawn, so return true but don't add an op |
| 610 | return true; |
| 611 | } |
| 612 | } else { |
| 613 | // If the transformed rectangle does not contain the combined rt and clip, the draw is too |
| 614 | // complex to be implemented as a clear |
| 615 | SkMatrix invM; |
| 616 | if (!viewMatrix.invert(&invM)) { |
| 617 | return false; |
| 618 | } |
| 619 | // The clip region in the rect's local space, so the test becomes the local rect containing |
| 620 | // the quad's points. |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 621 | GrQuad quad = GrQuad::MakeFromRect(rtRect, invM); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 622 | if (!rect_contains_inclusive(rect, quad.point(0)) || |
| 623 | !rect_contains_inclusive(rect, quad.point(1)) || |
| 624 | !rect_contains_inclusive(rect, quad.point(2)) || |
| 625 | !rect_contains_inclusive(rect, quad.point(3))) { |
| 626 | // No containment, so rtRect can't be filled by a solid color |
| 627 | return false; |
| 628 | } |
| 629 | // combinedRect can be filled by a solid color but doesn't need to be modified since it's |
| 630 | // inside the quad to be drawn. |
| 631 | } |
| 632 | |
| 633 | // Almost every condition is met; now it requires that the combined rect align with pixel |
| 634 | // boundaries in order for it to become a scissor-clear. Ignore the AA status in this case |
| 635 | // since non-AA with partial-pixel coordinates can be rounded differently on the GPU, |
| 636 | // leading to unexpected differences between a scissor test and a rasterized quad. |
| 637 | // Also skip very small rectangles since the scissor+clear doesn't by us much then. |
| 638 | if (combinedRect.contains(rtRect)) { |
| 639 | // Full screen clear |
| 640 | this->clear(nullptr, clearColor, CanClearFullscreen::kYes); |
| 641 | return true; |
| 642 | } else if (GrClip::IsPixelAligned(combinedRect) && |
| 643 | combinedRect.width() > 256 && combinedRect.height() > 256) { |
| 644 | // Scissor + clear (round shouldn't do anything since we are pixel aligned) |
| 645 | SkIRect scissorRect; |
| 646 | combinedRect.round(&scissorRect); |
| 647 | this->clear(&scissorRect, clearColor, CanClearFullscreen::kNo); |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | // If we got here, we can't use a scissor + clear, but combinedRect represents the correct |
| 652 | // geometry combination of quad + clip so we can perform a simplified fill rect op. We do this |
| 653 | // mostly to avoid mismatches in rounding logic on the CPU vs. the GPU, which frequently appears |
| 654 | // when drawing and clipping something to the same non-AA rect that never-the-less has |
| 655 | // non-integer coordinates. |
| 656 | |
| 657 | // For AA, use non-AA only when both clip and draw are non-AA. |
| 658 | if (clipAA == GrAA::kYes) { |
| 659 | aa = GrAA::kYes; |
| 660 | } |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 661 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 662 | this->addDrawOp(GrFixedClip::Disabled(), |
| 663 | GrFillRectOp::Make(fContext, std::move(paint), aaType, SkMatrix::I(), |
| 664 | combinedRect)); |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | void GrRenderTargetContext::drawFilledRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 669 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 670 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 671 | const SkMatrix& viewMatrix, |
| 672 | const SkRect& rect, |
| 673 | const GrUserStencilSettings* ss) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 674 | |
| 675 | if (!ss) { |
| 676 | if (this->drawFilledRectAsClear(clip, std::move(paint), aa, viewMatrix, rect)) { |
| 677 | return; |
| 678 | } |
| 679 | // Fall through to fill rect op |
| 680 | assert_alive(paint); |
| 681 | } |
| 682 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 683 | SkRect croppedRect = rect; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 684 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 685 | // The rectangle would not be drawn, so no need to add a draw op to the list |
| 686 | return; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 687 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 688 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 689 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 690 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), aaType, viewMatrix, |
| 691 | croppedRect, ss)); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 694 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 695 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 696 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 697 | const SkMatrix& viewMatrix, |
| 698 | const SkRect& rect, |
| 699 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 700 | if (!style) { |
| 701 | style = &GrStyle::SimpleFill(); |
| 702 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 703 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 704 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 705 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 706 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRect", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 707 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 708 | // Path effects should've been devolved to a path in SkGpuDevice |
| 709 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 710 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 711 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 712 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 713 | const SkStrokeRec& stroke = style->strokeRec(); |
Robert Phillips | 8c8b046 | 2018-08-24 16:18:03 -0400 | [diff] [blame] | 714 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 715 | this->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect); |
| 716 | return; |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 717 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 718 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 719 | if ((!rect.width() || !rect.height()) && |
| 720 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 721 | SkScalar r = stroke.getWidth() / 2; |
| 722 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 723 | switch (stroke.getJoin()) { |
| 724 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 725 | this->drawRect( |
| 726 | clip, std::move(paint), aa, viewMatrix, |
| 727 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 728 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 729 | return; |
| 730 | case SkPaint::kRound_Join: |
| 731 | // Raster draws nothing when both dimensions are empty. |
| 732 | if (rect.width() || rect.height()){ |
| 733 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 734 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 735 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 736 | return; |
| 737 | } |
| 738 | case SkPaint::kBevel_Join: |
| 739 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 740 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 741 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 742 | &GrStyle::SimpleFill()); |
| 743 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 744 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 745 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 746 | &GrStyle::SimpleFill()); |
| 747 | } |
| 748 | return; |
| 749 | } |
| 750 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 751 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 752 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 753 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 754 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 755 | op = GrStrokeRectOp::Make(fContext, std::move(paint), aaType, viewMatrix, rect, stroke); |
| 756 | // op may be null if the stroke is not supported or if using coverage aa and the view matrix |
| 757 | // does not preserve rectangles. |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 758 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 759 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 760 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 761 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 762 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 763 | assert_alive(paint); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 764 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(rect, *style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 767 | void GrRenderTargetContext::drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 768 | const SkMatrix& viewMatrix, const QuadSetEntry quads[], |
| 769 | int cnt) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 770 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 771 | this->addDrawOp(clip, GrFillRectOp::MakeSet(fContext, std::move(paint), aaType, viewMatrix, |
| 772 | quads, cnt)); |
| 773 | } |
| 774 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 775 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
| 776 | return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles( |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 777 | *fRenderTargetContext->caps()); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 778 | } |
| 779 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 780 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 781 | ASSERT_SINGLE_OWNER_PRIV |
| 782 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 783 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 784 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clearStencilClip", |
| 785 | fRenderTargetContext->fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 786 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 787 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 788 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 789 | fRenderTargetContext->internalStencilClear(clip, insideStencilMask); |
| 790 | } |
| 791 | |
| 792 | void GrRenderTargetContext::internalStencilClear(const GrFixedClip& clip, bool insideStencilMask) { |
| 793 | if (this->caps()->performStencilClearsAsDraws()) { |
| 794 | const GrUserStencilSettings* ss = GrStencilSettings::SetClipBitSettings(insideStencilMask); |
| 795 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 796 | |
| 797 | // Configure the paint to have no impact on the color buffer |
| 798 | GrPaint paint; |
| 799 | paint.setColor4f({0.f, 0.f, 0.f, 0.f}); |
| 800 | paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
| 801 | |
| 802 | // Mark stencil usage here before addDrawOp() so that it doesn't try to re-call |
| 803 | // internalStencilClear() just because the op has stencil settings. |
| 804 | this->setNeedsStencil(); |
| 805 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), |
| 806 | GrAAType::kNone, SkMatrix::I(), rtRect, ss)); |
| 807 | } else { |
| 808 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(fContext, clip, insideStencilMask, |
| 809 | fRenderTargetProxy.get())); |
| 810 | if (!op) { |
| 811 | return; |
| 812 | } |
| 813 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 814 | } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 817 | void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 818 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 819 | const SkMatrix& viewMatrix, |
| 820 | const GrPath* path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 821 | ASSERT_SINGLE_OWNER_PRIV |
| 822 | RETURN_IF_ABANDONED_PRIV |
| 823 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 824 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilPath", |
| 825 | fRenderTargetContext->fContext); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 826 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 827 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 828 | SkASSERT(path); |
| 829 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 830 | |
| 831 | // FIXME: Use path bounds instead of this WAR once |
| 832 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 833 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 834 | |
| 835 | // Setup clip |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 836 | GrAppliedHardClip appliedClip; |
| 837 | if (!clip.apply(fRenderTargetContext->width(), fRenderTargetContext->height(), &appliedClip, |
| 838 | &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 839 | return; |
| 840 | } |
| 841 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 842 | fRenderTargetContext->setNeedsStencil(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 843 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 844 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(fRenderTargetContext->fContext, |
| 845 | viewMatrix, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 846 | GrAA::kYes == doStencilMSAA, |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 847 | path->getFillType(), |
| 848 | appliedClip.hasStencilClip(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 849 | appliedClip.scissorState(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 850 | path); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 851 | if (!op) { |
| 852 | return; |
| 853 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 854 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 855 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 858 | void GrRenderTargetContextPriv::stencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 859 | const GrUserStencilSettings* ss, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 860 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 861 | const SkMatrix& viewMatrix, |
| 862 | const SkRect& rect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 863 | ASSERT_SINGLE_OWNER_PRIV |
| 864 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 865 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 866 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilRect", |
| 867 | fRenderTargetContext->fContext); |
| 868 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 869 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 870 | |
| 871 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 872 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 873 | auto aaType = (GrAA::kYes == doStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone; |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 874 | std::unique_ptr<GrDrawOp> op = GrFillRectOp::Make( |
| 875 | fRenderTargetContext->fContext, std::move(paint), aaType, viewMatrix, rect, ss); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 876 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 879 | bool GrRenderTargetContextPriv::drawAndStencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 880 | const GrUserStencilSettings* ss, |
| 881 | SkRegion::Op op, |
| 882 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 883 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 884 | const SkMatrix& viewMatrix, |
| 885 | const SkRect& rect) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 886 | ASSERT_SINGLE_OWNER_PRIV |
| 887 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 888 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 889 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilRect", |
| 890 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 891 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 892 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 893 | |
| 894 | GrPaint paint; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 895 | paint.setCoverageSetOpXPFactory(op, invert); |
| 896 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 897 | // This will always succeed to draw a rectangle |
| 898 | fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, ss); |
| 899 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 900 | } |
| 901 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 902 | void GrRenderTargetContext::fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 903 | GrQuadAAFlags edgeAA, const SkMatrix& viewMatrix, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 904 | const SkRect& rect, const SkRect* localRect) { |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 905 | ASSERT_SINGLE_OWNER |
| 906 | RETURN_IF_ABANDONED |
| 907 | SkDEBUGCODE(this->validate();) |
| 908 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithEdgeAA", fContext); |
| 909 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 910 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 911 | std::unique_ptr<GrDrawOp> op; |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 912 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 913 | if (localRect) { |
| 914 | // If local coordinates are provided, skip the optimization check to go through |
| 915 | // drawFilledRect, and also calculate clipped local coordinates |
| 916 | SkRect croppedRect = rect; |
| 917 | SkRect croppedLocalRect = *localRect; |
| 918 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect, |
| 919 | &croppedLocalRect)) { |
| 920 | return; |
| 921 | } |
| 922 | op = GrFillRectOp::MakePerEdgeWithLocalRect(fContext, std::move(paint), aaType, edgeAA, |
| 923 | viewMatrix, croppedRect, croppedLocalRect); |
| 924 | } else { |
| 925 | // If aaType turns into MSAA, make sure to keep quads with no AA edges as MSAA. Sending |
| 926 | // those to drawFilledRect() would have it turn off MSAA in that case, which breaks seaming |
| 927 | // with any partial AA edges that kept MSAA. |
| 928 | if (aaType != GrAAType::kMSAA && |
| 929 | (edgeAA == GrQuadAAFlags::kNone || edgeAA == GrQuadAAFlags::kAll)) { |
| 930 | // This is equivalent to a regular filled rect draw, so route through there to take |
| 931 | // advantage of draw->clear optimizations |
| 932 | this->drawFilledRect(clip, std::move(paint), GrAA(edgeAA == GrQuadAAFlags::kAll), |
| 933 | viewMatrix, rect); |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | SkRect croppedRect = rect; |
| 938 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
| 939 | return; |
| 940 | } |
| 941 | op = GrFillRectOp::MakePerEdge(fContext, std::move(paint), aaType, edgeAA, viewMatrix, |
| 942 | croppedRect); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | AutoCheckFlush acf(this->drawingManager()); |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 946 | this->addDrawOp(clip, std::move(op)); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 947 | } |
| 948 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 949 | void GrRenderTargetContext::fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 950 | GrQuadAAFlags edgeAA, const SkMatrix& viewMatrix, |
| 951 | const SkPoint quad[4], const SkPoint localQuad[4]) { |
| 952 | ASSERT_SINGLE_OWNER |
| 953 | RETURN_IF_ABANDONED |
| 954 | SkDEBUGCODE(this->validate();) |
| 955 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillQuadWithEdgeAA", fContext); |
| 956 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 957 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 958 | |
| 959 | AutoCheckFlush acf(this->drawingManager()); |
| 960 | // MakePerEdgeQuad automatically does the right thing if localQuad is null or not |
| 961 | this->addDrawOp(clip, GrFillRectOp::MakePerEdgeQuad(fContext, std::move(paint), aaType, edgeAA, |
| 962 | viewMatrix, quad, localQuad)); |
| 963 | } |
| 964 | |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 965 | // Creates a paint for GrFillRectOp that matches behavior of GrTextureOp |
| 966 | static void draw_texture_to_grpaint(sk_sp<GrTextureProxy> proxy, const SkRect* domain, |
| 967 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 968 | const SkPMColor4f& color, sk_sp<GrColorSpaceXform> csXform, |
| 969 | GrPaint* paint) { |
| 970 | paint->setColor4f(color); |
| 971 | paint->setXPFactory(SkBlendMode_AsXPFactory(mode)); |
| 972 | |
| 973 | std::unique_ptr<GrFragmentProcessor> fp; |
| 974 | if (domain) { |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 975 | SkRect correctedDomain = *domain; |
| 976 | if (filter == GrSamplerState::Filter::kBilerp) { |
| 977 | // Inset by 1/2 pixel, which GrTextureOp and GrTextureAdjuster handle automatically |
| 978 | correctedDomain.inset(0.5f, 0.5f); |
| 979 | } |
| 980 | fp = GrTextureDomainEffect::Make(std::move(proxy), SkMatrix::I(), correctedDomain, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 981 | GrTextureDomain::kClamp_Mode, filter); |
| 982 | } else { |
| 983 | fp = GrSimpleTextureEffect::Make(std::move(proxy), SkMatrix::I(), filter); |
| 984 | } |
| 985 | |
| 986 | fp = GrColorSpaceXformEffect::Make(std::move(fp), csXform); |
| 987 | paint->addColorFragmentProcessor(std::move(fp)); |
| 988 | } |
| 989 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 990 | void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 991 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 992 | const SkPMColor4f& color, const SkRect& srcRect, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 993 | const SkRect& dstRect, GrAA aa, GrQuadAAFlags aaFlags, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 994 | SkCanvas::SrcRectConstraint constraint, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 995 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 996 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 997 | ASSERT_SINGLE_OWNER |
| 998 | RETURN_IF_ABANDONED |
| 999 | SkDEBUGCODE(this->validate();) |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1000 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexture", fContext); |
Brian Salomon | f170904 | 2018-10-03 11:57:00 -0400 | [diff] [blame] | 1001 | if (constraint == SkCanvas::kStrict_SrcRectConstraint && |
| 1002 | srcRect.contains(proxy->getWorstCaseBoundsRect())) { |
| 1003 | constraint = SkCanvas::kFast_SrcRectConstraint; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1004 | } |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1005 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1006 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | ff9d6d3 | 2017-08-30 10:27:49 -0400 | [diff] [blame] | 1007 | SkRect clippedDstRect = dstRect; |
| 1008 | SkRect clippedSrcRect = srcRect; |
| 1009 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect, |
| 1010 | &clippedSrcRect)) { |
| 1011 | return; |
| 1012 | } |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1013 | |
| 1014 | AutoCheckFlush acf(this->drawingManager()); |
| 1015 | |
| 1016 | std::unique_ptr<GrDrawOp> op; |
| 1017 | if (mode != SkBlendMode::kSrcOver) { |
| 1018 | // Emulation mode with GrPaint and GrFillRectOp |
| 1019 | if (filter != GrSamplerState::Filter::kNearest && |
| 1020 | !GrTextureOp::GetFilterHasEffect(viewMatrix, clippedSrcRect, clippedDstRect)) { |
| 1021 | filter = GrSamplerState::Filter::kNearest; |
| 1022 | } |
| 1023 | |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1024 | GrPaint paint; |
| 1025 | draw_texture_to_grpaint(std::move(proxy), |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1026 | constraint == SkCanvas::kStrict_SrcRectConstraint ? &srcRect : nullptr, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1027 | filter, mode, color, std::move(textureColorSpaceXform), &paint); |
| 1028 | op = GrFillRectOp::MakePerEdgeWithLocalRect(fContext, std::move(paint), aaType, aaFlags, |
| 1029 | viewMatrix, clippedDstRect, clippedSrcRect); |
| 1030 | } else { |
| 1031 | // Can use a lighter weight op that can chain across proxies |
| 1032 | op = GrTextureOp::Make(fContext, std::move(proxy), filter, color, clippedSrcRect, |
| 1033 | clippedDstRect, aaType, aaFlags, constraint, viewMatrix, |
| 1034 | std::move(textureColorSpaceXform)); |
| 1035 | } |
| 1036 | |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 1037 | this->addDrawOp(clip, std::move(op)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1040 | void GrRenderTargetContext::drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
| 1041 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 1042 | const SkPMColor4f& color, const SkPoint srcQuad[4], |
| 1043 | const SkPoint dstQuad[4], GrAA aa, |
| 1044 | GrQuadAAFlags aaFlags, const SkRect* domain, |
| 1045 | const SkMatrix& viewMatrix, |
| 1046 | sk_sp<GrColorSpaceXform> texXform) { |
| 1047 | ASSERT_SINGLE_OWNER |
| 1048 | RETURN_IF_ABANDONED |
| 1049 | SkDEBUGCODE(this->validate();) |
| 1050 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureQuad", fContext); |
| 1051 | if (domain && domain->contains(proxy->getWorstCaseBoundsRect())) { |
| 1052 | domain = nullptr; |
| 1053 | } |
| 1054 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1055 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1056 | |
| 1057 | // Unlike drawTexture(), don't bother cropping or optimizing the filter type since we're |
| 1058 | // sampling an arbitrary quad of the texture. |
| 1059 | AutoCheckFlush acf(this->drawingManager()); |
| 1060 | std::unique_ptr<GrDrawOp> op; |
| 1061 | if (mode != SkBlendMode::kSrcOver) { |
| 1062 | // Emulation mode, but don't bother converting to kNearest filter since it's an arbitrary |
| 1063 | // quad that is being drawn, which makes the tests too expensive here |
| 1064 | GrPaint paint; |
| 1065 | draw_texture_to_grpaint( |
| 1066 | std::move(proxy), domain, filter, mode, color, std::move(texXform), &paint); |
| 1067 | op = GrFillRectOp::MakePerEdgeQuad(fContext, std::move(paint), aaType, aaFlags, viewMatrix, |
| 1068 | dstQuad, srcQuad); |
| 1069 | } else { |
| 1070 | // Use lighter weight GrTextureOp |
| 1071 | op = GrTextureOp::MakeQuad(fContext, std::move(proxy), filter, color, srcQuad, dstQuad, |
| 1072 | aaType, aaFlags, domain, viewMatrix, std::move(texXform)); |
| 1073 | } |
| 1074 | |
| 1075 | this->addDrawOp(clip, std::move(op)); |
| 1076 | } |
| 1077 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1078 | void GrRenderTargetContext::drawTextureSet(const GrClip& clip, const TextureSetEntry set[], int cnt, |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1079 | GrSamplerState::Filter filter, SkBlendMode mode, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1080 | GrAA aa, SkCanvas::SrcRectConstraint constraint, |
| 1081 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 1082 | sk_sp<GrColorSpaceXform> texXform) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1083 | ASSERT_SINGLE_OWNER |
| 1084 | RETURN_IF_ABANDONED |
| 1085 | SkDEBUGCODE(this->validate();) |
| 1086 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureSet", fContext); |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1087 | |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1088 | if (mode != SkBlendMode::kSrcOver || |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1089 | !fContext->priv().caps()->dynamicStateArrayGeometryProcessorTextureSupport()) { |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1090 | // Draw one at a time with GrFillRectOp and a GrPaint that emulates what GrTextureOp does |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1091 | SkMatrix ctm; |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1092 | for (int i = 0; i < cnt; ++i) { |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1093 | float alpha = set[i].fAlpha; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1094 | ctm = viewMatrix; |
| 1095 | if (set[i].fPreViewMatrix) { |
| 1096 | ctm.preConcat(*set[i].fPreViewMatrix); |
| 1097 | } |
| 1098 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1099 | if (set[i].fDstClipQuad == nullptr) { |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1100 | // Stick with original rectangles, which allows the ops to know more about what's |
| 1101 | // being drawn. |
| 1102 | this->drawTexture(clip, set[i].fProxy, filter, mode, {alpha, alpha, alpha, alpha}, |
| 1103 | set[i].fSrcRect, set[i].fDstRect, aa, set[i].fAAFlags, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1104 | constraint, ctm, texXform); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1105 | } else { |
| 1106 | // Generate interpolated texture coordinates to match the dst clip |
| 1107 | SkPoint srcQuad[4]; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1108 | GrMapRectPoints(set[i].fDstRect, set[i].fSrcRect, set[i].fDstClipQuad, srcQuad, 4); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1109 | const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint |
| 1110 | ? &set[i].fSrcRect : nullptr; |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1111 | this->drawTextureQuad(clip, set[i].fProxy, filter, mode, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1112 | {alpha, alpha, alpha, alpha}, srcQuad, set[i].fDstClipQuad, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1113 | aa, set[i].fAAFlags, domain, ctm, texXform); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1114 | } |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1115 | } |
| 1116 | } else { |
| 1117 | // Can use a single op, avoiding GrPaint creation, and can batch across proxies |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1118 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1119 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1120 | auto op = GrTextureOp::MakeSet(fContext, set, cnt, filter, aaType, constraint, viewMatrix, |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 1121 | std::move(texXform)); |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1122 | this->addDrawOp(clip, std::move(op)); |
| 1123 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1126 | void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1127 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1128 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1129 | const SkMatrix& viewMatrix, |
| 1130 | const SkRect& rectToDraw, |
| 1131 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1132 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 1133 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1134 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1135 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithLocalMatrix", fContext); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 1136 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 1137 | SkRect croppedRect = rectToDraw; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 1138 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 1139 | return; |
| 1140 | } |
| 1141 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1142 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1143 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1144 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 1145 | this->addDrawOp(clip, GrFillRectOp::MakeWithLocalMatrix(fContext, std::move(paint), aaType, |
| 1146 | viewMatrix, localMatrix, croppedRect)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1149 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1150 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1151 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1152 | sk_sp<SkVertices> vertices, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1153 | const SkVertices::Bone bones[], |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1154 | int boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1155 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1156 | ASSERT_SINGLE_OWNER |
| 1157 | RETURN_IF_ABANDONED |
| 1158 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1159 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawVertices", fContext); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1160 | |
| 1161 | AutoCheckFlush acf(this->drawingManager()); |
| 1162 | |
| 1163 | SkASSERT(vertices); |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1164 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1165 | std::unique_ptr<GrDrawOp> op = GrDrawVerticesOp::Make( |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1166 | fContext, std::move(paint), std::move(vertices), bones, boneCount, viewMatrix, aaType, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1167 | this->colorSpaceInfo().refColorSpaceXformFromSRGB(), overridePrimType); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 1168 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /////////////////////////////////////////////////////////////////////////////// |
| 1172 | |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1173 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
| 1174 | GrPaint&& paint, |
| 1175 | const SkMatrix& viewMatrix, |
| 1176 | int spriteCount, |
| 1177 | const SkRSXform xform[], |
| 1178 | const SkRect texRect[], |
| 1179 | const SkColor colors[]) { |
| 1180 | ASSERT_SINGLE_OWNER |
| 1181 | RETURN_IF_ABANDONED |
| 1182 | SkDEBUGCODE(this->validate();) |
| 1183 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawAtlas", fContext); |
| 1184 | |
| 1185 | AutoCheckFlush acf(this->drawingManager()); |
| 1186 | |
| 1187 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
| 1188 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(fContext, std::move(paint), viewMatrix, |
| 1189 | aaType, spriteCount, xform, texRect, colors); |
| 1190 | this->addDrawOp(clip, std::move(op)); |
| 1191 | } |
| 1192 | |
| 1193 | /////////////////////////////////////////////////////////////////////////////// |
| 1194 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1195 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1196 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1197 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1198 | const SkMatrix& viewMatrix, |
| 1199 | const SkRRect& rrect, |
| 1200 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1201 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1202 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1203 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1204 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRRect", fContext); |
Robert Phillips | 8529080 | 2018-07-02 13:14:28 -0400 | [diff] [blame] | 1205 | |
| 1206 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1207 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1211 | GrNoClip noclip; |
| 1212 | const GrClip* clip = &origClip; |
| 1213 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 1214 | // 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] | 1215 | // 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] | 1216 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 1217 | // 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] | 1218 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. This |
| 1219 | // 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] | 1220 | SkRRect devRRect; |
Michael Ludwig | 2839884 | 2019-03-25 10:24:24 -0400 | [diff] [blame] | 1221 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.transform(viewMatrix, &devRRect) && |
| 1222 | clip->quickContains(devRRect)) { |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1223 | clip = &noclip; |
| 1224 | } |
| 1225 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1226 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 1227 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1228 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1229 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1230 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 1231 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1232 | std::unique_ptr<GrDrawOp> op; |
| 1233 | if (style.isSimpleFill()) { |
| 1234 | assert_alive(paint); |
| 1235 | op = GrFillRRectOp::Make( |
| 1236 | fContext, aaType, viewMatrix, rrect, *this->caps(), std::move(paint)); |
| 1237 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1238 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1239 | assert_alive(paint); |
| 1240 | op = GrOvalOpFactory::MakeRRectOp( |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1241 | fContext, std::move(paint), viewMatrix, rrect, stroke, this->caps()->shaderCaps()); |
| 1242 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1243 | } |
| 1244 | if (op) { |
| 1245 | this->addDrawOp(*clip, std::move(op)); |
| 1246 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1247 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1248 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1249 | assert_alive(paint); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1250 | this->drawShapeUsingPathRenderer(*clip, std::move(paint), aa, viewMatrix, |
| 1251 | GrShape(rrect, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1254 | /////////////////////////////////////////////////////////////////////////////// |
| 1255 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1256 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 1257 | SkPoint3 result; |
| 1258 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 1259 | result.fZ = pt.fZ; |
| 1260 | return result; |
| 1261 | } |
| 1262 | |
| 1263 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1264 | const SkMatrix& viewMatrix, |
| 1265 | const SkPath& path, |
| 1266 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1267 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1268 | if (fContext->priv().abandoned()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1269 | return true; |
| 1270 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1271 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1272 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFastShadow", fContext); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1273 | |
| 1274 | // check z plane |
| 1275 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 1276 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 1277 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 1278 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 1279 | return false; |
| 1280 | } |
| 1281 | |
| 1282 | SkRRect rrect; |
| 1283 | SkRect rect; |
| 1284 | // we can only handle rects, circles, and rrects with circular corners |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1285 | bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsSimpleCircular(rrect) && |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1286 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 1287 | if (!isRRect && |
| 1288 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 1289 | rect.width() > SK_ScalarNearlyZero) { |
| 1290 | rrect.setOval(rect); |
| 1291 | isRRect = true; |
| 1292 | } |
| 1293 | if (!isRRect && path.isRect(&rect)) { |
| 1294 | rrect.setRect(rect); |
| 1295 | isRRect = true; |
| 1296 | } |
| 1297 | |
| 1298 | if (!isRRect) { |
| 1299 | return false; |
| 1300 | } |
| 1301 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1302 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1303 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1304 | } |
| 1305 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1306 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1307 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1308 | // transform light |
| 1309 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 1310 | |
| 1311 | // 1/scale |
| 1312 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
| 1313 | SkScalarInvert(viewMatrix[SkMatrix::kMScaleX]) : |
| 1314 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 1315 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1316 | |
| 1317 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1318 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
| 1319 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1320 | if (SkColorGetA(rec.fAmbientColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1321 | SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight); |
| 1322 | const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight); |
| 1323 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1324 | |
| 1325 | // Outset the shadow rrect to the border of the penumbra |
| 1326 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1327 | SkRRect ambientRRect; |
| 1328 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1329 | // If the rrect was an oval then its outset will also be one. |
| 1330 | // We set it explicitly to avoid errors. |
| 1331 | if (rrect.isOval()) { |
| 1332 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1333 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1334 | SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1335 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1336 | } |
| 1337 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1338 | GrColor ambientColor = SkColorToPremulGrColor(rec.fAmbientColor); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1339 | if (transparent) { |
| 1340 | // set a large inset to force a fill |
| 1341 | devSpaceInsetWidth = ambientRRect.width(); |
| 1342 | } |
Jim Van Verth | 39e7165 | 2018-04-23 18:08:45 +0000 | [diff] [blame] | 1343 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1344 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1345 | ambientColor, |
| 1346 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1347 | ambientRRect, |
| 1348 | devSpaceAmbientBlur, |
Jim Van Verth | fb18639 | 2018-09-11 11:37:46 -0400 | [diff] [blame] | 1349 | devSpaceInsetWidth); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1350 | SkASSERT(op); |
| 1351 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1352 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1353 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1354 | if (SkColorGetA(rec.fSpotColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1355 | SkScalar devSpaceSpotBlur; |
| 1356 | SkScalar spotScale; |
| 1357 | SkVector spotOffset; |
| 1358 | SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY, |
| 1359 | devLightPos.fZ, rec.fLightRadius, |
| 1360 | &devSpaceSpotBlur, &spotScale, &spotOffset); |
| 1361 | // handle scale of radius due to CTM |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1362 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1363 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1364 | // Adjust translate for the effect of the scale. |
| 1365 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1366 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1367 | // This offset is in dev space, need to transform it into source space. |
| 1368 | SkMatrix ctmInverse; |
| 1369 | if (viewMatrix.invert(&ctmInverse)) { |
| 1370 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1371 | } else { |
| 1372 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1373 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1374 | SkASSERT(false); |
| 1375 | } |
| 1376 | |
| 1377 | // Compute the transformed shadow rrect |
| 1378 | SkRRect spotShadowRRect; |
| 1379 | SkMatrix shadowTransform; |
| 1380 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1381 | rrect.transform(shadowTransform, &spotShadowRRect); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1382 | SkScalar spotRadius = SkRRectPriv::GetSimpleRadii(spotShadowRRect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1383 | |
| 1384 | // Compute the insetWidth |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1385 | SkScalar blurOutset = srcSpaceSpotBlur; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1386 | SkScalar insetWidth = blurOutset; |
| 1387 | if (transparent) { |
| 1388 | // If transparent, just do a fill |
| 1389 | insetWidth += spotShadowRRect.width(); |
| 1390 | } else { |
| 1391 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1392 | // border. We want to extend this inset area so that it meets up with the caster |
| 1393 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1394 | // |
| 1395 | // We compare the min and max corners inset by the radius between the original |
| 1396 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1397 | // between the scaled radius and the original radius gives the distance from the |
| 1398 | // transformed shadow shape to the original shape in that corner. The max |
| 1399 | // of these gives the maximum distance we need to cover. |
| 1400 | // |
| 1401 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1402 | // that to get the full insetWidth. |
| 1403 | SkScalar maxOffset; |
| 1404 | if (rrect.isRect()) { |
| 1405 | // Manhattan distance works better for rects |
| 1406 | maxOffset = SkTMax(SkTMax(SkTAbs(spotShadowRRect.rect().fLeft - |
| 1407 | rrect.rect().fLeft), |
| 1408 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1409 | rrect.rect().fTop)), |
| 1410 | SkTMax(SkTAbs(spotShadowRRect.rect().fRight - |
| 1411 | rrect.rect().fRight), |
| 1412 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1413 | rrect.rect().fBottom))); |
| 1414 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1415 | SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1416 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1417 | rrect.rect().fLeft + dr, |
| 1418 | spotShadowRRect.rect().fTop - |
| 1419 | rrect.rect().fTop + dr); |
| 1420 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1421 | rrect.rect().fRight - dr, |
| 1422 | spotShadowRRect.rect().fBottom - |
| 1423 | rrect.rect().fBottom - dr); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 1424 | maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset), |
| 1425 | SkPointPriv::LengthSqd(lowerRightOffset))) + dr; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1426 | } |
Jim Van Verth | 4c8c1e8 | 2018-04-23 17:14:48 -0400 | [diff] [blame] | 1427 | insetWidth += SkTMax(blurOutset, maxOffset); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | // Outset the shadow rrect to the border of the penumbra |
| 1431 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1432 | if (spotShadowRRect.isOval()) { |
| 1433 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1434 | } else { |
| 1435 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1436 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1437 | } |
| 1438 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1439 | GrColor spotColor = SkColorToPremulGrColor(rec.fSpotColor); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1440 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1441 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1442 | spotColor, |
| 1443 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1444 | spotShadowRRect, |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1445 | 2.0f * devSpaceSpotBlur, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1446 | insetWidth); |
| 1447 | SkASSERT(op); |
| 1448 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | /////////////////////////////////////////////////////////////////////////////// |
| 1455 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1456 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1457 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1458 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1459 | const SkMatrix& viewMatrix, |
| 1460 | const SkRRect& origOuter, |
| 1461 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1462 | SkASSERT(!origInner.isEmpty()); |
| 1463 | SkASSERT(!origOuter.isEmpty()); |
| 1464 | |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1465 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1466 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1467 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 45839f9 | 2017-12-04 09:02:35 -0500 | [diff] [blame] | 1468 | |
| 1469 | if (GrAAType::kMSAA == aaType) { |
| 1470 | return false; |
| 1471 | } |
| 1472 | |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1473 | if (GrAAType::kCoverage == aaType && SkRRectPriv::IsCircle(*inner) |
| 1474 | && SkRRectPriv::IsCircle(*outer)) { |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1475 | auto outerR = outer->width() / 2.f; |
| 1476 | auto innerR = inner->width() / 2.f; |
| 1477 | auto cx = outer->getBounds().fLeft + outerR; |
| 1478 | auto cy = outer->getBounds().fTop + outerR; |
| 1479 | if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && |
| 1480 | SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { |
| 1481 | auto avgR = (innerR + outerR) / 2.f; |
| 1482 | auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); |
| 1483 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1484 | stroke.setStrokeStyle(outerR - innerR); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1485 | auto op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1486 | circleBounds, GrStyle(stroke, nullptr), |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1487 | this->caps()->shaderCaps()); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1488 | if (op) { |
| 1489 | this->addDrawOp(clip, std::move(op)); |
| 1490 | return true; |
| 1491 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1492 | assert_alive(paint); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1493 | } |
| 1494 | } |
| 1495 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 1496 | GrClipEdgeType innerEdgeType, outerEdgeType; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1497 | if (GrAAType::kCoverage == aaType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1498 | innerEdgeType = GrClipEdgeType::kInverseFillAA; |
| 1499 | outerEdgeType = GrClipEdgeType::kFillAA; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1500 | } else { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1501 | innerEdgeType = GrClipEdgeType::kInverseFillBW; |
| 1502 | outerEdgeType = GrClipEdgeType::kFillBW; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1503 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1504 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1505 | SkMatrix inverseVM; |
| 1506 | if (!viewMatrix.isIdentity()) { |
| 1507 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1508 | return false; |
| 1509 | } |
| 1510 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1511 | return false; |
| 1512 | } |
| 1513 | if (!viewMatrix.invert(&inverseVM)) { |
| 1514 | return false; |
| 1515 | } |
| 1516 | } else { |
| 1517 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1518 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1519 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1520 | const auto& caps = *this->caps()->shaderCaps(); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1521 | // TODO these need to be a geometry processors |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1522 | auto innerEffect = GrRRectEffect::Make(innerEdgeType, *inner, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1523 | if (!innerEffect) { |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1527 | auto outerEffect = GrRRectEffect::Make(outerEdgeType, *outer, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1528 | if (!outerEffect) { |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1532 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1533 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1534 | |
| 1535 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1536 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1537 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1538 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1539 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1540 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1541 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1542 | return true; |
| 1543 | } |
| 1544 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1545 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1546 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1547 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1548 | const SkMatrix& viewMatrix, |
| 1549 | const SkRRect& outer, |
| 1550 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1551 | ASSERT_SINGLE_OWNER |
| 1552 | RETURN_IF_ABANDONED |
| 1553 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1554 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawDRRect", fContext); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1555 | |
| 1556 | SkASSERT(!outer.isEmpty()); |
| 1557 | SkASSERT(!inner.isEmpty()); |
| 1558 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1559 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1560 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1561 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1562 | return; |
| 1563 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1564 | assert_alive(paint); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1565 | |
| 1566 | SkPath path; |
| 1567 | path.setIsVolatile(true); |
| 1568 | path.addRRect(inner); |
| 1569 | path.addRRect(outer); |
| 1570 | path.setFillType(SkPath::kEvenOdd_FillType); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1571 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(path)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1572 | } |
| 1573 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1574 | /////////////////////////////////////////////////////////////////////////////// |
| 1575 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1576 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1577 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1578 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1579 | const SkMatrix& viewMatrix, |
| 1580 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1581 | const GrStyle& style, |
| 1582 | const GrUserStencilSettings* ss) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1583 | ASSERT_SINGLE_OWNER |
| 1584 | RETURN_IF_ABANDONED |
| 1585 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1586 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRegion", fContext); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1587 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1588 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1589 | // 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] | 1590 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1591 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1592 | SkScalarIsInt(viewMatrix.getTranslateX()) && |
| 1593 | SkScalarIsInt(viewMatrix.getTranslateY())) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1594 | aa = GrAA::kNo; |
| 1595 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1596 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1597 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1598 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1599 | SkPath path; |
| 1600 | region.getBoundaryPath(&path); |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 1601 | path.setIsVolatile(true); |
| 1602 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1603 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1606 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1607 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(fContext, std::move(paint), viewMatrix, region, |
| 1608 | aaType, ss); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1609 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1612 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1613 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1614 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1615 | const SkMatrix& viewMatrix, |
| 1616 | const SkRect& oval, |
| 1617 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1618 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1619 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1620 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1621 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawOval", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1622 | |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1623 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1624 | |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1625 | if (oval.isEmpty() && !style.pathEffect()) { |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1626 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
| 1627 | return; |
| 1628 | } |
| 1629 | |
| 1630 | this->drawRect(clip, std::move(paint), aa, viewMatrix, oval, &style); |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1631 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1634 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1635 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1636 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1637 | |
| 1638 | std::unique_ptr<GrDrawOp> op; |
| 1639 | if (style.isSimpleFill()) { |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 1640 | // GrFillRRectOp has special geometry and a fragment-shader branch to conditionally evaluate |
| 1641 | // the arc equation. This same special geometry and fragment branch also turn out to be a |
| 1642 | // substantial optimization for drawing ovals (namely, by not evaluating the arc equation |
| 1643 | // inside the oval's inner diamond). Given these optimizations, it's a clear win to draw |
| 1644 | // ovals the exact same way we do round rects. |
Chris Dalton | ebc38c9 | 2018-11-28 16:58:09 -0700 | [diff] [blame] | 1645 | // |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1646 | // However, we still don't draw true circles as round rects in coverage mode, because it can |
| 1647 | // cause perf regressions on some platforms as compared to the dedicated circle Op. |
| 1648 | if (GrAAType::kCoverage != aaType || oval.height() != oval.width()) { |
Chris Dalton | bf341ae | 2019-03-27 00:28:22 +0000 | [diff] [blame] | 1649 | assert_alive(paint); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1650 | op = GrFillRRectOp::Make(fContext, aaType, viewMatrix, SkRRect::MakeOval(oval), |
| 1651 | *this->caps(), std::move(paint)); |
Chris Dalton | bf341ae | 2019-03-27 00:28:22 +0000 | [diff] [blame] | 1652 | } |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1653 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1654 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1655 | assert_alive(paint); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1656 | op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, oval, style, |
| 1657 | this->caps()->shaderCaps()); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1658 | } |
| 1659 | if (op) { |
| 1660 | this->addDrawOp(clip, std::move(op)); |
| 1661 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1662 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1663 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1664 | assert_alive(paint); |
Brian Salomon | 5209d7f | 2018-04-20 16:52:42 -0400 | [diff] [blame] | 1665 | this->drawShapeUsingPathRenderer( |
| 1666 | clip, std::move(paint), aa, viewMatrix, |
| 1667 | GrShape(SkRRect::MakeOval(oval), SkPath::kCW_Direction, 2, false, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1670 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1671 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1672 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1673 | const SkMatrix& viewMatrix, |
| 1674 | const SkRect& oval, |
| 1675 | SkScalar startAngle, |
| 1676 | SkScalar sweepAngle, |
| 1677 | bool useCenter, |
| 1678 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1679 | ASSERT_SINGLE_OWNER |
| 1680 | RETURN_IF_ABANDONED |
| 1681 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1682 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawArc", fContext); |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1683 | |
| 1684 | AutoCheckFlush acf(this->drawingManager()); |
| 1685 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1686 | GrAAType aaType = this->chooseAAType(aa); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1687 | if (GrAAType::kCoverage == aaType) { |
| 1688 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
| 1689 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(fContext, |
| 1690 | std::move(paint), |
| 1691 | viewMatrix, |
| 1692 | oval, |
| 1693 | startAngle, |
| 1694 | sweepAngle, |
| 1695 | useCenter, |
| 1696 | style, |
| 1697 | shaderCaps); |
| 1698 | if (op) { |
| 1699 | this->addDrawOp(clip, std::move(op)); |
| 1700 | return; |
| 1701 | } |
| 1702 | assert_alive(paint); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1703 | } |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 1704 | this->drawShapeUsingPathRenderer( |
| 1705 | clip, std::move(paint), aa, viewMatrix, |
| 1706 | GrShape::MakeArc(oval, startAngle, sweepAngle, useCenter, style)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1709 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1710 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1711 | const SkMatrix& viewMatrix, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1712 | sk_sp<GrTextureProxy> image, |
| 1713 | sk_sp<GrColorSpaceXform> csxf, |
| 1714 | GrSamplerState::Filter filter, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1715 | std::unique_ptr<SkLatticeIter> iter, |
| 1716 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1717 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1718 | RETURN_IF_ABANDONED |
| 1719 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1720 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawImageLattice", fContext); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1721 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1722 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1723 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1724 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1725 | GrLatticeOp::MakeNonAA(fContext, std::move(paint), viewMatrix, std::move(image), |
| 1726 | std::move(csxf), filter, std::move(iter), dst); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1727 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1730 | void GrRenderTargetContext::drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable, |
| 1731 | const SkRect& bounds) { |
| 1732 | std::unique_ptr<GrOp> op(GrDrawableOp::Make(fContext, std::move(drawable), bounds)); |
| 1733 | SkASSERT(op); |
| 1734 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1735 | } |
| 1736 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1737 | GrSemaphoresSubmitted GrRenderTargetContext::prepareForExternalIO( |
Greg Daniel | b9990e4 | 2019-04-10 16:28:52 -0400 | [diff] [blame] | 1738 | SkSurface::BackendSurfaceAccess access, GrFlushFlags flags, int numSemaphores, |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 1739 | GrBackendSemaphore backendSemaphores[]) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1740 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1741 | if (fContext->priv().abandoned()) { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 1742 | return GrSemaphoresSubmitted::kNo; |
| 1743 | } |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1744 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1745 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "prepareForExternalIO", fContext); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1746 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1747 | return this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get(), |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 1748 | access, flags, |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1749 | numSemaphores, |
| 1750 | backendSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1751 | } |
| 1752 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1753 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1754 | const GrBackendSemaphore waitSemaphores[]) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1755 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1756 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1757 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1758 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "waitOnSemaphores", fContext); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1759 | |
| 1760 | AutoCheckFlush acf(this->drawingManager()); |
| 1761 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1762 | if (numSemaphores && !this->caps()->fenceSyncSupport()) { |
| 1763 | return false; |
| 1764 | } |
| 1765 | |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1766 | auto direct = fContext->priv().asDirectContext(); |
| 1767 | if (!direct) { |
| 1768 | return false; |
| 1769 | } |
| 1770 | |
| 1771 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1772 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1773 | SkTArray<sk_sp<GrSemaphore>> semaphores(numSemaphores); |
| 1774 | for (int i = 0; i < numSemaphores; ++i) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1775 | sk_sp<GrSemaphore> sema = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 1776 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 1777 | kAdopt_GrWrapOwnership); |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1778 | std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(fContext, std::move(sema), |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1779 | fRenderTargetProxy.get())); |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 1780 | this->getRTOpList()->addWaitOp(std::move(waitOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1781 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1782 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1783 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1784 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1785 | void GrRenderTargetContext::insertEventMarker(const SkString& str) { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 1786 | std::unique_ptr<GrOp> op(GrDebugMarkerOp::Make(fContext, fRenderTargetProxy.get(), str)); |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1787 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1788 | } |
| 1789 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 1790 | const GrCaps* GrRenderTargetContext::caps() const { |
| 1791 | return fContext->priv().caps(); |
| 1792 | } |
| 1793 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1794 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1795 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1796 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1797 | const SkMatrix& viewMatrix, |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1798 | const SkPath& path, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1799 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1800 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1801 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1802 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1803 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPath", fContext); |
| 1804 | |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1805 | GrShape shape(path, style); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1806 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 1807 | this->drawShape(clip, std::move(paint), aa, viewMatrix, shape); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | void GrRenderTargetContext::drawShape(const GrClip& clip, |
| 1811 | GrPaint&& paint, |
| 1812 | GrAA aa, |
| 1813 | const SkMatrix& viewMatrix, |
| 1814 | const GrShape& shape) { |
| 1815 | ASSERT_SINGLE_OWNER |
| 1816 | RETURN_IF_ABANDONED |
| 1817 | SkDEBUGCODE(this->validate();) |
| 1818 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawShape", fContext); |
| 1819 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1820 | if (shape.isEmpty()) { |
| 1821 | if (shape.inverseFilled()) { |
| 1822 | this->drawPaint(clip, std::move(paint), viewMatrix); |
| 1823 | } |
| 1824 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1827 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1828 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1829 | if (!shape.style().hasPathEffect()) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1830 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1831 | SkRRect rrect; |
| 1832 | // We can ignore the starting point and direction since there is no path effect. |
| 1833 | bool inverted; |
| 1834 | if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) { |
| 1835 | if (rrect.isRect()) { |
| 1836 | this->drawRect(clip, std::move(paint), aa, viewMatrix, rrect.rect(), |
| 1837 | &shape.style()); |
| 1838 | return; |
| 1839 | } else if (rrect.isOval()) { |
| 1840 | this->drawOval(clip, std::move(paint), aa, viewMatrix, rrect.rect(), shape.style()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1841 | return; |
| 1842 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1843 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, shape.style()); |
| 1844 | return; |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 1845 | } else if (GrAAType::kCoverage == aaType && shape.style().isSimpleFill() && |
| 1846 | viewMatrix.rectStaysRect()) { |
| 1847 | // TODO: the rectStaysRect restriction could be lifted if we were willing to apply |
| 1848 | // the matrix to all the points individually rather than just to the rect |
| 1849 | SkRect rects[2]; |
| 1850 | if (shape.asNestedRects(rects)) { |
| 1851 | // Concave AA paths are expensive - try to avoid them for special cases |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 1852 | std::unique_ptr<GrDrawOp> op = GrStrokeRectOp::MakeNested( |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 1853 | fContext, std::move(paint), viewMatrix, rects); |
| 1854 | if (op) { |
| 1855 | this->addDrawOp(clip, std::move(op)); |
| 1856 | } |
| 1857 | // Returning here indicates that there is nothing to draw in this case. |
| 1858 | return; |
| 1859 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1860 | } |
| 1861 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1862 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1863 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, shape); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 1866 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1867 | const GrUserStencilSettings* ss, |
| 1868 | SkRegion::Op op, |
| 1869 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1870 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1871 | const SkMatrix& viewMatrix, |
| 1872 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1873 | ASSERT_SINGLE_OWNER_PRIV |
| 1874 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1875 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1876 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilPath", |
| 1877 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1878 | |
| 1879 | if (path.isEmpty() && path.isInverseFillType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1880 | this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1881 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 1882 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1883 | return true; |
| 1884 | } |
| 1885 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1886 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1887 | |
| 1888 | // An Assumption here is that path renderer would use some form of tweaking |
| 1889 | // the src color (either the input alpha or in the frag shader) to implement |
| 1890 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1891 | // thing WRT to the blend then we'll need some query on the PR. |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1892 | auto aaTypeFlags = choose_path_aa_type_flags( |
| 1893 | aa, fRenderTargetContext->fsaaType(), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1894 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1895 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1896 | SkIRect clipConservativeBounds; |
| 1897 | clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 1898 | &clipConservativeBounds, nullptr); |
| 1899 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1900 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1901 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1902 | canDrawArgs.fCaps = fRenderTargetContext->caps(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1903 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1904 | canDrawArgs.fShape = &shape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1905 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1906 | canDrawArgs.fAATypeFlags = aaTypeFlags; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1907 | SkASSERT(!fRenderTargetContext->wrapsVkSecondaryCB()); |
| 1908 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = false; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1909 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1910 | |
| 1911 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1912 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 1913 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1914 | if (!pr) { |
| 1915 | return false; |
| 1916 | } |
| 1917 | |
| 1918 | GrPaint paint; |
| 1919 | paint.setCoverageSetOpXPFactory(op, invert); |
| 1920 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1921 | GrPathRenderer::DrawPathArgs args{fRenderTargetContext->drawingManager()->getContext(), |
| 1922 | std::move(paint), |
| 1923 | ss, |
| 1924 | fRenderTargetContext, |
| 1925 | &clip, |
| 1926 | &clipConservativeBounds, |
| 1927 | &viewMatrix, |
| 1928 | &shape, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1929 | aaTypeFlags, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 1930 | fRenderTargetContext->colorSpaceInfo().isLinearlyBlended()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1931 | pr->drawPath(args); |
| 1932 | return true; |
| 1933 | } |
| 1934 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1935 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1936 | ASSERT_SINGLE_OWNER_PRIV |
| 1937 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1938 | if (fRenderTargetContext->fContext->priv().abandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1939 | return SkBudgeted::kNo; |
| 1940 | } |
| 1941 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1942 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1943 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 1944 | return fRenderTargetContext->fRenderTargetProxy->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1947 | void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, |
| 1948 | GrPaint&& paint, |
| 1949 | GrAA aa, |
| 1950 | const SkMatrix& viewMatrix, |
| 1951 | const GrShape& originalShape) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1952 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1953 | RETURN_IF_ABANDONED |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1954 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "internalDrawPath", fContext); |
| 1955 | |
Jim Van Verth | f86073a | 2018-10-02 13:05:38 -0400 | [diff] [blame] | 1956 | if (!viewMatrix.isFinite() || !originalShape.bounds().isFinite()) { |
| 1957 | return; |
| 1958 | } |
| 1959 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1960 | SkIRect clipConservativeBounds; |
| 1961 | clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr); |
| 1962 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1963 | GrShape tempShape; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1964 | auto aaTypeFlags = choose_path_aa_type_flags(aa, this->fsaaType(), *this->caps()); |
| 1965 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1966 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1967 | canDrawArgs.fCaps = this->caps(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1968 | canDrawArgs.fViewMatrix = &viewMatrix; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1969 | canDrawArgs.fShape = &originalShape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1970 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1971 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = this->wrapsVkSecondaryCB(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1972 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1973 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1974 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 1975 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1976 | if (originalShape.isEmpty() && !originalShape.inverseFilled()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1977 | return; |
| 1978 | } |
| 1979 | |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 1980 | canDrawArgs.fAATypeFlags = aaTypeFlags; |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1981 | |
| 1982 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
| 1983 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
| 1984 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 1985 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1986 | if (!pr && originalShape.style().pathEffect()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1987 | // 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] | 1988 | tempShape = originalShape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 1989 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1990 | return; |
| 1991 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1992 | canDrawArgs.fShape = &tempShape; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1993 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1994 | } |
| 1995 | if (!pr) { |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1996 | if (canDrawArgs.fShape->style().applies()) { |
| 1997 | tempShape = canDrawArgs.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, |
| 1998 | styleScale); |
| 1999 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2000 | return; |
| 2001 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2002 | canDrawArgs.fShape = &tempShape; |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 2003 | // This time, allow SW renderer |
| 2004 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
| 2005 | } else { |
| 2006 | pr = this->drawingManager()->getSoftwarePathRenderer(); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 2007 | } |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2008 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2009 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2010 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2011 | #ifdef SK_DEBUG |
| 2012 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 2013 | #endif |
| 2014 | return; |
| 2015 | } |
| 2016 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 2017 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2018 | std::move(paint), |
| 2019 | &GrUserStencilSettings::kUnused, |
| 2020 | this, |
| 2021 | &clip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2022 | &clipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2023 | &viewMatrix, |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2024 | canDrawArgs.fShape, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2025 | aaTypeFlags, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 2026 | this->colorSpaceInfo().isLinearlyBlended()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 2027 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2030 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 2031 | *bounds = op->bounds(); |
| 2032 | if (op->hasZeroArea()) { |
| 2033 | if (op->hasAABloat()) { |
| 2034 | bounds->outset(0.5f, 0.5f); |
| 2035 | } else { |
| 2036 | // We don't know which way the particular GPU will snap lines or points at integer |
| 2037 | // coords. So we ensure that the bounds is large enough for either snap. |
| 2038 | SkRect before = *bounds; |
| 2039 | bounds->roundOut(bounds); |
| 2040 | if (bounds->fLeft == before.fLeft) { |
| 2041 | bounds->fLeft -= 1; |
| 2042 | } |
| 2043 | if (bounds->fTop == before.fTop) { |
| 2044 | bounds->fTop -= 1; |
| 2045 | } |
| 2046 | if (bounds->fRight == before.fRight) { |
| 2047 | bounds->fRight += 1; |
| 2048 | } |
| 2049 | if (bounds->fBottom == before.fBottom) { |
| 2050 | bounds->fBottom += 1; |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2056 | void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op, |
| 2057 | const std::function<WillAddOpFn>& willAddFn) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2058 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 2059 | if (fContext->priv().abandoned()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2060 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2061 | return; |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 2062 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 2063 | SkDEBUGCODE(this->validate();) |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 2064 | SkDEBUGCODE(op->fAddDrawOpCalled = true;) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2065 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "addDrawOp", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 2066 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2067 | // Setup clip |
| 2068 | SkRect bounds; |
| 2069 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 2070 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2071 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
| 2072 | if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA, |
| 2073 | fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip, |
| 2074 | &bounds)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2075 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2076 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2077 | } |
| 2078 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2079 | if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil || |
| 2080 | appliedClip.hasStencilClip()) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 2081 | if (this->caps()->performStencilClearsAsDraws()) { |
| 2082 | // Must use an op to perform the clear of the stencil buffer before this op, but only |
| 2083 | // have to clear the first time any draw needs it (this also ensures we don't loop |
| 2084 | // forever when the internal stencil clear adds a draw op that has stencil settings). |
| 2085 | if (!fRenderTargetProxy->needsStencil()) { |
| 2086 | // Send false so that the stencil buffer is fully cleared to 0 |
| 2087 | this->internalStencilClear(GrFixedClip::Disabled(), /* inside mask */ false); |
| 2088 | } |
| 2089 | } else { |
| 2090 | // Just make sure the stencil buffer is cleared before the draw op, easy to do it as |
| 2091 | // a load at the start |
| 2092 | this->getRTOpList()->setStencilLoadOp(GrLoadOp::kClear); |
| 2093 | } |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 2094 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 2095 | this->setNeedsStencil(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2096 | } |
| 2097 | |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 2098 | GrClampType clampType = GrPixelConfigClampType(this->colorSpaceInfo().config()); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2099 | GrXferProcessor::DstProxy dstProxy; |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 2100 | GrProcessorSet::Analysis analysis = op->finalize( |
| 2101 | *this->caps(), &appliedClip, this->fsaaType(), clampType); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 2102 | if (analysis.requiresDstTexture()) { |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2103 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, *op, &dstProxy)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2104 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2105 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | op->setClippedBounds(bounds); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2110 | auto opList = this->getRTOpList(); |
| 2111 | if (willAddFn) { |
| 2112 | willAddFn(op.get(), opList->uniqueID()); |
| 2113 | } |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 2114 | opList->addDrawOp(std::move(op), analysis, std::move(appliedClip), dstProxy, *this->caps()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2115 | } |
| 2116 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2117 | bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2118 | const GrOp& op, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 2119 | GrXferProcessor::DstProxy* dstProxy) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2120 | // If we are wrapping a vulkan secondary command buffer, we can't make a dst copy because we |
| 2121 | // don't actually have a VkImage to make a copy of. Additionally we don't have the power to |
| 2122 | // start and stop the render pass in order to make the copy. |
| 2123 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 2124 | return false; |
| 2125 | } |
| 2126 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2127 | if (this->caps()->textureBarrierSupport()) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2128 | if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2129 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 2130 | // will be responsible to detect this situation and request a texture barrier. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2131 | dstProxy->setProxy(sk_ref_sp(texProxy)); |
| 2132 | dstProxy->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2133 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2137 | SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2138 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2139 | SkIRect clippedRect; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2140 | clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect); |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2141 | SkRect opBounds = op.bounds(); |
| 2142 | // If the op has aa bloating or is a infinitely thin geometry (hairline) outset the bounds by |
| 2143 | // 0.5 pixels. |
| 2144 | if (op.hasAABloat() || op.hasZeroArea()) { |
| 2145 | opBounds.outset(0.5f, 0.5f); |
| 2146 | // An antialiased/hairline draw can sometimes bleed outside of the clips bounds. For |
| 2147 | // performance we may ignore the clip when the draw is entirely inside the clip is float |
| 2148 | // space but will hit pixels just outside the clip when actually rasterizing. |
| 2149 | clippedRect.outset(1, 1); |
| 2150 | clippedRect.intersect(SkIRect::MakeWH(rtProxy->width(), rtProxy->height())); |
| 2151 | } |
| 2152 | SkIRect opIBounds; |
| 2153 | opBounds.roundOut(&opIBounds); |
| 2154 | if (!clippedRect.intersect(opIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2155 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2156 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2157 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2158 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 2162 | // have per-sample dst values by making the copy multisampled. |
| 2163 | GrSurfaceDesc desc; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2164 | bool rectsMustMatch = false; |
| 2165 | bool disallowSubrect = false; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2166 | GrSurfaceOrigin origin; |
| 2167 | if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &origin, &rectsMustMatch, |
| 2168 | &disallowSubrect)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2169 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2170 | desc.fConfig = rtProxy->config(); |
Greg Daniel | 1efe322 | 2018-04-04 14:02:51 -0400 | [diff] [blame] | 2171 | origin = rtProxy->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2172 | } |
| 2173 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2174 | if (!disallowSubrect) { |
| 2175 | copyRect = clippedRect; |
| 2176 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2177 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2178 | SkIPoint dstPoint, dstOffset; |
| 2179 | SkBackingFit fit; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2180 | if (rectsMustMatch) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2181 | desc.fWidth = rtProxy->width(); |
| 2182 | desc.fHeight = rtProxy->height(); |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2183 | dstPoint = {copyRect.fLeft, copyRect.fTop}; |
| 2184 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2185 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2186 | } else { |
| 2187 | desc.fWidth = copyRect.width(); |
| 2188 | desc.fHeight = copyRect.height(); |
| 2189 | dstPoint = {0, 0}; |
| 2190 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2191 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2192 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2193 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 2194 | SkASSERT(rtProxy->backendFormat().textureType() == GrTextureType::k2D); |
| 2195 | const GrBackendFormat& format = rtProxy->backendFormat(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2196 | sk_sp<GrSurfaceContext> sContext = fContext->priv().makeDeferredSurfaceContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 2197 | format, desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 2198 | sk_ref_sp(this->colorSpaceInfo().colorSpace())); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2199 | if (!sContext) { |
| 2200 | SkDebugf("setupDstTexture: surfaceContext creation failed.\n"); |
| 2201 | return false; |
| 2202 | } |
| 2203 | |
| 2204 | if (!sContext->copy(rtProxy, copyRect, dstPoint)) { |
| 2205 | SkDebugf("setupDstTexture: copy failed.\n"); |
| 2206 | return false; |
| 2207 | } |
| 2208 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2209 | dstProxy->setProxy(sContext->asTextureProxyRef()); |
| 2210 | dstProxy->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2211 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 2212 | } |