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 | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 13 | #include "GrColor.h" |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 14 | #include "GrContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 15 | #include "GrDrawingManager.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 16 | #include "GrFixedClip.h" |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 17 | #include "GrGpuResourcePriv.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 18 | #include "GrPathRenderer.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 19 | #include "GrPipelineBuilder.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 20 | #include "GrRenderTarget.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 21 | #include "GrRenderTargetContextPriv.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 22 | #include "GrResourceProvider.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 23 | #include "GrStencilAttachment.h" |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 24 | #include "SkDrawShadowRec.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 25 | #include "SkLatticeIter.h" |
| 26 | #include "SkMatrixPriv.h" |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 27 | #include "SkShadowUtils.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 28 | #include "SkSurfacePriv.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 29 | #include "effects/GrRRectEffect.h" |
| 30 | #include "instanced/InstancedRendering.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 31 | #include "ops/GrClearOp.h" |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 32 | #include "ops/GrClearStencilClipOp.h" |
Robert Phillips | e440721 | 2017-04-13 10:13:16 -0400 | [diff] [blame] | 33 | #include "ops/GrDiscardOp.h" |
Brian Salomon | 0f35332 | 2017-05-03 20:58:59 +0000 | [diff] [blame] | 34 | #include "ops/GrDrawAtlasOp.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 35 | #include "ops/GrDrawOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 36 | #include "ops/GrDrawVerticesOp.h" |
| 37 | #include "ops/GrLatticeOp.h" |
| 38 | #include "ops/GrOp.h" |
| 39 | #include "ops/GrOvalOpFactory.h" |
| 40 | #include "ops/GrRectOpFactory.h" |
| 41 | #include "ops/GrRegionOp.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 42 | #include "ops/GrSemaphoreOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 43 | #include "ops/GrShadowRRectOp.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 44 | #include "ops/GrStencilPathOp.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 45 | #include "text/GrAtlasTextContext.h" |
| 46 | #include "text/GrStencilAndCoverTextContext.h" |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 47 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 48 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 49 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 50 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 51 | #define ASSERT_SINGLE_OWNER_PRIV \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 52 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 53 | #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } |
| 54 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } |
| 55 | #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } |
| 56 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return false; } |
| 57 | #define RETURN_NULL_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 58 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 59 | ////////////////////////////////////////////////////////////////////////////// |
| 60 | |
| 61 | GrAAType GrChooseAAType(GrAA aa, GrFSAAType fsaaType, GrAllowMixedSamples allowMixedSamples, |
| 62 | const GrCaps& caps) { |
| 63 | if (GrAA::kNo == aa) { |
| 64 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type reflect |
| 65 | // that. |
| 66 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !caps.multisampleDisableSupport()) { |
| 67 | return GrAAType::kMSAA; |
| 68 | } |
| 69 | return GrAAType::kNone; |
| 70 | } |
| 71 | switch (fsaaType) { |
| 72 | case GrFSAAType::kNone: |
| 73 | return GrAAType::kCoverage; |
| 74 | case GrFSAAType::kUnifiedMSAA: |
| 75 | return GrAAType::kMSAA; |
| 76 | case GrFSAAType::kMixedSamples: |
| 77 | return GrAllowMixedSamples::kYes == allowMixedSamples ? GrAAType::kMixedSamples |
| 78 | : GrAAType::kCoverage; |
| 79 | } |
| 80 | SkFAIL("Unexpected fsaa type"); |
| 81 | return GrAAType::kNone; |
| 82 | } |
| 83 | |
| 84 | ////////////////////////////////////////////////////////////////////////////// |
| 85 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 86 | class AutoCheckFlush { |
| 87 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 88 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 89 | SkASSERT(fDrawingManager); |
| 90 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 91 | ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 92 | |
| 93 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 94 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 97 | bool GrRenderTargetContext::wasAbandoned() const { |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 98 | return this->drawingManager()->wasAbandoned(); |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 101 | // 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] | 102 | // 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] | 103 | // 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] | 104 | // when the renderTargetContext attempts to use it (via getOpList). |
| 105 | GrRenderTargetContext::GrRenderTargetContext(GrContext* context, |
| 106 | GrDrawingManager* drawingMgr, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 107 | sk_sp<GrRenderTargetProxy> rtp, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 108 | sk_sp<SkColorSpace> colorSpace, |
| 109 | const SkSurfaceProps* surfaceProps, |
| 110 | GrAuditTrail* auditTrail, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 111 | GrSingleOwner* singleOwner, |
| 112 | bool managedOpList) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 113 | : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 114 | , fRenderTargetProxy(std::move(rtp)) |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 115 | , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 116 | , fInstancedPipelineInfo(fRenderTargetProxy.get()) |
brianosman | 5a7ae7e | 2016-09-12 12:07:25 -0700 | [diff] [blame] | 117 | , fColorXformFromSRGB(nullptr) |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 118 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
| 119 | , fManagedOpList(managedOpList) { |
brianosman | 5a7ae7e | 2016-09-12 12:07:25 -0700 | [diff] [blame] | 120 | if (fColorSpace) { |
| 121 | // sRGB sources are very common (SkColor, etc...), so we cache that gamut transformation |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 122 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 123 | fColorXformFromSRGB = GrColorSpaceXform::Make(srgbColorSpace.get(), fColorSpace.get()); |
brianosman | 5a7ae7e | 2016-09-12 12:07:25 -0700 | [diff] [blame] | 124 | } |
Robert Phillips | d991486 | 2017-06-14 15:16:59 -0400 | [diff] [blame] | 125 | |
| 126 | // MDB TODO: to ensure all resources still get allocated in the correct order in the hybrid |
| 127 | // world we need to get the correct opList here so that it, in turn, can grab and hold |
| 128 | // its rendertarget. |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 129 | this->getRTOpList(); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 130 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 131 | } |
| 132 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 133 | #ifdef SK_DEBUG |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 134 | void GrRenderTargetContext::validate() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 135 | SkASSERT(fRenderTargetProxy); |
| 136 | fRenderTargetProxy->validate(fContext); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 137 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 138 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 139 | SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 140 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 141 | } |
| 142 | #endif |
| 143 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 144 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 145 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 148 | GrTextureProxy* GrRenderTargetContext::asTextureProxy() { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 149 | return fRenderTargetProxy->asTextureProxy(); |
| 150 | } |
| 151 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 152 | sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() { |
| 153 | return sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 154 | } |
| 155 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 156 | GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 157 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 158 | SkDEBUGCODE(this->validate();) |
| 159 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 160 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 161 | fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy.get(), fManagedOpList); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 164 | return fOpList.get(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 167 | GrOpList* GrRenderTargetContext::getOpList() { |
| 168 | return this->getRTOpList(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 171 | void GrRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 172 | const SkMatrix& viewMatrix, const char text[], |
| 173 | size_t byteLength, SkScalar x, SkScalar y, |
| 174 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 175 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 176 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 177 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 178 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 179 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 180 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 181 | atlasTextContext->drawText(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, text, |
| 182 | byteLength, x, y, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 183 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 184 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 185 | void GrRenderTargetContext::drawPosText(const GrClip& clip, const SkPaint& paint, |
| 186 | const SkMatrix& viewMatrix, const char text[], |
| 187 | size_t byteLength, const SkScalar pos[], |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 188 | int scalarsPerPosition, const SkPoint& offset, |
| 189 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 190 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 191 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 192 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 193 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPosText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 194 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 195 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 196 | atlasTextContext->drawPosText(fContext, this, clip, paint, viewMatrix, fSurfaceProps, text, |
| 197 | byteLength, pos, scalarsPerPosition, offset, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 198 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 199 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 200 | void GrRenderTargetContext::drawTextBlob(const GrClip& clip, const SkPaint& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 201 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 202 | SkScalar x, SkScalar y, SkDrawFilter* filter, |
| 203 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 204 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 205 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 206 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 207 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawTextBlob"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 208 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 209 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 210 | atlasTextContext->drawTextBlob(fContext, this, clip, paint, viewMatrix, fSurfaceProps, blob, x, |
| 211 | y, filter, clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 214 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 215 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 216 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 217 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 218 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::discard"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 219 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 220 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 221 | |
Robert Phillips | e440721 | 2017-04-13 10:13:16 -0400 | [diff] [blame] | 222 | // Currently this just inserts a discard op. However, once in MDB this can remove all the |
| 223 | // previously recorded ops and change the load op to discard. |
| 224 | if (this->caps()->discardRenderTargetSupport()) { |
Robert Phillips | 955235f | 2017-05-18 12:17:35 -0400 | [diff] [blame] | 225 | std::unique_ptr<GrOp> op(GrDiscardOp::Make(fRenderTargetProxy.get())); |
Robert Phillips | e440721 | 2017-04-13 10:13:16 -0400 | [diff] [blame] | 226 | if (!op) { |
| 227 | return; |
| 228 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 229 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
Robert Phillips | e440721 | 2017-04-13 10:13:16 -0400 | [diff] [blame] | 230 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 233 | void GrRenderTargetContext::clear(const SkIRect* rect, |
| 234 | const GrColor color, |
| 235 | bool canIgnoreRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 236 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 237 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 238 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 239 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::clear"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 240 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 241 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 242 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, canIgnoreRect); |
| 243 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 244 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 245 | void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor color) { |
| 246 | ASSERT_SINGLE_OWNER_PRIV |
| 247 | RETURN_IF_ABANDONED_PRIV |
| 248 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 249 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 250 | "GrRenderTargetContext::absClear"); |
| 251 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 252 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 253 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 254 | SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(), |
| 255 | fRenderTargetContext->fRenderTargetProxy->worstCaseHeight()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 256 | |
| 257 | if (clearRect) { |
| 258 | if (clearRect->contains(rtRect)) { |
| 259 | clearRect = nullptr; // full screen |
| 260 | } else { |
| 261 | if (!rtRect.intersect(*clearRect)) { |
| 262 | return; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // TODO: in a post-MDB world this should be handled at the OpList level. |
| 268 | // An op-list that is initially cleared and has no other ops should receive an |
| 269 | // extra draw. |
| 270 | if (fRenderTargetContext->fContext->caps()->useDrawInsteadOfClear()) { |
| 271 | // This works around a driver bug with clear by drawing a rect instead. |
| 272 | // The driver will ignore a clear if it is the only thing rendered to a |
| 273 | // target before the target is read. |
| 274 | GrPaint paint; |
| 275 | paint.setColor4f(GrColor4f::FromGrColor(color)); |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 276 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 277 | |
| 278 | // We don't call drawRect() here to avoid the cropping to the, possibly smaller, |
| 279 | // RenderTargetProxy bounds |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 280 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFill( |
| 281 | std::move(paint), SkMatrix::I(), SkRect::Make(rtRect), GrAAType::kNone); |
| 282 | fRenderTargetContext->addDrawOp(GrNoClip(), std::move(op)); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 283 | } else { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 284 | // This path doesn't handle coalescing of full screen clears b.c. it |
| 285 | // has to clear the entire render target - not just the content area. |
| 286 | // It could be done but will take more finagling. |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 287 | std::unique_ptr<GrOp> op(GrClearOp::Make(rtRect, color, !clearRect)); |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 288 | if (!op) { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 289 | return; |
| 290 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 291 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 295 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 296 | const GrColor color, |
| 297 | bool canIgnoreClip) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 298 | ASSERT_SINGLE_OWNER_PRIV |
| 299 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 300 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 301 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 302 | "GrRenderTargetContextPriv::clear"); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 303 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 304 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 305 | fRenderTargetContext->internalClear(clip, color, canIgnoreClip); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 308 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 309 | const GrColor color, |
| 310 | bool canIgnoreClip) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 311 | bool isFull = false; |
| 312 | if (!clip.hasWindowRectangles()) { |
| 313 | isFull = !clip.scissorEnabled() || |
| 314 | (canIgnoreClip && fContext->caps()->fullClearIsFree()) || |
| 315 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 316 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 317 | |
| 318 | if (fContext->caps()->useDrawInsteadOfClear()) { |
| 319 | // This works around a driver bug with clear by drawing a rect instead. |
| 320 | // The driver will ignore a clear if it is the only thing rendered to a |
| 321 | // target before the target is read. |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 322 | SkIRect clearRect = SkIRect::MakeWH(this->width(), this->height()); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 323 | if (isFull) { |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 324 | this->discard(); |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 325 | } else if (!clearRect.intersect(clip.scissorRect())) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 326 | return; |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | GrPaint paint; |
| 330 | paint.setColor4f(GrColor4f::FromGrColor(color)); |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 331 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 332 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 333 | this->drawRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), SkRect::Make(clearRect)); |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 334 | } else if (isFull) { |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 335 | this->getRTOpList()->fullClear(*this->caps(), color); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 336 | } else { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 337 | std::unique_ptr<GrOp> op(GrClearOp::Make(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 Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 351 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPaint"); |
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 | SkDebugf("Could not invert matrix\n"); |
| 380 | return; |
| 381 | } |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 382 | this->drawRect(clip, std::move(paint), GrAA::kNo, viewMatrix, r); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 383 | } else { |
| 384 | SkMatrix localMatrix; |
| 385 | if (!viewMatrix.invert(&localMatrix)) { |
| 386 | SkDebugf("Could not invert matrix\n"); |
| 387 | return; |
| 388 | } |
| 389 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 390 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 391 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 392 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
| 393 | std::move(paint), SkMatrix::I(), localMatrix, r, GrAAType::kNone); |
| 394 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 398 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 399 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 400 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 401 | } |
| 402 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 403 | // Attempts to crop a rect and optional local rect to the clip boundaries. |
| 404 | // Returns false if the draw can be skipped entirely. |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 405 | static bool crop_filled_rect(int width, int height, const GrClip& clip, |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 406 | const SkMatrix& viewMatrix, SkRect* rect, |
| 407 | SkRect* localRect = nullptr) { |
| 408 | if (!viewMatrix.rectStaysRect()) { |
| 409 | return true; |
| 410 | } |
| 411 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 412 | SkIRect clipDevBounds; |
| 413 | SkRect clipBounds; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 414 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 415 | clip.getConservativeBounds(width, height, &clipDevBounds); |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 416 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) { |
| 417 | return false; |
| 418 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 419 | |
| 420 | if (localRect) { |
| 421 | if (!rect->intersects(clipBounds)) { |
| 422 | return false; |
| 423 | } |
| 424 | const SkScalar dx = localRect->width() / rect->width(); |
| 425 | const SkScalar dy = localRect->height() / rect->height(); |
| 426 | if (clipBounds.fLeft > rect->fLeft) { |
| 427 | localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx; |
| 428 | rect->fLeft = clipBounds.fLeft; |
| 429 | } |
| 430 | if (clipBounds.fTop > rect->fTop) { |
| 431 | localRect->fTop += (clipBounds.fTop - rect->fTop) * dy; |
| 432 | rect->fTop = clipBounds.fTop; |
| 433 | } |
| 434 | if (clipBounds.fRight < rect->fRight) { |
| 435 | localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx; |
| 436 | rect->fRight = clipBounds.fRight; |
| 437 | } |
| 438 | if (clipBounds.fBottom < rect->fBottom) { |
| 439 | localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy; |
| 440 | rect->fBottom = clipBounds.fBottom; |
| 441 | } |
| 442 | return true; |
| 443 | } |
| 444 | |
| 445 | return rect->intersect(clipBounds); |
| 446 | } |
| 447 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 448 | bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 449 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 450 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 451 | const SkMatrix& viewMatrix, |
| 452 | const SkRect& rect, |
| 453 | const GrUserStencilSettings* ss) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 454 | SkRect croppedRect = rect; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 455 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 456 | return true; |
| 457 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 458 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 459 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && |
| 460 | (!ss || ss->isDisabled(false))) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 461 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
| 462 | std::unique_ptr<GrDrawOp> op = oa->recordRect(croppedRect, viewMatrix, std::move(paint), |
| 463 | aa, fInstancedPipelineInfo); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 464 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 465 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 466 | return true; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 469 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 470 | std::unique_ptr<GrDrawOp> op; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 471 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 472 | op = GrRectOpFactory::MakeAAFill(std::move(paint), viewMatrix, croppedRect, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 473 | } else { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 474 | op = GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, croppedRect, aaType, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 475 | } |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 476 | if (!op) { |
| 477 | return false; |
| 478 | } |
| 479 | this->addDrawOp(clip, std::move(op)); |
| 480 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 483 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 484 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 485 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 486 | const SkMatrix& viewMatrix, |
| 487 | const SkRect& rect, |
| 488 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 489 | if (!style) { |
| 490 | style = &GrStyle::SimpleFill(); |
| 491 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 492 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 493 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 494 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 495 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRect"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 496 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 497 | // Path effects should've been devolved to a path in SkGpuDevice |
| 498 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 499 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 500 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 501 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 502 | const SkStrokeRec& stroke = style->strokeRec(); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 503 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 504 | |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 505 | if (!fContext->caps()->useDrawInsteadOfClear()) { |
| 506 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother |
| 507 | // checking cases where the RT is fully inside a stroke. |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 508 | SkRect rtRect = fRenderTargetProxy->getBoundsRect(); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 509 | // Does the clip contain the entire RT? |
| 510 | if (clip.quickContains(rtRect)) { |
| 511 | SkMatrix invM; |
| 512 | if (!viewMatrix.invert(&invM)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 515 | // Does the rect bound the RT? |
| 516 | SkPoint srcSpaceRTQuad[4]; |
| 517 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 518 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 519 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 520 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 521 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 522 | // Will it blend? |
| 523 | GrColor clearColor; |
| 524 | if (paint.isConstantBlendedColor(&clearColor)) { |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 525 | this->clear(nullptr, clearColor, true); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 526 | return; |
| 527 | } |
| 528 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 531 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 532 | if (this->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, nullptr)) { |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 533 | return; |
| 534 | } |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 535 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 536 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 537 | if ((!rect.width() || !rect.height()) && |
| 538 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 539 | SkScalar r = stroke.getWidth() / 2; |
| 540 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 541 | switch (stroke.getJoin()) { |
| 542 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 543 | this->drawRect( |
| 544 | clip, std::move(paint), aa, viewMatrix, |
| 545 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 546 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 547 | return; |
| 548 | case SkPaint::kRound_Join: |
| 549 | // Raster draws nothing when both dimensions are empty. |
| 550 | if (rect.width() || rect.height()){ |
| 551 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 552 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 553 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 554 | return; |
| 555 | } |
| 556 | case SkPaint::kBevel_Join: |
| 557 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 558 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 559 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 560 | &GrStyle::SimpleFill()); |
| 561 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 562 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 563 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 564 | &GrStyle::SimpleFill()); |
| 565 | } |
| 566 | return; |
| 567 | } |
| 568 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 569 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 570 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 571 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 572 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 573 | if (GrAAType::kCoverage == aaType) { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 574 | // The stroke path needs the rect to remain axis aligned (no rotation or skew). |
| 575 | if (viewMatrix.rectStaysRect()) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 576 | op = GrRectOpFactory::MakeAAStroke(std::move(paint), viewMatrix, rect, stroke); |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 577 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 578 | } else { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 579 | op = GrRectOpFactory::MakeNonAAStroke(std::move(paint), viewMatrix, rect, stroke, |
| 580 | aaType); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 581 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 582 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 583 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 584 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 585 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 586 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 587 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 588 | |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 589 | SkPath path; |
| 590 | path.setIsVolatile(true); |
| 591 | path.addRect(rect); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 592 | this->internalDrawPath(clip, std::move(paint), aa, viewMatrix, path, *style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 595 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
| 596 | return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles( |
| 597 | *fRenderTargetContext->fContext->caps()); |
| 598 | } |
| 599 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 600 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 601 | ASSERT_SINGLE_OWNER_PRIV |
| 602 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 603 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 604 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 605 | "GrRenderTargetContextPriv::clearStencilClip"); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 606 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 607 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 608 | |
Robert Phillips | 2f4ddf6 | 2017-06-01 08:48:19 -0400 | [diff] [blame] | 609 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make( |
| 610 | clip, insideStencilMask, |
| 611 | fRenderTargetContext->fRenderTargetProxy.get())); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 612 | if (!op) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 613 | return; |
| 614 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 615 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 618 | void GrRenderTargetContextPriv::stencilPath(const GrClip& clip, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 619 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 620 | const SkMatrix& viewMatrix, |
| 621 | const GrPath* path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 622 | ASSERT_SINGLE_OWNER_PRIV |
| 623 | RETURN_IF_ABANDONED_PRIV |
| 624 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 625 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 626 | "GrRenderTargetContext::stencilPath"); |
| 627 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 628 | SkASSERT(aaType != GrAAType::kCoverage); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 629 | |
| 630 | bool useHWAA = GrAATypeIsHW(aaType); |
| 631 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 632 | SkASSERT(path); |
| 633 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 634 | |
| 635 | // FIXME: Use path bounds instead of this WAR once |
| 636 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 637 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 638 | |
| 639 | // Setup clip |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 640 | GrAppliedClip appliedClip; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 641 | if (!clip.apply(fRenderTargetContext->fContext, fRenderTargetContext, useHWAA, true, |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 642 | &appliedClip, &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 643 | return; |
| 644 | } |
| 645 | |
| 646 | // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never |
| 647 | // attempt this in a situation that would require coverage AA. |
| 648 | SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); |
| 649 | |
| 650 | GrRenderTarget* rt = fRenderTargetContext->accessRenderTarget(); |
| 651 | if (!rt) { |
| 652 | return; |
| 653 | } |
| 654 | GrStencilAttachment* stencilAttachment = |
| 655 | fRenderTargetContext->fContext->resourceProvider()->attachStencilAttachment(rt); |
| 656 | if (!stencilAttachment) { |
| 657 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(viewMatrix, |
| 662 | useHWAA, |
| 663 | path->getFillType(), |
| 664 | appliedClip.hasStencilClip(), |
| 665 | stencilAttachment->bits(), |
| 666 | appliedClip.scissorState(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 667 | path); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 668 | if (!op) { |
| 669 | return; |
| 670 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 671 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 672 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 675 | void GrRenderTargetContextPriv::stencilRect(const GrClip& clip, |
| 676 | const GrUserStencilSettings* ss, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 677 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 678 | const SkMatrix& viewMatrix, |
| 679 | const SkRect& rect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 680 | ASSERT_SINGLE_OWNER_PRIV |
| 681 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 682 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 683 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 684 | "GrRenderTargetContext::stencilRect"); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 685 | SkASSERT(GrAAType::kCoverage != aaType); |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 686 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 687 | |
| 688 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 689 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 690 | std::unique_ptr<GrDrawOp> op = |
| 691 | GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, rect, aaType, ss); |
| 692 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 695 | bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, |
| 696 | const GrUserStencilSettings* ss, |
| 697 | SkRegion::Op op, |
| 698 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 699 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 700 | const SkMatrix& viewMatrix, |
| 701 | const SkRect& rect) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 702 | ASSERT_SINGLE_OWNER_PRIV |
| 703 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 704 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 705 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 706 | "GrRenderTargetContext::drawAndStencilRect"); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 707 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 708 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 709 | |
| 710 | GrPaint paint; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 711 | paint.setCoverageSetOpXPFactory(op, invert); |
| 712 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 713 | if (fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, ss)) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 714 | return true; |
| 715 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 716 | SkPath path; |
| 717 | path.setIsVolatile(true); |
| 718 | path.addRect(rect); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 719 | return this->drawAndStencilPath(clip, ss, op, invert, aa, viewMatrix, path); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 720 | } |
| 721 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 722 | void GrRenderTargetContext::fillRectToRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 723 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 724 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 725 | const SkMatrix& viewMatrix, |
| 726 | const SkRect& rectToDraw, |
| 727 | const SkRect& localRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 728 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 729 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 730 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 731 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::fillRectToRect"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 732 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 733 | SkRect croppedRect = rectToDraw; |
| 734 | SkRect croppedLocalRect = localRect; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 735 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, |
| 736 | &croppedRect, &croppedLocalRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 737 | return; |
| 738 | } |
| 739 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 740 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 741 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 742 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 743 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
| 744 | std::unique_ptr<GrDrawOp> op(oa->recordRect(croppedRect, viewMatrix, std::move(paint), |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 745 | croppedLocalRect, aa, fInstancedPipelineInfo)); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 746 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 747 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 748 | return; |
| 749 | } |
| 750 | } |
| 751 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 752 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 753 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 754 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalRect( |
| 755 | std::move(paint), viewMatrix, croppedRect, croppedLocalRect, aaType); |
| 756 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 757 | return; |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 758 | } |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 759 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 760 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalRect( |
| 761 | std::move(paint), viewMatrix, croppedRect, croppedLocalRect); |
| 762 | if (op) { |
| 763 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | |
| 767 | SkMatrix viewAndUnLocalMatrix; |
| 768 | if (!viewAndUnLocalMatrix.setRectToRect(localRect, rectToDraw, SkMatrix::kFill_ScaleToFit)) { |
| 769 | SkDebugf("fillRectToRect called with empty local matrix.\n"); |
| 770 | return; |
| 771 | } |
| 772 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 773 | |
| 774 | SkPath path; |
| 775 | path.setIsVolatile(true); |
| 776 | path.addRect(localRect); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 777 | this->internalDrawPath(clip, std::move(paint), aa, viewAndUnLocalMatrix, path, GrStyle()); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 780 | void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 781 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 782 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 783 | const SkMatrix& viewMatrix, |
| 784 | const SkRect& rectToDraw, |
| 785 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 786 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 787 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 788 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 789 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::fillRectWithLocalMatrix"); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 790 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 791 | SkRect croppedRect = rectToDraw; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 792 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 796 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 797 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 798 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 799 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
| 800 | std::unique_ptr<GrDrawOp> op(oa->recordRect(croppedRect, viewMatrix, std::move(paint), |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 801 | localMatrix, aa, fInstancedPipelineInfo)); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 802 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 803 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 804 | return; |
| 805 | } |
| 806 | } |
| 807 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 808 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 809 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 810 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
| 811 | std::move(paint), viewMatrix, localMatrix, croppedRect, aaType); |
| 812 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 813 | return; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 814 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 815 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 816 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalMatrix( |
| 817 | std::move(paint), viewMatrix, localMatrix, croppedRect); |
| 818 | if (op) { |
| 819 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 820 | return; |
| 821 | } |
| 822 | |
| 823 | SkMatrix viewAndUnLocalMatrix; |
| 824 | if (!localMatrix.invert(&viewAndUnLocalMatrix)) { |
| 825 | SkDebugf("fillRectWithLocalMatrix called with degenerate local matrix.\n"); |
| 826 | return; |
| 827 | } |
| 828 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 829 | |
| 830 | SkPath path; |
| 831 | path.setIsVolatile(true); |
| 832 | path.addRect(rectToDraw); |
| 833 | path.transform(localMatrix); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 834 | this->internalDrawPath(clip, std::move(paint), aa, viewAndUnLocalMatrix, path, GrStyle()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 837 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 838 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 839 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 840 | sk_sp<SkVertices> vertices, |
| 841 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 842 | ASSERT_SINGLE_OWNER |
| 843 | RETURN_IF_ABANDONED |
| 844 | SkDEBUGCODE(this->validate();) |
| 845 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawVertices"); |
| 846 | |
| 847 | AutoCheckFlush acf(this->drawingManager()); |
| 848 | |
| 849 | SkASSERT(vertices); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame^] | 850 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
| 851 | std::unique_ptr<GrDrawOp> op = |
| 852 | GrDrawVerticesOp::Make(std::move(paint), std::move(vertices), viewMatrix, aaType, |
| 853 | this->isGammaCorrect(), fColorXformFromSRGB, overridePrimType); |
| 854 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /////////////////////////////////////////////////////////////////////////////// |
| 858 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 859 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 860 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 861 | const SkMatrix& viewMatrix, |
| 862 | int spriteCount, |
| 863 | const SkRSXform xform[], |
| 864 | const SkRect texRect[], |
| 865 | const SkColor colors[]) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 866 | ASSERT_SINGLE_OWNER |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 867 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 868 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 869 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawAtlas"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 870 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 871 | AutoCheckFlush acf(this->drawingManager()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 872 | |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 873 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
| 874 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(std::move(paint), viewMatrix, aaType, |
| 875 | spriteCount, xform, texRect, colors); |
| 876 | this->addDrawOp(clip, std::move(op)); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /////////////////////////////////////////////////////////////////////////////// |
| 880 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 881 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 882 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 883 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 884 | const SkMatrix& viewMatrix, |
| 885 | const SkRRect& rrect, |
| 886 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 887 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 888 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 889 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 890 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRRect"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 891 | if (rrect.isEmpty()) { |
| 892 | return; |
| 893 | } |
| 894 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 895 | GrNoClip noclip; |
| 896 | const GrClip* clip = &origClip; |
| 897 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 898 | // 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] | 899 | // 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] | 900 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 901 | // attempts to mitigate the stencil clip cost but will only help when the entire clip stack |
| 902 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. |
| 903 | SkRRect devRRect; |
| 904 | if (rrect.transform(viewMatrix, &devRRect) && clip->quickContains(devRRect)) { |
| 905 | clip = &noclip; |
| 906 | } |
| 907 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 908 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 909 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 910 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 911 | const SkStrokeRec stroke = style.strokeRec(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 912 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 913 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && |
| 914 | stroke.isFillStyle()) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 915 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 916 | std::unique_ptr<GrDrawOp> op( |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 917 | oa->recordRRect(rrect, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo)); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 918 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 919 | this->addDrawOp(*clip, std::move(op)); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | } |
| 923 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 924 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 925 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 926 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 927 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeRRectOp(std::move(paint), |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 928 | viewMatrix, |
| 929 | rrect, |
| 930 | stroke, |
| 931 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 932 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 933 | this->addDrawOp(*clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 934 | return; |
| 935 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 936 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 937 | |
| 938 | SkPath path; |
| 939 | path.setIsVolatile(true); |
| 940 | path.addRRect(rrect); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 941 | this->internalDrawPath(*clip, std::move(paint), aa, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 944 | /////////////////////////////////////////////////////////////////////////////// |
| 945 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 946 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 947 | SkPoint3 result; |
| 948 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 949 | result.fZ = pt.fZ; |
| 950 | return result; |
| 951 | } |
| 952 | |
| 953 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 954 | GrColor color4ub, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 955 | const SkMatrix& viewMatrix, |
| 956 | const SkPath& path, |
| 957 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 958 | ASSERT_SINGLE_OWNER |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 959 | if (this->drawingManager()->wasAbandoned()) { |
| 960 | return true; |
| 961 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 962 | SkDEBUGCODE(this->validate();) |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 963 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawFastShadow"); |
| 964 | |
| 965 | // check z plane |
| 966 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 967 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 968 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 969 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 970 | return false; |
| 971 | } |
| 972 | |
| 973 | SkRRect rrect; |
| 974 | SkRect rect; |
| 975 | // we can only handle rects, circles, and rrects with circular corners |
| 976 | bool isRRect = path.isRRect(&rrect) && rrect.isSimpleCircular() && |
| 977 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 978 | if (!isRRect && |
| 979 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 980 | rect.width() > SK_ScalarNearlyZero) { |
| 981 | rrect.setOval(rect); |
| 982 | isRRect = true; |
| 983 | } |
| 984 | if (!isRRect && path.isRect(&rect)) { |
| 985 | rrect.setRect(rect); |
| 986 | isRRect = true; |
| 987 | } |
| 988 | |
| 989 | if (!isRRect) { |
| 990 | return false; |
| 991 | } |
| 992 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 993 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 994 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 995 | } |
| 996 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 997 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 998 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 999 | // transform light |
| 1000 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 1001 | |
| 1002 | // 1/scale |
| 1003 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
| 1004 | SkScalarInvert(viewMatrix[SkMatrix::kMScaleX]) : |
| 1005 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 1006 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1007 | |
| 1008 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1009 | GrColor4f color = GrColor4f::FromGrColor(color4ub); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1010 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1011 | bool tonalColor = SkToBool(rec.fFlags & SkShadowFlags::kTonalColor_ShadowFlag); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1012 | |
| 1013 | if (rec.fAmbientAlpha > 0) { |
| 1014 | static constexpr float kHeightFactor = 1.0f / 128.0f; |
| 1015 | static constexpr float kGeomFactor = 64.0f; |
| 1016 | |
| 1017 | SkScalar devSpaceInsetWidth = occluderHeight * kHeightFactor * kGeomFactor; |
| 1018 | const float umbraAlpha = (1.0f + SkTMax(occluderHeight * kHeightFactor, 0.0f)); |
| 1019 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraAlpha; |
| 1020 | |
| 1021 | // Outset the shadow rrect to the border of the penumbra |
| 1022 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1023 | SkRRect ambientRRect; |
| 1024 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1025 | // If the rrect was an oval then its outset will also be one. |
| 1026 | // We set it explicitly to avoid errors. |
| 1027 | if (rrect.isOval()) { |
| 1028 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1029 | } else { |
| 1030 | SkScalar outsetRad = rrect.getSimpleRadii().fX + ambientPathOutset; |
| 1031 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1032 | } |
| 1033 | |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1034 | GrColor ambientColor; |
| 1035 | if (tonalColor) { |
| 1036 | // with tonal color, the color only applies to the spot shadow |
| 1037 | ambientColor = GrColorPackRGBA(0, 0, 0, 255.999f*rec.fAmbientAlpha); |
| 1038 | } else { |
| 1039 | ambientColor = color.mulByScalar(rec.fAmbientAlpha).toGrColor(); |
| 1040 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1041 | if (transparent) { |
| 1042 | // set a large inset to force a fill |
| 1043 | devSpaceInsetWidth = ambientRRect.width(); |
| 1044 | } |
| 1045 | // the fraction of the blur we want to apply is devSpaceInsetWidth/devSpaceAmbientBlur, |
| 1046 | // which is just 1/umbraAlpha. |
| 1047 | SkScalar blurClamp = SkScalarInvert(umbraAlpha); |
| 1048 | |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1049 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(ambientColor, viewMatrix, |
| 1050 | ambientRRect, |
| 1051 | devSpaceAmbientBlur, |
| 1052 | devSpaceInsetWidth, |
| 1053 | blurClamp); |
| 1054 | SkASSERT(op); |
| 1055 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1056 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1057 | |
| 1058 | if (rec.fSpotAlpha > 0) { |
| 1059 | float zRatio = SkTPin(occluderHeight / (devLightPos.fZ - occluderHeight), 0.0f, 0.95f); |
| 1060 | |
| 1061 | SkScalar devSpaceSpotBlur = 2.0f * rec.fLightRadius * zRatio; |
| 1062 | // handle scale of radius and pad due to CTM |
| 1063 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1064 | |
| 1065 | // Compute the scale and translation for the spot shadow. |
| 1066 | const SkScalar spotScale = devLightPos.fZ / (devLightPos.fZ - occluderHeight); |
| 1067 | SkPoint spotOffset = SkPoint::Make(zRatio*(-devLightPos.fX), zRatio*(-devLightPos.fY)); |
| 1068 | // Adjust translate for the effect of the scale. |
| 1069 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1070 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1071 | // This offset is in dev space, need to transform it into source space. |
| 1072 | SkMatrix ctmInverse; |
| 1073 | if (viewMatrix.invert(&ctmInverse)) { |
| 1074 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1075 | } else { |
| 1076 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1077 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1078 | SkASSERT(false); |
| 1079 | } |
| 1080 | |
| 1081 | // Compute the transformed shadow rrect |
| 1082 | SkRRect spotShadowRRect; |
| 1083 | SkMatrix shadowTransform; |
| 1084 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1085 | rrect.transform(shadowTransform, &spotShadowRRect); |
| 1086 | SkScalar spotRadius = spotShadowRRect.getSimpleRadii().fX; |
| 1087 | |
| 1088 | // Compute the insetWidth |
| 1089 | SkScalar blurOutset = 0.5f*srcSpaceSpotBlur; |
| 1090 | SkScalar insetWidth = blurOutset; |
| 1091 | if (transparent) { |
| 1092 | // If transparent, just do a fill |
| 1093 | insetWidth += spotShadowRRect.width(); |
| 1094 | } else { |
| 1095 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1096 | // border. We want to extend this inset area so that it meets up with the caster |
| 1097 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1098 | // |
| 1099 | // We compare the min and max corners inset by the radius between the original |
| 1100 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1101 | // between the scaled radius and the original radius gives the distance from the |
| 1102 | // transformed shadow shape to the original shape in that corner. The max |
| 1103 | // of these gives the maximum distance we need to cover. |
| 1104 | // |
| 1105 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1106 | // that to get the full insetWidth. |
| 1107 | SkScalar maxOffset; |
| 1108 | if (rrect.isRect()) { |
| 1109 | // Manhattan distance works better for rects |
| 1110 | maxOffset = SkTMax(SkTMax(SkTAbs(spotShadowRRect.rect().fLeft - |
| 1111 | rrect.rect().fLeft), |
| 1112 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1113 | rrect.rect().fTop)), |
| 1114 | SkTMax(SkTAbs(spotShadowRRect.rect().fRight - |
| 1115 | rrect.rect().fRight), |
| 1116 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1117 | rrect.rect().fBottom))); |
| 1118 | } else { |
| 1119 | SkScalar dr = spotRadius - rrect.getSimpleRadii().fX; |
| 1120 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1121 | rrect.rect().fLeft + dr, |
| 1122 | spotShadowRRect.rect().fTop - |
| 1123 | rrect.rect().fTop + dr); |
| 1124 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1125 | rrect.rect().fRight - dr, |
| 1126 | spotShadowRRect.rect().fBottom - |
| 1127 | rrect.rect().fBottom - dr); |
| 1128 | maxOffset = SkScalarSqrt(SkTMax(upperLeftOffset.lengthSqd(), |
| 1129 | lowerRightOffset.lengthSqd())) + dr; |
| 1130 | } |
| 1131 | insetWidth += maxOffset; |
| 1132 | } |
| 1133 | |
| 1134 | // Outset the shadow rrect to the border of the penumbra |
| 1135 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1136 | if (spotShadowRRect.isOval()) { |
| 1137 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1138 | } else { |
| 1139 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1140 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1141 | } |
| 1142 | |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1143 | GrColor spotColor; |
| 1144 | if (tonalColor) { |
| 1145 | SkScalar colorScale; |
| 1146 | SkScalar tonalAlpha; |
| 1147 | SkShadowUtils::ComputeTonalColorParams(color.fRGBA[0], color.fRGBA[1], |
| 1148 | color.fRGBA[2], rec.fSpotAlpha, |
| 1149 | &colorScale, &tonalAlpha); |
| 1150 | color.fRGBA[0] *= colorScale; |
| 1151 | color.fRGBA[1] *= colorScale; |
| 1152 | color.fRGBA[2] *= colorScale; |
| 1153 | color.fRGBA[3] = tonalAlpha; |
| 1154 | spotColor = color.toGrColor(); |
| 1155 | } else { |
| 1156 | spotColor = color.mulByScalar(rec.fSpotAlpha).toGrColor(); |
| 1157 | } |
| 1158 | |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1159 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(spotColor, viewMatrix, |
| 1160 | spotShadowRRect, |
| 1161 | devSpaceSpotBlur, |
| 1162 | insetWidth); |
| 1163 | SkASSERT(op); |
| 1164 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /////////////////////////////////////////////////////////////////////////////// |
| 1171 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1172 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1173 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1174 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1175 | const SkMatrix& viewMatrix, |
| 1176 | const SkRRect& origOuter, |
| 1177 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1178 | SkASSERT(!origInner.isEmpty()); |
| 1179 | SkASSERT(!origOuter.isEmpty()); |
| 1180 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 1181 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 1182 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
| 1183 | std::unique_ptr<GrDrawOp> op(oa->recordDRRect( |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1184 | origOuter, origInner, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo)); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1185 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1186 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1187 | return true; |
| 1188 | } |
| 1189 | } |
| 1190 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1191 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1192 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1193 | GrPrimitiveEdgeType innerEdgeType, outerEdgeType; |
| 1194 | if (GrAAType::kCoverage == aaType) { |
| 1195 | innerEdgeType = kInverseFillAA_GrProcessorEdgeType; |
| 1196 | outerEdgeType = kFillAA_GrProcessorEdgeType; |
| 1197 | } else { |
| 1198 | innerEdgeType = kInverseFillBW_GrProcessorEdgeType; |
| 1199 | outerEdgeType = kFillBW_GrProcessorEdgeType; |
| 1200 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1201 | |
| 1202 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1203 | SkMatrix inverseVM; |
| 1204 | if (!viewMatrix.isIdentity()) { |
| 1205 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1206 | return false; |
| 1207 | } |
| 1208 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1209 | return false; |
| 1210 | } |
| 1211 | if (!viewMatrix.invert(&inverseVM)) { |
| 1212 | return false; |
| 1213 | } |
| 1214 | } else { |
| 1215 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1216 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1217 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1218 | // TODO these need to be a geometry processors |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 1219 | sk_sp<GrFragmentProcessor> innerEffect(GrRRectEffect::Make(innerEdgeType, *inner)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1220 | if (!innerEffect) { |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 1224 | sk_sp<GrFragmentProcessor> outerEffect(GrRRectEffect::Make(outerEdgeType, *outer)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1225 | if (!outerEffect) { |
| 1226 | return false; |
| 1227 | } |
| 1228 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1229 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1230 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1231 | |
| 1232 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1233 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1234 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1235 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1236 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1237 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1238 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1239 | return true; |
| 1240 | } |
| 1241 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1242 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1243 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1244 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1245 | const SkMatrix& viewMatrix, |
| 1246 | const SkRRect& outer, |
| 1247 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1248 | ASSERT_SINGLE_OWNER |
| 1249 | RETURN_IF_ABANDONED |
| 1250 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1251 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawDRRect"); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1252 | |
| 1253 | SkASSERT(!outer.isEmpty()); |
| 1254 | SkASSERT(!inner.isEmpty()); |
| 1255 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1256 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1257 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1258 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | SkPath path; |
| 1263 | path.setIsVolatile(true); |
| 1264 | path.addRRect(inner); |
| 1265 | path.addRRect(outer); |
| 1266 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 1267 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1268 | this->internalDrawPath(clip, std::move(paint), aa, viewMatrix, path, GrStyle::SimpleFill()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1269 | } |
| 1270 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1271 | /////////////////////////////////////////////////////////////////////////////// |
| 1272 | |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1273 | static inline bool is_int(float x) { |
| 1274 | return x == (float) sk_float_round2int(x); |
| 1275 | } |
| 1276 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1277 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1278 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1279 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1280 | const SkMatrix& viewMatrix, |
| 1281 | const SkRegion& region, |
| 1282 | const GrStyle& style) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1283 | ASSERT_SINGLE_OWNER |
| 1284 | RETURN_IF_ABANDONED |
| 1285 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1286 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRegion"); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1287 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1288 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1289 | // 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] | 1290 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1291 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
| 1292 | is_int(viewMatrix.getTranslateX()) && |
| 1293 | is_int(viewMatrix.getTranslateY())) { |
| 1294 | aa = GrAA::kNo; |
| 1295 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1296 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1297 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1298 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1299 | SkPath path; |
| 1300 | region.getBoundaryPath(&path); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1301 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1304 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
| 1305 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(std::move(paint), viewMatrix, region, aaType); |
| 1306 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1309 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1310 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1311 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1312 | const SkMatrix& viewMatrix, |
| 1313 | const SkRect& oval, |
| 1314 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1315 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1316 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1317 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1318 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawOval"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1319 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1320 | if (oval.isEmpty()) { |
| 1321 | return; |
| 1322 | } |
| 1323 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1324 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1325 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1326 | AutoCheckFlush acf(this->drawingManager()); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1327 | const SkStrokeRec& stroke = style.strokeRec(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1328 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 1329 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && |
| 1330 | stroke.isFillStyle()) { |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 1331 | gr_instanced::OpAllocator* oa = this->drawingManager()->instancingAllocator(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1332 | std::unique_ptr<GrDrawOp> op( |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 1333 | oa->recordOval(oval, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo)); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1334 | if (op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1335 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1336 | return; |
| 1337 | } |
| 1338 | } |
| 1339 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1340 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1341 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 1342 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1343 | std::unique_ptr<GrDrawOp> op = |
| 1344 | GrOvalOpFactory::MakeOvalOp(std::move(paint), viewMatrix, oval, stroke, shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1345 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1346 | this->addDrawOp(clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1347 | return; |
| 1348 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1349 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1350 | |
| 1351 | SkPath path; |
| 1352 | path.setIsVolatile(true); |
| 1353 | path.addOval(oval); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1354 | this->internalDrawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1357 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1358 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1359 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1360 | const SkMatrix& viewMatrix, |
| 1361 | const SkRect& oval, |
| 1362 | SkScalar startAngle, |
| 1363 | SkScalar sweepAngle, |
| 1364 | bool useCenter, |
| 1365 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1366 | ASSERT_SINGLE_OWNER |
| 1367 | RETURN_IF_ABANDONED |
| 1368 | SkDEBUGCODE(this->validate();) |
| 1369 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawArc"); |
| 1370 | |
| 1371 | AutoCheckFlush acf(this->drawingManager()); |
| 1372 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1373 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1374 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 1375 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1376 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(std::move(paint), |
| 1377 | viewMatrix, |
| 1378 | oval, |
| 1379 | startAngle, |
| 1380 | sweepAngle, |
| 1381 | useCenter, |
| 1382 | style, |
| 1383 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1384 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1385 | this->addDrawOp(clip, std::move(op)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1386 | return; |
| 1387 | } |
| 1388 | } |
| 1389 | SkPath path; |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 1390 | SkPathPriv::CreateDrawArcPath(&path, oval, startAngle, sweepAngle, useCenter, |
| 1391 | style.isSimpleFill()); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1392 | this->internalDrawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1395 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1396 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1397 | const SkMatrix& viewMatrix, |
| 1398 | int imageWidth, |
| 1399 | int imageHeight, |
| 1400 | std::unique_ptr<SkLatticeIter> iter, |
| 1401 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1402 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1403 | RETURN_IF_ABANDONED |
| 1404 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1405 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawImageLattice"); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1406 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1407 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1408 | |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1409 | std::unique_ptr<GrDrawOp> op = GrLatticeOp::MakeNonAA(std::move(paint), viewMatrix, imageWidth, |
| 1410 | imageHeight, std::move(iter), dst); |
| 1411 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1412 | } |
| 1413 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1414 | bool GrRenderTargetContext::prepareForExternalIO(int numSemaphores, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1415 | GrBackendSemaphore* backendSemaphores) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1416 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1417 | RETURN_FALSE_IF_ABANDONED |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1418 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1419 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::prepareForExternalIO"); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1420 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1421 | if (numSemaphores && !this->caps()->fenceSyncSupport()) { |
| 1422 | this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get()); |
| 1423 | return false; |
| 1424 | } |
| 1425 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1426 | SkTArray<sk_sp<GrSemaphore>> semaphores(numSemaphores); |
| 1427 | for (int i = 0; i < numSemaphores; ++i) { |
| 1428 | semaphores.push_back(fContext->resourceProvider()->makeSemaphore(false)); |
Greg Daniel | a2cebd8 | 2017-06-21 16:09:50 -0400 | [diff] [blame] | 1429 | // Create signal semaphore ops and force the final one to call flush. |
| 1430 | bool forceFlush = (i == (numSemaphores - 1)); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1431 | std::unique_ptr<GrOp> signalOp(GrSemaphoreOp::MakeSignal(semaphores.back(), |
Greg Daniel | a2cebd8 | 2017-06-21 16:09:50 -0400 | [diff] [blame] | 1432 | fRenderTargetProxy.get(), |
| 1433 | forceFlush)); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1434 | this->getRTOpList()->addOp(std::move(signalOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 1437 | this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1438 | |
| 1439 | for (int i = 0; i < numSemaphores; ++i) { |
| 1440 | semaphores[i]->setBackendSemaphore(&backendSemaphores[i]); |
| 1441 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1442 | return true; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1445 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1446 | const GrBackendSemaphore* waitSemaphores) { |
| 1447 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1448 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1449 | SkDEBUGCODE(this->validate();) |
| 1450 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::waitOnSemaphores"); |
| 1451 | |
| 1452 | AutoCheckFlush acf(this->drawingManager()); |
| 1453 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1454 | if (numSemaphores && !this->caps()->fenceSyncSupport()) { |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1458 | SkTArray<sk_sp<GrSemaphore>> semaphores(numSemaphores); |
| 1459 | for (int i = 0; i < numSemaphores; ++i) { |
| 1460 | sk_sp<GrSemaphore> sema = fContext->resourceProvider()->wrapBackendSemaphore( |
| 1461 | waitSemaphores[i], kAdopt_GrWrapOwnership); |
| 1462 | std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(sema, fRenderTargetProxy.get())); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1463 | this->getRTOpList()->addOp(std::move(waitOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1464 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1465 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1466 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1467 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1468 | // Can 'path' be drawn as a pair of filled nested rectangles? |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1469 | 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] | 1470 | |
| 1471 | if (path.isInverseFillType()) { |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
| 1475 | // TODO: this restriction could be lifted if we were willing to apply |
| 1476 | // the matrix to all the points individually rather than just to the rect |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 1477 | if (!viewMatrix.rectStaysRect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | |
| 1481 | SkPath::Direction dirs[2]; |
| 1482 | if (!path.isNestedFillRects(rects, dirs)) { |
| 1483 | return false; |
| 1484 | } |
| 1485 | |
| 1486 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 1487 | // The two rects need to be wound opposite to each other |
| 1488 | return false; |
| 1489 | } |
| 1490 | |
| 1491 | // Right now, nested rects where the margin is not the same width |
| 1492 | // all around do not render correctly |
| 1493 | const SkScalar* outer = rects[0].asScalars(); |
| 1494 | const SkScalar* inner = rects[1].asScalars(); |
| 1495 | |
| 1496 | bool allEq = true; |
| 1497 | |
| 1498 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 1499 | bool allGoE1 = margin >= SK_Scalar1; |
| 1500 | |
| 1501 | for (int i = 1; i < 4; ++i) { |
| 1502 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 1503 | if (temp < SK_Scalar1) { |
| 1504 | allGoE1 = false; |
| 1505 | } |
| 1506 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 1507 | allEq = false; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | return allEq || allGoE1; |
| 1512 | } |
| 1513 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1514 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1515 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1516 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1517 | const SkMatrix& viewMatrix, |
| 1518 | const SkPath& path, |
| 1519 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1520 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1521 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1522 | SkDEBUGCODE(this->validate();) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1523 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPath"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1524 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1525 | if (path.isEmpty()) { |
| 1526 | if (path.isInverseFillType()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1527 | this->drawPaint(clip, std::move(paint), viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1528 | } |
| 1529 | return; |
| 1530 | } |
| 1531 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1532 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1533 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1534 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1535 | if (GrAAType::kCoverage == aaType && !style.pathEffect()) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1536 | if (style.isSimpleFill() && !path.isConvex()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1537 | // Concave AA paths are expensive - try to avoid them for special cases |
| 1538 | SkRect rects[2]; |
| 1539 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1540 | if (fills_as_nested_rects(viewMatrix, path, rects)) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 1541 | std::unique_ptr<GrDrawOp> op = |
| 1542 | GrRectOpFactory::MakeAAFillNestedRects(std::move(paint), viewMatrix, rects); |
Brian Salomon | 5f970fe | 2017-06-16 17:30:59 -0400 | [diff] [blame] | 1543 | if (op) { |
| 1544 | this->addDrawOp(clip, std::move(op)); |
bsalomon | 40ef485 | 2016-05-02 13:22:13 -0700 | [diff] [blame] | 1545 | } |
Brian Salomon | 5f970fe | 2017-06-16 17:30:59 -0400 | [diff] [blame] | 1546 | // A null return indicates that there is nothing to draw in this case. |
| 1547 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | SkRect ovalRect; |
| 1551 | bool isOval = path.isOval(&ovalRect); |
| 1552 | |
| 1553 | if (isOval && !path.isInverseFillType()) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 1554 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1555 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeOvalOp( |
| 1556 | std::move(paint), viewMatrix, ovalRect, style.strokeRec(), shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1557 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1558 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1559 | return; |
| 1560 | } |
| 1561 | } |
| 1562 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1563 | |
| 1564 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
| 1565 | // Scratch textures can be recycled after they are returned to the texture |
| 1566 | // cache. This presents a potential hazard for buffered drawing. However, |
| 1567 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 1568 | // OK. |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1569 | this->internalDrawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1572 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, |
| 1573 | const GrUserStencilSettings* ss, |
| 1574 | SkRegion::Op op, |
| 1575 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1576 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1577 | const SkMatrix& viewMatrix, |
| 1578 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1579 | ASSERT_SINGLE_OWNER_PRIV |
| 1580 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1581 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1582 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 1583 | "GrRenderTargetContextPriv::drawAndStencilPath"); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1584 | |
| 1585 | if (path.isEmpty() && path.isInverseFillType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1586 | this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1587 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 1588 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1589 | return true; |
| 1590 | } |
| 1591 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1592 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1593 | |
| 1594 | // An Assumption here is that path renderer would use some form of tweaking |
| 1595 | // the src color (either the input alpha or in the frag shader) to implement |
| 1596 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1597 | // 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] | 1598 | GrAAType aaType = fRenderTargetContext->chooseAAType(aa, GrAllowMixedSamples::kNo); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1599 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1600 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1601 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1602 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 1603 | canDrawArgs.fCaps = fRenderTargetContext->drawingManager()->getContext()->caps(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1604 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1605 | canDrawArgs.fShape = &shape; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1606 | canDrawArgs.fAAType = aaType; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1607 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1608 | |
| 1609 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1610 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 1611 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1612 | if (!pr) { |
| 1613 | return false; |
| 1614 | } |
| 1615 | |
| 1616 | GrPaint paint; |
| 1617 | paint.setCoverageSetOpXPFactory(op, invert); |
| 1618 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1619 | GrPathRenderer::DrawPathArgs args{ |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 1620 | fRenderTargetContext->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1621 | std::move(paint), |
| 1622 | ss, |
| 1623 | fRenderTargetContext, |
| 1624 | &clip, |
| 1625 | &viewMatrix, |
| 1626 | &shape, |
| 1627 | aaType, |
| 1628 | fRenderTargetContext->isGammaCorrect()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1629 | pr->drawPath(args); |
| 1630 | return true; |
| 1631 | } |
| 1632 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1633 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1634 | ASSERT_SINGLE_OWNER_PRIV |
| 1635 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1636 | if (fRenderTargetContext->wasAbandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1637 | return SkBudgeted::kNo; |
| 1638 | } |
| 1639 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1640 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1641 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 1642 | return fRenderTargetContext->fRenderTargetProxy->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1645 | void GrRenderTargetContext::internalDrawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1646 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1647 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1648 | const SkMatrix& viewMatrix, |
| 1649 | const SkPath& path, |
| 1650 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1651 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1652 | RETURN_IF_ABANDONED |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1653 | SkASSERT(!path.isEmpty()); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1654 | GrShape shape; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1655 | // NVPR cannot handle hairlines, so this would get picked up by a different stencil and |
| 1656 | // cover path renderer (i.e. default path renderer). The hairline renderer produces much |
| 1657 | // smoother hairlines than MSAA. |
| 1658 | GrAllowMixedSamples allowMixedSamples = |
| 1659 | style.isSimpleHairline() ? GrAllowMixedSamples::kNo : GrAllowMixedSamples::kYes; |
| 1660 | GrAAType aaType = this->chooseAAType(aa, allowMixedSamples); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1661 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 1662 | canDrawArgs.fCaps = this->drawingManager()->getContext()->caps(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1663 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1664 | canDrawArgs.fShape = &shape; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1665 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1666 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1667 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 1668 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1669 | do { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1670 | shape = GrShape(path, style); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1671 | if (shape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1672 | return; |
| 1673 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1674 | |
| 1675 | canDrawArgs.fAAType = aaType; |
| 1676 | |
| 1677 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1678 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1679 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 1680 | |
| 1681 | if (!pr && shape.style().pathEffect()) { |
| 1682 | // It didn't work above, so try again with the path effect applied. |
| 1683 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1684 | if (shape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1685 | return; |
| 1686 | } |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1687 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1688 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1689 | if (!pr) { |
| 1690 | if (shape.style().applies()) { |
| 1691 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale); |
| 1692 | if (shape.isEmpty()) { |
| 1693 | return; |
| 1694 | } |
| 1695 | } |
| 1696 | // This time, allow SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1697 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1698 | } |
Brian Salomon | 0abc8b4 | 2016-12-13 10:22:54 -0500 | [diff] [blame] | 1699 | if (!pr && GrAATypeIsHW(aaType)) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1700 | // There are exceptional cases where we may wind up falling back to coverage based AA |
| 1701 | // when the target is MSAA (e.g. through disabling path renderers via GrContextOptions). |
| 1702 | aaType = GrAAType::kCoverage; |
| 1703 | } else { |
| 1704 | break; |
| 1705 | } |
| 1706 | } while(true); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1707 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1708 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1709 | #ifdef SK_DEBUG |
| 1710 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 1711 | #endif |
| 1712 | return; |
| 1713 | } |
| 1714 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 1715 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1716 | std::move(paint), |
| 1717 | &GrUserStencilSettings::kUnused, |
| 1718 | this, |
| 1719 | &clip, |
| 1720 | &viewMatrix, |
| 1721 | &shape, |
| 1722 | aaType, |
| 1723 | this->isGammaCorrect()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1724 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1727 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 1728 | *bounds = op->bounds(); |
| 1729 | if (op->hasZeroArea()) { |
| 1730 | if (op->hasAABloat()) { |
| 1731 | bounds->outset(0.5f, 0.5f); |
| 1732 | } else { |
| 1733 | // We don't know which way the particular GPU will snap lines or points at integer |
| 1734 | // coords. So we ensure that the bounds is large enough for either snap. |
| 1735 | SkRect before = *bounds; |
| 1736 | bounds->roundOut(bounds); |
| 1737 | if (bounds->fLeft == before.fLeft) { |
| 1738 | bounds->fLeft -= 1; |
| 1739 | } |
| 1740 | if (bounds->fTop == before.fTop) { |
| 1741 | bounds->fTop -= 1; |
| 1742 | } |
| 1743 | if (bounds->fRight == before.fRight) { |
| 1744 | bounds->fRight += 1; |
| 1745 | } |
| 1746 | if (bounds->fBottom == before.fBottom) { |
| 1747 | bounds->fBottom += 1; |
| 1748 | } |
| 1749 | } |
| 1750 | } |
| 1751 | } |
| 1752 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1753 | uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1754 | ASSERT_SINGLE_OWNER |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1755 | if (this->drawingManager()->wasAbandoned()) { |
| 1756 | return SK_InvalidUniqueID; |
| 1757 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1758 | SkDEBUGCODE(this->validate();) |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1759 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::addDrawOp"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 1760 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1761 | // Setup clip |
| 1762 | SkRect bounds; |
| 1763 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1764 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1765 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
| 1766 | if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA, |
| 1767 | fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip, |
| 1768 | &bounds)) { |
| 1769 | return SK_InvalidUniqueID; |
| 1770 | } |
| 1771 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1772 | if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil || |
| 1773 | appliedClip.hasStencilClip()) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 1774 | // This forces instantiation of the render target. |
| 1775 | GrRenderTarget* rt = this->accessRenderTarget(); |
| 1776 | if (!rt) { |
| 1777 | return SK_InvalidUniqueID; |
| 1778 | } |
| 1779 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1780 | if (!fContext->resourceProvider()->attachStencilAttachment(rt)) { |
| 1781 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 1782 | return SK_InvalidUniqueID; |
| 1783 | } |
| 1784 | } |
| 1785 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1786 | GrXferProcessor::DstProxy dstProxy; |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 1787 | if (op->finalize(*this->caps(), &appliedClip) == GrDrawOp::RequiresDstTexture::kYes) { |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1788 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, op->bounds(), &dstProxy)) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1789 | return SK_InvalidUniqueID; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1794 | return this->getRTOpList()->addOp(std::move(op), *this->caps(), |
| 1795 | std::move(appliedClip), dstProxy); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1796 | } |
| 1797 | |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 1798 | uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipelineBuilder, |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 1799 | const GrClip& clip, |
| 1800 | std::unique_ptr<GrLegacyMeshDrawOp> op) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1801 | ASSERT_SINGLE_OWNER |
| 1802 | if (this->drawingManager()->wasAbandoned()) { |
| 1803 | return SK_InvalidUniqueID; |
| 1804 | } |
| 1805 | SkDEBUGCODE(this->validate();) |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 1806 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::addLegacyMeshDrawOp"); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1807 | |
| 1808 | // Setup clip |
| 1809 | SkRect bounds; |
| 1810 | op_bounds(&bounds, op.get()); |
| 1811 | GrAppliedClip appliedClip; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1812 | if (!clip.apply(fContext, this, pipelineBuilder.isHWAntialias(), |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1813 | pipelineBuilder.hasUserStencilSettings(), &appliedClip, &bounds)) { |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1814 | return SK_InvalidUniqueID; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | // This forces instantiation of the render target. Pipeline creation is moving to flush time |
| 1818 | // by which point instantiation must have occurred anyway. |
| 1819 | GrRenderTarget* rt = this->accessRenderTarget(); |
| 1820 | if (!rt) { |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1821 | return SK_InvalidUniqueID; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | GrResourceProvider* resourceProvider = fContext->resourceProvider(); |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 1825 | bool usesStencil = pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip(); |
| 1826 | if (usesStencil) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1827 | if (!resourceProvider->attachStencilAttachment(this->accessRenderTarget())) { |
| 1828 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1829 | return SK_InvalidUniqueID; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1833 | bool isMixedSamples = GrFSAAType::kMixedSamples == this->fsaaType() && |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 1834 | (pipelineBuilder.isHWAntialias() || usesStencil); |
| 1835 | |
| 1836 | GrColor overrideColor; |
| 1837 | GrProcessorSet::Analysis analysis = op->analyzeUpdateAndRecordProcessors( |
| 1838 | &pipelineBuilder, &appliedClip, isMixedSamples, *this->caps(), &overrideColor); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1839 | |
| 1840 | GrPipeline::InitArgs args; |
| 1841 | pipelineBuilder.getPipelineInitArgs(&args); |
| 1842 | args.fAppliedClip = &appliedClip; |
| 1843 | args.fRenderTarget = rt; |
| 1844 | args.fCaps = this->caps(); |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 1845 | args.fResourceProvider = resourceProvider; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1846 | |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 1847 | if (analysis.requiresDstTexture()) { |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1848 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, bounds, &args.fDstProxy)) { |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1849 | return SK_InvalidUniqueID; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1850 | } |
| 1851 | } |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 1852 | op->initPipeline(args, analysis, overrideColor); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 1853 | |
| 1854 | // Add the pipeline dependencies on textures, etc before recording this op. |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 1855 | op->addDependenciesTo(this->getOpList(), *this->caps()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 1856 | |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1857 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1858 | return this->getRTOpList()->addOp(std::move(op), *this->caps()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1859 | } |
| 1860 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1861 | bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1862 | const SkRect& opBounds, |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1863 | GrXferProcessor::DstProxy* dstProxy) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1864 | if (this->caps()->textureBarrierSupport()) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1865 | if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1866 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 1867 | // will be responsible to detect this situation and request a texture barrier. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1868 | dstProxy->setProxy(sk_ref_sp(texProxy)); |
| 1869 | dstProxy->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1870 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1871 | } |
| 1872 | } |
| 1873 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1874 | SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1875 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1876 | SkIRect clippedRect; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1877 | clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1878 | SkIRect drawIBounds; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1879 | opBounds.roundOut(&drawIBounds); |
Brian Salomon | 859621f | 2017-03-16 09:21:54 -0400 | [diff] [blame] | 1880 | // Cover up for any precision issues by outsetting the op bounds a pixel in each direction. |
| 1881 | drawIBounds.outset(1, 1); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1882 | if (!clippedRect.intersect(drawIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1883 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1884 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1885 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1886 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 1890 | // have per-sample dst values by making the copy multisampled. |
| 1891 | GrSurfaceDesc desc; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1892 | bool rectsMustMatch = false; |
| 1893 | bool disallowSubrect = false; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1894 | if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &rectsMustMatch, &disallowSubrect)) { |
| 1895 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1896 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1897 | desc.fConfig = rtProxy->config(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1898 | } |
| 1899 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1900 | if (!disallowSubrect) { |
| 1901 | copyRect = clippedRect; |
| 1902 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1903 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1904 | SkIPoint dstPoint, dstOffset; |
| 1905 | SkBackingFit fit; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1906 | if (rectsMustMatch) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1907 | SkASSERT(desc.fOrigin == rtProxy->origin()); |
| 1908 | desc.fWidth = rtProxy->width(); |
| 1909 | desc.fHeight = rtProxy->height(); |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1910 | dstPoint = {copyRect.fLeft, copyRect.fTop}; |
| 1911 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1912 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1913 | } else { |
| 1914 | desc.fWidth = copyRect.width(); |
| 1915 | desc.fHeight = copyRect.height(); |
| 1916 | dstPoint = {0, 0}; |
| 1917 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1918 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1919 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1920 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1921 | sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeDeferredSurfaceContext( |
| 1922 | desc, |
| 1923 | fit, |
| 1924 | SkBudgeted::kYes); |
| 1925 | if (!sContext) { |
| 1926 | SkDebugf("setupDstTexture: surfaceContext creation failed.\n"); |
| 1927 | return false; |
| 1928 | } |
| 1929 | |
| 1930 | if (!sContext->copy(rtProxy, copyRect, dstPoint)) { |
| 1931 | SkDebugf("setupDstTexture: copy failed.\n"); |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1935 | dstProxy->setProxy(sContext->asTextureProxyRef()); |
| 1936 | dstProxy->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1937 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1938 | } |