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