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