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