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 | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 19 | #include "GrOpList.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 20 | #include "GrPathRenderer.h" |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 21 | #include "GrQuad.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 22 | #include "GrRenderTarget.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 23 | #include "GrRenderTargetContextPriv.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 24 | #include "GrResourceProvider.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 25 | #include "GrShape.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 26 | #include "GrStencilAttachment.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 27 | #include "GrStyle.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 28 | #include "GrTracing.h" |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 29 | #include "SkDrawShadowInfo.h" |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 30 | #include "SkGlyphRun.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 31 | #include "SkGr.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 32 | #include "SkLatticeIter.h" |
| 33 | #include "SkMatrixPriv.h" |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 34 | #include "SkRRectPriv.h" |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 35 | #include "SkShadowUtils.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 36 | #include "SkSurfacePriv.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 37 | #include "effects/GrRRectEffect.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 38 | #include "ops/GrAtlasTextOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 39 | #include "ops/GrClearOp.h" |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 40 | #include "ops/GrClearStencilClipOp.h" |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 41 | #include "ops/GrDebugMarkerOp.h" |
Brian Salomon | 0f35332 | 2017-05-03 20:58:59 +0000 | [diff] [blame] | 42 | #include "ops/GrDrawAtlasOp.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 43 | #include "ops/GrDrawOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 44 | #include "ops/GrDrawVerticesOp.h" |
| 45 | #include "ops/GrLatticeOp.h" |
| 46 | #include "ops/GrOp.h" |
| 47 | #include "ops/GrOvalOpFactory.h" |
| 48 | #include "ops/GrRectOpFactory.h" |
| 49 | #include "ops/GrRegionOp.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 50 | #include "ops/GrSemaphoreOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 51 | #include "ops/GrShadowRRectOp.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 52 | #include "ops/GrStencilPathOp.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 53 | #include "ops/GrTextureOp.h" |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 54 | #include "text/GrTextContext.h" |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 55 | #include "text/GrTextTarget.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 56 | |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 57 | |
| 58 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 59 | class GrRenderTargetContext::TextTarget : public GrTextTarget { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 60 | public: |
| 61 | TextTarget(GrRenderTargetContext* renderTargetContext) |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 62 | : GrTextTarget(renderTargetContext->width(), renderTargetContext->height(), |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 63 | renderTargetContext->colorSpaceInfo()) |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 64 | , fRenderTargetContext(renderTargetContext) |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame^] | 65 | , fGlyphPainter{*renderTargetContext}{} |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 66 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 67 | void addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) override { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 68 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 69 | } |
| 70 | |
| 71 | void drawPath(const GrClip& clip, const SkPath& path, const SkPaint& paint, |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 72 | const SkMatrix& viewMatrix, bool pathIsMutable) override { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 73 | // TODO: we are losing the mutability of the path here |
| 74 | GrShape shape(path, paint); |
| 75 | |
| 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 | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 110 | #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } |
| 111 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } |
| 112 | #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } |
| 113 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return false; } |
| 114 | #define RETURN_NULL_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { 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 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 154 | bool GrRenderTargetContext::wasAbandoned() const { |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 155 | return this->drawingManager()->wasAbandoned(); |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 158 | // 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] | 159 | // 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] | 160 | // 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] | 161 | // when the renderTargetContext attempts to use it (via getOpList). |
| 162 | GrRenderTargetContext::GrRenderTargetContext(GrContext* context, |
| 163 | GrDrawingManager* drawingMgr, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 164 | sk_sp<GrRenderTargetProxy> rtp, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 165 | sk_sp<SkColorSpace> colorSpace, |
| 166 | const SkSurfaceProps* surfaceProps, |
| 167 | GrAuditTrail* auditTrail, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 168 | GrSingleOwner* singleOwner, |
| 169 | bool managedOpList) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 170 | : GrSurfaceContext(context, drawingMgr, rtp->config(), std::move(colorSpace), auditTrail, |
| 171 | singleOwner) |
| 172 | , fRenderTargetProxy(std::move(rtp)) |
| 173 | , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 174 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
| 175 | , fManagedOpList(managedOpList) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 176 | GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider(); |
| 177 | if (resourceProvider && !resourceProvider->explicitlyAllocateGPUResources()) { |
| 178 | // MDB TODO: to ensure all resources still get allocated in the correct order in the hybrid |
| 179 | // world we need to get the correct opList here so that it, in turn, can grab and hold |
| 180 | // its rendertarget. |
| 181 | this->getRTOpList(); |
| 182 | } |
| 183 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 184 | fTextTarget.reset(new TextTarget(this)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 185 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 186 | } |
| 187 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 188 | #ifdef SK_DEBUG |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 189 | void GrRenderTargetContext::validate() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 190 | SkASSERT(fRenderTargetProxy); |
| 191 | fRenderTargetProxy->validate(fContext); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 192 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 193 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 194 | SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 195 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 196 | } |
| 197 | #endif |
| 198 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 199 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 200 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 203 | GrTextureProxy* GrRenderTargetContext::asTextureProxy() { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 204 | return fRenderTargetProxy->asTextureProxy(); |
| 205 | } |
| 206 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 207 | const GrTextureProxy* GrRenderTargetContext::asTextureProxy() const { |
| 208 | return fRenderTargetProxy->asTextureProxy(); |
| 209 | } |
| 210 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 211 | sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() { |
| 212 | return sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 213 | } |
| 214 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 215 | GrMipMapped GrRenderTargetContext::mipMapped() const { |
| 216 | if (const GrTextureProxy* proxy = this->asTextureProxy()) { |
| 217 | return proxy->mipMapped(); |
| 218 | } |
| 219 | return GrMipMapped::kNo; |
| 220 | } |
| 221 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 222 | GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 223 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 224 | SkDEBUGCODE(this->validate();) |
| 225 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 226 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 227 | fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy.get(), fManagedOpList); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 230 | return fOpList.get(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 233 | GrOpList* GrRenderTargetContext::getOpList() { |
| 234 | return this->getRTOpList(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 237 | void GrRenderTargetContext::drawGlyphRunList( |
| 238 | const GrClip& clip, const SkMatrix& viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 239 | const SkGlyphRunList& blob) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 240 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 241 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 242 | SkDEBUGCODE(this->validate();) |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 243 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawGlyphRunList", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 244 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 245 | GrTextContext* atlasTextContext = this->drawingManager()->getTextContext(); |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 246 | atlasTextContext->drawGlyphRunList(fContext, fTextTarget.get(), clip, viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 247 | fSurfaceProps, blob); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 250 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 251 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 252 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 253 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 254 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "discard", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 255 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 256 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 257 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 258 | this->getRTOpList()->discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 261 | void GrRenderTargetContext::clear(const SkIRect* rect, |
| 262 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 263 | CanClearFullscreen canClearFullscreen) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 264 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 265 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 266 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 267 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "clear", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 268 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 269 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 270 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, |
| 271 | canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 272 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 273 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 274 | void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor color) { |
| 275 | ASSERT_SINGLE_OWNER_PRIV |
| 276 | RETURN_IF_ABANDONED_PRIV |
| 277 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 278 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "absClear", |
| 279 | fRenderTargetContext->fContext); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 280 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 281 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 282 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 283 | SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(), |
| 284 | fRenderTargetContext->fRenderTargetProxy->worstCaseHeight()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 285 | |
| 286 | if (clearRect) { |
| 287 | if (clearRect->contains(rtRect)) { |
| 288 | clearRect = nullptr; // full screen |
| 289 | } else { |
| 290 | if (!rtRect.intersect(*clearRect)) { |
| 291 | return; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // TODO: in a post-MDB world this should be handled at the OpList level. |
| 297 | // An op-list that is initially cleared and has no other ops should receive an |
| 298 | // extra draw. |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 299 | // This path doesn't handle coalescing of full screen clears b.c. it |
| 300 | // has to clear the entire render target - not just the content area. |
| 301 | // It could be done but will take more finagling. |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 302 | std::unique_ptr<GrOp> op(GrClearOp::Make(fRenderTargetContext->fContext, rtRect, |
| 303 | color, !clearRect)); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 304 | if (!op) { |
| 305 | return; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 306 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 307 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 310 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 311 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 312 | CanClearFullscreen canClearFullscreen) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 313 | ASSERT_SINGLE_OWNER_PRIV |
| 314 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 315 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 316 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clear", |
| 317 | fRenderTargetContext->fContext); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 318 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 319 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 320 | fRenderTargetContext->internalClear(clip, color, canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 323 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 324 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 325 | CanClearFullscreen canClearFullscreen) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 326 | bool isFull = false; |
| 327 | if (!clip.hasWindowRectangles()) { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 328 | isFull = !clip.scissorEnabled() || |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 329 | (CanClearFullscreen::kYes == canClearFullscreen && |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 330 | this->caps()->preferFullscreenClears()) || |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 331 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 332 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 333 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 334 | if (isFull) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 335 | this->getRTOpList()->fullClear(fContext, color); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 336 | } else { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 337 | std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip, color, this->asSurfaceProxy())); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 338 | if (!op) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 339 | return; |
| 340 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 341 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 342 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 345 | void GrRenderTargetContext::drawPaint(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 346 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 347 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 348 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 349 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 350 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 351 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPaint", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 352 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 353 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 354 | // don't overflow fixed-point implementations |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 355 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 356 | SkRect r = fRenderTargetProxy->getBoundsRect(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 357 | |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 358 | SkRRect rrect; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 359 | GrAA aa; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 360 | // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We only do the |
| 361 | // transformation for non-rect rrects. Rects caused a performance regression on an Android |
| 362 | // test that needs investigation. We also skip cases where there are fragment processors |
| 363 | // because they may depend on having correct local coords and this path draws in device space |
| 364 | // without a local matrix. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 365 | if (!paint.numTotalFragmentProcessors() && clip.isRRect(r, &rrect, &aa) && !rrect.isRect()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 366 | this->drawRRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect, |
| 367 | GrStyle::SimpleFill()); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 371 | |
| 372 | bool isPerspective = viewMatrix.hasPerspective(); |
| 373 | |
| 374 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 375 | // map the four corners and bound them with a new rect. This will not |
| 376 | // produce a correct result for some perspective matrices. |
| 377 | if (!isPerspective) { |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 378 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &r, r)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 379 | return; |
| 380 | } |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 381 | this->drawRect(clip, std::move(paint), GrAA::kNo, viewMatrix, r); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 382 | } else { |
| 383 | SkMatrix localMatrix; |
| 384 | if (!viewMatrix.invert(&localMatrix)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 385 | return; |
| 386 | } |
| 387 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 388 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 389 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 390 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 391 | fContext, std::move(paint), SkMatrix::I(), localMatrix, r, GrAAType::kNone); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 392 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 396 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 397 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 398 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 399 | } |
| 400 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 401 | // Attempts to crop a rect and optional local rect to the clip boundaries. |
| 402 | // Returns false if the draw can be skipped entirely. |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 403 | static bool crop_filled_rect(int width, int height, const GrClip& clip, |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 404 | const SkMatrix& viewMatrix, SkRect* rect, |
| 405 | SkRect* localRect = nullptr) { |
| 406 | if (!viewMatrix.rectStaysRect()) { |
| 407 | return true; |
| 408 | } |
| 409 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 410 | SkIRect clipDevBounds; |
| 411 | SkRect clipBounds; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 412 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 413 | clip.getConservativeBounds(width, height, &clipDevBounds); |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 414 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) { |
| 415 | return false; |
| 416 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 417 | |
| 418 | if (localRect) { |
| 419 | if (!rect->intersects(clipBounds)) { |
| 420 | return false; |
| 421 | } |
| 422 | const SkScalar dx = localRect->width() / rect->width(); |
| 423 | const SkScalar dy = localRect->height() / rect->height(); |
| 424 | if (clipBounds.fLeft > rect->fLeft) { |
| 425 | localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx; |
| 426 | rect->fLeft = clipBounds.fLeft; |
| 427 | } |
| 428 | if (clipBounds.fTop > rect->fTop) { |
| 429 | localRect->fTop += (clipBounds.fTop - rect->fTop) * dy; |
| 430 | rect->fTop = clipBounds.fTop; |
| 431 | } |
| 432 | if (clipBounds.fRight < rect->fRight) { |
| 433 | localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx; |
| 434 | rect->fRight = clipBounds.fRight; |
| 435 | } |
| 436 | if (clipBounds.fBottom < rect->fBottom) { |
| 437 | localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy; |
| 438 | rect->fBottom = clipBounds.fBottom; |
| 439 | } |
| 440 | return true; |
| 441 | } |
| 442 | |
| 443 | return rect->intersect(clipBounds); |
| 444 | } |
| 445 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 446 | bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 447 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 448 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 449 | const SkMatrix& viewMatrix, |
| 450 | const SkRect& rect, |
| 451 | const GrUserStencilSettings* ss) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 452 | SkRect croppedRect = rect; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 453 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 454 | return true; |
| 455 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 456 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 457 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 458 | std::unique_ptr<GrDrawOp> op; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 459 | if (GrAAType::kCoverage == aaType) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 460 | op = GrRectOpFactory::MakeAAFill(fContext, std::move(paint), viewMatrix, croppedRect, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 461 | } else { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 462 | op = GrRectOpFactory::MakeNonAAFill(fContext, std::move(paint), viewMatrix, croppedRect, |
| 463 | aaType, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 464 | } |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 465 | if (!op) { |
| 466 | return false; |
| 467 | } |
| 468 | this->addDrawOp(clip, std::move(op)); |
| 469 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 472 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 473 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 474 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 475 | const SkMatrix& viewMatrix, |
| 476 | const SkRect& rect, |
| 477 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 478 | if (!style) { |
| 479 | style = &GrStyle::SimpleFill(); |
| 480 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 481 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 482 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 483 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 484 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRect", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 485 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 486 | // Path effects should've been devolved to a path in SkGpuDevice |
| 487 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 488 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 489 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 490 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 491 | const SkStrokeRec& stroke = style->strokeRec(); |
Robert Phillips | c90b4db | 2018-04-23 15:12:00 +0000 | [diff] [blame] | 492 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && !paint.numCoverageFragmentProcessors()) { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 493 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother |
| 494 | // checking cases where the RT is fully inside a stroke. |
| 495 | SkRect rtRect = fRenderTargetProxy->getBoundsRect(); |
| 496 | // Does the clip contain the entire RT? |
| 497 | if (clip.quickContains(rtRect)) { |
| 498 | SkMatrix invM; |
| 499 | if (!viewMatrix.invert(&invM)) { |
| 500 | return; |
| 501 | } |
| 502 | // Does the rect bound the RT? |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 503 | GrQuad quad(rtRect, invM); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 504 | if (rect_contains_inclusive(rect, quad.point(0)) && |
| 505 | rect_contains_inclusive(rect, quad.point(1)) && |
| 506 | rect_contains_inclusive(rect, quad.point(2)) && |
| 507 | rect_contains_inclusive(rect, quad.point(3))) { |
| 508 | // Will it blend? |
| 509 | GrColor clearColor; |
| 510 | if (paint.isConstantBlendedColor(&clearColor)) { |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 511 | this->clear(nullptr, clearColor, |
| 512 | GrRenderTargetContext::CanClearFullscreen::kYes); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | } |
| 516 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 517 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 518 | if (this->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, nullptr)) { |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 519 | return; |
| 520 | } |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 521 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 522 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 523 | if ((!rect.width() || !rect.height()) && |
| 524 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 525 | SkScalar r = stroke.getWidth() / 2; |
| 526 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 527 | switch (stroke.getJoin()) { |
| 528 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 529 | this->drawRect( |
| 530 | clip, std::move(paint), aa, viewMatrix, |
| 531 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 532 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 533 | return; |
| 534 | case SkPaint::kRound_Join: |
| 535 | // Raster draws nothing when both dimensions are empty. |
| 536 | if (rect.width() || rect.height()){ |
| 537 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 538 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 539 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | case SkPaint::kBevel_Join: |
| 543 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 544 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 545 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 546 | &GrStyle::SimpleFill()); |
| 547 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 548 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 549 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 550 | &GrStyle::SimpleFill()); |
| 551 | } |
| 552 | return; |
| 553 | } |
| 554 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 555 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 556 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 557 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 558 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 559 | if (GrAAType::kCoverage == aaType) { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 560 | // The stroke path needs the rect to remain axis aligned (no rotation or skew). |
| 561 | if (viewMatrix.rectStaysRect()) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 562 | op = GrRectOpFactory::MakeAAStroke(fContext, std::move(paint), viewMatrix, rect, |
| 563 | stroke); |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 564 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 565 | } else { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 566 | op = GrRectOpFactory::MakeNonAAStroke(fContext, std::move(paint), viewMatrix, rect, |
| 567 | stroke, aaType); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 568 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 569 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 570 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 571 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 572 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 573 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 574 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 575 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(rect, *style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 578 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
| 579 | return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles( |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 580 | *fRenderTargetContext->caps()); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 581 | } |
| 582 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 583 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 584 | ASSERT_SINGLE_OWNER_PRIV |
| 585 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 586 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 587 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clearStencilClip", |
| 588 | fRenderTargetContext->fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 589 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 590 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 591 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 592 | GrRenderTargetProxy* rtProxy = fRenderTargetContext->fRenderTargetProxy.get(); |
| 593 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(fRenderTargetContext->fContext, |
| 594 | clip, insideStencilMask, rtProxy)); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 595 | if (!op) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 596 | return; |
| 597 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 598 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 601 | void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 602 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 603 | const SkMatrix& viewMatrix, |
| 604 | const GrPath* path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 605 | ASSERT_SINGLE_OWNER_PRIV |
| 606 | RETURN_IF_ABANDONED_PRIV |
| 607 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 608 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilPath", |
| 609 | fRenderTargetContext->fContext); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 610 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 611 | SkASSERT(aaType != GrAAType::kCoverage); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 612 | |
| 613 | bool useHWAA = GrAATypeIsHW(aaType); |
| 614 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 615 | SkASSERT(path); |
| 616 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 617 | |
| 618 | // FIXME: Use path bounds instead of this WAR once |
| 619 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 620 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 621 | |
| 622 | // Setup clip |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 623 | GrAppliedHardClip appliedClip; |
| 624 | if (!clip.apply(fRenderTargetContext->width(), fRenderTargetContext->height(), &appliedClip, |
| 625 | &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 626 | return; |
| 627 | } |
| 628 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 629 | fRenderTargetContext->setNeedsStencil(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 630 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 631 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(fRenderTargetContext->fContext, |
| 632 | viewMatrix, |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 633 | useHWAA, |
| 634 | path->getFillType(), |
| 635 | appliedClip.hasStencilClip(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 636 | appliedClip.scissorState(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 637 | path); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 638 | if (!op) { |
| 639 | return; |
| 640 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 641 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 642 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 645 | void GrRenderTargetContextPriv::stencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 646 | const GrUserStencilSettings* ss, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 647 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 648 | const SkMatrix& viewMatrix, |
| 649 | const SkRect& rect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 650 | ASSERT_SINGLE_OWNER_PRIV |
| 651 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 652 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 653 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilRect", |
| 654 | fRenderTargetContext->fContext); |
| 655 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 656 | SkASSERT(GrAAType::kCoverage != aaType); |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 657 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 658 | |
| 659 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 660 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 661 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFill(fRenderTargetContext->fContext, |
| 662 | std::move(paint), viewMatrix, |
| 663 | rect, aaType, ss); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 664 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 667 | bool GrRenderTargetContextPriv::drawAndStencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 668 | const GrUserStencilSettings* ss, |
| 669 | SkRegion::Op op, |
| 670 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 671 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 672 | const SkMatrix& viewMatrix, |
| 673 | const SkRect& rect) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 674 | ASSERT_SINGLE_OWNER_PRIV |
| 675 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 676 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 677 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilRect", |
| 678 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 679 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 680 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 681 | |
| 682 | GrPaint paint; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 683 | paint.setCoverageSetOpXPFactory(op, invert); |
| 684 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 685 | if (fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, ss)) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 686 | return true; |
| 687 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 688 | SkPath path; |
| 689 | path.setIsVolatile(true); |
| 690 | path.addRect(rect); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 691 | return this->drawAndStencilPath(clip, ss, op, invert, aa, viewMatrix, path); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 694 | void GrRenderTargetContext::fillRectToRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 695 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 696 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 697 | const SkMatrix& viewMatrix, |
| 698 | const SkRect& rectToDraw, |
| 699 | const SkRect& localRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 700 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 701 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 702 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 703 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectToRect", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 704 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 705 | SkRect croppedRect = rectToDraw; |
| 706 | SkRect croppedLocalRect = localRect; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 707 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, |
| 708 | &croppedRect, &croppedLocalRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 709 | return; |
| 710 | } |
| 711 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 712 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 713 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 714 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 715 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 716 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalRect( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 717 | fContext, std::move(paint), viewMatrix, croppedRect, croppedLocalRect, aaType); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 718 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 719 | return; |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 720 | } |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 721 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 722 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalRect( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 723 | fContext, std::move(paint), viewMatrix, croppedRect, croppedLocalRect); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 724 | if (op) { |
| 725 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 726 | return; |
| 727 | } |
| 728 | |
| 729 | SkMatrix viewAndUnLocalMatrix; |
| 730 | if (!viewAndUnLocalMatrix.setRectToRect(localRect, rectToDraw, SkMatrix::kFill_ScaleToFit)) { |
| 731 | SkDebugf("fillRectToRect called with empty local matrix.\n"); |
| 732 | return; |
| 733 | } |
| 734 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 735 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 736 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewAndUnLocalMatrix, |
| 737 | GrShape(localRect)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 740 | static bool must_filter(const SkRect& src, const SkRect& dst, const SkMatrix& ctm) { |
| 741 | // We don't currently look for 90 degree rotations, mirroring, or downscales that sample at |
| 742 | // texel centers. |
| 743 | if (!ctm.isTranslate()) { |
| 744 | return true; |
| 745 | } |
| 746 | if (src.width() != dst.width() || src.height() != dst.height()) { |
| 747 | return true; |
| 748 | } |
| 749 | // Check that the device space rectangle's fractional offset is the same as the src rectangle, |
| 750 | // and that therefore integers in the src image fall on integers in device space. |
| 751 | SkScalar x = ctm.getTranslateX(), y = ctm.getTranslateY(); |
| 752 | x += dst.fLeft; y += dst.fTop; |
| 753 | x -= src.fLeft; y -= src.fTop; |
| 754 | return !SkScalarIsInt(x) || !SkScalarIsInt(y); |
| 755 | } |
| 756 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 757 | void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
| 758 | GrSamplerState::Filter filter, GrColor color, |
| 759 | const SkRect& srcRect, const SkRect& dstRect, GrAA aa, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 760 | SkCanvas::SrcRectConstraint constraint, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 761 | const SkMatrix& viewMatrix, |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 762 | sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 763 | sk_sp<GrColorSpaceXform> paintColorSpaceXform) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 764 | ASSERT_SINGLE_OWNER |
| 765 | RETURN_IF_ABANDONED |
| 766 | SkDEBUGCODE(this->validate();) |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 767 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexture", fContext); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 768 | if (filter != GrSamplerState::Filter::kNearest && !must_filter(srcRect, dstRect, viewMatrix)) { |
| 769 | filter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 770 | } |
Brian Salomon | d8eb7b6 | 2018-05-25 10:08:05 -0400 | [diff] [blame] | 771 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
| 772 | if (constraint == SkCanvas::kStrict_SrcRectConstraint) { |
| 773 | // No need to use a texture domain with nearest filtering unless there is AA bloating. |
| 774 | // Also, no need if the srcRect contains the entire texture. |
| 775 | if (filter == GrSamplerState::Filter::kNearest && aaType != GrAAType::kCoverage) { |
| 776 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 777 | } else if (srcRect.contains(proxy->getWorstCaseBoundsRect())) { |
| 778 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 779 | } |
| 780 | } |
Brian Salomon | ff9d6d3 | 2017-08-30 10:27:49 -0400 | [diff] [blame] | 781 | SkRect clippedDstRect = dstRect; |
| 782 | SkRect clippedSrcRect = srcRect; |
| 783 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect, |
| 784 | &clippedSrcRect)) { |
| 785 | return; |
| 786 | } |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 787 | this->addDrawOp(clip, GrTextureOp::Make(fContext, std::move(proxy), filter, color, |
| 788 | clippedSrcRect, clippedDstRect, aaType, constraint, |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 789 | viewMatrix, std::move(textureColorSpaceXform), |
| 790 | std::move(paintColorSpaceXform))); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 791 | } |
| 792 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 793 | void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 794 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 795 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 796 | const SkMatrix& viewMatrix, |
| 797 | const SkRect& rectToDraw, |
| 798 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 799 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 800 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 801 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 802 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithLocalMatrix", fContext); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 803 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 804 | SkRect croppedRect = rectToDraw; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 805 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 809 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 810 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 811 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 812 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 813 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 814 | fContext, std::move(paint), viewMatrix, localMatrix, croppedRect, aaType); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 815 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 816 | return; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 817 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 818 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 819 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalMatrix( |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 820 | fContext, std::move(paint), viewMatrix, localMatrix, croppedRect); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 821 | if (op) { |
| 822 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | |
| 826 | SkMatrix viewAndUnLocalMatrix; |
| 827 | if (!localMatrix.invert(&viewAndUnLocalMatrix)) { |
| 828 | SkDebugf("fillRectWithLocalMatrix called with degenerate local matrix.\n"); |
| 829 | return; |
| 830 | } |
| 831 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 832 | |
| 833 | SkPath path; |
| 834 | path.setIsVolatile(true); |
| 835 | path.addRect(rectToDraw); |
| 836 | path.transform(localMatrix); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 837 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewAndUnLocalMatrix, |
| 838 | GrShape(path)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 841 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 842 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 843 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 844 | sk_sp<SkVertices> vertices, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 845 | const SkVertices::Bone bones[], |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 846 | int boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 847 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 848 | ASSERT_SINGLE_OWNER |
| 849 | RETURN_IF_ABANDONED |
| 850 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 851 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawVertices", fContext); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 852 | |
| 853 | AutoCheckFlush acf(this->drawingManager()); |
| 854 | |
| 855 | SkASSERT(vertices); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 856 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 857 | std::unique_ptr<GrDrawOp> op = GrDrawVerticesOp::Make( |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 858 | fContext, std::move(paint), std::move(vertices), bones, boneCount, viewMatrix, aaType, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 859 | this->colorSpaceInfo().refColorSpaceXformFromSRGB(), overridePrimType); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 860 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | /////////////////////////////////////////////////////////////////////////////// |
| 864 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 865 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 866 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 867 | const SkMatrix& viewMatrix, |
| 868 | int spriteCount, |
| 869 | const SkRSXform xform[], |
| 870 | const SkRect texRect[], |
| 871 | const SkColor colors[]) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 872 | ASSERT_SINGLE_OWNER |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 873 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 874 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 875 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawAtlas", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 876 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 877 | AutoCheckFlush acf(this->drawingManager()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 878 | |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 879 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 880 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(fContext, std::move(paint), viewMatrix, |
| 881 | aaType, spriteCount, xform, texRect, colors); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 882 | this->addDrawOp(clip, std::move(op)); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /////////////////////////////////////////////////////////////////////////////// |
| 886 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 887 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 888 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 889 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 890 | const SkMatrix& viewMatrix, |
| 891 | const SkRRect& rrect, |
| 892 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 893 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 894 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 895 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 896 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRRect", fContext); |
Robert Phillips | 8529080 | 2018-07-02 13:14:28 -0400 | [diff] [blame] | 897 | |
| 898 | const SkStrokeRec& stroke = style.strokeRec(); |
| 899 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 903 | GrNoClip noclip; |
| 904 | const GrClip* clip = &origClip; |
| 905 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 906 | // 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] | 907 | // 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] | 908 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 909 | // attempts to mitigate the stencil clip cost but will only help when the entire clip stack |
| 910 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. |
| 911 | SkRRect devRRect; |
| 912 | if (rrect.transform(viewMatrix, &devRRect) && clip->quickContains(devRRect)) { |
| 913 | clip = &noclip; |
| 914 | } |
| 915 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 916 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 917 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 918 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 919 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 920 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 921 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 922 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 923 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeRRectOp(fContext, |
| 924 | std::move(paint), |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 925 | viewMatrix, |
| 926 | rrect, |
| 927 | stroke, |
| 928 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 929 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 930 | this->addDrawOp(*clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 931 | return; |
| 932 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 933 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 934 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 935 | this->drawShapeUsingPathRenderer(*clip, std::move(paint), aa, viewMatrix, |
| 936 | GrShape(rrect, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 939 | /////////////////////////////////////////////////////////////////////////////// |
| 940 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 941 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 942 | SkPoint3 result; |
| 943 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 944 | result.fZ = pt.fZ; |
| 945 | return result; |
| 946 | } |
| 947 | |
| 948 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 949 | const SkMatrix& viewMatrix, |
| 950 | const SkPath& path, |
| 951 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 952 | ASSERT_SINGLE_OWNER |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 953 | if (this->drawingManager()->wasAbandoned()) { |
| 954 | return true; |
| 955 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 956 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 957 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFastShadow", fContext); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 958 | |
| 959 | // check z plane |
| 960 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 961 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 962 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 963 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 964 | return false; |
| 965 | } |
| 966 | |
| 967 | SkRRect rrect; |
| 968 | SkRect rect; |
| 969 | // we can only handle rects, circles, and rrects with circular corners |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 970 | bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsSimpleCircular(rrect) && |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 971 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 972 | if (!isRRect && |
| 973 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 974 | rect.width() > SK_ScalarNearlyZero) { |
| 975 | rrect.setOval(rect); |
| 976 | isRRect = true; |
| 977 | } |
| 978 | if (!isRRect && path.isRect(&rect)) { |
| 979 | rrect.setRect(rect); |
| 980 | isRRect = true; |
| 981 | } |
| 982 | |
| 983 | if (!isRRect) { |
| 984 | return false; |
| 985 | } |
| 986 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 987 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 988 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 989 | } |
| 990 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 991 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 992 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 993 | // transform light |
| 994 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 995 | |
| 996 | // 1/scale |
| 997 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
| 998 | SkScalarInvert(viewMatrix[SkMatrix::kMScaleX]) : |
| 999 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 1000 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1001 | |
| 1002 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1003 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
| 1004 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1005 | if (SkColorGetA(rec.fAmbientColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1006 | SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight); |
| 1007 | const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight); |
| 1008 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1009 | |
| 1010 | // Outset the shadow rrect to the border of the penumbra |
| 1011 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1012 | SkRRect ambientRRect; |
| 1013 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1014 | // If the rrect was an oval then its outset will also be one. |
| 1015 | // We set it explicitly to avoid errors. |
| 1016 | if (rrect.isOval()) { |
| 1017 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1018 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1019 | SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1020 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1021 | } |
| 1022 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1023 | GrColor ambientColor = SkColorToPremulGrColor(rec.fAmbientColor); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1024 | if (transparent) { |
| 1025 | // set a large inset to force a fill |
| 1026 | devSpaceInsetWidth = ambientRRect.width(); |
| 1027 | } |
Jim Van Verth | 39e7165 | 2018-04-23 18:08:45 +0000 | [diff] [blame] | 1028 | // the fraction of the blur we want to apply is devSpaceInsetWidth/devSpaceAmbientBlur, |
| 1029 | // which is just 1/umbraRecipAlpha. |
| 1030 | SkScalar blurClamp = SkScalarInvert(umbraRecipAlpha); |
| 1031 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1032 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1033 | ambientColor, |
| 1034 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1035 | ambientRRect, |
| 1036 | devSpaceAmbientBlur, |
Jim Van Verth | 39e7165 | 2018-04-23 18:08:45 +0000 | [diff] [blame] | 1037 | devSpaceInsetWidth, |
| 1038 | blurClamp); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1039 | SkASSERT(op); |
| 1040 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1041 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1042 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1043 | if (SkColorGetA(rec.fSpotColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1044 | SkScalar devSpaceSpotBlur; |
| 1045 | SkScalar spotScale; |
| 1046 | SkVector spotOffset; |
| 1047 | SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY, |
| 1048 | devLightPos.fZ, rec.fLightRadius, |
| 1049 | &devSpaceSpotBlur, &spotScale, &spotOffset); |
| 1050 | // handle scale of radius due to CTM |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1051 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1052 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1053 | // Adjust translate for the effect of the scale. |
| 1054 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1055 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1056 | // This offset is in dev space, need to transform it into source space. |
| 1057 | SkMatrix ctmInverse; |
| 1058 | if (viewMatrix.invert(&ctmInverse)) { |
| 1059 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1060 | } else { |
| 1061 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1062 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1063 | SkASSERT(false); |
| 1064 | } |
| 1065 | |
| 1066 | // Compute the transformed shadow rrect |
| 1067 | SkRRect spotShadowRRect; |
| 1068 | SkMatrix shadowTransform; |
| 1069 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1070 | rrect.transform(shadowTransform, &spotShadowRRect); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1071 | SkScalar spotRadius = SkRRectPriv::GetSimpleRadii(spotShadowRRect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1072 | |
| 1073 | // Compute the insetWidth |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1074 | SkScalar blurOutset = srcSpaceSpotBlur; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1075 | SkScalar insetWidth = blurOutset; |
| 1076 | if (transparent) { |
| 1077 | // If transparent, just do a fill |
| 1078 | insetWidth += spotShadowRRect.width(); |
| 1079 | } else { |
| 1080 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1081 | // border. We want to extend this inset area so that it meets up with the caster |
| 1082 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1083 | // |
| 1084 | // We compare the min and max corners inset by the radius between the original |
| 1085 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1086 | // between the scaled radius and the original radius gives the distance from the |
| 1087 | // transformed shadow shape to the original shape in that corner. The max |
| 1088 | // of these gives the maximum distance we need to cover. |
| 1089 | // |
| 1090 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1091 | // that to get the full insetWidth. |
| 1092 | SkScalar maxOffset; |
| 1093 | if (rrect.isRect()) { |
| 1094 | // Manhattan distance works better for rects |
| 1095 | maxOffset = SkTMax(SkTMax(SkTAbs(spotShadowRRect.rect().fLeft - |
| 1096 | rrect.rect().fLeft), |
| 1097 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1098 | rrect.rect().fTop)), |
| 1099 | SkTMax(SkTAbs(spotShadowRRect.rect().fRight - |
| 1100 | rrect.rect().fRight), |
| 1101 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1102 | rrect.rect().fBottom))); |
| 1103 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1104 | SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1105 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1106 | rrect.rect().fLeft + dr, |
| 1107 | spotShadowRRect.rect().fTop - |
| 1108 | rrect.rect().fTop + dr); |
| 1109 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1110 | rrect.rect().fRight - dr, |
| 1111 | spotShadowRRect.rect().fBottom - |
| 1112 | rrect.rect().fBottom - dr); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 1113 | maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset), |
| 1114 | SkPointPriv::LengthSqd(lowerRightOffset))) + dr; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1115 | } |
Jim Van Verth | 4c8c1e8 | 2018-04-23 17:14:48 -0400 | [diff] [blame] | 1116 | insetWidth += SkTMax(blurOutset, maxOffset); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | // Outset the shadow rrect to the border of the penumbra |
| 1120 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1121 | if (spotShadowRRect.isOval()) { |
| 1122 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1123 | } else { |
| 1124 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1125 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1126 | } |
| 1127 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1128 | GrColor spotColor = SkColorToPremulGrColor(rec.fSpotColor); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1129 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1130 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1131 | spotColor, |
| 1132 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1133 | spotShadowRRect, |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1134 | 2.0f * devSpaceSpotBlur, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1135 | insetWidth); |
| 1136 | SkASSERT(op); |
| 1137 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /////////////////////////////////////////////////////////////////////////////// |
| 1144 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1145 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1146 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1147 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1148 | const SkMatrix& viewMatrix, |
| 1149 | const SkRRect& origOuter, |
| 1150 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1151 | SkASSERT(!origInner.isEmpty()); |
| 1152 | SkASSERT(!origOuter.isEmpty()); |
| 1153 | |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1154 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1155 | |
Brian Salomon | 45839f9 | 2017-12-04 09:02:35 -0500 | [diff] [blame] | 1156 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
| 1157 | |
| 1158 | if (GrAAType::kMSAA == aaType) { |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1162 | if (GrAAType::kCoverage == aaType && SkRRectPriv::IsCircle(*inner) |
| 1163 | && SkRRectPriv::IsCircle(*outer)) { |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1164 | auto outerR = outer->width() / 2.f; |
| 1165 | auto innerR = inner->width() / 2.f; |
| 1166 | auto cx = outer->getBounds().fLeft + outerR; |
| 1167 | auto cy = outer->getBounds().fTop + outerR; |
| 1168 | if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && |
| 1169 | SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { |
| 1170 | auto avgR = (innerR + outerR) / 2.f; |
| 1171 | auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); |
| 1172 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1173 | stroke.setStrokeStyle(outerR - innerR); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1174 | auto op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, |
| 1175 | circleBounds, GrStyle(stroke, nullptr), |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1176 | this->caps()->shaderCaps()); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1177 | if (op) { |
| 1178 | this->addDrawOp(clip, std::move(op)); |
| 1179 | return true; |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 1184 | GrClipEdgeType innerEdgeType, outerEdgeType; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1185 | if (GrAAType::kCoverage == aaType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1186 | innerEdgeType = GrClipEdgeType::kInverseFillAA; |
| 1187 | outerEdgeType = GrClipEdgeType::kFillAA; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1188 | } else { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1189 | innerEdgeType = GrClipEdgeType::kInverseFillBW; |
| 1190 | outerEdgeType = GrClipEdgeType::kFillBW; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1191 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1192 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1193 | SkMatrix inverseVM; |
| 1194 | if (!viewMatrix.isIdentity()) { |
| 1195 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1196 | return false; |
| 1197 | } |
| 1198 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1199 | return false; |
| 1200 | } |
| 1201 | if (!viewMatrix.invert(&inverseVM)) { |
| 1202 | return false; |
| 1203 | } |
| 1204 | } else { |
| 1205 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1206 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1207 | |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1208 | const auto& caps = *this->caps()->shaderCaps(); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1209 | // TODO these need to be a geometry processors |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1210 | auto innerEffect = GrRRectEffect::Make(innerEdgeType, *inner, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1211 | if (!innerEffect) { |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1215 | auto outerEffect = GrRRectEffect::Make(outerEdgeType, *outer, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1216 | if (!outerEffect) { |
| 1217 | return false; |
| 1218 | } |
| 1219 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1220 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1221 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1222 | |
| 1223 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1224 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1225 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1226 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1227 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1228 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1229 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1230 | return true; |
| 1231 | } |
| 1232 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1233 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1234 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1235 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1236 | const SkMatrix& viewMatrix, |
| 1237 | const SkRRect& outer, |
| 1238 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1239 | ASSERT_SINGLE_OWNER |
| 1240 | RETURN_IF_ABANDONED |
| 1241 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1242 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawDRRect", fContext); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1243 | |
| 1244 | SkASSERT(!outer.isEmpty()); |
| 1245 | SkASSERT(!inner.isEmpty()); |
| 1246 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1247 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1248 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1249 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | SkPath path; |
| 1254 | path.setIsVolatile(true); |
| 1255 | path.addRRect(inner); |
| 1256 | path.addRRect(outer); |
| 1257 | path.setFillType(SkPath::kEvenOdd_FillType); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1258 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(path)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1261 | /////////////////////////////////////////////////////////////////////////////// |
| 1262 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1263 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1264 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1265 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1266 | const SkMatrix& viewMatrix, |
| 1267 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1268 | const GrStyle& style, |
| 1269 | const GrUserStencilSettings* ss) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1270 | ASSERT_SINGLE_OWNER |
| 1271 | RETURN_IF_ABANDONED |
| 1272 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1273 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRegion", fContext); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1274 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1275 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1276 | // 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] | 1277 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1278 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1279 | SkScalarIsInt(viewMatrix.getTranslateX()) && |
| 1280 | SkScalarIsInt(viewMatrix.getTranslateY())) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1281 | aa = GrAA::kNo; |
| 1282 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1283 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1284 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1285 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1286 | SkPath path; |
| 1287 | region.getBoundaryPath(&path); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1288 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1291 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1292 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(fContext, std::move(paint), viewMatrix, region, |
| 1293 | aaType, ss); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1294 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1297 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1298 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1299 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1300 | const SkMatrix& viewMatrix, |
| 1301 | const SkRect& oval, |
| 1302 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1303 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1304 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1305 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1306 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawOval", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1307 | |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1308 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1309 | |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1310 | if (oval.isEmpty() && !style.pathEffect()) { |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1311 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | this->drawRect(clip, std::move(paint), aa, viewMatrix, oval, &style); |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1316 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1319 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1320 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1321 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1322 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1323 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1324 | if (auto op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, oval, |
| 1325 | style, shaderCaps)) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1326 | this->addDrawOp(clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1327 | return; |
| 1328 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1329 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1330 | |
Brian Salomon | 5209d7f | 2018-04-20 16:52:42 -0400 | [diff] [blame] | 1331 | this->drawShapeUsingPathRenderer( |
| 1332 | clip, std::move(paint), aa, viewMatrix, |
| 1333 | GrShape(SkRRect::MakeOval(oval), SkPath::kCW_Direction, 2, false, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1336 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1337 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1338 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1339 | const SkMatrix& viewMatrix, |
| 1340 | const SkRect& oval, |
| 1341 | SkScalar startAngle, |
| 1342 | SkScalar sweepAngle, |
| 1343 | bool useCenter, |
| 1344 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1345 | ASSERT_SINGLE_OWNER |
| 1346 | RETURN_IF_ABANDONED |
| 1347 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1348 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawArc", fContext); |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1349 | |
| 1350 | AutoCheckFlush acf(this->drawingManager()); |
| 1351 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1352 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1353 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1354 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1355 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(fContext, |
| 1356 | std::move(paint), |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1357 | viewMatrix, |
| 1358 | oval, |
| 1359 | startAngle, |
| 1360 | sweepAngle, |
| 1361 | useCenter, |
| 1362 | style, |
| 1363 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1364 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1365 | this->addDrawOp(clip, std::move(op)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | } |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 1369 | this->drawShapeUsingPathRenderer( |
| 1370 | clip, std::move(paint), aa, viewMatrix, |
| 1371 | GrShape::MakeArc(oval, startAngle, sweepAngle, useCenter, style)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1374 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1375 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1376 | const SkMatrix& viewMatrix, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1377 | sk_sp<GrTextureProxy> image, |
| 1378 | sk_sp<GrColorSpaceXform> csxf, |
| 1379 | GrSamplerState::Filter filter, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1380 | std::unique_ptr<SkLatticeIter> iter, |
| 1381 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1382 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1383 | RETURN_IF_ABANDONED |
| 1384 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1385 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawImageLattice", fContext); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1386 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1387 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1388 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1389 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1390 | GrLatticeOp::MakeNonAA(fContext, std::move(paint), viewMatrix, std::move(image), |
| 1391 | std::move(csxf), filter, std::move(iter), dst); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1392 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1395 | GrSemaphoresSubmitted GrRenderTargetContext::prepareForExternalIO( |
| 1396 | int numSemaphores, GrBackendSemaphore backendSemaphores[]) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1397 | ASSERT_SINGLE_OWNER |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1398 | if (this->drawingManager()->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; } |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1399 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1400 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "prepareForExternalIO", fContext); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1401 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1402 | return this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get(), |
| 1403 | numSemaphores, |
| 1404 | backendSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1407 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1408 | const GrBackendSemaphore* waitSemaphores) { |
| 1409 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1410 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1411 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1412 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "waitOnSemaphores", fContext); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1413 | |
| 1414 | AutoCheckFlush acf(this->drawingManager()); |
| 1415 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1416 | if (numSemaphores && !this->caps()->fenceSyncSupport()) { |
| 1417 | return false; |
| 1418 | } |
| 1419 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1420 | auto resourceProvider = fContext->contextPriv().resourceProvider(); |
| 1421 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1422 | SkTArray<sk_sp<GrSemaphore>> semaphores(numSemaphores); |
| 1423 | for (int i = 0; i < numSemaphores; ++i) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1424 | sk_sp<GrSemaphore> sema = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 1425 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 1426 | kAdopt_GrWrapOwnership); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1427 | std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(fContext, sema, |
| 1428 | fRenderTargetProxy.get())); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1429 | this->getRTOpList()->addOp(std::move(waitOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1430 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1431 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1432 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1433 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1434 | void GrRenderTargetContext::insertEventMarker(const SkString& str) { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 1435 | std::unique_ptr<GrOp> op(GrDebugMarkerOp::Make(fContext, fRenderTargetProxy.get(), str)); |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1436 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1437 | } |
| 1438 | |
| 1439 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1440 | // Can 'path' be drawn as a pair of filled nested rectangles? |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1441 | static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path, SkRect rects[2]) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1442 | |
| 1443 | if (path.isInverseFillType()) { |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | // TODO: this restriction could be lifted if we were willing to apply |
| 1448 | // the matrix to all the points individually rather than just to the rect |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 1449 | if (!viewMatrix.rectStaysRect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | |
| 1453 | SkPath::Direction dirs[2]; |
| 1454 | if (!path.isNestedFillRects(rects, dirs)) { |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
| 1458 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 1459 | // The two rects need to be wound opposite to each other |
| 1460 | return false; |
| 1461 | } |
| 1462 | |
| 1463 | // Right now, nested rects where the margin is not the same width |
| 1464 | // all around do not render correctly |
| 1465 | const SkScalar* outer = rects[0].asScalars(); |
| 1466 | const SkScalar* inner = rects[1].asScalars(); |
| 1467 | |
| 1468 | bool allEq = true; |
| 1469 | |
| 1470 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 1471 | bool allGoE1 = margin >= SK_Scalar1; |
| 1472 | |
| 1473 | for (int i = 1; i < 4; ++i) { |
| 1474 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 1475 | if (temp < SK_Scalar1) { |
| 1476 | allGoE1 = false; |
| 1477 | } |
| 1478 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 1479 | allEq = false; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | return allEq || allGoE1; |
| 1484 | } |
| 1485 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1486 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1487 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1488 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1489 | const SkMatrix& viewMatrix, |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1490 | const SkPath& path, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1491 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1492 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1493 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1494 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1495 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPath", fContext); |
| 1496 | |
| 1497 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
| 1498 | if (GrAAType::kCoverage == aaType) { |
| 1499 | // TODO: Make GrShape check for nested rects. |
| 1500 | SkRect rects[2]; |
| 1501 | if (style.isSimpleFill() && fills_as_nested_rects(viewMatrix, path, rects)) { |
| 1502 | // Concave AA paths are expensive - try to avoid them for special cases |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 1503 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillNestedRects( |
| 1504 | fContext, std::move(paint), viewMatrix, rects); |
| 1505 | if (op) { |
| 1506 | this->addDrawOp(clip, std::move(op)); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1507 | } |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 1508 | // Returning here indicates that there is nothing to draw in this case. |
| 1509 | return; |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1510 | } |
| 1511 | } |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1512 | |
| 1513 | GrShape shape(path, style); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1514 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 1515 | this->drawShape(clip, std::move(paint), aa, viewMatrix, shape); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | void GrRenderTargetContext::drawShape(const GrClip& clip, |
| 1519 | GrPaint&& paint, |
| 1520 | GrAA aa, |
| 1521 | const SkMatrix& viewMatrix, |
| 1522 | const GrShape& shape) { |
| 1523 | ASSERT_SINGLE_OWNER |
| 1524 | RETURN_IF_ABANDONED |
| 1525 | SkDEBUGCODE(this->validate();) |
| 1526 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawShape", fContext); |
| 1527 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1528 | if (shape.isEmpty()) { |
| 1529 | if (shape.inverseFilled()) { |
| 1530 | this->drawPaint(clip, std::move(paint), viewMatrix); |
| 1531 | } |
| 1532 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1535 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1536 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1537 | if (!shape.style().hasPathEffect()) { |
| 1538 | SkRRect rrect; |
| 1539 | // We can ignore the starting point and direction since there is no path effect. |
| 1540 | bool inverted; |
| 1541 | if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) { |
| 1542 | if (rrect.isRect()) { |
| 1543 | this->drawRect(clip, std::move(paint), aa, viewMatrix, rrect.rect(), |
| 1544 | &shape.style()); |
| 1545 | return; |
| 1546 | } else if (rrect.isOval()) { |
| 1547 | this->drawOval(clip, std::move(paint), aa, viewMatrix, rrect.rect(), shape.style()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1548 | return; |
| 1549 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1550 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, shape.style()); |
| 1551 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1552 | } |
| 1553 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1554 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1555 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, shape); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 1558 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1559 | const GrUserStencilSettings* ss, |
| 1560 | SkRegion::Op op, |
| 1561 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1562 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1563 | const SkMatrix& viewMatrix, |
| 1564 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1565 | ASSERT_SINGLE_OWNER_PRIV |
| 1566 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1567 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1568 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilPath", |
| 1569 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1570 | |
| 1571 | if (path.isEmpty() && path.isInverseFillType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1572 | this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1573 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 1574 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1575 | return true; |
| 1576 | } |
| 1577 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1578 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1579 | |
| 1580 | // An Assumption here is that path renderer would use some form of tweaking |
| 1581 | // the src color (either the input alpha or in the frag shader) to implement |
| 1582 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1583 | // 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] | 1584 | GrAAType aaType = fRenderTargetContext->chooseAAType(aa, GrAllowMixedSamples::kNo); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1585 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1586 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1587 | SkIRect clipConservativeBounds; |
| 1588 | clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 1589 | &clipConservativeBounds, nullptr); |
| 1590 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1591 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1592 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1593 | canDrawArgs.fCaps = fRenderTargetContext->caps(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1594 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1595 | canDrawArgs.fShape = &shape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1596 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1597 | canDrawArgs.fAAType = aaType; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1598 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1599 | |
| 1600 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1601 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 1602 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1603 | if (!pr) { |
| 1604 | return false; |
| 1605 | } |
| 1606 | |
| 1607 | GrPaint paint; |
| 1608 | paint.setCoverageSetOpXPFactory(op, invert); |
| 1609 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1610 | GrPathRenderer::DrawPathArgs args{fRenderTargetContext->drawingManager()->getContext(), |
| 1611 | std::move(paint), |
| 1612 | ss, |
| 1613 | fRenderTargetContext, |
| 1614 | &clip, |
| 1615 | &clipConservativeBounds, |
| 1616 | &viewMatrix, |
| 1617 | &shape, |
| 1618 | aaType, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 1619 | fRenderTargetContext->colorSpaceInfo().isLinearlyBlended()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1620 | pr->drawPath(args); |
| 1621 | return true; |
| 1622 | } |
| 1623 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1624 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1625 | ASSERT_SINGLE_OWNER_PRIV |
| 1626 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1627 | if (fRenderTargetContext->wasAbandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1628 | return SkBudgeted::kNo; |
| 1629 | } |
| 1630 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1631 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1632 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 1633 | return fRenderTargetContext->fRenderTargetProxy->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1636 | void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, |
| 1637 | GrPaint&& paint, |
| 1638 | GrAA aa, |
| 1639 | const SkMatrix& viewMatrix, |
| 1640 | const GrShape& originalShape) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1641 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1642 | RETURN_IF_ABANDONED |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1643 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "internalDrawPath", fContext); |
| 1644 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1645 | SkIRect clipConservativeBounds; |
| 1646 | clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr); |
| 1647 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1648 | GrShape tempShape; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1649 | // NVPR cannot handle hairlines, so this would get picked up by a different stencil and |
| 1650 | // cover path renderer (i.e. default path renderer). The hairline renderer produces much |
| 1651 | // smoother hairlines than MSAA. |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1652 | GrAllowMixedSamples allowMixedSamples = originalShape.style().isSimpleHairline() |
| 1653 | ? GrAllowMixedSamples::kNo |
| 1654 | : GrAllowMixedSamples::kYes; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1655 | GrAAType aaType = this->chooseAAType(aa, allowMixedSamples); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1656 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1657 | canDrawArgs.fCaps = this->caps(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1658 | canDrawArgs.fViewMatrix = &viewMatrix; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1659 | canDrawArgs.fShape = &originalShape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1660 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1661 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1662 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1663 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 1664 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1665 | if (originalShape.isEmpty() && !originalShape.inverseFilled()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1666 | return; |
| 1667 | } |
| 1668 | |
| 1669 | canDrawArgs.fAAType = aaType; |
| 1670 | |
| 1671 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
| 1672 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
| 1673 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 1674 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1675 | if (!pr && originalShape.style().pathEffect()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1676 | // 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] | 1677 | tempShape = originalShape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 1678 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1679 | return; |
| 1680 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1681 | canDrawArgs.fShape = &tempShape; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1682 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1683 | } |
| 1684 | if (!pr) { |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1685 | if (canDrawArgs.fShape->style().applies()) { |
| 1686 | tempShape = canDrawArgs.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, |
| 1687 | styleScale); |
| 1688 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1689 | return; |
| 1690 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1691 | canDrawArgs.fShape = &tempShape; |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 1692 | // This time, allow SW renderer |
| 1693 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
| 1694 | } else { |
| 1695 | pr = this->drawingManager()->getSoftwarePathRenderer(); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1696 | } |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1697 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1698 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1699 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1700 | #ifdef SK_DEBUG |
| 1701 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 1702 | #endif |
| 1703 | return; |
| 1704 | } |
| 1705 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 1706 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1707 | std::move(paint), |
| 1708 | &GrUserStencilSettings::kUnused, |
| 1709 | this, |
| 1710 | &clip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1711 | &clipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1712 | &viewMatrix, |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1713 | canDrawArgs.fShape, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1714 | aaType, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 1715 | this->colorSpaceInfo().isLinearlyBlended()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1716 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1719 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 1720 | *bounds = op->bounds(); |
| 1721 | if (op->hasZeroArea()) { |
| 1722 | if (op->hasAABloat()) { |
| 1723 | bounds->outset(0.5f, 0.5f); |
| 1724 | } else { |
| 1725 | // We don't know which way the particular GPU will snap lines or points at integer |
| 1726 | // coords. So we ensure that the bounds is large enough for either snap. |
| 1727 | SkRect before = *bounds; |
| 1728 | bounds->roundOut(bounds); |
| 1729 | if (bounds->fLeft == before.fLeft) { |
| 1730 | bounds->fLeft -= 1; |
| 1731 | } |
| 1732 | if (bounds->fTop == before.fTop) { |
| 1733 | bounds->fTop -= 1; |
| 1734 | } |
| 1735 | if (bounds->fRight == before.fRight) { |
| 1736 | bounds->fRight += 1; |
| 1737 | } |
| 1738 | if (bounds->fBottom == before.fBottom) { |
| 1739 | bounds->fBottom += 1; |
| 1740 | } |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1745 | uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1746 | ASSERT_SINGLE_OWNER |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1747 | if (this->drawingManager()->wasAbandoned()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 1748 | fContext->contextPriv().opMemoryPool()->release(std::move(op)); |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1749 | return SK_InvalidUniqueID; |
| 1750 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1751 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1752 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "addDrawOp", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 1753 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1754 | // Setup clip |
| 1755 | SkRect bounds; |
| 1756 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1757 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1758 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
| 1759 | if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA, |
| 1760 | fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip, |
| 1761 | &bounds)) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 1762 | fContext->contextPriv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1763 | return SK_InvalidUniqueID; |
| 1764 | } |
| 1765 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1766 | if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil || |
| 1767 | appliedClip.hasStencilClip()) { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 1768 | this->getOpList()->setStencilLoadOp(GrLoadOp::kClear); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 1769 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 1770 | this->setNeedsStencil(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1771 | } |
| 1772 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1773 | GrXferProcessor::DstProxy dstProxy; |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 1774 | if (GrDrawOp::RequiresDstTexture::kYes == op->finalize(*this->caps(), &appliedClip)) { |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1775 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, op->bounds(), &dstProxy)) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 1776 | fContext->contextPriv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1777 | return SK_InvalidUniqueID; |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1782 | return this->getRTOpList()->addOp(std::move(op), *this->caps(), |
| 1783 | std::move(appliedClip), dstProxy); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1784 | } |
| 1785 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1786 | bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 1787 | const SkRect& opBounds, |
| 1788 | GrXferProcessor::DstProxy* dstProxy) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1789 | if (this->caps()->textureBarrierSupport()) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1790 | if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1791 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 1792 | // will be responsible to detect this situation and request a texture barrier. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1793 | dstProxy->setProxy(sk_ref_sp(texProxy)); |
| 1794 | dstProxy->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1795 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1799 | SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1800 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1801 | SkIRect clippedRect; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1802 | clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1803 | SkIRect drawIBounds; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1804 | opBounds.roundOut(&drawIBounds); |
Brian Salomon | 859621f | 2017-03-16 09:21:54 -0400 | [diff] [blame] | 1805 | // Cover up for any precision issues by outsetting the op bounds a pixel in each direction. |
| 1806 | drawIBounds.outset(1, 1); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1807 | if (!clippedRect.intersect(drawIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1808 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1809 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1810 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1811 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 1815 | // have per-sample dst values by making the copy multisampled. |
| 1816 | GrSurfaceDesc desc; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1817 | bool rectsMustMatch = false; |
| 1818 | bool disallowSubrect = false; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1819 | GrSurfaceOrigin origin; |
| 1820 | if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &origin, &rectsMustMatch, |
| 1821 | &disallowSubrect)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1822 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1823 | desc.fConfig = rtProxy->config(); |
Greg Daniel | 1efe322 | 2018-04-04 14:02:51 -0400 | [diff] [blame] | 1824 | origin = rtProxy->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1825 | } |
| 1826 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1827 | if (!disallowSubrect) { |
| 1828 | copyRect = clippedRect; |
| 1829 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1830 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1831 | SkIPoint dstPoint, dstOffset; |
| 1832 | SkBackingFit fit; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1833 | if (rectsMustMatch) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1834 | desc.fWidth = rtProxy->width(); |
| 1835 | desc.fHeight = rtProxy->height(); |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1836 | dstPoint = {copyRect.fLeft, copyRect.fTop}; |
| 1837 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1838 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1839 | } else { |
| 1840 | desc.fWidth = copyRect.width(); |
| 1841 | desc.fHeight = copyRect.height(); |
| 1842 | dstPoint = {0, 0}; |
| 1843 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1844 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1845 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1846 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1847 | sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeDeferredSurfaceContext( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1848 | desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 1849 | sk_ref_sp(this->colorSpaceInfo().colorSpace())); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1850 | if (!sContext) { |
| 1851 | SkDebugf("setupDstTexture: surfaceContext creation failed.\n"); |
| 1852 | return false; |
| 1853 | } |
| 1854 | |
| 1855 | if (!sContext->copy(rtProxy, copyRect, dstPoint)) { |
| 1856 | SkDebugf("setupDstTexture: copy failed.\n"); |
| 1857 | return false; |
| 1858 | } |
| 1859 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1860 | dstProxy->setProxy(sContext->asTextureProxyRef()); |
| 1861 | dstProxy->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1862 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1863 | } |