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