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