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