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