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