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