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