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