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