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 | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 9 | #include "../private/GrAuditTrail.h" |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 10 | #include "../private/SkShadowFlags.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 11 | #include "GrAppliedClip.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 12 | #include "GrBackendSemaphore.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 13 | #include "GrBlurUtils.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 14 | #include "GrColor.h" |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 15 | #include "GrContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 16 | #include "GrDrawingManager.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 17 | #include "GrFixedClip.h" |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 18 | #include "GrGpuResourcePriv.h" |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 19 | #include "GrOpList.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 20 | #include "GrPathRenderer.h" |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 21 | #include "GrQuad.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 22 | #include "GrRenderTarget.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 23 | #include "GrRenderTargetContextPriv.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 24 | #include "GrResourceProvider.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 25 | #include "GrStencilAttachment.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 26 | #include "GrTracing.h" |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 27 | #include "SkDrawShadowInfo.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 28 | #include "SkGr.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 29 | #include "SkLatticeIter.h" |
| 30 | #include "SkMatrixPriv.h" |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 31 | #include "SkRRectPriv.h" |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 32 | #include "SkShadowUtils.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 33 | #include "SkSurfacePriv.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 34 | #include "effects/GrRRectEffect.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 35 | #include "ops/GrAtlasTextOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 36 | #include "ops/GrClearOp.h" |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 37 | #include "ops/GrClearStencilClipOp.h" |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 38 | #include "ops/GrDebugMarkerOp.h" |
Brian Salomon | 0f35332 | 2017-05-03 20:58:59 +0000 | [diff] [blame] | 39 | #include "ops/GrDrawAtlasOp.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 40 | #include "ops/GrDrawOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 41 | #include "ops/GrDrawVerticesOp.h" |
| 42 | #include "ops/GrLatticeOp.h" |
| 43 | #include "ops/GrOp.h" |
| 44 | #include "ops/GrOvalOpFactory.h" |
| 45 | #include "ops/GrRectOpFactory.h" |
| 46 | #include "ops/GrRegionOp.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 47 | #include "ops/GrSemaphoreOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 48 | #include "ops/GrShadowRRectOp.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 49 | #include "ops/GrStencilPathOp.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 50 | #include "ops/GrTextureOp.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 51 | #include "text/GrAtlasTextContext.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 52 | #include "text/GrTextUtils.h" |
| 53 | |
| 54 | class GrRenderTargetContext::TextTarget : public GrTextUtils::Target { |
| 55 | public: |
| 56 | TextTarget(GrRenderTargetContext* renderTargetContext) |
| 57 | : Target(renderTargetContext->width(), renderTargetContext->height(), |
| 58 | renderTargetContext->colorSpaceInfo()) |
| 59 | , fRenderTargetContext(renderTargetContext) {} |
| 60 | |
| 61 | void addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) { |
| 62 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 63 | } |
| 64 | |
| 65 | void drawPath(const GrClip& clip, const SkPath& path, const SkPaint& paint, |
| 66 | const SkMatrix& viewMatrix, const SkMatrix* pathMatrix, |
| 67 | const SkIRect& clipBounds) { |
| 68 | GrBlurUtils::drawPathWithMaskFilter(fRenderTargetContext->fContext, fRenderTargetContext, |
| 69 | clip, path, paint, viewMatrix, pathMatrix, clipBounds, |
| 70 | false); |
| 71 | } |
| 72 | |
| 73 | void makeGrPaint(GrMaskFormat maskFormat, const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 74 | GrPaint* grPaint) { |
| 75 | GrContext* context = fRenderTargetContext->fContext; |
| 76 | const GrColorSpaceInfo& colorSpaceInfo = fRenderTargetContext->colorSpaceInfo(); |
| 77 | if (kARGB_GrMaskFormat == maskFormat) { |
| 78 | SkPaintToGrPaintWithPrimitiveColor(context, colorSpaceInfo, skPaint, grPaint); |
| 79 | } else { |
| 80 | SkPaintToGrPaint(context, colorSpaceInfo, skPaint, viewMatrix, grPaint); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | GrRenderTargetContext* fRenderTargetContext; |
| 86 | }; |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 87 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 88 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 89 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 90 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 91 | #define ASSERT_SINGLE_OWNER_PRIV \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 92 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 93 | #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } |
| 94 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } |
| 95 | #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } |
| 96 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return false; } |
| 97 | #define RETURN_NULL_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 98 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 99 | ////////////////////////////////////////////////////////////////////////////// |
| 100 | |
| 101 | GrAAType GrChooseAAType(GrAA aa, GrFSAAType fsaaType, GrAllowMixedSamples allowMixedSamples, |
| 102 | const GrCaps& caps) { |
| 103 | if (GrAA::kNo == aa) { |
| 104 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type reflect |
| 105 | // that. |
| 106 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !caps.multisampleDisableSupport()) { |
| 107 | return GrAAType::kMSAA; |
| 108 | } |
| 109 | return GrAAType::kNone; |
| 110 | } |
| 111 | switch (fsaaType) { |
| 112 | case GrFSAAType::kNone: |
| 113 | return GrAAType::kCoverage; |
| 114 | case GrFSAAType::kUnifiedMSAA: |
| 115 | return GrAAType::kMSAA; |
| 116 | case GrFSAAType::kMixedSamples: |
| 117 | return GrAllowMixedSamples::kYes == allowMixedSamples ? GrAAType::kMixedSamples |
| 118 | : GrAAType::kCoverage; |
| 119 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 120 | SK_ABORT("Unexpected fsaa type"); |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 121 | return GrAAType::kNone; |
| 122 | } |
| 123 | |
| 124 | ////////////////////////////////////////////////////////////////////////////// |
| 125 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 126 | class AutoCheckFlush { |
| 127 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 128 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 129 | SkASSERT(fDrawingManager); |
| 130 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 131 | ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 132 | |
| 133 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 134 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 137 | bool GrRenderTargetContext::wasAbandoned() const { |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 138 | return this->drawingManager()->wasAbandoned(); |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 141 | // 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] | 142 | // 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] | 143 | // 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] | 144 | // when the renderTargetContext attempts to use it (via getOpList). |
| 145 | GrRenderTargetContext::GrRenderTargetContext(GrContext* context, |
| 146 | GrDrawingManager* drawingMgr, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 147 | sk_sp<GrRenderTargetProxy> rtp, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 148 | sk_sp<SkColorSpace> colorSpace, |
| 149 | const SkSurfaceProps* surfaceProps, |
| 150 | GrAuditTrail* auditTrail, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 151 | GrSingleOwner* singleOwner, |
| 152 | bool managedOpList) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 153 | : GrSurfaceContext(context, drawingMgr, rtp->config(), std::move(colorSpace), auditTrail, |
| 154 | singleOwner) |
| 155 | , fRenderTargetProxy(std::move(rtp)) |
| 156 | , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 157 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
| 158 | , fManagedOpList(managedOpList) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 159 | GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider(); |
| 160 | if (resourceProvider && !resourceProvider->explicitlyAllocateGPUResources()) { |
| 161 | // MDB TODO: to ensure all resources still get allocated in the correct order in the hybrid |
| 162 | // world we need to get the correct opList here so that it, in turn, can grab and hold |
| 163 | // its rendertarget. |
| 164 | this->getRTOpList(); |
| 165 | } |
| 166 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 167 | fTextTarget.reset(new TextTarget(this)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 168 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 169 | } |
| 170 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 171 | #ifdef SK_DEBUG |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 172 | void GrRenderTargetContext::validate() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 173 | SkASSERT(fRenderTargetProxy); |
| 174 | fRenderTargetProxy->validate(fContext); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 175 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 176 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 177 | SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 178 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 179 | } |
| 180 | #endif |
| 181 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 182 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 183 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 186 | GrTextureProxy* GrRenderTargetContext::asTextureProxy() { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 187 | return fRenderTargetProxy->asTextureProxy(); |
| 188 | } |
| 189 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 190 | const GrTextureProxy* GrRenderTargetContext::asTextureProxy() const { |
| 191 | return fRenderTargetProxy->asTextureProxy(); |
| 192 | } |
| 193 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 194 | sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() { |
| 195 | return sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 196 | } |
| 197 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 198 | GrMipMapped GrRenderTargetContext::mipMapped() const { |
| 199 | if (const GrTextureProxy* proxy = this->asTextureProxy()) { |
| 200 | return proxy->mipMapped(); |
| 201 | } |
| 202 | return GrMipMapped::kNo; |
| 203 | } |
| 204 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 205 | GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 206 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 207 | SkDEBUGCODE(this->validate();) |
| 208 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 209 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 210 | fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy.get(), fManagedOpList); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 213 | return fOpList.get(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 216 | GrOpList* GrRenderTargetContext::getOpList() { |
| 217 | return this->getRTOpList(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 220 | void GrRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 221 | const SkMatrix& viewMatrix, const char text[], |
| 222 | size_t byteLength, SkScalar x, SkScalar y, |
| 223 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 224 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 225 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 226 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 227 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawText", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 228 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 229 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 230 | atlasTextContext->drawText(fContext, fTextTarget.get(), clip, skPaint, viewMatrix, |
| 231 | fSurfaceProps, text, byteLength, x, y, clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 232 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 233 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 234 | void GrRenderTargetContext::drawPosText(const GrClip& clip, const SkPaint& paint, |
| 235 | const SkMatrix& viewMatrix, const char text[], |
| 236 | size_t byteLength, const SkScalar pos[], |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 237 | int scalarsPerPosition, const SkPoint& offset, |
| 238 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 239 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 240 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 241 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 242 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPosText", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 243 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 244 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 245 | atlasTextContext->drawPosText(fContext, fTextTarget.get(), clip, paint, viewMatrix, |
| 246 | fSurfaceProps, text, byteLength, pos, scalarsPerPosition, offset, |
| 247 | clipBounds); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 248 | } |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 249 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 250 | void GrRenderTargetContext::drawTextBlob(const GrClip& clip, const SkPaint& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 251 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 252 | SkScalar x, SkScalar y, SkDrawFilter* filter, |
| 253 | const SkIRect& clipBounds) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 254 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 255 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 256 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 257 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextBlob", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 258 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 259 | GrAtlasTextContext* atlasTextContext = this->drawingManager()->getAtlasTextContext(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 260 | atlasTextContext->drawTextBlob(fContext, fTextTarget.get(), clip, paint, viewMatrix, |
| 261 | fSurfaceProps, blob, x, y, filter, clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 264 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 265 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 266 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 267 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 268 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "discard", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 269 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 270 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 271 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 272 | this->getRTOpList()->discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 275 | void GrRenderTargetContext::clear(const SkIRect* rect, |
| 276 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 277 | CanClearFullscreen canClearFullscreen) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 278 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 279 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 280 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 281 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "clear", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 282 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 283 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 284 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, |
| 285 | canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 286 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 287 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 288 | void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor color) { |
| 289 | ASSERT_SINGLE_OWNER_PRIV |
| 290 | RETURN_IF_ABANDONED_PRIV |
| 291 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 292 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "absClear", |
| 293 | fRenderTargetContext->fContext); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 294 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 295 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 296 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 297 | SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(), |
| 298 | fRenderTargetContext->fRenderTargetProxy->worstCaseHeight()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 299 | |
| 300 | if (clearRect) { |
| 301 | if (clearRect->contains(rtRect)) { |
| 302 | clearRect = nullptr; // full screen |
| 303 | } else { |
| 304 | if (!rtRect.intersect(*clearRect)) { |
| 305 | return; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // TODO: in a post-MDB world this should be handled at the OpList level. |
| 311 | // An op-list that is initially cleared and has no other ops should receive an |
| 312 | // extra draw. |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 313 | // This path doesn't handle coalescing of full screen clears b.c. it |
| 314 | // has to clear the entire render target - not just the content area. |
| 315 | // It could be done but will take more finagling. |
| 316 | std::unique_ptr<GrOp> op(GrClearOp::Make(rtRect, color, !clearRect)); |
| 317 | if (!op) { |
| 318 | return; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 319 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 320 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 323 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 324 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 325 | CanClearFullscreen canClearFullscreen) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 326 | ASSERT_SINGLE_OWNER_PRIV |
| 327 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 328 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 329 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clear", |
| 330 | fRenderTargetContext->fContext); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 331 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 332 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 333 | fRenderTargetContext->internalClear(clip, color, canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 336 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 337 | const GrColor color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 338 | CanClearFullscreen canClearFullscreen) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 339 | bool isFull = false; |
| 340 | if (!clip.hasWindowRectangles()) { |
| 341 | isFull = !clip.scissorEnabled() || |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 342 | (CanClearFullscreen::kYes == canClearFullscreen && |
| 343 | fContext->caps()->preferFullscreenClears()) || |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 344 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 345 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 346 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 347 | if (isFull) { |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 348 | this->getRTOpList()->fullClear(*this->caps(), color); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 349 | } else { |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 350 | std::unique_ptr<GrOp> op(GrClearOp::Make(clip, color, this->asSurfaceProxy())); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 351 | if (!op) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 352 | return; |
| 353 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 354 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 355 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 358 | void GrRenderTargetContext::drawPaint(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 359 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 360 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 361 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 362 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 363 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 364 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPaint", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 365 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 366 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 367 | // don't overflow fixed-point implementations |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 368 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 369 | SkRect r = fRenderTargetProxy->getBoundsRect(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 370 | |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 371 | SkRRect rrect; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 372 | GrAA aa; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 373 | // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We only do the |
| 374 | // transformation for non-rect rrects. Rects caused a performance regression on an Android |
| 375 | // test that needs investigation. We also skip cases where there are fragment processors |
| 376 | // because they may depend on having correct local coords and this path draws in device space |
| 377 | // without a local matrix. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 378 | if (!paint.numTotalFragmentProcessors() && clip.isRRect(r, &rrect, &aa) && !rrect.isRect()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 379 | this->drawRRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect, |
| 380 | GrStyle::SimpleFill()); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 384 | |
| 385 | bool isPerspective = viewMatrix.hasPerspective(); |
| 386 | |
| 387 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 388 | // map the four corners and bound them with a new rect. This will not |
| 389 | // produce a correct result for some perspective matrices. |
| 390 | if (!isPerspective) { |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 391 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &r, r)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 392 | SkDebugf("Could not invert matrix\n"); |
| 393 | return; |
| 394 | } |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 395 | this->drawRect(clip, std::move(paint), GrAA::kNo, viewMatrix, r); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 396 | } else { |
| 397 | SkMatrix localMatrix; |
| 398 | if (!viewMatrix.invert(&localMatrix)) { |
| 399 | SkDebugf("Could not invert matrix\n"); |
| 400 | return; |
| 401 | } |
| 402 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 403 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 404 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 405 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
| 406 | std::move(paint), SkMatrix::I(), localMatrix, r, GrAAType::kNone); |
| 407 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 411 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 412 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 413 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 414 | } |
| 415 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 416 | // Attempts to crop a rect and optional local rect to the clip boundaries. |
| 417 | // Returns false if the draw can be skipped entirely. |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 418 | static bool crop_filled_rect(int width, int height, const GrClip& clip, |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 419 | const SkMatrix& viewMatrix, SkRect* rect, |
| 420 | SkRect* localRect = nullptr) { |
| 421 | if (!viewMatrix.rectStaysRect()) { |
| 422 | return true; |
| 423 | } |
| 424 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 425 | SkIRect clipDevBounds; |
| 426 | SkRect clipBounds; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 427 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 428 | clip.getConservativeBounds(width, height, &clipDevBounds); |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 429 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) { |
| 430 | return false; |
| 431 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 432 | |
| 433 | if (localRect) { |
| 434 | if (!rect->intersects(clipBounds)) { |
| 435 | return false; |
| 436 | } |
| 437 | const SkScalar dx = localRect->width() / rect->width(); |
| 438 | const SkScalar dy = localRect->height() / rect->height(); |
| 439 | if (clipBounds.fLeft > rect->fLeft) { |
| 440 | localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx; |
| 441 | rect->fLeft = clipBounds.fLeft; |
| 442 | } |
| 443 | if (clipBounds.fTop > rect->fTop) { |
| 444 | localRect->fTop += (clipBounds.fTop - rect->fTop) * dy; |
| 445 | rect->fTop = clipBounds.fTop; |
| 446 | } |
| 447 | if (clipBounds.fRight < rect->fRight) { |
| 448 | localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx; |
| 449 | rect->fRight = clipBounds.fRight; |
| 450 | } |
| 451 | if (clipBounds.fBottom < rect->fBottom) { |
| 452 | localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy; |
| 453 | rect->fBottom = clipBounds.fBottom; |
| 454 | } |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | return rect->intersect(clipBounds); |
| 459 | } |
| 460 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 461 | bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 462 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 463 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 464 | const SkMatrix& viewMatrix, |
| 465 | const SkRect& rect, |
| 466 | const GrUserStencilSettings* ss) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 467 | SkRect croppedRect = rect; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 468 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 469 | return true; |
| 470 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 471 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 472 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 473 | std::unique_ptr<GrDrawOp> op; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 474 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 475 | op = GrRectOpFactory::MakeAAFill(std::move(paint), viewMatrix, croppedRect, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 476 | } else { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 477 | op = GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, croppedRect, aaType, ss); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 478 | } |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 479 | if (!op) { |
| 480 | return false; |
| 481 | } |
| 482 | this->addDrawOp(clip, std::move(op)); |
| 483 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 486 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 487 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 488 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 489 | const SkMatrix& viewMatrix, |
| 490 | const SkRect& rect, |
| 491 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 492 | if (!style) { |
| 493 | style = &GrStyle::SimpleFill(); |
| 494 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 495 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 496 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 497 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 498 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRect", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 499 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 500 | // Path effects should've been devolved to a path in SkGpuDevice |
| 501 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 502 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 503 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 504 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 505 | const SkStrokeRec& stroke = style->strokeRec(); |
robertphillips | 3ab14ca | 2016-07-10 11:49:39 -0700 | [diff] [blame] | 506 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 507 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother |
| 508 | // checking cases where the RT is fully inside a stroke. |
| 509 | SkRect rtRect = fRenderTargetProxy->getBoundsRect(); |
| 510 | // Does the clip contain the entire RT? |
| 511 | if (clip.quickContains(rtRect)) { |
| 512 | SkMatrix invM; |
| 513 | if (!viewMatrix.invert(&invM)) { |
| 514 | return; |
| 515 | } |
| 516 | // Does the rect bound the RT? |
| 517 | GrQuad quad; |
| 518 | quad.setFromMappedRect(rtRect, invM); |
| 519 | if (rect_contains_inclusive(rect, quad.point(0)) && |
| 520 | rect_contains_inclusive(rect, quad.point(1)) && |
| 521 | rect_contains_inclusive(rect, quad.point(2)) && |
| 522 | rect_contains_inclusive(rect, quad.point(3))) { |
| 523 | // Will it blend? |
| 524 | GrColor clearColor; |
| 525 | if (paint.isConstantBlendedColor(&clearColor)) { |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 526 | this->clear(nullptr, clearColor, |
| 527 | GrRenderTargetContext::CanClearFullscreen::kYes); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 528 | return; |
| 529 | } |
| 530 | } |
| 531 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 532 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 533 | if (this->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, nullptr)) { |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 534 | return; |
| 535 | } |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 536 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 537 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 538 | if ((!rect.width() || !rect.height()) && |
| 539 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 540 | SkScalar r = stroke.getWidth() / 2; |
| 541 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 542 | switch (stroke.getJoin()) { |
| 543 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 544 | this->drawRect( |
| 545 | clip, std::move(paint), aa, viewMatrix, |
| 546 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 547 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 548 | return; |
| 549 | case SkPaint::kRound_Join: |
| 550 | // Raster draws nothing when both dimensions are empty. |
| 551 | if (rect.width() || rect.height()){ |
| 552 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 553 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 554 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | case SkPaint::kBevel_Join: |
| 558 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 559 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 560 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 561 | &GrStyle::SimpleFill()); |
| 562 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 563 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 564 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 565 | &GrStyle::SimpleFill()); |
| 566 | } |
| 567 | return; |
| 568 | } |
| 569 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 570 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 571 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 572 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 573 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 574 | if (GrAAType::kCoverage == aaType) { |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 575 | // The stroke path needs the rect to remain axis aligned (no rotation or skew). |
| 576 | if (viewMatrix.rectStaysRect()) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 577 | op = GrRectOpFactory::MakeAAStroke(std::move(paint), viewMatrix, rect, stroke); |
cdalton | bb53948 | 2016-01-04 09:48:25 -0800 | [diff] [blame] | 578 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 579 | } else { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 580 | op = GrRectOpFactory::MakeNonAAStroke(std::move(paint), viewMatrix, rect, stroke, |
| 581 | aaType); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 582 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 583 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 584 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 585 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 586 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 587 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 588 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 589 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(rect, *style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 592 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
| 593 | return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles( |
| 594 | *fRenderTargetContext->fContext->caps()); |
| 595 | } |
| 596 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 597 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 598 | ASSERT_SINGLE_OWNER_PRIV |
| 599 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 600 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 601 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clearStencilClip", |
| 602 | fRenderTargetContext->fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 603 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 604 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 605 | |
Robert Phillips | 2f4ddf6 | 2017-06-01 08:48:19 -0400 | [diff] [blame] | 606 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make( |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 607 | clip, insideStencilMask, |
| 608 | fRenderTargetContext->fRenderTargetProxy.get())); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 609 | if (!op) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 610 | return; |
| 611 | } |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 612 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 615 | void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 616 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 617 | const SkMatrix& viewMatrix, |
| 618 | const GrPath* path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 619 | ASSERT_SINGLE_OWNER_PRIV |
| 620 | RETURN_IF_ABANDONED_PRIV |
| 621 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 622 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilPath", |
| 623 | fRenderTargetContext->fContext); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 624 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 625 | SkASSERT(aaType != GrAAType::kCoverage); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 626 | |
| 627 | bool useHWAA = GrAATypeIsHW(aaType); |
| 628 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 629 | SkASSERT(path); |
| 630 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 631 | |
| 632 | // FIXME: Use path bounds instead of this WAR once |
| 633 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 634 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 635 | |
| 636 | // Setup clip |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 637 | GrAppliedHardClip appliedClip; |
| 638 | if (!clip.apply(fRenderTargetContext->width(), fRenderTargetContext->height(), &appliedClip, |
| 639 | &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 643 | fRenderTargetContext->setNeedsStencil(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 644 | |
| 645 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(viewMatrix, |
| 646 | useHWAA, |
| 647 | path->getFillType(), |
| 648 | appliedClip.hasStencilClip(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 649 | appliedClip.scissorState(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 650 | path); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 651 | if (!op) { |
| 652 | return; |
| 653 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 654 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 655 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 658 | void GrRenderTargetContextPriv::stencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 659 | const GrUserStencilSettings* ss, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 660 | GrAAType aaType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 661 | const SkMatrix& viewMatrix, |
| 662 | const SkRect& rect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 663 | ASSERT_SINGLE_OWNER_PRIV |
| 664 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 665 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 666 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilRect", |
| 667 | fRenderTargetContext->fContext); |
| 668 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 669 | SkASSERT(GrAAType::kCoverage != aaType); |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 670 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 671 | |
| 672 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 673 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 674 | std::unique_ptr<GrDrawOp> op = |
| 675 | GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, rect, aaType, ss); |
| 676 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 679 | bool GrRenderTargetContextPriv::drawAndStencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 680 | const GrUserStencilSettings* ss, |
| 681 | SkRegion::Op op, |
| 682 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 683 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 684 | const SkMatrix& viewMatrix, |
| 685 | const SkRect& rect) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 686 | ASSERT_SINGLE_OWNER_PRIV |
| 687 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 688 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 689 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilRect", |
| 690 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 691 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 692 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 693 | |
| 694 | GrPaint paint; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 695 | paint.setCoverageSetOpXPFactory(op, invert); |
| 696 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 697 | if (fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, ss)) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 698 | return true; |
| 699 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 700 | SkPath path; |
| 701 | path.setIsVolatile(true); |
| 702 | path.addRect(rect); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 703 | return this->drawAndStencilPath(clip, ss, op, invert, aa, viewMatrix, path); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 706 | void GrRenderTargetContext::fillRectToRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 707 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 708 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 709 | const SkMatrix& viewMatrix, |
| 710 | const SkRect& rectToDraw, |
| 711 | const SkRect& localRect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 712 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 713 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 714 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 715 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectToRect", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 716 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 717 | SkRect croppedRect = rectToDraw; |
| 718 | SkRect croppedLocalRect = localRect; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 719 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, |
| 720 | &croppedRect, &croppedLocalRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 721 | return; |
| 722 | } |
| 723 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 724 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 725 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 726 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 727 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 728 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalRect( |
| 729 | std::move(paint), viewMatrix, croppedRect, croppedLocalRect, aaType); |
| 730 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 731 | return; |
joshualitt | 04194f3 | 2016-01-13 10:08:27 -0800 | [diff] [blame] | 732 | } |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 733 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 734 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalRect( |
| 735 | std::move(paint), viewMatrix, croppedRect, croppedLocalRect); |
| 736 | if (op) { |
| 737 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 738 | return; |
| 739 | } |
| 740 | |
| 741 | SkMatrix viewAndUnLocalMatrix; |
| 742 | if (!viewAndUnLocalMatrix.setRectToRect(localRect, rectToDraw, SkMatrix::kFill_ScaleToFit)) { |
| 743 | SkDebugf("fillRectToRect called with empty local matrix.\n"); |
| 744 | return; |
| 745 | } |
| 746 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 747 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 748 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewAndUnLocalMatrix, |
| 749 | GrShape(localRect)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 752 | static bool must_filter(const SkRect& src, const SkRect& dst, const SkMatrix& ctm) { |
| 753 | // We don't currently look for 90 degree rotations, mirroring, or downscales that sample at |
| 754 | // texel centers. |
| 755 | if (!ctm.isTranslate()) { |
| 756 | return true; |
| 757 | } |
| 758 | if (src.width() != dst.width() || src.height() != dst.height()) { |
| 759 | return true; |
| 760 | } |
| 761 | // Check that the device space rectangle's fractional offset is the same as the src rectangle, |
| 762 | // and that therefore integers in the src image fall on integers in device space. |
| 763 | SkScalar x = ctm.getTranslateX(), y = ctm.getTranslateY(); |
| 764 | x += dst.fLeft; y += dst.fTop; |
| 765 | x -= src.fLeft; y -= src.fTop; |
| 766 | return !SkScalarIsInt(x) || !SkScalarIsInt(y); |
| 767 | } |
| 768 | |
| 769 | void GrRenderTargetContext::drawTextureAffine(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 770 | GrSamplerState::Filter filter, GrColor color, |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 771 | const SkRect& srcRect, const SkRect& dstRect, GrAA aa, |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 772 | const SkMatrix& viewMatrix, |
| 773 | sk_sp<GrColorSpaceXform> colorSpaceXform) { |
| 774 | ASSERT_SINGLE_OWNER |
| 775 | RETURN_IF_ABANDONED |
| 776 | SkDEBUGCODE(this->validate();) |
| 777 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureAffine", fContext); |
| 778 | SkASSERT(!viewMatrix.hasPerspective()); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 779 | if (filter != GrSamplerState::Filter::kNearest && !must_filter(srcRect, dstRect, viewMatrix)) { |
| 780 | filter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 781 | } |
Brian Salomon | ff9d6d3 | 2017-08-30 10:27:49 -0400 | [diff] [blame] | 782 | SkRect clippedDstRect = dstRect; |
| 783 | SkRect clippedSrcRect = srcRect; |
| 784 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect, |
| 785 | &clippedSrcRect)) { |
| 786 | return; |
| 787 | } |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 788 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 789 | bool allowSRGB = SkToBool(this->colorSpaceInfo().colorSpace()); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 790 | this->addDrawOp( |
| 791 | clip, GrTextureOp::Make(std::move(proxy), filter, color, clippedSrcRect, clippedDstRect, |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 792 | aaType, viewMatrix, std::move(colorSpaceXform), allowSRGB)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 795 | void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 796 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 797 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 798 | const SkMatrix& viewMatrix, |
| 799 | const SkRect& rectToDraw, |
| 800 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 801 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 802 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 803 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 804 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithLocalMatrix", fContext); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 805 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 806 | SkRect croppedRect = rectToDraw; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 807 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 811 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 812 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 813 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 814 | if (GrAAType::kCoverage != aaType) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 815 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( |
| 816 | std::move(paint), viewMatrix, localMatrix, croppedRect, aaType); |
| 817 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 818 | return; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 819 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 820 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 821 | std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalMatrix( |
| 822 | std::move(paint), viewMatrix, localMatrix, croppedRect); |
| 823 | if (op) { |
| 824 | this->addDrawOp(clip, std::move(op)); |
csmartdalton | fc49d56 | 2016-07-26 17:05:47 -0700 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
| 828 | SkMatrix viewAndUnLocalMatrix; |
| 829 | if (!localMatrix.invert(&viewAndUnLocalMatrix)) { |
| 830 | SkDebugf("fillRectWithLocalMatrix called with degenerate local matrix.\n"); |
| 831 | return; |
| 832 | } |
| 833 | viewAndUnLocalMatrix.postConcat(viewMatrix); |
| 834 | |
| 835 | SkPath path; |
| 836 | path.setIsVolatile(true); |
| 837 | path.addRect(rectToDraw); |
| 838 | path.transform(localMatrix); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 839 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewAndUnLocalMatrix, |
| 840 | GrShape(path)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 843 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 844 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 845 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 846 | sk_sp<SkVertices> vertices, |
| 847 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 848 | ASSERT_SINGLE_OWNER |
| 849 | RETURN_IF_ABANDONED |
| 850 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 851 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawVertices", fContext); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 852 | |
| 853 | AutoCheckFlush acf(this->drawingManager()); |
| 854 | |
| 855 | SkASSERT(vertices); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 856 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 857 | std::unique_ptr<GrDrawOp> op = GrDrawVerticesOp::Make( |
| 858 | std::move(paint), std::move(vertices), viewMatrix, aaType, |
| 859 | this->colorSpaceInfo().isGammaCorrect(), |
| 860 | this->colorSpaceInfo().refColorSpaceXformFromSRGB(), overridePrimType); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 861 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /////////////////////////////////////////////////////////////////////////////// |
| 865 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 866 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 867 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 868 | const SkMatrix& viewMatrix, |
| 869 | int spriteCount, |
| 870 | const SkRSXform xform[], |
| 871 | const SkRect texRect[], |
| 872 | const SkColor colors[]) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 873 | ASSERT_SINGLE_OWNER |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 874 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 875 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 876 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawAtlas", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 877 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 878 | AutoCheckFlush acf(this->drawingManager()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 879 | |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 880 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
| 881 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(std::move(paint), viewMatrix, aaType, |
| 882 | spriteCount, xform, texRect, colors); |
| 883 | this->addDrawOp(clip, std::move(op)); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /////////////////////////////////////////////////////////////////////////////// |
| 887 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 888 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 889 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 890 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 891 | const SkMatrix& viewMatrix, |
| 892 | const SkRRect& rrect, |
| 893 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 894 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 895 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 896 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 897 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRRect", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 898 | if (rrect.isEmpty()) { |
| 899 | return; |
| 900 | } |
| 901 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 902 | GrNoClip noclip; |
| 903 | const GrClip* clip = &origClip; |
| 904 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 905 | // 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] | 906 | // 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] | 907 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 908 | // attempts to mitigate the stencil clip cost but will only help when the entire clip stack |
| 909 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. |
| 910 | SkRRect devRRect; |
| 911 | if (rrect.transform(viewMatrix, &devRRect) && clip->quickContains(devRRect)) { |
| 912 | clip = &noclip; |
| 913 | } |
| 914 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 915 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 916 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 917 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 918 | const SkStrokeRec stroke = style.strokeRec(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 919 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 920 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 921 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 922 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 923 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeRRectOp(std::move(paint), |
| 924 | viewMatrix, |
| 925 | rrect, |
| 926 | stroke, |
| 927 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 928 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 929 | this->addDrawOp(*clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 930 | return; |
| 931 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 932 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 933 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 934 | this->drawShapeUsingPathRenderer(*clip, std::move(paint), aa, viewMatrix, |
| 935 | GrShape(rrect, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 938 | /////////////////////////////////////////////////////////////////////////////// |
| 939 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 940 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 941 | SkPoint3 result; |
| 942 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 943 | result.fZ = pt.fZ; |
| 944 | return result; |
| 945 | } |
| 946 | |
| 947 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 948 | const SkMatrix& viewMatrix, |
| 949 | const SkPath& path, |
| 950 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 951 | ASSERT_SINGLE_OWNER |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 952 | if (this->drawingManager()->wasAbandoned()) { |
| 953 | return true; |
| 954 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 955 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 956 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFastShadow", fContext); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 957 | |
| 958 | // check z plane |
| 959 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 960 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 961 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 962 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | SkRRect rrect; |
| 967 | SkRect rect; |
| 968 | // we can only handle rects, circles, and rrects with circular corners |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 969 | bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsSimpleCircular(rrect) && |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 970 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 971 | if (!isRRect && |
| 972 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 973 | rect.width() > SK_ScalarNearlyZero) { |
| 974 | rrect.setOval(rect); |
| 975 | isRRect = true; |
| 976 | } |
| 977 | if (!isRRect && path.isRect(&rect)) { |
| 978 | rrect.setRect(rect); |
| 979 | isRRect = true; |
| 980 | } |
| 981 | |
| 982 | if (!isRRect) { |
| 983 | return false; |
| 984 | } |
| 985 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 986 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 987 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 988 | } |
| 989 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 990 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 991 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 992 | // transform light |
| 993 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 994 | |
| 995 | // 1/scale |
| 996 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
| 997 | SkScalarInvert(viewMatrix[SkMatrix::kMScaleX]) : |
| 998 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 999 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1000 | |
| 1001 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1002 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
| 1003 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1004 | if (SkColorGetA(rec.fAmbientColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1005 | SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight); |
| 1006 | const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight); |
| 1007 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1008 | |
| 1009 | // Outset the shadow rrect to the border of the penumbra |
| 1010 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1011 | SkRRect ambientRRect; |
| 1012 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1013 | // If the rrect was an oval then its outset will also be one. |
| 1014 | // We set it explicitly to avoid errors. |
| 1015 | if (rrect.isOval()) { |
| 1016 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1017 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1018 | SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1019 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1020 | } |
| 1021 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1022 | GrColor ambientColor = SkColorToPremulGrColor(rec.fAmbientColor); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1023 | if (transparent) { |
| 1024 | // set a large inset to force a fill |
| 1025 | devSpaceInsetWidth = ambientRRect.width(); |
| 1026 | } |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1027 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(ambientColor, viewMatrix, |
| 1028 | ambientRRect, |
| 1029 | devSpaceAmbientBlur, |
Jim Van Verth | d75b343 | 2018-04-19 14:47:53 -0400 | [diff] [blame] | 1030 | devSpaceInsetWidth); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1031 | SkASSERT(op); |
| 1032 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1033 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1034 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1035 | if (SkColorGetA(rec.fSpotColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1036 | SkScalar devSpaceSpotBlur; |
| 1037 | SkScalar spotScale; |
| 1038 | SkVector spotOffset; |
| 1039 | SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY, |
| 1040 | devLightPos.fZ, rec.fLightRadius, |
| 1041 | &devSpaceSpotBlur, &spotScale, &spotOffset); |
| 1042 | // handle scale of radius due to CTM |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1043 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1044 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1045 | // Adjust translate for the effect of the scale. |
| 1046 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1047 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1048 | // This offset is in dev space, need to transform it into source space. |
| 1049 | SkMatrix ctmInverse; |
| 1050 | if (viewMatrix.invert(&ctmInverse)) { |
| 1051 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1052 | } else { |
| 1053 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1054 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1055 | SkASSERT(false); |
| 1056 | } |
| 1057 | |
| 1058 | // Compute the transformed shadow rrect |
| 1059 | SkRRect spotShadowRRect; |
| 1060 | SkMatrix shadowTransform; |
| 1061 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1062 | rrect.transform(shadowTransform, &spotShadowRRect); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1063 | SkScalar spotRadius = SkRRectPriv::GetSimpleRadii(spotShadowRRect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1064 | |
| 1065 | // Compute the insetWidth |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1066 | SkScalar blurOutset = srcSpaceSpotBlur; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1067 | SkScalar insetWidth = blurOutset; |
| 1068 | if (transparent) { |
| 1069 | // If transparent, just do a fill |
| 1070 | insetWidth += spotShadowRRect.width(); |
| 1071 | } else { |
| 1072 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1073 | // border. We want to extend this inset area so that it meets up with the caster |
| 1074 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1075 | // |
| 1076 | // We compare the min and max corners inset by the radius between the original |
| 1077 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1078 | // between the scaled radius and the original radius gives the distance from the |
| 1079 | // transformed shadow shape to the original shape in that corner. The max |
| 1080 | // of these gives the maximum distance we need to cover. |
| 1081 | // |
| 1082 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1083 | // that to get the full insetWidth. |
| 1084 | SkScalar maxOffset; |
| 1085 | if (rrect.isRect()) { |
| 1086 | // Manhattan distance works better for rects |
| 1087 | maxOffset = SkTMax(SkTMax(SkTAbs(spotShadowRRect.rect().fLeft - |
| 1088 | rrect.rect().fLeft), |
| 1089 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1090 | rrect.rect().fTop)), |
| 1091 | SkTMax(SkTAbs(spotShadowRRect.rect().fRight - |
| 1092 | rrect.rect().fRight), |
| 1093 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1094 | rrect.rect().fBottom))); |
| 1095 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1096 | SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1097 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1098 | rrect.rect().fLeft + dr, |
| 1099 | spotShadowRRect.rect().fTop - |
| 1100 | rrect.rect().fTop + dr); |
| 1101 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1102 | rrect.rect().fRight - dr, |
| 1103 | spotShadowRRect.rect().fBottom - |
| 1104 | rrect.rect().fBottom - dr); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 1105 | maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset), |
| 1106 | SkPointPriv::LengthSqd(lowerRightOffset))) + dr; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1107 | } |
| 1108 | insetWidth += maxOffset; |
| 1109 | } |
| 1110 | |
| 1111 | // Outset the shadow rrect to the border of the penumbra |
| 1112 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1113 | if (spotShadowRRect.isOval()) { |
| 1114 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1115 | } else { |
| 1116 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1117 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1118 | } |
| 1119 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1120 | GrColor spotColor = SkColorToPremulGrColor(rec.fSpotColor); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1121 | |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1122 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(spotColor, viewMatrix, |
| 1123 | spotShadowRRect, |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1124 | 2.0f * devSpaceSpotBlur, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1125 | insetWidth); |
| 1126 | SkASSERT(op); |
| 1127 | this->addDrawOp(clip, std::move(op)); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | /////////////////////////////////////////////////////////////////////////////// |
| 1134 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1135 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1136 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1137 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1138 | const SkMatrix& viewMatrix, |
| 1139 | const SkRRect& origOuter, |
| 1140 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1141 | SkASSERT(!origInner.isEmpty()); |
| 1142 | SkASSERT(!origOuter.isEmpty()); |
| 1143 | |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1144 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1145 | |
Brian Salomon | 45839f9 | 2017-12-04 09:02:35 -0500 | [diff] [blame] | 1146 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
| 1147 | |
| 1148 | if (GrAAType::kMSAA == aaType) { |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1152 | if (GrAAType::kCoverage == aaType && SkRRectPriv::IsCircle(*inner) |
| 1153 | && SkRRectPriv::IsCircle(*outer)) { |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1154 | auto outerR = outer->width() / 2.f; |
| 1155 | auto innerR = inner->width() / 2.f; |
| 1156 | auto cx = outer->getBounds().fLeft + outerR; |
| 1157 | auto cy = outer->getBounds().fTop + outerR; |
| 1158 | if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && |
| 1159 | SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { |
| 1160 | auto avgR = (innerR + outerR) / 2.f; |
| 1161 | auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); |
| 1162 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1163 | stroke.setStrokeStyle(outerR - innerR); |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1164 | auto op = GrOvalOpFactory::MakeOvalOp(std::move(paint), viewMatrix, circleBounds, |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame^] | 1165 | GrStyle(stroke, nullptr), |
| 1166 | this->caps()->shaderCaps()); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1167 | if (op) { |
| 1168 | this->addDrawOp(clip, std::move(op)); |
| 1169 | return true; |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 1174 | GrClipEdgeType innerEdgeType, outerEdgeType; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1175 | if (GrAAType::kCoverage == aaType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1176 | innerEdgeType = GrClipEdgeType::kInverseFillAA; |
| 1177 | outerEdgeType = GrClipEdgeType::kFillAA; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1178 | } else { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1179 | innerEdgeType = GrClipEdgeType::kInverseFillBW; |
| 1180 | outerEdgeType = GrClipEdgeType::kFillBW; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1181 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1182 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1183 | SkMatrix inverseVM; |
| 1184 | if (!viewMatrix.isIdentity()) { |
| 1185 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1186 | return false; |
| 1187 | } |
| 1188 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1189 | return false; |
| 1190 | } |
| 1191 | if (!viewMatrix.invert(&inverseVM)) { |
| 1192 | return false; |
| 1193 | } |
| 1194 | } else { |
| 1195 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1196 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1197 | |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1198 | const auto& caps = *this->caps()->shaderCaps(); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1199 | // TODO these need to be a geometry processors |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1200 | auto innerEffect = GrRRectEffect::Make(innerEdgeType, *inner, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1201 | if (!innerEffect) { |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1205 | auto outerEffect = GrRRectEffect::Make(outerEdgeType, *outer, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1206 | if (!outerEffect) { |
| 1207 | return false; |
| 1208 | } |
| 1209 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1210 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1211 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1212 | |
| 1213 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1214 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1215 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1216 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1217 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1218 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1219 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1220 | return true; |
| 1221 | } |
| 1222 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1223 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1224 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1225 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1226 | const SkMatrix& viewMatrix, |
| 1227 | const SkRRect& outer, |
| 1228 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1229 | ASSERT_SINGLE_OWNER |
| 1230 | RETURN_IF_ABANDONED |
| 1231 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1232 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawDRRect", fContext); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1233 | |
| 1234 | SkASSERT(!outer.isEmpty()); |
| 1235 | SkASSERT(!inner.isEmpty()); |
| 1236 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1237 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1238 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1239 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | SkPath path; |
| 1244 | path.setIsVolatile(true); |
| 1245 | path.addRRect(inner); |
| 1246 | path.addRRect(outer); |
| 1247 | path.setFillType(SkPath::kEvenOdd_FillType); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1248 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(path)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1251 | /////////////////////////////////////////////////////////////////////////////// |
| 1252 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1253 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1254 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1255 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1256 | const SkMatrix& viewMatrix, |
| 1257 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1258 | const GrStyle& style, |
| 1259 | const GrUserStencilSettings* ss) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1260 | ASSERT_SINGLE_OWNER |
| 1261 | RETURN_IF_ABANDONED |
| 1262 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1263 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRegion", fContext); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1264 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1265 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1266 | // 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] | 1267 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1268 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1269 | SkScalarIsInt(viewMatrix.getTranslateX()) && |
| 1270 | SkScalarIsInt(viewMatrix.getTranslateY())) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1271 | aa = GrAA::kNo; |
| 1272 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1273 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1274 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1275 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1276 | SkPath path; |
| 1277 | region.getBoundaryPath(&path); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1278 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1281 | GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1282 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(std::move(paint), viewMatrix, region, aaType, |
| 1283 | ss); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1284 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1287 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1288 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1289 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1290 | const SkMatrix& viewMatrix, |
| 1291 | const SkRect& oval, |
| 1292 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1293 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1294 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1295 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1296 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawOval", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1297 | |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame^] | 1298 | if (oval.isEmpty() && !style.pathEffect()) { |
| 1299 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1302 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1303 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1304 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1305 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 1306 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame^] | 1307 | if (auto op = GrOvalOpFactory::MakeOvalOp(std::move(paint), viewMatrix, oval, style, |
| 1308 | shaderCaps)) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1309 | this->addDrawOp(clip, std::move(op)); |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1310 | return; |
| 1311 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1312 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1313 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1314 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, |
| 1315 | GrShape(SkRRect::MakeOval(oval), style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1318 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1319 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1320 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1321 | const SkMatrix& viewMatrix, |
| 1322 | const SkRect& oval, |
| 1323 | SkScalar startAngle, |
| 1324 | SkScalar sweepAngle, |
| 1325 | bool useCenter, |
| 1326 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1327 | ASSERT_SINGLE_OWNER |
| 1328 | RETURN_IF_ABANDONED |
| 1329 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1330 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawArc", fContext); |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1331 | |
| 1332 | AutoCheckFlush acf(this->drawingManager()); |
| 1333 | |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1334 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1335 | if (GrAAType::kCoverage == aaType) { |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 1336 | const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
Brian Salomon | ea26d6b | 2018-01-23 20:33:21 +0000 | [diff] [blame] | 1337 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(std::move(paint), |
| 1338 | viewMatrix, |
| 1339 | oval, |
| 1340 | startAngle, |
| 1341 | sweepAngle, |
| 1342 | useCenter, |
| 1343 | style, |
| 1344 | shaderCaps); |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 1345 | if (op) { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 1346 | this->addDrawOp(clip, std::move(op)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1347 | return; |
| 1348 | } |
| 1349 | } |
| 1350 | SkPath path; |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 1351 | SkPathPriv::CreateDrawArcPath(&path, oval, startAngle, sweepAngle, useCenter, |
| 1352 | style.isSimpleFill()); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1353 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(path, style)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1356 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1357 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1358 | const SkMatrix& viewMatrix, |
| 1359 | int imageWidth, |
| 1360 | int imageHeight, |
| 1361 | std::unique_ptr<SkLatticeIter> iter, |
| 1362 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1363 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1364 | RETURN_IF_ABANDONED |
| 1365 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1366 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawImageLattice", fContext); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1367 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1368 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1369 | |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1370 | std::unique_ptr<GrDrawOp> op = GrLatticeOp::MakeNonAA(std::move(paint), viewMatrix, imageWidth, |
| 1371 | imageHeight, std::move(iter), dst); |
| 1372 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1375 | GrSemaphoresSubmitted GrRenderTargetContext::prepareForExternalIO( |
| 1376 | int numSemaphores, GrBackendSemaphore backendSemaphores[]) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1377 | ASSERT_SINGLE_OWNER |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1378 | if (this->drawingManager()->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; } |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1379 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1380 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "prepareForExternalIO", fContext); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1381 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 1382 | return this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get(), |
| 1383 | numSemaphores, |
| 1384 | backendSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1385 | } |
| 1386 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1387 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1388 | const GrBackendSemaphore* waitSemaphores) { |
| 1389 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1390 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1391 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1392 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "waitOnSemaphores", fContext); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1393 | |
| 1394 | AutoCheckFlush acf(this->drawingManager()); |
| 1395 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1396 | if (numSemaphores && !this->caps()->fenceSyncSupport()) { |
| 1397 | return false; |
| 1398 | } |
| 1399 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1400 | auto resourceProvider = fContext->contextPriv().resourceProvider(); |
| 1401 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1402 | SkTArray<sk_sp<GrSemaphore>> semaphores(numSemaphores); |
| 1403 | for (int i = 0; i < numSemaphores; ++i) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1404 | sk_sp<GrSemaphore> sema = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 1405 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 1406 | kAdopt_GrWrapOwnership); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1407 | std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(sema, fRenderTargetProxy.get())); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1408 | this->getRTOpList()->addOp(std::move(waitOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1409 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1410 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1411 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1412 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1413 | void GrRenderTargetContext::insertEventMarker(const SkString& str) { |
| 1414 | std::unique_ptr<GrOp> op(GrDebugMarkerOp::Make(fRenderTargetProxy.get(), str)); |
| 1415 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1416 | } |
| 1417 | |
| 1418 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1419 | // Can 'path' be drawn as a pair of filled nested rectangles? |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1420 | 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] | 1421 | |
| 1422 | if (path.isInverseFillType()) { |
| 1423 | return false; |
| 1424 | } |
| 1425 | |
| 1426 | // TODO: this restriction could be lifted if we were willing to apply |
| 1427 | // the matrix to all the points individually rather than just to the rect |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 1428 | if (!viewMatrix.rectStaysRect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | SkPath::Direction dirs[2]; |
| 1433 | if (!path.isNestedFillRects(rects, dirs)) { |
| 1434 | return false; |
| 1435 | } |
| 1436 | |
| 1437 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 1438 | // The two rects need to be wound opposite to each other |
| 1439 | return false; |
| 1440 | } |
| 1441 | |
| 1442 | // Right now, nested rects where the margin is not the same width |
| 1443 | // all around do not render correctly |
| 1444 | const SkScalar* outer = rects[0].asScalars(); |
| 1445 | const SkScalar* inner = rects[1].asScalars(); |
| 1446 | |
| 1447 | bool allEq = true; |
| 1448 | |
| 1449 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 1450 | bool allGoE1 = margin >= SK_Scalar1; |
| 1451 | |
| 1452 | for (int i = 1; i < 4; ++i) { |
| 1453 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 1454 | if (temp < SK_Scalar1) { |
| 1455 | allGoE1 = false; |
| 1456 | } |
| 1457 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 1458 | allEq = false; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | return allEq || allGoE1; |
| 1463 | } |
| 1464 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1465 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1466 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1467 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1468 | const SkMatrix& viewMatrix, |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1469 | const SkPath& path, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1470 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1471 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1472 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1473 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1474 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawPath", fContext); |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1475 | |
| 1476 | GrShape shape(path, style); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1477 | if (shape.isEmpty()) { |
| 1478 | if (shape.inverseFilled()) { |
| 1479 | this->drawPaint(clip, std::move(paint), viewMatrix); |
| 1480 | } |
| 1481 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1484 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1485 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1486 | if (!shape.style().hasPathEffect()) { |
| 1487 | SkRRect rrect; |
| 1488 | // We can ignore the starting point and direction since there is no path effect. |
| 1489 | bool inverted; |
| 1490 | if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) { |
| 1491 | if (rrect.isRect()) { |
| 1492 | this->drawRect(clip, std::move(paint), aa, viewMatrix, rrect.rect(), |
| 1493 | &shape.style()); |
| 1494 | return; |
| 1495 | } else if (rrect.isOval()) { |
| 1496 | this->drawOval(clip, std::move(paint), aa, viewMatrix, rrect.rect(), shape.style()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1497 | return; |
| 1498 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1499 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, shape.style()); |
| 1500 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1501 | } |
| 1502 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 1503 | |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1504 | GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); |
| 1505 | if (GrAAType::kCoverage == aaType) { |
| 1506 | // TODO: Make GrShape check for nested rects. |
| 1507 | SkRect rects[2]; |
| 1508 | if (shape.style().isSimpleFill() && fills_as_nested_rects(viewMatrix, path, rects)) { |
| 1509 | // Concave AA paths are expensive - try to avoid them for special cases |
| 1510 | SkRect rects[2]; |
| 1511 | |
| 1512 | if (fills_as_nested_rects(viewMatrix, path, rects)) { |
| 1513 | std::unique_ptr<GrDrawOp> op = |
| 1514 | GrRectOpFactory::MakeAAFillNestedRects(std::move(paint), viewMatrix, rects); |
| 1515 | if (op) { |
| 1516 | this->addDrawOp(clip, std::move(op)); |
| 1517 | } |
| 1518 | // A null return indicates that there is nothing to draw in this case. |
| 1519 | return; |
| 1520 | } |
| 1521 | } |
| 1522 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1523 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, shape); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 1526 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1527 | const GrUserStencilSettings* ss, |
| 1528 | SkRegion::Op op, |
| 1529 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1530 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1531 | const SkMatrix& viewMatrix, |
| 1532 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1533 | ASSERT_SINGLE_OWNER_PRIV |
| 1534 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1535 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1536 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilPath", |
| 1537 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1538 | |
| 1539 | if (path.isEmpty() && path.isInverseFillType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1540 | this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1541 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 1542 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1543 | return true; |
| 1544 | } |
| 1545 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1546 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1547 | |
| 1548 | // An Assumption here is that path renderer would use some form of tweaking |
| 1549 | // the src color (either the input alpha or in the frag shader) to implement |
| 1550 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1551 | // thing WRT to the blend then we'll need some query on the PR. |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1552 | GrAAType aaType = fRenderTargetContext->chooseAAType(aa, GrAllowMixedSamples::kNo); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1553 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1554 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1555 | SkIRect clipConservativeBounds; |
| 1556 | clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 1557 | &clipConservativeBounds, nullptr); |
| 1558 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1559 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1560 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 1561 | canDrawArgs.fCaps = fRenderTargetContext->drawingManager()->getContext()->caps(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1562 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1563 | canDrawArgs.fShape = &shape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1564 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1565 | canDrawArgs.fAAType = aaType; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 1566 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1567 | |
| 1568 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1569 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 1570 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1571 | if (!pr) { |
| 1572 | return false; |
| 1573 | } |
| 1574 | |
| 1575 | GrPaint paint; |
| 1576 | paint.setCoverageSetOpXPFactory(op, invert); |
| 1577 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1578 | GrPathRenderer::DrawPathArgs args{fRenderTargetContext->drawingManager()->getContext(), |
| 1579 | std::move(paint), |
| 1580 | ss, |
| 1581 | fRenderTargetContext, |
| 1582 | &clip, |
| 1583 | &clipConservativeBounds, |
| 1584 | &viewMatrix, |
| 1585 | &shape, |
| 1586 | aaType, |
| 1587 | fRenderTargetContext->colorSpaceInfo().isGammaCorrect()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 1588 | pr->drawPath(args); |
| 1589 | return true; |
| 1590 | } |
| 1591 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1592 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1593 | ASSERT_SINGLE_OWNER_PRIV |
| 1594 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1595 | if (fRenderTargetContext->wasAbandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1596 | return SkBudgeted::kNo; |
| 1597 | } |
| 1598 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1599 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1600 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 1601 | return fRenderTargetContext->fRenderTargetProxy->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1604 | void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, |
| 1605 | GrPaint&& paint, |
| 1606 | GrAA aa, |
| 1607 | const SkMatrix& viewMatrix, |
| 1608 | const GrShape& originalShape) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1609 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1610 | RETURN_IF_ABANDONED |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1611 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "internalDrawPath", fContext); |
| 1612 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1613 | SkIRect clipConservativeBounds; |
| 1614 | clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr); |
| 1615 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1616 | GrShape tempShape; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1617 | // NVPR cannot handle hairlines, so this would get picked up by a different stencil and |
| 1618 | // cover path renderer (i.e. default path renderer). The hairline renderer produces much |
| 1619 | // smoother hairlines than MSAA. |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1620 | GrAllowMixedSamples allowMixedSamples = originalShape.style().isSimpleHairline() |
| 1621 | ? GrAllowMixedSamples::kNo |
| 1622 | : GrAllowMixedSamples::kYes; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1623 | GrAAType aaType = this->chooseAAType(aa, allowMixedSamples); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1624 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 1625 | canDrawArgs.fCaps = this->drawingManager()->getContext()->caps(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1626 | canDrawArgs.fViewMatrix = &viewMatrix; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1627 | canDrawArgs.fShape = &originalShape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1628 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1629 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 1630 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1631 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 1632 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1633 | if (originalShape.isEmpty() && !originalShape.inverseFilled()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1634 | return; |
| 1635 | } |
| 1636 | |
| 1637 | canDrawArgs.fAAType = aaType; |
| 1638 | |
| 1639 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
| 1640 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
| 1641 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 1642 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1643 | if (!pr && originalShape.style().pathEffect()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1644 | // It didn't work above, so try again with the path effect applied. |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1645 | tempShape = originalShape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 1646 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1647 | return; |
| 1648 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1649 | canDrawArgs.fShape = &tempShape; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1650 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1651 | } |
| 1652 | if (!pr) { |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1653 | if (canDrawArgs.fShape->style().applies()) { |
| 1654 | tempShape = canDrawArgs.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, |
| 1655 | styleScale); |
| 1656 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1657 | return; |
| 1658 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1659 | canDrawArgs.fShape = &tempShape; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1660 | } |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 1661 | // This time, allow SW renderer |
| 1662 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
| 1663 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1664 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1665 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1666 | #ifdef SK_DEBUG |
| 1667 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 1668 | #endif |
| 1669 | return; |
| 1670 | } |
| 1671 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 1672 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1673 | std::move(paint), |
| 1674 | &GrUserStencilSettings::kUnused, |
| 1675 | this, |
| 1676 | &clip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 1677 | &clipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1678 | &viewMatrix, |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1679 | canDrawArgs.fShape, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1680 | aaType, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1681 | this->colorSpaceInfo().isGammaCorrect()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1682 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1685 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 1686 | *bounds = op->bounds(); |
| 1687 | if (op->hasZeroArea()) { |
| 1688 | if (op->hasAABloat()) { |
| 1689 | bounds->outset(0.5f, 0.5f); |
| 1690 | } else { |
| 1691 | // We don't know which way the particular GPU will snap lines or points at integer |
| 1692 | // coords. So we ensure that the bounds is large enough for either snap. |
| 1693 | SkRect before = *bounds; |
| 1694 | bounds->roundOut(bounds); |
| 1695 | if (bounds->fLeft == before.fLeft) { |
| 1696 | bounds->fLeft -= 1; |
| 1697 | } |
| 1698 | if (bounds->fTop == before.fTop) { |
| 1699 | bounds->fTop -= 1; |
| 1700 | } |
| 1701 | if (bounds->fRight == before.fRight) { |
| 1702 | bounds->fRight += 1; |
| 1703 | } |
| 1704 | if (bounds->fBottom == before.fBottom) { |
| 1705 | bounds->fBottom += 1; |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1711 | uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1712 | ASSERT_SINGLE_OWNER |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 1713 | if (this->drawingManager()->wasAbandoned()) { |
| 1714 | return SK_InvalidUniqueID; |
| 1715 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1716 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1717 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "addDrawOp", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 1718 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1719 | // Setup clip |
| 1720 | SkRect bounds; |
| 1721 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 1722 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1723 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
| 1724 | if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA, |
| 1725 | fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip, |
| 1726 | &bounds)) { |
| 1727 | return SK_InvalidUniqueID; |
| 1728 | } |
| 1729 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1730 | if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil || |
| 1731 | appliedClip.hasStencilClip()) { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 1732 | this->getOpList()->setStencilLoadOp(GrLoadOp::kClear); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 1733 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 1734 | this->setNeedsStencil(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1737 | GrPixelConfigIsClamped dstIsClamped = |
| 1738 | GrGetPixelConfigIsClamped(this->colorSpaceInfo().config()); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1739 | GrXferProcessor::DstProxy dstProxy; |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 1740 | if (GrDrawOp::RequiresDstTexture::kYes == op->finalize(*this->caps(), &appliedClip, |
| 1741 | dstIsClamped)) { |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1742 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, op->bounds(), &dstProxy)) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1743 | return SK_InvalidUniqueID; |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 1748 | return this->getRTOpList()->addOp(std::move(op), *this->caps(), |
| 1749 | std::move(appliedClip), dstProxy); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1752 | bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 1753 | const SkRect& opBounds, |
| 1754 | GrXferProcessor::DstProxy* dstProxy) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1755 | if (this->caps()->textureBarrierSupport()) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1756 | if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1757 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 1758 | // will be responsible to detect this situation and request a texture barrier. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1759 | dstProxy->setProxy(sk_ref_sp(texProxy)); |
| 1760 | dstProxy->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1761 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1765 | SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1766 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1767 | SkIRect clippedRect; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1768 | clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1769 | SkIRect drawIBounds; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1770 | opBounds.roundOut(&drawIBounds); |
Brian Salomon | 859621f | 2017-03-16 09:21:54 -0400 | [diff] [blame] | 1771 | // Cover up for any precision issues by outsetting the op bounds a pixel in each direction. |
| 1772 | drawIBounds.outset(1, 1); |
Eric Karl | 72e551e | 2017-04-04 13:42:10 -0700 | [diff] [blame] | 1773 | if (!clippedRect.intersect(drawIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1774 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1775 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1776 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1777 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 1781 | // have per-sample dst values by making the copy multisampled. |
| 1782 | GrSurfaceDesc desc; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1783 | bool rectsMustMatch = false; |
| 1784 | bool disallowSubrect = false; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1785 | GrSurfaceOrigin origin; |
| 1786 | if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &origin, &rectsMustMatch, |
| 1787 | &disallowSubrect)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1788 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1789 | desc.fConfig = rtProxy->config(); |
Greg Daniel | 1efe322 | 2018-04-04 14:02:51 -0400 | [diff] [blame] | 1790 | origin = rtProxy->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1791 | } |
| 1792 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1793 | if (!disallowSubrect) { |
| 1794 | copyRect = clippedRect; |
| 1795 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1796 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1797 | SkIPoint dstPoint, dstOffset; |
| 1798 | SkBackingFit fit; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1799 | if (rectsMustMatch) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1800 | desc.fWidth = rtProxy->width(); |
| 1801 | desc.fHeight = rtProxy->height(); |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1802 | dstPoint = {copyRect.fLeft, copyRect.fTop}; |
| 1803 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1804 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1805 | } else { |
| 1806 | desc.fWidth = copyRect.width(); |
| 1807 | desc.fHeight = copyRect.height(); |
| 1808 | dstPoint = {0, 0}; |
| 1809 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1810 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 1811 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 1812 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1813 | sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeDeferredSurfaceContext( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1814 | desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 1815 | sk_ref_sp(this->colorSpaceInfo().colorSpace())); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1816 | if (!sContext) { |
| 1817 | SkDebugf("setupDstTexture: surfaceContext creation failed.\n"); |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | if (!sContext->copy(rtProxy, copyRect, dstPoint)) { |
| 1822 | SkDebugf("setupDstTexture: copy failed.\n"); |
| 1823 | return false; |
| 1824 | } |
| 1825 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 1826 | dstProxy->setProxy(sContext->asTextureProxyRef()); |
| 1827 | dstProxy->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 1828 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1829 | } |