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