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" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 10 | #include "GrDrawContext.h" |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 11 | #include "GrDrawContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 12 | #include "GrDrawingManager.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 13 | #include "GrOvalRenderer.h" |
| 14 | #include "GrPathRenderer.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
| 16 | #include "GrRenderTargetPriv.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 17 | #include "GrResourceProvider.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 18 | #include "SkSurfacePriv.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 19 | |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 20 | #include "batches/GrBatch.h" |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 21 | #include "batches/GrClearBatch.h" |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 22 | #include "batches/GrDrawAtlasBatch.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 23 | #include "batches/GrDrawVerticesBatch.h" |
joshualitt | 7fc2a26 | 2015-08-10 10:30:14 -0700 | [diff] [blame] | 24 | #include "batches/GrRectBatchFactory.h" |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 25 | #include "batches/GrNinePatch.h" // TODO Factory |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 26 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 27 | #include "effects/GrRRectEffect.h" |
| 28 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 29 | #include "instanced/InstancedRendering.h" |
| 30 | |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 31 | #include "text/GrAtlasTextContext.h" |
| 32 | #include "text/GrStencilAndCoverTextContext.h" |
| 33 | |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 34 | #include "../private/GrAuditTrail.h" |
| 35 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 36 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 37 | #define ASSERT_SINGLE_OWNER \ |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 38 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 39 | #define ASSERT_SINGLE_OWNER_PRIV \ |
| 40 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSingleOwner);) |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 41 | #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 42 | #define RETURN_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandoned()) { return; } |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 43 | #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } |
| 44 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandoned()) { return false; } |
| 45 | #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 46 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 47 | using gr_instanced::InstancedRendering; |
| 48 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 49 | class AutoCheckFlush { |
| 50 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 51 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 52 | SkASSERT(fDrawingManager); |
| 53 | } |
| 54 | ~AutoCheckFlush() { fDrawingManager->getContext()->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 55 | |
| 56 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 57 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 60 | bool GrDrawContext::wasAbandoned() const { |
| 61 | return fDrawingManager->wasAbandoned(); |
| 62 | } |
| 63 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 64 | // In MDB mode the reffing of the 'getLastDrawTarget' call's result allows in-progress |
| 65 | // drawTargets to be picked up and added to by drawContexts lower in the call |
| 66 | // stack. When this occurs with a closed drawTarget, a new one will be allocated |
| 67 | // when the drawContext attempts to use it (via getDrawTarget). |
joshualitt | 1b39f43 | 2016-02-11 06:46:52 -0800 | [diff] [blame] | 68 | GrDrawContext::GrDrawContext(GrContext* context, |
| 69 | GrDrawingManager* drawingMgr, |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 70 | sk_sp<GrRenderTarget> rt, |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 71 | const SkSurfaceProps* surfaceProps, |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 72 | GrAuditTrail* auditTrail, |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 73 | GrSingleOwner* singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 74 | : fDrawingManager(drawingMgr) |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 75 | , fRenderTarget(std::move(rt)) |
| 76 | , fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget())) |
joshualitt | 1b39f43 | 2016-02-11 06:46:52 -0800 | [diff] [blame] | 77 | , fContext(context) |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 78 | , fInstancedPipelineInfo(fRenderTarget.get()) |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 79 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 80 | , fAuditTrail(auditTrail) |
joshualitt | 6d0872d | 2016-01-11 08:27:48 -0800 | [diff] [blame] | 81 | #ifdef SK_DEBUG |
| 82 | , fSingleOwner(singleOwner) |
| 83 | #endif |
| 84 | { |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 85 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 86 | } |
| 87 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 88 | #ifdef SK_DEBUG |
| 89 | void GrDrawContext::validate() const { |
| 90 | SkASSERT(fRenderTarget); |
| 91 | ASSERT_OWNED_RESOURCE(fRenderTarget); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 92 | |
| 93 | if (fDrawTarget && !fDrawTarget->isClosed()) { |
| 94 | SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); |
| 95 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 96 | } |
| 97 | #endif |
| 98 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 99 | GrDrawContext::~GrDrawContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 100 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 101 | SkSafeUnref(fDrawTarget); |
| 102 | } |
| 103 | |
| 104 | GrDrawTarget* GrDrawContext::getDrawTarget() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 105 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 106 | SkDEBUGCODE(this->validate();) |
| 107 | |
| 108 | if (!fDrawTarget || fDrawTarget->isClosed()) { |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 109 | fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | return fDrawTarget; |
| 113 | } |
| 114 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 115 | bool GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 116 | ASSERT_SINGLE_OWNER |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 117 | RETURN_FALSE_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 118 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 119 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::copySurface"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 120 | |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 121 | return this->getDrawTarget()->copySurface(fRenderTarget.get(), src, srcRect, dstPoint); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 122 | } |
| 123 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 124 | void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 125 | const SkPaint& skPaint, |
| 126 | const SkMatrix& viewMatrix, |
| 127 | const char text[], size_t byteLength, |
| 128 | SkScalar x, SkScalar y, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 129 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 130 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 131 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 132 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 133 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 134 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 135 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 136 | } |
| 137 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 138 | fAtlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps, |
| 139 | text, byteLength, x, y, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 140 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 141 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 142 | void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 143 | const SkPaint& skPaint, |
| 144 | const SkMatrix& viewMatrix, |
| 145 | const char text[], size_t byteLength, |
| 146 | const SkScalar pos[], int scalarsPerPosition, |
| 147 | const SkPoint& offset, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 148 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 149 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 150 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 151 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPosText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 152 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 153 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 154 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 155 | } |
| 156 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 157 | fAtlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, |
| 158 | fSurfaceProps, text, byteLength, pos, scalarsPerPosition, |
| 159 | offset, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 160 | |
| 161 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 162 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 163 | void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 164 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 165 | SkScalar x, SkScalar y, |
| 166 | SkDrawFilter* filter, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 167 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 168 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 169 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 170 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawTextBlob"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 171 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 172 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 173 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 174 | } |
| 175 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 176 | fAtlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob, |
| 177 | x, y, filter, clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 178 | } |
| 179 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 180 | void GrDrawContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 181 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 182 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 183 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 184 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::discard"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 185 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 186 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 187 | this->getDrawTarget()->discard(fRenderTarget.get()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 188 | } |
| 189 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 190 | void GrDrawContext::clear(const SkIRect* rect, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 191 | const GrColor color, |
| 192 | bool canIgnoreRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 193 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 194 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 195 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 196 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 197 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 198 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 199 | |
| 200 | const SkIRect rtRect = SkIRect::MakeWH(this->width(), this->height()); |
| 201 | SkIRect clippedRect; |
| 202 | if (!rect || |
| 203 | (canIgnoreRect && fContext->caps()->fullClearIsFree()) || |
| 204 | rect->contains(rtRect)) { |
| 205 | rect = &rtRect; |
| 206 | } else { |
| 207 | clippedRect = *rect; |
| 208 | if (!clippedRect.intersect(rtRect)) { |
| 209 | return; |
| 210 | } |
| 211 | rect = &clippedRect; |
| 212 | } |
| 213 | |
| 214 | if (fContext->caps()->useDrawInsteadOfClear()) { |
| 215 | // This works around a driver bug with clear by drawing a rect instead. |
| 216 | // The driver will ignore a clear if it is the only thing rendered to a |
| 217 | // target before the target is read. |
| 218 | if (rect == &rtRect) { |
| 219 | this->discard(); |
| 220 | } |
| 221 | |
| 222 | GrPaint paint; |
| 223 | paint.setColor4f(GrColor4f::FromGrColor(color)); |
| 224 | paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); |
| 225 | |
| 226 | this->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(*rect)); |
| 227 | } else { |
| 228 | sk_sp<GrBatch> batch = GrClearBatch::Make(*rect, color, this->accessRenderTarget()); |
| 229 | this->getDrawTarget()->addBatch(std::move(batch)); |
| 230 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 234 | void GrDrawContext::drawPaint(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 235 | const GrPaint& origPaint, |
| 236 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 237 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 238 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 239 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 240 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 241 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 242 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 243 | // don't overflow fixed-point implementations |
| 244 | SkRect r; |
| 245 | r.setLTRB(0, 0, |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 246 | SkIntToScalar(fRenderTarget->width()), |
| 247 | SkIntToScalar(fRenderTarget->height())); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 248 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
| 249 | |
| 250 | // by definition this fills the entire clip, no need for AA |
| 251 | if (paint->isAntiAlias()) { |
| 252 | paint.writable()->setAntiAlias(false); |
| 253 | } |
| 254 | |
| 255 | bool isPerspective = viewMatrix.hasPerspective(); |
| 256 | |
| 257 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 258 | // map the four corners and bound them with a new rect. This will not |
| 259 | // produce a correct result for some perspective matrices. |
| 260 | if (!isPerspective) { |
| 261 | SkMatrix inverse; |
| 262 | if (!viewMatrix.invert(&inverse)) { |
| 263 | SkDebugf("Could not invert matrix\n"); |
| 264 | return; |
| 265 | } |
| 266 | inverse.mapRect(&r); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 267 | this->drawRect(clip, *paint, viewMatrix, r); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 268 | } else { |
| 269 | SkMatrix localMatrix; |
| 270 | if (!viewMatrix.invert(&localMatrix)) { |
| 271 | SkDebugf("Could not invert matrix\n"); |
| 272 | return; |
| 273 | } |
| 274 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 275 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 276 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 277 | this->drawNonAAFilledRect(clip, *paint, SkMatrix::I(), r, nullptr, &localMatrix, nullptr); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 281 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 282 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 283 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 284 | } |
| 285 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 286 | static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { |
| 287 | return viewMatrix.preservesRightAngles(); |
| 288 | } |
| 289 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 290 | static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt, |
| 291 | bool* useHWAA = nullptr) { |
| 292 | if (!paint.isAntiAlias()) { |
| 293 | if (useHWAA) { |
| 294 | *useHWAA = false; |
| 295 | } |
| 296 | return false; |
| 297 | } else { |
| 298 | if (useHWAA) { |
| 299 | *useHWAA = rt->isUnifiedMultisampled(); |
| 300 | } |
| 301 | return !rt->isUnifiedMultisampled(); |
| 302 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 303 | } |
| 304 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 305 | bool GrDrawContext::drawFilledRect(const GrClip& clip, |
| 306 | const GrPaint& paint, |
| 307 | const SkMatrix& viewMatrix, |
| 308 | const SkRect& rect, |
| 309 | const GrUserStencilSettings* ss) { |
| 310 | |
| 311 | SkAutoTUnref<GrDrawBatch> batch; |
| 312 | bool useHWAA; |
| 313 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 314 | if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 315 | batch.reset(ir->recordRect(rect, viewMatrix, paint.getColor(), |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 316 | paint.isAntiAlias(), fInstancedPipelineInfo, |
| 317 | &useHWAA)); |
| 318 | if (batch) { |
| 319 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 320 | if (ss) { |
| 321 | pipelineBuilder.setUserStencil(ss); |
| 322 | } |
| 323 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 324 | return true; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 327 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 328 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 329 | // The fill path can handle rotation but not skew. |
| 330 | if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 331 | SkRect devBoundRect; |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 332 | viewMatrix.mapRect(&devBoundRect, rect); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 333 | |
| 334 | batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix, |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 335 | rect, devBoundRect)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 336 | if (batch) { |
| 337 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 338 | if (ss) { |
| 339 | pipelineBuilder.setUserStencil(ss); |
| 340 | } |
| 341 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 342 | return true; |
| 343 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 344 | } |
| 345 | } else { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 346 | this->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullptr, ss); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 347 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 348 | } |
| 349 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 350 | return false; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 351 | } |
| 352 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 353 | void GrDrawContext::drawRect(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 354 | const GrPaint& paint, |
| 355 | const SkMatrix& viewMatrix, |
| 356 | const SkRect& rect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 357 | const GrStyle* style) { |
| 358 | if (!style) { |
| 359 | style = &GrStyle::SimpleFill(); |
| 360 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 361 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 362 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 363 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 364 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 365 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 366 | // Path effects should've been devolved to a path in SkGpuDevice |
| 367 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 368 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 369 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 370 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 371 | const SkStrokeRec& stroke = style->strokeRec(); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 372 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
| 373 | |
| 374 | if (!fContext->caps()->useDrawInsteadOfClear()) { |
| 375 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother |
| 376 | // checking cases where the RT is fully inside a stroke. |
| 377 | SkRect rtRect; |
| 378 | fRenderTarget->getBoundsRect(&rtRect); |
| 379 | // Does the clip contain the entire RT? |
| 380 | if (clip.quickContains(rtRect)) { |
| 381 | SkMatrix invM; |
| 382 | if (!viewMatrix.invert(&invM)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 383 | return; |
| 384 | } |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 385 | // Does the rect bound the RT? |
| 386 | SkPoint srcSpaceRTQuad[4]; |
| 387 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 388 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 389 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 390 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 391 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 392 | // Will it blend? |
| 393 | GrColor clearColor; |
| 394 | if (paint.isConstantBlendedColor(&clearColor)) { |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 395 | this->clear(nullptr, clearColor, true); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 401 | |
| 402 | if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { |
| 403 | return; |
| 404 | } |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 405 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 406 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 407 | if ((!rect.width() || !rect.height()) && |
| 408 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 409 | SkScalar r = stroke.getWidth() / 2; |
| 410 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 411 | switch (stroke.getJoin()) { |
| 412 | case SkPaint::kMiter_Join: |
| 413 | this->drawRect(clip, paint, viewMatrix, |
| 414 | {rect.fLeft - r, rect.fTop - r, |
| 415 | rect.fRight + r, rect.fBottom + r}, |
| 416 | &GrStyle::SimpleFill()); |
| 417 | return; |
| 418 | case SkPaint::kRound_Join: |
| 419 | // Raster draws nothing when both dimensions are empty. |
| 420 | if (rect.width() || rect.height()){ |
| 421 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
| 422 | this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle::SimpleFill()); |
| 423 | return; |
| 424 | } |
| 425 | case SkPaint::kBevel_Join: |
| 426 | if (!rect.width()) { |
| 427 | this->drawRect(clip, paint, viewMatrix, |
| 428 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 429 | &GrStyle::SimpleFill()); |
| 430 | } else { |
| 431 | this->drawRect(clip, paint, viewMatrix, |
| 432 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 433 | &GrStyle::SimpleFill()); |
| 434 | } |
| 435 | return; |
| 436 | } |
| 437 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 438 | |
| 439 | bool useHWAA; |
| 440 | bool snapToPixelCenters = false; |
| 441 | SkAutoTUnref<GrDrawBatch> batch; |
| 442 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 443 | GrColor color = paint.getColor(); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 444 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 445 | // The stroke path needs the rect to remain axis aligned (no rotation or skew). |
| 446 | if (viewMatrix.rectStaysRect()) { |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 447 | batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, stroke)); |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 448 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 449 | } else { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 450 | // 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] | 451 | // 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] | 452 | // when MSAA is enabled because it can cause ugly artifacts. |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 453 | snapToPixelCenters = stroke.getStyle() == SkStrokeRec::kHairline_Style && |
| 454 | !fRenderTarget->isUnifiedMultisampled(); |
| 455 | batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, |
| 456 | stroke, snapToPixelCenters)); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 457 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 458 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 459 | if (batch) { |
| 460 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 461 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 462 | if (snapToPixelCenters) { |
| 463 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
| 464 | snapToPixelCenters); |
| 465 | } |
| 466 | |
| 467 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 468 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 469 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 470 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 471 | |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 472 | SkPath path; |
| 473 | path.setIsVolatile(true); |
| 474 | path.addRect(rect); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 475 | this->internalDrawPath(clip, paint, viewMatrix, path, *style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 476 | } |
| 477 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 478 | void GrDrawContextPriv::clearStencilClip(const SkIRect& rect, bool insideClip) { |
| 479 | ASSERT_SINGLE_OWNER_PRIV |
| 480 | RETURN_IF_ABANDONED_PRIV |
| 481 | SkDEBUGCODE(fDrawContext->validate();) |
| 482 | GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::clearStencilClip"); |
| 483 | |
| 484 | AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 485 | fDrawContext->getDrawTarget()->clearStencilClip(rect, insideClip, |
| 486 | fDrawContext->accessRenderTarget()); |
| 487 | } |
| 488 | |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame^] | 489 | void GrDrawContextPriv::stencilPath(const GrClip& clip, |
| 490 | const GrUserStencilSettings* ss, |
| 491 | bool useHWAA, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 492 | const SkMatrix& viewMatrix, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame^] | 493 | const GrPath* path) { |
| 494 | fDrawContext->getDrawTarget()->stencilPath(fDrawContext, clip, ss, useHWAA, viewMatrix, path); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void GrDrawContextPriv::stencilRect(const GrFixedClip& clip, |
| 498 | const GrUserStencilSettings* ss, |
csmartdalton | 656dbe4 | 2016-06-10 12:32:57 -0700 | [diff] [blame] | 499 | bool useHWAA, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 500 | const SkMatrix& viewMatrix, |
| 501 | const SkRect& rect) { |
| 502 | ASSERT_SINGLE_OWNER_PRIV |
| 503 | RETURN_IF_ABANDONED_PRIV |
| 504 | SkDEBUGCODE(fDrawContext->validate();) |
| 505 | GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencilRect"); |
| 506 | |
| 507 | AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 508 | |
| 509 | GrPaint paint; |
csmartdalton | 656dbe4 | 2016-06-10 12:32:57 -0700 | [diff] [blame] | 510 | paint.setAntiAlias(useHWAA); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 511 | paint.setXPFactory(GrDisableColorXPFactory::Make()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 512 | |
csmartdalton | 656dbe4 | 2016-06-10 12:32:57 -0700 | [diff] [blame] | 513 | SkASSERT(!useHWAA || fDrawContext->isStencilBufferMultisampled()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 514 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 515 | fDrawContext->drawFilledRect(clip, paint, viewMatrix, rect, ss); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 516 | } |
| 517 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 518 | bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 519 | const GrUserStencilSettings* ss, |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 520 | SkRegion::Op op, |
| 521 | bool invert, |
| 522 | bool doAA, |
| 523 | const SkMatrix& viewMatrix, |
| 524 | const SkRect& rect) { |
| 525 | ASSERT_SINGLE_OWNER_PRIV |
| 526 | RETURN_FALSE_IF_ABANDONED_PRIV |
| 527 | SkDEBUGCODE(fDrawContext->validate();) |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 528 | GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAndStencilRect"); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 529 | |
| 530 | AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 531 | |
| 532 | GrPaint paint; |
| 533 | paint.setAntiAlias(doAA); |
| 534 | paint.setCoverageSetOpXPFactory(op, invert); |
| 535 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 536 | if (fDrawContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 537 | return true; |
| 538 | } |
| 539 | |
| 540 | SkPath path; |
| 541 | path.setIsVolatile(true); |
| 542 | path.addRect(rect); |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 543 | return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 544 | } |
| 545 | |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 546 | void GrDrawContext::fillRectToRect(const GrClip& clip, |
| 547 | const GrPaint& paint, |
| 548 | const SkMatrix& viewMatrix, |
| 549 | const SkRect& rectToDraw, |
| 550 | const SkRect& localRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 551 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 552 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 553 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 554 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 555 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 556 | AutoCheckFlush acf(fDrawingManager); |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 557 | SkAutoTUnref<GrDrawBatch> batch; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 558 | bool useHWAA; |
| 559 | |
| 560 | if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 561 | batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), localRect, |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 562 | paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); |
| 563 | if (batch) { |
| 564 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 565 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 566 | return; |
| 567 | } |
| 568 | } |
| 569 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 570 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 571 | view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 572 | batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw, |
| 573 | localRect)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 574 | if (batch) { |
| 575 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 576 | this->drawBatch(pipelineBuilder, clip, batch); |
| 577 | return; |
| 578 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 579 | } else { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 580 | this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, &localRect, |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 581 | nullptr, nullptr); |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 582 | } |
| 583 | |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 584 | } |
| 585 | |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 586 | void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
| 587 | const GrPaint& paint, |
| 588 | const SkMatrix& viewMatrix, |
| 589 | const SkRect& rectToDraw, |
| 590 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 591 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 592 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 593 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 594 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatrix"); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 595 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 596 | AutoCheckFlush acf(fDrawingManager); |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 597 | SkAutoTUnref<GrDrawBatch> batch; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 598 | bool useHWAA; |
| 599 | |
| 600 | if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 601 | batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), localMatrix, |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 602 | paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); |
| 603 | if (batch) { |
| 604 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 605 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 606 | return; |
| 607 | } |
| 608 | } |
| 609 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 610 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 611 | view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 612 | batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 613 | rectToDraw)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 614 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 615 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 616 | } else { |
msarett | ba3880f | 2016-07-12 18:48:21 -0700 | [diff] [blame] | 617 | this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, nullptr, |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 618 | &localMatrix, nullptr); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 619 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 620 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 621 | } |
| 622 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 623 | void GrDrawContext::drawVertices(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 624 | const GrPaint& paint, |
| 625 | const SkMatrix& viewMatrix, |
| 626 | GrPrimitiveType primitiveType, |
| 627 | int vertexCount, |
| 628 | const SkPoint positions[], |
| 629 | const SkPoint texCoords[], |
| 630 | const GrColor colors[], |
| 631 | const uint16_t indices[], |
| 632 | int indexCount) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 633 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 634 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 635 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 636 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawVertices"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 637 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 638 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 639 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 640 | // TODO clients should give us bounds |
| 641 | SkRect bounds; |
| 642 | if (!bounds.setBoundsCheck(positions, vertexCount)) { |
| 643 | SkDebugf("drawVertices call empty bounds\n"); |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | viewMatrix.mapRect(&bounds); |
| 648 | |
| 649 | // If we don't have AA then we outset for a half pixel in each direction to account for |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 650 | // snapping. We also do this for the "hair" primitive types: lines and points since they have |
| 651 | // a 1 pixel thickness in device space. |
| 652 | if (!paint.isAntiAlias() || GrIsPrimTypeLines(primitiveType) || |
| 653 | kPoints_GrPrimitiveType == primitiveType) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 654 | bounds.outset(0.5f, 0.5f); |
| 655 | } |
| 656 | |
bsalomon | d92b419 | 2016-06-30 07:59:23 -0700 | [diff] [blame] | 657 | SkAutoTUnref<GrDrawBatch> batch(new GrDrawVerticesBatch(paint.getColor(), |
| 658 | primitiveType, viewMatrix, positions, |
| 659 | vertexCount, indices, indexCount, |
| 660 | colors, texCoords, bounds)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 661 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 662 | GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 663 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /////////////////////////////////////////////////////////////////////////////// |
| 667 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 668 | void GrDrawContext::drawAtlas(const GrClip& clip, |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 669 | const GrPaint& paint, |
| 670 | const SkMatrix& viewMatrix, |
| 671 | int spriteCount, |
| 672 | const SkRSXform xform[], |
| 673 | const SkRect texRect[], |
| 674 | const SkColor colors[]) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 675 | ASSERT_SINGLE_OWNER |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 676 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 677 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 678 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 679 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 680 | AutoCheckFlush acf(fDrawingManager); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 681 | |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame] | 682 | SkAutoTUnref<GrDrawBatch> batch(new GrDrawAtlasBatch(paint.getColor(), viewMatrix, spriteCount, |
| 683 | xform, texRect, colors)); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 684 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 685 | GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 686 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /////////////////////////////////////////////////////////////////////////////// |
| 690 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 691 | void GrDrawContext::drawRRect(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 692 | const GrPaint& paint, |
| 693 | const SkMatrix& viewMatrix, |
| 694 | const SkRRect& rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 695 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 696 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 697 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 698 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 699 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 700 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 701 | if (rrect.isEmpty()) { |
| 702 | return; |
| 703 | } |
| 704 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 705 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 706 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 707 | AutoCheckFlush acf(fDrawingManager); |
| 708 | const SkStrokeRec stroke = style.strokeRec(); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 709 | bool useHWAA; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 710 | |
| 711 | if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) { |
| 712 | InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
| 713 | SkAutoTUnref<GrDrawBatch> batch(ir->recordRRect(rrect, viewMatrix, paint.getColor(), |
| 714 | paint.isAntiAlias(), fInstancedPipelineInfo, |
| 715 | &useHWAA)); |
| 716 | if (batch) { |
| 717 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 718 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 719 | return; |
| 720 | } |
| 721 | } |
| 722 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 723 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 724 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 725 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.getColor(), |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 726 | viewMatrix, |
| 727 | rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 728 | stroke, |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 729 | shaderCaps)); |
| 730 | if (batch) { |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 731 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 732 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 733 | return; |
| 734 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 735 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 736 | |
| 737 | SkPath path; |
| 738 | path.setIsVolatile(true); |
| 739 | path.addRRect(rrect); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 740 | this->internalDrawPath(clip, paint, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 741 | } |
| 742 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 743 | bool GrDrawContext::drawFilledDRRect(const GrClip& clip, |
| 744 | const GrPaint& paintIn, |
| 745 | const SkMatrix& viewMatrix, |
| 746 | const SkRRect& origOuter, |
| 747 | const SkRRect& origInner) { |
| 748 | SkASSERT(!origInner.isEmpty()); |
| 749 | SkASSERT(!origOuter.isEmpty()); |
| 750 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 751 | if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
| 752 | bool useHWAA; |
| 753 | SkAutoTUnref<GrDrawBatch> batch(ir->recordDRRect(origOuter, origInner, viewMatrix, |
| 754 | paintIn.getColor(), paintIn.isAntiAlias(), |
| 755 | fInstancedPipelineInfo, &useHWAA)); |
| 756 | if (batch) { |
| 757 | GrPipelineBuilder pipelineBuilder(paintIn, useHWAA); |
| 758 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 759 | return true; |
| 760 | } |
| 761 | } |
| 762 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 763 | bool applyAA = paintIn.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled(); |
| 764 | |
| 765 | GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType : |
| 766 | kInverseFillBW_GrProcessorEdgeType; |
| 767 | GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
| 768 | kFillBW_GrProcessorEdgeType; |
| 769 | |
| 770 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 771 | SkMatrix inverseVM; |
| 772 | if (!viewMatrix.isIdentity()) { |
| 773 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 774 | return false; |
| 775 | } |
| 776 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 777 | return false; |
| 778 | } |
| 779 | if (!viewMatrix.invert(&inverseVM)) { |
| 780 | return false; |
| 781 | } |
| 782 | } else { |
| 783 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 784 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 785 | |
| 786 | GrPaint grPaint(paintIn); |
| 787 | grPaint.setAntiAlias(false); |
| 788 | |
| 789 | // TODO these need to be a geometry processors |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 790 | sk_sp<GrFragmentProcessor> innerEffect(GrRRectEffect::Make(innerEdgeType, *inner)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 791 | if (!innerEffect) { |
| 792 | return false; |
| 793 | } |
| 794 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 795 | sk_sp<GrFragmentProcessor> outerEffect(GrRRectEffect::Make(outerEdgeType, *outer)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 796 | if (!outerEffect) { |
| 797 | return false; |
| 798 | } |
| 799 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 800 | grPaint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 801 | grPaint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 802 | |
| 803 | SkRect bounds = outer->getBounds(); |
| 804 | if (applyAA) { |
| 805 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 806 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 807 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 808 | this->fillRectWithLocalMatrix(clip, grPaint, SkMatrix::I(), bounds, inverseVM); |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | void GrDrawContext::drawDRRect(const GrClip& clip, |
| 813 | const GrPaint& paint, |
| 814 | const SkMatrix& viewMatrix, |
| 815 | const SkRRect& outer, |
| 816 | const SkRRect& inner) { |
| 817 | ASSERT_SINGLE_OWNER |
| 818 | RETURN_IF_ABANDONED |
| 819 | SkDEBUGCODE(this->validate();) |
| 820 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect"); |
| 821 | |
| 822 | SkASSERT(!outer.isEmpty()); |
| 823 | SkASSERT(!inner.isEmpty()); |
| 824 | |
| 825 | AutoCheckFlush acf(fDrawingManager); |
| 826 | |
| 827 | if (this->drawFilledDRRect(clip, paint, viewMatrix, outer, inner)) { |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | SkPath path; |
| 832 | path.setIsVolatile(true); |
| 833 | path.addRRect(inner); |
| 834 | path.addRRect(outer); |
| 835 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 836 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 837 | this->internalDrawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 838 | } |
| 839 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 840 | /////////////////////////////////////////////////////////////////////////////// |
| 841 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 842 | void GrDrawContext::drawOval(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 843 | const GrPaint& paint, |
| 844 | const SkMatrix& viewMatrix, |
| 845 | const SkRect& oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 846 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 847 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 848 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 849 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 850 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 851 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 852 | if (oval.isEmpty()) { |
| 853 | return; |
| 854 | } |
| 855 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 856 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 857 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 858 | AutoCheckFlush acf(fDrawingManager); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 859 | const SkStrokeRec& stroke = style.strokeRec(); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 860 | bool useHWAA; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 861 | |
| 862 | if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) { |
| 863 | InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
| 864 | SkAutoTUnref<GrDrawBatch> batch(ir->recordOval(oval, viewMatrix, paint.getColor(), |
| 865 | paint.isAntiAlias(), fInstancedPipelineInfo, |
| 866 | &useHWAA)); |
| 867 | if (batch) { |
| 868 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 869 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 870 | return; |
| 871 | } |
| 872 | } |
| 873 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 874 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 875 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 876 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(), |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 877 | viewMatrix, |
| 878 | oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 879 | stroke, |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 880 | shaderCaps)); |
| 881 | if (batch) { |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 882 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 883 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 884 | return; |
| 885 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 886 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 887 | |
| 888 | SkPath path; |
| 889 | path.setIsVolatile(true); |
| 890 | path.addOval(oval); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 891 | this->internalDrawPath(clip, paint, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 892 | } |
| 893 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 894 | void GrDrawContext::drawImageNine(const GrClip& clip, |
| 895 | const GrPaint& paint, |
| 896 | const SkMatrix& viewMatrix, |
| 897 | int imageWidth, |
| 898 | int imageHeight, |
| 899 | const SkIRect& center, |
| 900 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 901 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 902 | RETURN_IF_ABANDONED |
| 903 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 904 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 905 | |
| 906 | AutoCheckFlush acf(fDrawingManager); |
| 907 | |
| 908 | SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), viewMatrix, |
| 909 | imageWidth, imageHeight, |
| 910 | center, dst)); |
| 911 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 912 | GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 913 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 917 | void GrDrawContext::drawNonAAFilledRect(const GrClip& clip, |
| 918 | const GrPaint& paint, |
| 919 | const SkMatrix& viewMatrix, |
| 920 | const SkRect& rect, |
| 921 | const SkRect* localRect, |
| 922 | const SkMatrix* localMatrix, |
| 923 | const GrUserStencilSettings* ss) { |
| 924 | SkAutoTUnref<GrDrawBatch> batch( |
| 925 | GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect, |
| 926 | localMatrix)); |
| 927 | GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
| 928 | if (ss) { |
| 929 | pipelineBuilder.setUserStencil(ss); |
| 930 | } |
| 931 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 932 | } |
| 933 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 934 | // Can 'path' be drawn as a pair of filled nested rectangles? |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 935 | 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] | 936 | |
| 937 | if (path.isInverseFillType()) { |
| 938 | return false; |
| 939 | } |
| 940 | |
| 941 | // TODO: this restriction could be lifted if we were willing to apply |
| 942 | // the matrix to all the points individually rather than just to the rect |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 943 | if (!viewMatrix.rectStaysRect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 944 | return false; |
| 945 | } |
| 946 | |
| 947 | SkPath::Direction dirs[2]; |
| 948 | if (!path.isNestedFillRects(rects, dirs)) { |
| 949 | return false; |
| 950 | } |
| 951 | |
| 952 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 953 | // The two rects need to be wound opposite to each other |
| 954 | return false; |
| 955 | } |
| 956 | |
| 957 | // Right now, nested rects where the margin is not the same width |
| 958 | // all around do not render correctly |
| 959 | const SkScalar* outer = rects[0].asScalars(); |
| 960 | const SkScalar* inner = rects[1].asScalars(); |
| 961 | |
| 962 | bool allEq = true; |
| 963 | |
| 964 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 965 | bool allGoE1 = margin >= SK_Scalar1; |
| 966 | |
| 967 | for (int i = 1; i < 4; ++i) { |
| 968 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 969 | if (temp < SK_Scalar1) { |
| 970 | allGoE1 = false; |
| 971 | } |
| 972 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 973 | allEq = false; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | return allEq || allGoE1; |
| 978 | } |
| 979 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 980 | void GrDrawContext::drawPath(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 981 | const GrPaint& paint, |
| 982 | const SkMatrix& viewMatrix, |
| 983 | const SkPath& path, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 984 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 985 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 986 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 987 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 988 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 989 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 990 | if (path.isEmpty()) { |
| 991 | if (path.isInverseFillType()) { |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 992 | this->drawPaint(clip, paint, viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 993 | } |
| 994 | return; |
| 995 | } |
| 996 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 997 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 998 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 999 | bool useHWAA; |
| 1000 | if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && !style.pathEffect()) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1001 | if (style.isSimpleFill() && !path.isConvex()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1002 | // Concave AA paths are expensive - try to avoid them for special cases |
| 1003 | SkRect rects[2]; |
| 1004 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1005 | if (fills_as_nested_rects(viewMatrix, path, rects)) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 1006 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFillNestedRects( |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1007 | paint.getColor(), viewMatrix, rects)); |
bsalomon | 40ef485 | 2016-05-02 13:22:13 -0700 | [diff] [blame] | 1008 | if (batch) { |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 1009 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1010 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
bsalomon | 40ef485 | 2016-05-02 13:22:13 -0700 | [diff] [blame] | 1011 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1012 | return; |
| 1013 | } |
| 1014 | } |
| 1015 | SkRect ovalRect; |
| 1016 | bool isOval = path.isOval(&ovalRect); |
| 1017 | |
| 1018 | if (isOval && !path.isInverseFillType()) { |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1019 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1020 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(), |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1021 | viewMatrix, |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1022 | ovalRect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1023 | style.strokeRec(), |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1024 | shaderCaps)); |
| 1025 | if (batch) { |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 1026 | GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1027 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1028 | return; |
| 1029 | } |
| 1030 | } |
| 1031 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1032 | |
| 1033 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
| 1034 | // Scratch textures can be recycled after they are returned to the texture |
| 1035 | // cache. This presents a potential hazard for buffered drawing. However, |
| 1036 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 1037 | // OK. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1038 | this->internalDrawPath(clip, paint, viewMatrix, path, style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 1041 | bool GrDrawContextPriv::drawAndStencilPath(const GrFixedClip& clip, |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1042 | const GrUserStencilSettings* ss, |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1043 | SkRegion::Op op, |
| 1044 | bool invert, |
| 1045 | bool doAA, |
| 1046 | const SkMatrix& viewMatrix, |
| 1047 | const SkPath& path) { |
| 1048 | ASSERT_SINGLE_OWNER_PRIV |
| 1049 | RETURN_FALSE_IF_ABANDONED_PRIV |
| 1050 | SkDEBUGCODE(fDrawContext->validate();) |
| 1051 | GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPath"); |
| 1052 | |
| 1053 | if (path.isEmpty() && path.isInverseFillType()) { |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 1054 | this->drawAndStencilRect(clip, ss, op, invert, false, SkMatrix::I(), |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 1055 | SkRect::MakeIWH(fDrawContext->width(), |
| 1056 | fDrawContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1057 | return true; |
| 1058 | } |
| 1059 | |
| 1060 | AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 1061 | |
| 1062 | // An Assumption here is that path renderer would use some form of tweaking |
| 1063 | // the src color (either the input alpha or in the frag shader) to implement |
| 1064 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1065 | // thing WRT to the blend then we'll need some query on the PR. |
| 1066 | bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisampled(); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1067 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1068 | bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMultisampled(); |
| 1069 | |
| 1070 | const GrPathRendererChain::DrawType type = |
| 1071 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 1072 | : GrPathRendererChain::kColor_DrawType; |
| 1073 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1074 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1075 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 1076 | canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps()->shaderCaps(); |
| 1077 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1078 | canDrawArgs.fShape = &shape; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1079 | canDrawArgs.fAntiAlias = useCoverageAA; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1080 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1081 | canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; |
| 1082 | |
| 1083 | // Don't allow the SW renderer |
| 1084 | GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
| 1085 | if (!pr) { |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
| 1089 | GrPaint paint; |
| 1090 | paint.setCoverageSetOpXPFactory(op, invert); |
| 1091 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1092 | GrPathRenderer::DrawPathArgs args; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1093 | args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resourceProvider(); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1094 | args.fPaint = &paint; |
| 1095 | args.fUserStencilSettings = ss; |
| 1096 | args.fDrawContext = fDrawContext; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 1097 | args.fClip = &clip; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1098 | args.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1099 | args.fShape = &shape; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1100 | args.fAntiAlias = useCoverageAA; |
brianosman | 0e3c554 | 2016-04-13 13:56:21 -0700 | [diff] [blame] | 1101 | args.fGammaCorrect = fDrawContext->isGammaCorrect(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1102 | pr->drawPath(args); |
| 1103 | return true; |
| 1104 | } |
| 1105 | |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1106 | void GrDrawContext::internalDrawPath(const GrClip& clip, |
| 1107 | const GrPaint& paint, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1108 | const SkMatrix& viewMatrix, |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1109 | const SkPath& path, |
| 1110 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1111 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1112 | RETURN_IF_ABANDONED |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1113 | SkASSERT(!path.isEmpty()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1114 | |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 1115 | bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1116 | constexpr bool kHasUserStencilSettings = false; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1117 | bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1118 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1119 | const GrPathRendererChain::DrawType type = |
| 1120 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 1121 | : GrPathRendererChain::kColor_DrawType; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1122 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1123 | GrShape shape(path, style); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1124 | if (shape.isEmpty()) { |
| 1125 | return; |
| 1126 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1127 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 1128 | canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(); |
| 1129 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1130 | canDrawArgs.fShape = &shape; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1131 | canDrawArgs.fAntiAlias = useCoverageAA; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1132 | canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1133 | canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; |
| 1134 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1135 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1136 | GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1137 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1138 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1139 | if (!pr && shape.style().pathEffect()) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1140 | // It didn't work above, so try again with the path effect applied. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1141 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 1142 | if (shape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1143 | return; |
| 1144 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1145 | pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1146 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1147 | if (!pr) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1148 | if (shape.style().applies()) { |
| 1149 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale); |
| 1150 | if (shape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1151 | return; |
| 1152 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1153 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1154 | // This time, allow SW renderer |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1155 | pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1158 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1159 | #ifdef SK_DEBUG |
| 1160 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 1161 | #endif |
| 1162 | return; |
| 1163 | } |
| 1164 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1165 | GrPathRenderer::DrawPathArgs args; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 1166 | args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1167 | args.fPaint = &paint; |
| 1168 | args.fUserStencilSettings = &GrUserStencilSettings::kUnused; |
| 1169 | args.fDrawContext = this; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 1170 | args.fClip = &clip; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1171 | args.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1172 | args.fShape = canDrawArgs.fShape; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1173 | args.fAntiAlias = useCoverageAA; |
brianosman | 0e3c554 | 2016-04-13 13:56:21 -0700 | [diff] [blame] | 1174 | args.fGammaCorrect = this->isGammaCorrect(); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1175 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1178 | void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 1179 | GrDrawBatch* batch) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1180 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 1181 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1182 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 1183 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 1184 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1185 | this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1186 | } |