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