robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 9 | #include "GrBatchTest.h" |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 10 | #include "GrColor.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 11 | #include "GrDrawContext.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 | |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 26 | #include "text/GrAtlasTextContext.h" |
| 27 | #include "text/GrStencilAndCoverTextContext.h" |
| 28 | |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 29 | #include "../private/GrAuditTrail.h" |
| 30 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 31 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 32 | #define ASSERT_SINGLE_OWNER \ |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 33 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 34 | #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
| 35 | #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; } |
| 36 | #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 37 | |
| 38 | class AutoCheckFlush { |
| 39 | public: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 40 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
| 41 | SkASSERT(fDrawingManager); |
| 42 | } |
| 43 | ~AutoCheckFlush() { fDrawingManager->getContext()->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 44 | |
| 45 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 46 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 49 | // In MDB mode the reffing of the 'getLastDrawTarget' call's result allows in-progress |
| 50 | // drawTargets to be picked up and added to by drawContexts lower in the call |
| 51 | // stack. When this occurs with a closed drawTarget, a new one will be allocated |
| 52 | // when the drawContext attempts to use it (via getDrawTarget). |
joshualitt | 1b39f43 | 2016-02-11 06:46:52 -0800 | [diff] [blame] | 53 | GrDrawContext::GrDrawContext(GrContext* context, |
| 54 | GrDrawingManager* drawingMgr, |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 55 | GrRenderTarget* rt, |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 56 | const SkSurfaceProps* surfaceProps, |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 57 | GrAuditTrail* auditTrail, |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 58 | GrSingleOwner* singleOwner) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 59 | : fDrawingManager(drawingMgr) |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 60 | , fRenderTarget(rt) |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 61 | , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) |
joshualitt | 1b39f43 | 2016-02-11 06:46:52 -0800 | [diff] [blame] | 62 | , fContext(context) |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 63 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 64 | , fAuditTrail(auditTrail) |
joshualitt | 6d0872d | 2016-01-11 08:27:48 -0800 | [diff] [blame] | 65 | #ifdef SK_DEBUG |
| 66 | , fSingleOwner(singleOwner) |
| 67 | #endif |
| 68 | { |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 69 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 70 | } |
| 71 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 72 | #ifdef SK_DEBUG |
| 73 | void GrDrawContext::validate() const { |
| 74 | SkASSERT(fRenderTarget); |
| 75 | ASSERT_OWNED_RESOURCE(fRenderTarget); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 76 | |
| 77 | if (fDrawTarget && !fDrawTarget->isClosed()) { |
| 78 | SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); |
| 79 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 80 | } |
| 81 | #endif |
| 82 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 83 | GrDrawContext::~GrDrawContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 84 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 85 | SkSafeUnref(fDrawTarget); |
| 86 | } |
| 87 | |
| 88 | GrDrawTarget* GrDrawContext::getDrawTarget() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 89 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 90 | SkDEBUGCODE(this->validate();) |
| 91 | |
| 92 | if (!fDrawTarget || fDrawTarget->isClosed()) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 93 | fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | return fDrawTarget; |
| 97 | } |
| 98 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 99 | bool GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 100 | ASSERT_SINGLE_OWNER |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 101 | RETURN_FALSE_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 102 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 103 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::copySurface"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 104 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 105 | return this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 106 | } |
| 107 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 108 | void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 109 | const SkPaint& skPaint, |
| 110 | const SkMatrix& viewMatrix, |
| 111 | const char text[], size_t byteLength, |
| 112 | SkScalar x, SkScalar y, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 113 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 114 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 115 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 116 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 117 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 118 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 119 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 120 | } |
| 121 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 122 | fAtlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps, |
| 123 | text, byteLength, x, y, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 124 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 125 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 126 | void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 127 | const SkPaint& skPaint, |
| 128 | const SkMatrix& viewMatrix, |
| 129 | const char text[], size_t byteLength, |
| 130 | const SkScalar pos[], int scalarsPerPosition, |
| 131 | const SkPoint& offset, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 132 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 133 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 134 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 135 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPosText"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 136 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 137 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 138 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 139 | } |
| 140 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 141 | fAtlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, |
| 142 | fSurfaceProps, text, byteLength, pos, scalarsPerPosition, |
| 143 | offset, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 144 | |
| 145 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 146 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 147 | void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 148 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 149 | SkScalar x, SkScalar y, |
| 150 | SkDrawFilter* filter, const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 151 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 152 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 153 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 154 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawTextBlob"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 155 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 156 | if (!fAtlasTextContext) { |
joshualitt | 8db8678 | 2016-02-17 05:40:00 -0800 | [diff] [blame] | 157 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 158 | } |
| 159 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 160 | fAtlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob, |
| 161 | x, y, filter, clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 162 | } |
| 163 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 164 | void GrDrawContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 165 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 166 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 167 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 168 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::discard"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 169 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 170 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 171 | this->getDrawTarget()->discard(fRenderTarget); |
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::clear(const SkIRect* rect, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 175 | const GrColor color, |
| 176 | bool canIgnoreRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 177 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 178 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 179 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 180 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 181 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 182 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 183 | this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 187 | void GrDrawContext::drawPaint(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 188 | const GrPaint& origPaint, |
| 189 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 190 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 191 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 192 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 193 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 194 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 195 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 196 | // don't overflow fixed-point implementations |
| 197 | SkRect r; |
| 198 | r.setLTRB(0, 0, |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 199 | SkIntToScalar(fRenderTarget->width()), |
| 200 | SkIntToScalar(fRenderTarget->height())); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 201 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
| 202 | |
| 203 | // by definition this fills the entire clip, no need for AA |
| 204 | if (paint->isAntiAlias()) { |
| 205 | paint.writable()->setAntiAlias(false); |
| 206 | } |
| 207 | |
| 208 | bool isPerspective = viewMatrix.hasPerspective(); |
| 209 | |
| 210 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 211 | // map the four corners and bound them with a new rect. This will not |
| 212 | // produce a correct result for some perspective matrices. |
| 213 | if (!isPerspective) { |
| 214 | SkMatrix inverse; |
| 215 | if (!viewMatrix.invert(&inverse)) { |
| 216 | SkDebugf("Could not invert matrix\n"); |
| 217 | return; |
| 218 | } |
| 219 | inverse.mapRect(&r); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 220 | this->drawRect(clip, *paint, viewMatrix, r); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 221 | } else { |
| 222 | SkMatrix localMatrix; |
| 223 | if (!viewMatrix.invert(&localMatrix)) { |
| 224 | SkDebugf("Could not invert matrix\n"); |
| 225 | return; |
| 226 | } |
| 227 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 228 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 229 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 230 | GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 231 | SkAutoTUnref<GrDrawBatch> batch( |
| 232 | GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix::I(), r, nullptr, |
| 233 | &localMatrix)); |
| 234 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 238 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 239 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 240 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 241 | } |
| 242 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 243 | static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { |
| 244 | return viewMatrix.preservesRightAngles(); |
| 245 | } |
| 246 | |
| 247 | static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt) { |
| 248 | return paint.isAntiAlias() && !rt->isUnifiedMultisampled(); |
| 249 | } |
| 250 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 251 | void GrDrawContext::drawRect(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 252 | const GrPaint& paint, |
| 253 | const SkMatrix& viewMatrix, |
| 254 | const SkRect& rect, |
| 255 | const GrStrokeInfo* strokeInfo) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 256 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 257 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 258 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 259 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 260 | |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 261 | // Dashing should've been devolved to a path in SkGpuDevice |
| 262 | SkASSERT(!strokeInfo || !strokeInfo->isDashed()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 263 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 264 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 265 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 266 | SkScalar width = nullptr == strokeInfo ? -1 : strokeInfo->getWidth(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 267 | |
| 268 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking |
| 269 | // cases where the RT is fully inside a stroke. |
| 270 | if (width < 0) { |
| 271 | SkRect rtRect; |
robertphillips | 954cbc1 | 2015-12-02 10:33:46 -0800 | [diff] [blame] | 272 | fRenderTarget->getBoundsRect(&rtRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 273 | SkRect clipSpaceRTRect = rtRect; |
| 274 | bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); |
| 275 | if (checkClip) { |
| 276 | clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), |
| 277 | SkIntToScalar(clip.origin().fY)); |
| 278 | } |
| 279 | // Does the clip contain the entire RT? |
| 280 | if (!checkClip || clip.quickContains(clipSpaceRTRect)) { |
| 281 | SkMatrix invM; |
| 282 | if (!viewMatrix.invert(&invM)) { |
| 283 | return; |
| 284 | } |
| 285 | // Does the rect bound the RT? |
| 286 | SkPoint srcSpaceRTQuad[4]; |
| 287 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 288 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 289 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 290 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 291 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 292 | // Will it blend? |
| 293 | GrColor clearColor; |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 294 | if (paint.isConstantBlendedColor(&clearColor)) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 295 | this->getDrawTarget()->clear(nullptr, clearColor, true, fRenderTarget); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 302 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 303 | GrColor color = paint.getColor(); |
| 304 | |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 305 | SkAutoTUnref<GrDrawBatch> batch; |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 306 | if (should_apply_coverage_aa(paint, fRenderTarget)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 307 | if (width >= 0) { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 308 | // The stroke path needs the rect to remain axis aligned (no rotation or skew). |
| 309 | if (viewMatrix.rectStaysRect()) { |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 310 | batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 311 | *strokeInfo)); |
| 312 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 313 | } else { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 314 | // The fill path can handle rotation but not skew. |
| 315 | if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 316 | SkRect devBoundRect; |
| 317 | viewMatrix.mapRect(&devBoundRect, rect); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 318 | batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect, |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 319 | devBoundRect)); |
| 320 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 321 | } |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 322 | if (!batch) { |
| 323 | SkPath path; |
| 324 | path.setIsVolatile(true); |
| 325 | path.addRect(rect); |
| 326 | this->internalDrawPath(&pipelineBuilder, viewMatrix, color, true, path, *strokeInfo); |
| 327 | SkASSERT(paint.isAntiAlias()); |
| 328 | return; |
| 329 | } |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 330 | } else if (width >= 0) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 331 | // Non-AA hairlines are snapped to pixel centers to make which pixels are hit deterministic |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 332 | bool snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisampled()); |
| 333 | batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, width, |
| 334 | snapToPixelCenters)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 335 | |
| 336 | // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 337 | // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when MSAA |
| 338 | // is enabled because it can cause ugly artifacts. |
| 339 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
| 340 | snapToPixelCenters); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 341 | } else { |
| 342 | // filled BW rect |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 343 | batch.reset(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, nullptr, nullptr)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 344 | } |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 345 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 346 | } |
| 347 | |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 348 | void GrDrawContext::fillRectToRect(const GrClip& clip, |
| 349 | const GrPaint& paint, |
| 350 | const SkMatrix& viewMatrix, |
| 351 | const SkRect& rectToDraw, |
| 352 | const SkRect& localRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 353 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 354 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 355 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 356 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 357 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 358 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 359 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 360 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 361 | SkAutoTUnref<GrDrawBatch> batch; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 362 | if (should_apply_coverage_aa(paint, fRenderTarget) && |
| 363 | view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 364 | batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw, |
| 365 | localRect)); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 366 | } else { |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 367 | batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rectToDraw, |
| 368 | &localRect, nullptr)); |
| 369 | } |
| 370 | |
| 371 | if (batch) { |
| 372 | this->drawBatch(&pipelineBuilder, batch); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 373 | } |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 374 | } |
| 375 | |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 376 | void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
| 377 | const GrPaint& paint, |
| 378 | const SkMatrix& viewMatrix, |
| 379 | const SkRect& rectToDraw, |
| 380 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 381 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 382 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 383 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 384 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatrix"); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 385 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 386 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 387 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 388 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 389 | |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 390 | SkAutoTUnref<GrDrawBatch> batch; |
robertphillips | 954cbc1 | 2015-12-02 10:33:46 -0800 | [diff] [blame] | 391 | if (should_apply_coverage_aa(paint, fRenderTarget) && |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 392 | view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 393 | batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, |
| 394 | rectToDraw)); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 395 | } else { |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 396 | batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rectToDraw, |
| 397 | nullptr, &localMatrix)); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 398 | } |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 399 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 400 | } |
| 401 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 402 | void GrDrawContext::drawVertices(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 403 | const GrPaint& paint, |
| 404 | const SkMatrix& viewMatrix, |
| 405 | GrPrimitiveType primitiveType, |
| 406 | int vertexCount, |
| 407 | const SkPoint positions[], |
| 408 | const SkPoint texCoords[], |
| 409 | const GrColor colors[], |
| 410 | const uint16_t indices[], |
| 411 | int indexCount) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 412 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 413 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 414 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 415 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawVertices"); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 416 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 417 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 418 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 419 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 420 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 421 | // TODO clients should give us bounds |
| 422 | SkRect bounds; |
| 423 | if (!bounds.setBoundsCheck(positions, vertexCount)) { |
| 424 | SkDebugf("drawVertices call empty bounds\n"); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | viewMatrix.mapRect(&bounds); |
| 429 | |
| 430 | // 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] | 431 | // snapping. We also do this for the "hair" primitive types: lines and points since they have |
| 432 | // a 1 pixel thickness in device space. |
| 433 | if (!paint.isAntiAlias() || GrIsPrimTypeLines(primitiveType) || |
| 434 | kPoints_GrPrimitiveType == primitiveType) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 435 | bounds.outset(0.5f, 0.5f); |
| 436 | } |
| 437 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 438 | GrDrawVerticesBatch::Geometry geometry; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 439 | geometry.fColor = paint.getColor(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 440 | SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveType, viewMatrix, |
| 441 | positions, vertexCount, indices, |
| 442 | indexCount, colors, texCoords, |
| 443 | bounds)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 444 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 445 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /////////////////////////////////////////////////////////////////////////////// |
| 449 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 450 | void GrDrawContext::drawAtlas(const GrClip& clip, |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 451 | const GrPaint& paint, |
| 452 | const SkMatrix& viewMatrix, |
| 453 | int spriteCount, |
| 454 | const SkRSXform xform[], |
| 455 | const SkRect texRect[], |
| 456 | const SkColor colors[]) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 457 | ASSERT_SINGLE_OWNER |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 458 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 459 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 460 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 461 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 462 | AutoCheckFlush acf(fDrawingManager); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 463 | |
| 464 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 465 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 466 | GrDrawAtlasBatch::Geometry geometry; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 467 | geometry.fColor = paint.getColor(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 468 | SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, |
| 469 | xform, texRect, colors)); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 470 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 471 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /////////////////////////////////////////////////////////////////////////////// |
| 475 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 476 | void GrDrawContext::drawRRect(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 477 | const GrPaint& paint, |
| 478 | const SkMatrix& viewMatrix, |
| 479 | const SkRRect& rrect, |
| 480 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 481 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 482 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 483 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 484 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 485 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 486 | if (rrect.isEmpty()) { |
| 487 | return; |
| 488 | } |
| 489 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 490 | SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path in SkGpuDevice |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 491 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 492 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 493 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 494 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 495 | GrColor color = paint.getColor(); |
| 496 | |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 497 | if (should_apply_coverage_aa(paint, fRenderTarget)) { |
| 498 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 499 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 500 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(color, |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 501 | viewMatrix, |
| 502 | rrect, |
| 503 | strokeInfo, |
| 504 | shaderCaps)); |
| 505 | if (batch) { |
| 506 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 507 | return; |
| 508 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 509 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 510 | |
| 511 | SkPath path; |
| 512 | path.setIsVolatile(true); |
| 513 | path.addRRect(rrect); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 514 | this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 515 | paint.isAntiAlias(), path, strokeInfo); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /////////////////////////////////////////////////////////////////////////////// |
| 519 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 520 | void GrDrawContext::drawOval(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 521 | const GrPaint& paint, |
| 522 | const SkMatrix& viewMatrix, |
| 523 | const SkRect& oval, |
| 524 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 525 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 526 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 527 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 528 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 529 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 530 | if (oval.isEmpty()) { |
| 531 | return; |
| 532 | } |
| 533 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 534 | SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path in SkGpuDevice |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 535 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 536 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 537 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 538 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 539 | GrColor color = paint.getColor(); |
| 540 | |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 541 | if (should_apply_coverage_aa(paint, fRenderTarget)) { |
| 542 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 543 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(color, |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 544 | viewMatrix, |
| 545 | oval, |
| 546 | strokeInfo, |
| 547 | shaderCaps)); |
| 548 | if (batch) { |
| 549 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 550 | return; |
| 551 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 552 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 553 | |
| 554 | SkPath path; |
| 555 | path.setIsVolatile(true); |
| 556 | path.addOval(oval); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 557 | this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 558 | paint.isAntiAlias(), path, strokeInfo); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 559 | } |
| 560 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 561 | void GrDrawContext::drawImageNine(const GrClip& clip, |
| 562 | const GrPaint& paint, |
| 563 | const SkMatrix& viewMatrix, |
| 564 | int imageWidth, |
| 565 | int imageHeight, |
| 566 | const SkIRect& center, |
| 567 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 568 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 569 | RETURN_IF_ABANDONED |
| 570 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 571 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 572 | |
| 573 | AutoCheckFlush acf(fDrawingManager); |
| 574 | |
| 575 | SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), viewMatrix, |
| 576 | imageWidth, imageHeight, |
| 577 | center, dst)); |
| 578 | |
| 579 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 580 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 581 | } |
| 582 | |
| 583 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 584 | // Can 'path' be drawn as a pair of filled nested rectangles? |
joshualitt | f9c5db2 | 2015-07-10 11:31:01 -0700 | [diff] [blame] | 585 | static bool is_nested_rects(const SkMatrix& viewMatrix, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 586 | const SkPath& path, |
| 587 | const SkStrokeRec& stroke, |
| 588 | SkRect rects[2]) { |
| 589 | SkASSERT(stroke.isFillStyle()); |
| 590 | |
| 591 | if (path.isInverseFillType()) { |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | // TODO: this restriction could be lifted if we were willing to apply |
| 596 | // the matrix to all the points individually rather than just to the rect |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 597 | if (!viewMatrix.rectStaysRect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | |
| 601 | SkPath::Direction dirs[2]; |
| 602 | if (!path.isNestedFillRects(rects, dirs)) { |
| 603 | return false; |
| 604 | } |
| 605 | |
| 606 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 607 | // The two rects need to be wound opposite to each other |
| 608 | return false; |
| 609 | } |
| 610 | |
| 611 | // Right now, nested rects where the margin is not the same width |
| 612 | // all around do not render correctly |
| 613 | const SkScalar* outer = rects[0].asScalars(); |
| 614 | const SkScalar* inner = rects[1].asScalars(); |
| 615 | |
| 616 | bool allEq = true; |
| 617 | |
| 618 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 619 | bool allGoE1 = margin >= SK_Scalar1; |
| 620 | |
| 621 | for (int i = 1; i < 4; ++i) { |
| 622 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 623 | if (temp < SK_Scalar1) { |
| 624 | allGoE1 = false; |
| 625 | } |
| 626 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 627 | allEq = false; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | return allEq || allGoE1; |
| 632 | } |
| 633 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 634 | void GrDrawContext::drawBatch(const GrClip& clip, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 635 | const GrPaint& paint, GrDrawBatch* batch) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 636 | ASSERT_SINGLE_OWNER |
joshualitt | b7ee1bf | 2015-08-10 11:59:02 -0700 | [diff] [blame] | 637 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 638 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 639 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
joshualitt | b7ee1bf | 2015-08-10 11:59:02 -0700 | [diff] [blame] | 640 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 641 | AutoCheckFlush acf(fDrawingManager); |
joshualitt | b7ee1bf | 2015-08-10 11:59:02 -0700 | [diff] [blame] | 642 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 643 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 644 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
joshualitt | b7ee1bf | 2015-08-10 11:59:02 -0700 | [diff] [blame] | 645 | } |
| 646 | |
cdalton | 8ff8d24 | 2015-12-08 10:20:32 -0800 | [diff] [blame] | 647 | void GrDrawContext::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, |
| 648 | GrDrawPathBatchBase* batch) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 649 | ASSERT_SINGLE_OWNER |
cdalton | 8ff8d24 | 2015-12-08 10:20:32 -0800 | [diff] [blame] | 650 | RETURN_IF_ABANDONED |
| 651 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 652 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPathBatch"); |
cdalton | 8ff8d24 | 2015-12-08 10:20:32 -0800 | [diff] [blame] | 653 | |
| 654 | AutoCheckFlush acf(fDrawingManager); |
| 655 | |
| 656 | this->getDrawTarget()->drawPathBatch(pipelineBuilder, batch); |
| 657 | } |
| 658 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 659 | void GrDrawContext::drawPath(const GrClip& clip, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 660 | const GrPaint& paint, |
| 661 | const SkMatrix& viewMatrix, |
| 662 | const SkPath& path, |
| 663 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 664 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 665 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 666 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 667 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 668 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 669 | if (path.isEmpty()) { |
| 670 | if (path.isInverseFillType()) { |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 671 | this->drawPaint(clip, paint, viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 672 | } |
| 673 | return; |
| 674 | } |
| 675 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 676 | GrColor color = paint.getColor(); |
| 677 | |
| 678 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
| 679 | // Scratch textures can be recycled after they are returned to the texture |
| 680 | // cache. This presents a potential hazard for buffered drawing. However, |
| 681 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 682 | // OK. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 683 | AutoCheckFlush acf(fDrawingManager); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 684 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 685 | GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 686 | if (should_apply_coverage_aa(paint, fRenderTarget) && !strokeInfo.isDashed()) { |
| 687 | if (strokeInfo.getWidth() < 0 && !path.isConvex()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 688 | // Concave AA paths are expensive - try to avoid them for special cases |
| 689 | SkRect rects[2]; |
| 690 | |
joshualitt | f9c5db2 | 2015-07-10 11:31:01 -0700 | [diff] [blame] | 691 | if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 692 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFillNestedRects( |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 693 | color, viewMatrix, rects)); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 694 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | } |
| 698 | SkRect ovalRect; |
| 699 | bool isOval = path.isOval(&ovalRect); |
| 700 | |
| 701 | if (isOval && !path.isInverseFillType()) { |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 702 | GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 703 | SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(color, |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 704 | viewMatrix, |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 705 | ovalRect, |
| 706 | strokeInfo, |
| 707 | shaderCaps)); |
| 708 | if (batch) { |
| 709 | this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | } |
| 713 | } |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 714 | this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 715 | paint.isAntiAlias(), path, strokeInfo); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 716 | } |
| 717 | |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 718 | void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 719 | const SkMatrix& viewMatrix, |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 720 | GrColor color, |
| 721 | bool useAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 722 | const SkPath& path, |
| 723 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 724 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 725 | RETURN_IF_ABANDONED |
| 726 | SkASSERT(!path.isEmpty()); |
| 727 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 728 | // An Assumption here is that path renderer would use some form of tweaking |
| 729 | // the src color (either the input alpha or in the frag shader) to implement |
| 730 | // aa. If we have some future driver-mojo path AA that can do the right |
| 731 | // thing WRT to the blend then we'll need some query on the PR. |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 732 | bool useCoverageAA = useAA && |
| 733 | !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled(); |
| 734 | bool isStencilDisabled = pipelineBuilder->getStencil().isDisabled(); |
| 735 | bool isStencilBufferMSAA = pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 736 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 737 | const GrPathRendererChain::DrawType type = |
| 738 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 739 | : GrPathRendererChain::kColor_DrawType; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 740 | |
| 741 | const SkPath* pathPtr = &path; |
| 742 | SkTLazy<SkPath> tmpPath; |
| 743 | const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
| 744 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 745 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 746 | canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(); |
| 747 | canDrawArgs.fViewMatrix = &viewMatrix; |
| 748 | canDrawArgs.fPath = pathPtr; |
| 749 | canDrawArgs.fStroke = strokeInfoPtr; |
| 750 | canDrawArgs.fAntiAlias = useCoverageAA; |
| 751 | canDrawArgs.fIsStencilDisabled = isStencilDisabled; |
| 752 | canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; |
| 753 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 754 | // Try a 1st time without stroking the path and without allowing the SW renderer |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 755 | GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 756 | |
| 757 | GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 758 | if (nullptr == pr && strokeInfo.isDashed()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 759 | // It didn't work above, so try again with dashed stroke converted to a dashless stroke. |
| 760 | if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pathPtr)) { |
| 761 | return; |
| 762 | } |
| 763 | pathPtr = tmpPath.get(); |
| 764 | if (pathPtr->isEmpty()) { |
| 765 | return; |
| 766 | } |
| 767 | strokeInfoPtr = &dashlessStrokeInfo; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 768 | |
| 769 | canDrawArgs.fPath = pathPtr; |
| 770 | canDrawArgs.fStroke = strokeInfoPtr; |
| 771 | |
| 772 | pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 773 | } |
| 774 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 775 | if (nullptr == pr) { |
| 776 | if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMatrix, nullptr) && |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 777 | !strokeInfoPtr->isFillStyle()) { |
| 778 | // It didn't work above, so try again with stroke converted to a fill. |
| 779 | if (!tmpPath.isValid()) { |
| 780 | tmpPath.init(); |
| 781 | } |
| 782 | dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())); |
| 783 | if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { |
| 784 | return; |
| 785 | } |
| 786 | pathPtr = tmpPath.get(); |
| 787 | if (pathPtr->isEmpty()) { |
| 788 | return; |
| 789 | } |
| 790 | dashlessStrokeInfo.setFillStyle(); |
| 791 | strokeInfoPtr = &dashlessStrokeInfo; |
| 792 | } |
| 793 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 794 | canDrawArgs.fPath = pathPtr; |
| 795 | canDrawArgs.fStroke = strokeInfoPtr; |
| 796 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 797 | // This time, allow SW renderer |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 798 | pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 799 | } |
| 800 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 801 | if (nullptr == pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 802 | #ifdef SK_DEBUG |
| 803 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 804 | #endif |
| 805 | return; |
| 806 | } |
| 807 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 808 | GrPathRenderer::DrawPathArgs args; |
robertphillips | b83bec5 | 2015-10-23 09:38:03 -0700 | [diff] [blame] | 809 | args.fTarget = this->getDrawTarget(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 810 | args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); |
ethannicholas | d2c7791 | 2016-02-25 13:43:16 -0800 | [diff] [blame] | 811 | args.fPipelineBuilder = pipelineBuilder; |
| 812 | args.fColor = color; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 813 | args.fViewMatrix = &viewMatrix; |
| 814 | args.fPath = pathPtr; |
| 815 | args.fStroke = strokeInfoPtr; |
| 816 | args.fAntiAlias = useCoverageAA; |
| 817 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 818 | } |
| 819 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 820 | void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 821 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 822 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 823 | SkDEBUGCODE(this->validate();) |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 824 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 825 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 826 | this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 827 | } |