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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkDrawable.h" |
| 9 | #include "include/gpu/GrBackendSemaphore.h" |
| 10 | #include "include/gpu/GrRenderTarget.h" |
| 11 | #include "include/private/GrAuditTrail.h" |
| 12 | #include "include/private/GrColor.h" |
| 13 | #include "include/private/GrOpList.h" |
| 14 | #include "include/private/GrRecordingContext.h" |
| 15 | #include "include/private/SkShadowFlags.h" |
| 16 | #include "include/utils/SkShadowUtils.h" |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 17 | #include "src/core/SkAutoPixmapStorage.h" |
| 18 | #include "src/core/SkConvertPixels.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/core/SkDrawShadowInfo.h" |
| 20 | #include "src/core/SkGlyphRunPainter.h" |
| 21 | #include "src/core/SkLatticeIter.h" |
| 22 | #include "src/core/SkMatrixPriv.h" |
| 23 | #include "src/core/SkRRectPriv.h" |
| 24 | #include "src/core/SkSurfacePriv.h" |
| 25 | #include "src/gpu/GrAppliedClip.h" |
| 26 | #include "src/gpu/GrBlurUtils.h" |
| 27 | #include "src/gpu/GrCaps.h" |
| 28 | #include "src/gpu/GrContextPriv.h" |
| 29 | #include "src/gpu/GrDrawingManager.h" |
| 30 | #include "src/gpu/GrFixedClip.h" |
| 31 | #include "src/gpu/GrGpuResourcePriv.h" |
| 32 | #include "src/gpu/GrMemoryPool.h" |
| 33 | #include "src/gpu/GrPathRenderer.h" |
| 34 | #include "src/gpu/GrQuad.h" |
| 35 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | ad44dd5 | 2019-05-14 14:01:39 -0500 | [diff] [blame] | 36 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 37 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 38 | #include "src/gpu/GrResourceProvider.h" |
| 39 | #include "src/gpu/GrShape.h" |
| 40 | #include "src/gpu/GrStencilAttachment.h" |
| 41 | #include "src/gpu/GrStyle.h" |
| 42 | #include "src/gpu/GrTracing.h" |
| 43 | #include "src/gpu/SkGr.h" |
| 44 | #include "src/gpu/effects/GrRRectEffect.h" |
| 45 | #include "src/gpu/effects/GrTextureDomain.h" |
| 46 | #include "src/gpu/ops/GrAtlasTextOp.h" |
| 47 | #include "src/gpu/ops/GrClearOp.h" |
| 48 | #include "src/gpu/ops/GrClearStencilClipOp.h" |
| 49 | #include "src/gpu/ops/GrDebugMarkerOp.h" |
| 50 | #include "src/gpu/ops/GrDrawAtlasOp.h" |
| 51 | #include "src/gpu/ops/GrDrawOp.h" |
| 52 | #include "src/gpu/ops/GrDrawVerticesOp.h" |
| 53 | #include "src/gpu/ops/GrDrawableOp.h" |
| 54 | #include "src/gpu/ops/GrFillRRectOp.h" |
| 55 | #include "src/gpu/ops/GrFillRectOp.h" |
| 56 | #include "src/gpu/ops/GrLatticeOp.h" |
| 57 | #include "src/gpu/ops/GrOp.h" |
| 58 | #include "src/gpu/ops/GrOvalOpFactory.h" |
| 59 | #include "src/gpu/ops/GrRegionOp.h" |
| 60 | #include "src/gpu/ops/GrSemaphoreOp.h" |
| 61 | #include "src/gpu/ops/GrShadowRRectOp.h" |
| 62 | #include "src/gpu/ops/GrStencilPathOp.h" |
| 63 | #include "src/gpu/ops/GrStrokeRectOp.h" |
| 64 | #include "src/gpu/ops/GrTextureOp.h" |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 65 | #include "src/gpu/ops/GrTransferFromOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 66 | #include "src/gpu/text/GrTextContext.h" |
| 67 | #include "src/gpu/text/GrTextTarget.h" |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 68 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 69 | class GrRenderTargetContext::TextTarget : public GrTextTarget { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 70 | public: |
| 71 | TextTarget(GrRenderTargetContext* renderTargetContext) |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 72 | : GrTextTarget(renderTargetContext->width(), renderTargetContext->height(), |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame] | 73 | renderTargetContext->colorSpaceInfo()) |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 74 | , fRenderTargetContext(renderTargetContext) |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 75 | , fGlyphPainter{*renderTargetContext}{} |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 76 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 77 | void addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) override { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 78 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 79 | } |
| 80 | |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 81 | void drawShape(const GrClip& clip, const SkPaint& paint, |
| 82 | const SkMatrix& viewMatrix, const GrShape& shape) override { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 83 | GrBlurUtils::drawShapeWithMaskFilter(fRenderTargetContext->fContext, fRenderTargetContext, |
| 84 | clip, paint, viewMatrix, shape); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void makeGrPaint(GrMaskFormat maskFormat, const SkPaint& skPaint, const SkMatrix& viewMatrix, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 88 | GrPaint* grPaint) override { |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 89 | auto context = fRenderTargetContext->fContext; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 90 | const GrColorSpaceInfo& colorSpaceInfo = fRenderTargetContext->colorSpaceInfo(); |
| 91 | if (kARGB_GrMaskFormat == maskFormat) { |
| 92 | SkPaintToGrPaintWithPrimitiveColor(context, colorSpaceInfo, skPaint, grPaint); |
| 93 | } else { |
| 94 | SkPaintToGrPaint(context, colorSpaceInfo, skPaint, viewMatrix, grPaint); |
| 95 | } |
| 96 | } |
| 97 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 98 | GrRecordingContext* getContext() override { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 99 | return fRenderTargetContext->fContext; |
| 100 | } |
| 101 | |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 102 | SkGlyphRunListPainter* glyphPainter() override { |
| 103 | return &fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 106 | private: |
| 107 | GrRenderTargetContext* fRenderTargetContext; |
Herb Derby | 6595687 | 2018-08-21 16:55:04 -0400 | [diff] [blame] | 108 | SkGlyphRunListPainter fGlyphPainter; |
Herb Derby | 74c6ed3 | 2018-07-28 18:07:54 -0400 | [diff] [blame] | 109 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 110 | }; |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 111 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 112 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 113 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 114 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 115 | #define ASSERT_SINGLE_OWNER_PRIV \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 116 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 117 | #define RETURN_IF_ABANDONED if (fContext->priv().abandoned()) { return; } |
| 118 | #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return; } |
| 119 | #define RETURN_FALSE_IF_ABANDONED if (fContext->priv().abandoned()) { return false; } |
| 120 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->fContext->priv().abandoned()) { return false; } |
| 121 | #define RETURN_NULL_IF_ABANDONED if (fContext->priv().abandoned()) { return nullptr; } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 122 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 123 | ////////////////////////////////////////////////////////////////////////////// |
| 124 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 125 | class AutoCheckFlush { |
| 126 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 127 | AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 128 | SkASSERT(fDrawingManager); |
| 129 | } |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 130 | ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 131 | |
| 132 | private: |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 133 | GrDrawingManager* fDrawingManager; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 136 | // 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] | 137 | // 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] | 138 | // 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] | 139 | // when the renderTargetContext attempts to use it (via getOpList). |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 140 | GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 141 | sk_sp<GrRenderTargetProxy> rtp, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 142 | sk_sp<SkColorSpace> colorSpace, |
| 143 | const SkSurfaceProps* surfaceProps, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 144 | bool managedOpList) |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 145 | : GrSurfaceContext(context, rtp->config(), std::move(colorSpace)) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 146 | , fRenderTargetProxy(std::move(rtp)) |
| 147 | , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 148 | , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
| 149 | , fManagedOpList(managedOpList) { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 150 | fTextTarget.reset(new TextTarget(this)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 151 | SkDEBUGCODE(this->validate();) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 152 | } |
| 153 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 154 | #ifdef SK_DEBUG |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 155 | void GrRenderTargetContext::validate() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 156 | SkASSERT(fRenderTargetProxy); |
| 157 | fRenderTargetProxy->validate(fContext); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 158 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 159 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 160 | SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 161 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 162 | } |
| 163 | #endif |
| 164 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 165 | GrRenderTargetContext::~GrRenderTargetContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 166 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 169 | inline GrAAType GrRenderTargetContext::chooseAAType(GrAA aa) { |
| 170 | auto fsaaType = this->fsaaType(); |
| 171 | if (GrAA::kNo == aa) { |
| 172 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type reflect |
| 173 | // that. |
| 174 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !this->caps()->multisampleDisableSupport()) { |
| 175 | return GrAAType::kMSAA; |
| 176 | } |
| 177 | return GrAAType::kNone; |
| 178 | } |
| 179 | switch (fsaaType) { |
| 180 | case GrFSAAType::kNone: |
| 181 | case GrFSAAType::kMixedSamples: |
| 182 | return GrAAType::kCoverage; |
| 183 | case GrFSAAType::kUnifiedMSAA: |
| 184 | return GrAAType::kMSAA; |
| 185 | } |
| 186 | SK_ABORT("Unexpected fsaa type"); |
| 187 | return GrAAType::kNone; |
| 188 | } |
| 189 | |
| 190 | static inline GrPathRenderer::AATypeFlags choose_path_aa_type_flags( |
| 191 | GrAA aa, GrFSAAType fsaaType, const GrCaps& caps) { |
| 192 | using AATypeFlags = GrPathRenderer::AATypeFlags; |
| 193 | if (GrAA::kNo == aa) { |
| 194 | // On some devices we cannot disable MSAA if it is enabled so we make the AA type flags |
| 195 | // reflect that. |
| 196 | if (fsaaType == GrFSAAType::kUnifiedMSAA && !caps.multisampleDisableSupport()) { |
| 197 | return AATypeFlags::kMSAA; |
| 198 | } |
| 199 | return AATypeFlags::kNone; |
| 200 | } |
| 201 | switch (fsaaType) { |
| 202 | case GrFSAAType::kNone: |
| 203 | return AATypeFlags::kCoverage; |
| 204 | case GrFSAAType::kMixedSamples: |
| 205 | return AATypeFlags::kCoverage | AATypeFlags::kMixedSampledStencilThenCover; |
| 206 | case GrFSAAType::kUnifiedMSAA: |
| 207 | return AATypeFlags::kMSAA; |
| 208 | } |
| 209 | SK_ABORT("Invalid GrFSAAType."); |
| 210 | return AATypeFlags::kNone; |
| 211 | } |
| 212 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 213 | GrTextureProxy* GrRenderTargetContext::asTextureProxy() { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 214 | return fRenderTargetProxy->asTextureProxy(); |
| 215 | } |
| 216 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 217 | const GrTextureProxy* GrRenderTargetContext::asTextureProxy() const { |
| 218 | return fRenderTargetProxy->asTextureProxy(); |
| 219 | } |
| 220 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 221 | sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() { |
| 222 | return sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 223 | } |
| 224 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 225 | GrMipMapped GrRenderTargetContext::mipMapped() const { |
| 226 | if (const GrTextureProxy* proxy = this->asTextureProxy()) { |
| 227 | return proxy->mipMapped(); |
| 228 | } |
| 229 | return GrMipMapped::kNo; |
| 230 | } |
| 231 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 232 | GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 233 | ASSERT_SINGLE_OWNER |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 234 | SkDEBUGCODE(this->validate();) |
| 235 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 236 | if (!fOpList || fOpList->isClosed()) { |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 237 | fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy, fManagedOpList); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 240 | return fOpList.get(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 243 | GrOpList* GrRenderTargetContext::getOpList() { |
| 244 | return this->getRTOpList(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 247 | void GrRenderTargetContext::drawGlyphRunList( |
| 248 | const GrClip& clip, const SkMatrix& viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 249 | const SkGlyphRunList& blob) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 250 | ASSERT_SINGLE_OWNER |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 251 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 252 | SkDEBUGCODE(this->validate();) |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 253 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawGlyphRunList", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 254 | |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 255 | // Drawing text can cause us to do inline uploads. This is not supported for wrapped vulkan |
| 256 | // secondary command buffers because it would require stopping and starting a render pass which |
| 257 | // we don't have access to. |
| 258 | if (this->wrapsVkSecondaryCB()) { |
| 259 | return; |
| 260 | } |
| 261 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 262 | GrTextContext* atlasTextContext = this->drawingManager()->getTextContext(); |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 263 | atlasTextContext->drawGlyphRunList(fContext, fTextTarget.get(), clip, viewMatrix, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 264 | fSurfaceProps, blob); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 267 | void GrRenderTargetContext::discard() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 268 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 269 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 270 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 271 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "discard", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 272 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 273 | AutoCheckFlush acf(this->drawingManager()); |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 274 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 275 | this->getRTOpList()->discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 278 | void GrRenderTargetContext::clear(const SkIRect* rect, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 279 | const SkPMColor4f& color, |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 280 | CanClearFullscreen canClearFullscreen) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 281 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 282 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 283 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 284 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "clear", fContext); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 285 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 286 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 287 | this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, |
| 288 | canClearFullscreen); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 289 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 290 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 291 | void GrRenderTargetContextPriv::clear(const GrFixedClip& clip, |
| 292 | const SkPMColor4f& color, |
| 293 | CanClearFullscreen canClearFullscreen) { |
| 294 | ASSERT_SINGLE_OWNER_PRIV |
| 295 | RETURN_IF_ABANDONED_PRIV |
| 296 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 297 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clear", |
| 298 | fRenderTargetContext->fContext); |
| 299 | |
| 300 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
| 301 | fRenderTargetContext->internalClear(clip, color, canClearFullscreen); |
| 302 | } |
| 303 | |
| 304 | static void clear_to_grpaint(const SkPMColor4f& color, GrPaint* paint) { |
| 305 | paint->setColor4f(color); |
| 306 | if (color.isOpaque()) { |
| 307 | // Can just rely on the src-over blend mode to do the right thing |
| 308 | paint->setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
| 309 | } else { |
| 310 | // A clear overwrites the prior color, so even if it's transparent, it behaves as if it |
| 311 | // were src blended |
| 312 | paint->setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | void GrRenderTargetContext::internalClear(const GrFixedClip& clip, |
| 317 | const SkPMColor4f& color, |
| 318 | CanClearFullscreen canClearFullscreen) { |
| 319 | bool isFull = false; |
| 320 | if (!clip.hasWindowRectangles()) { |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 321 | // TODO: wrt the shouldInitializeTextures path, it would be more performant to |
| 322 | // only clear the entire target if we knew it had not been cleared before. As |
| 323 | // is this could end up doing a lot of redundant clears. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 324 | isFull = !clip.scissorEnabled() || |
| 325 | (CanClearFullscreen::kYes == canClearFullscreen && |
Robert Phillips | 0e35ce2 | 2019-04-05 10:57:28 -0400 | [diff] [blame] | 326 | (this->caps()->preferFullscreenClears() || this->caps()->shouldInitializeTextures())) || |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 327 | clip.scissorRect().contains(SkIRect::MakeWH(this->width(), this->height())); |
| 328 | } |
| 329 | |
| 330 | if (isFull) { |
| 331 | if (this->getRTOpList()->resetForFullscreenClear() && |
| 332 | !this->caps()->performColorClearsAsDraws()) { |
| 333 | // The op list was emptied and native clears are allowed, so just use the load op |
| 334 | this->getRTOpList()->setColorLoadOp(GrLoadOp::kClear, color); |
| 335 | return; |
| 336 | } else { |
| 337 | // Will use an op for the clear, reset the load op to discard since the op will |
| 338 | // blow away the color buffer contents |
| 339 | this->getRTOpList()->setColorLoadOp(GrLoadOp::kDiscard); |
| 340 | } |
| 341 | |
| 342 | // Must add an op to the list (either because we couldn't use a load op, or because the |
| 343 | // clear load op isn't supported) |
| 344 | if (this->caps()->performColorClearsAsDraws()) { |
| 345 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 346 | GrPaint paint; |
| 347 | clear_to_grpaint(color, &paint); |
| 348 | this->addDrawOp(GrFixedClip::Disabled(), |
| 349 | GrFillRectOp::Make(fContext, std::move(paint), |
| 350 | GrAAType::kNone, SkMatrix::I(), rtRect)); |
| 351 | } else { |
| 352 | this->getRTOpList()->addOp(GrClearOp::Make(fContext, SkIRect::MakeEmpty(), color, |
| 353 | /* fullscreen */ true), *this->caps()); |
| 354 | } |
| 355 | } else { |
| 356 | if (this->caps()->performPartialClearsAsDraws()) { |
| 357 | // performPartialClearsAsDraws() also returns true if any clear has to be a draw. |
| 358 | SkRect scissor = SkRect::Make(clip.scissorRect()); |
| 359 | GrPaint paint; |
| 360 | clear_to_grpaint(color, &paint); |
| 361 | |
| 362 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), GrAAType::kNone, |
| 363 | SkMatrix::I(), scissor)); |
| 364 | } else { |
| 365 | std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip, color, |
| 366 | this->asSurfaceProxy())); |
| 367 | // This version of the clear op factory can return null if the clip doesn't intersect |
| 368 | // with the surface proxy's boundary |
| 369 | if (!op) { |
| 370 | return; |
| 371 | } |
| 372 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 377 | void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const SkPMColor4f& color) { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 378 | ASSERT_SINGLE_OWNER_PRIV |
| 379 | RETURN_IF_ABANDONED_PRIV |
| 380 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 381 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "absClear", |
| 382 | fRenderTargetContext->fContext); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 383 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 384 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 385 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 386 | SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(), |
| 387 | fRenderTargetContext->fRenderTargetProxy->worstCaseHeight()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 388 | |
| 389 | if (clearRect) { |
| 390 | if (clearRect->contains(rtRect)) { |
| 391 | clearRect = nullptr; // full screen |
| 392 | } else { |
| 393 | if (!rtRect.intersect(*clearRect)) { |
| 394 | return; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // TODO: in a post-MDB world this should be handled at the OpList level. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 400 | // This makes sure to always add an op to the list, instead of marking the clear as a load op. |
| 401 | // This code follows very similar logic to internalClear() below, but critical differences are |
| 402 | // highlighted in line related to absClear()'s unique behavior. |
| 403 | if (clearRect) { |
| 404 | if (fRenderTargetContext->caps()->performPartialClearsAsDraws()) { |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 405 | GrPaint paint; |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 406 | clear_to_grpaint(color, &paint); |
| 407 | |
| 408 | // Use the disabled clip; the rect geometry already matches the clear rectangle and |
| 409 | // if it were added to a scissor, that would be intersected with the logical surface |
| 410 | // bounds and not the worst case dimensions required here. |
| 411 | fRenderTargetContext->addDrawOp(GrFixedClip::Disabled(), |
| 412 | GrFillRectOp::Make(fRenderTargetContext->fContext, |
| 413 | std::move(paint), |
| 414 | GrAAType::kNone, |
| 415 | SkMatrix::I(), |
| 416 | SkRect::Make(rtRect))); |
| 417 | } else { |
| 418 | // Must use the ClearOp factory that takes a boolean (false) instead of a surface |
| 419 | // proxy. The surface proxy variant would intersect the clip rect with its logical |
| 420 | // bounds, which is not desired in this special case. |
| 421 | fRenderTargetContext->getRTOpList()->addOp( |
| 422 | GrClearOp::Make(fRenderTargetContext->fContext, rtRect, color, |
| 423 | /* fullscreen */ false), |
| 424 | *fRenderTargetContext->caps()); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 425 | } |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 426 | } else { |
| 427 | // Reset the oplist like in internalClear(), but do not rely on a load op for the clear |
| 428 | fRenderTargetContext->getRTOpList()->resetForFullscreenClear(); |
| 429 | fRenderTargetContext->getRTOpList()->setColorLoadOp(GrLoadOp::kDiscard); |
| 430 | |
| 431 | if (fRenderTargetContext->caps()->performColorClearsAsDraws()) { |
| 432 | // This draws a quad covering the worst case dimensions instead of just the logical |
| 433 | // width and height like in internalClear(). |
| 434 | GrPaint paint; |
| 435 | clear_to_grpaint(color, &paint); |
| 436 | fRenderTargetContext->addDrawOp(GrFixedClip::Disabled(), |
| 437 | GrFillRectOp::Make(fRenderTargetContext->fContext, |
| 438 | std::move(paint), |
| 439 | GrAAType::kNone, |
| 440 | SkMatrix::I(), |
| 441 | SkRect::Make(rtRect))); |
| 442 | } else { |
| 443 | // Nothing special about this path in absClear compared to internalClear() |
| 444 | fRenderTargetContext->getRTOpList()->addOp( |
| 445 | GrClearOp::Make(fRenderTargetContext->fContext, SkIRect::MakeEmpty(), color, |
| 446 | /* fullscreen */ true), |
| 447 | *fRenderTargetContext->caps()); |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 448 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 449 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 452 | void GrRenderTargetContext::drawPaint(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 453 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 454 | const SkMatrix& viewMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 455 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 456 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 457 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 458 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPaint", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 459 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 460 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 461 | // don't overflow fixed-point implementations |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 462 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 463 | SkRect r = fRenderTargetProxy->getBoundsRect(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 464 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 465 | // Check if we can optimize a clipped drawPaint(). We only do the transformation when there are |
| 466 | // no fragment processors because they may depend on having correct local coords and this path |
| 467 | // draws in device space without a local matrix. It currently handles converting clipRRect() |
| 468 | // to drawRRect() and solid colors to screen-filling drawRects() (which are then converted into |
| 469 | // clears if possible in drawRect). |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 470 | if (!paint.numTotalFragmentProcessors()) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 471 | SkRRect rrect; |
| 472 | GrAA aa = GrAA::kNo; |
| 473 | if (clip.isRRect(r, &rrect, &aa)) { |
| 474 | if (rrect.isRect()) { |
| 475 | // Use drawFilledRect() with no clip and the reduced rectangle |
| 476 | this->drawFilledRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect.rect()); |
| 477 | } else { |
| 478 | // Use drawRRect() with no clip |
| 479 | this->drawRRect(GrNoClip(), std::move(paint), aa, SkMatrix::I(), rrect, |
| 480 | GrStyle::SimpleFill()); |
| 481 | } |
| 482 | } else { |
| 483 | // Use drawFilledRect() with no view matrix to draw a fullscreen quad, but preserve |
| 484 | // the clip. Since the paint has no FPs we can drop the view matrix without worrying |
| 485 | // about local coordinates. If the clip is simple, drawFilledRect() will turn this into |
| 486 | // a clear or a scissored clear. |
| 487 | this->drawFilledRect(clip, std::move(paint), aa, SkMatrix::I(), r); |
Michael Ludwig | 3d6390e | 2018-10-09 11:45:16 -0400 | [diff] [blame] | 488 | } |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 489 | return; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 492 | // Since the paint is not trivial, there's no way at this point drawRect() could have converted |
| 493 | // this drawPaint() into an optimized clear. drawRect() would then use GrFillRectOp without |
| 494 | // a local matrix, so we can simplify things and use the local matrix variant to draw a screen |
| 495 | // filling rect with the inverse view matrix for local coords, which works for all matrix |
| 496 | // conditions. |
| 497 | SkMatrix localMatrix; |
| 498 | if (!viewMatrix.invert(&localMatrix)) { |
| 499 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 500 | } |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 501 | |
| 502 | AutoCheckFlush acf(this->drawingManager()); |
| 503 | std::unique_ptr<GrDrawOp> op = GrFillRectOp::MakeWithLocalMatrix( |
| 504 | fContext, std::move(paint), GrAAType::kNone, SkMatrix::I(), localMatrix, r); |
| 505 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 506 | } |
| 507 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 508 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 509 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 510 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 511 | } |
| 512 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 513 | // Attempts to crop a rect and optional local rect to the clip boundaries. |
| 514 | // Returns false if the draw can be skipped entirely. |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 515 | static bool crop_filled_rect(int width, int height, const GrClip& clip, |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 516 | const SkMatrix& viewMatrix, SkRect* rect, |
| 517 | SkRect* localRect = nullptr) { |
| 518 | if (!viewMatrix.rectStaysRect()) { |
| 519 | return true; |
| 520 | } |
| 521 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 522 | SkIRect clipDevBounds; |
| 523 | SkRect clipBounds; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 524 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 525 | clip.getConservativeBounds(width, height, &clipDevBounds); |
reed | a39667c | 2016-08-22 06:39:49 -0700 | [diff] [blame] | 526 | if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) { |
| 527 | return false; |
| 528 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 529 | |
| 530 | if (localRect) { |
| 531 | if (!rect->intersects(clipBounds)) { |
| 532 | return false; |
| 533 | } |
Michael Ludwig | 904657d | 2019-04-12 10:57:24 -0400 | [diff] [blame] | 534 | // localRect is force-sorted after clipping, so this is a sanity check to make sure callers |
| 535 | // aren't intentionally using inverted local rectangles. |
| 536 | SkASSERT(localRect->isSorted()); |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 537 | const SkScalar dx = localRect->width() / rect->width(); |
| 538 | const SkScalar dy = localRect->height() / rect->height(); |
| 539 | if (clipBounds.fLeft > rect->fLeft) { |
| 540 | localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx; |
| 541 | rect->fLeft = clipBounds.fLeft; |
| 542 | } |
| 543 | if (clipBounds.fTop > rect->fTop) { |
| 544 | localRect->fTop += (clipBounds.fTop - rect->fTop) * dy; |
| 545 | rect->fTop = clipBounds.fTop; |
| 546 | } |
| 547 | if (clipBounds.fRight < rect->fRight) { |
| 548 | localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx; |
| 549 | rect->fRight = clipBounds.fRight; |
| 550 | } |
| 551 | if (clipBounds.fBottom < rect->fBottom) { |
| 552 | localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy; |
| 553 | rect->fBottom = clipBounds.fBottom; |
| 554 | } |
Michael Ludwig | 904657d | 2019-04-12 10:57:24 -0400 | [diff] [blame] | 555 | // Ensure local coordinates remain sorted after clipping. If the original dstRect was very |
| 556 | // large, numeric precision can invert the localRect |
| 557 | localRect->sort(); |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 558 | return true; |
| 559 | } |
| 560 | |
| 561 | return rect->intersect(clipBounds); |
| 562 | } |
| 563 | |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 564 | GrQuadAAFlags set_edge_flag(GrQuadAAFlags currentFlags, GrQuadAAFlags edge, GrAA edgeState) { |
| 565 | if (edgeState == GrAA::kNo) { |
| 566 | // Turn off 'edge' in currentFlags |
| 567 | return currentFlags & (~edge); |
| 568 | } else { |
| 569 | // Turn on 'edge' in currentFlags |
| 570 | return currentFlags | edge; |
| 571 | } |
| 572 | } |
| 573 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 574 | bool GrRenderTargetContext::drawFilledRectAsClear(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 575 | const SkMatrix& viewMatrix, const SkRect& rect) { |
| 576 | // Rules for a filled rect to become a clear [+scissor]: |
| 577 | // 1. The paint is a constant blend color with no other FPs |
| 578 | // 2. The view matrix maps rectangles to rectangles, or the transformed quad fully covers |
| 579 | // the render target (or clear region in #3). |
| 580 | // 3. The clip is an intersection of rectangles, so the clear region will be the |
| 581 | // intersection of the clip and the provided rect. |
| 582 | // 4. The clear region aligns with pixel bounds |
| 583 | // 5. There are no user stencil settings (and since the clip was IOR, the clip won't need |
| 584 | // to use the stencil either). |
| 585 | // If all conditions pass, the filled rect can either be a fullscreen clear (if it's big |
| 586 | // enough), or the rectangle geometry will be used as the scissor clip on the clear. |
| 587 | // If everything passes but rule #4, this submits a simplified fill rect op instead so that the |
| 588 | // rounding differences between clip and draws don't fight each other. |
| 589 | // NOTE: we route draws into clear() regardless of performColorClearsAsDraws() since the |
| 590 | // clear call is allowed to reset the oplist even when it also happens to use a GrFillRectOp. |
| 591 | |
| 592 | SkPMColor4f clearColor; |
| 593 | if (paint.numCoverageFragmentProcessors() > 0 || !paint.isConstantBlendedColor(&clearColor)) { |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | const SkRect rtRect = fRenderTargetProxy->getBoundsRect(); |
| 598 | // Will be the intersection of render target, clip, and quad |
| 599 | SkRect combinedRect = rtRect; |
| 600 | |
| 601 | SkRRect clipRRect; |
| 602 | GrAA clipAA; |
| 603 | if (!clip.quickContains(rtRect)) { |
| 604 | // If the clip is an rrect with no rounding, then it can replace the full RT bounds as the |
| 605 | // limiting region, although we will have to worry about AA. If the clip is anything |
| 606 | // more complicated, just punt to the regular fill rect op. |
| 607 | if (!clip.isRRect(rtRect, &clipRRect, &clipAA) || !clipRRect.isRect()) { |
| 608 | return false; |
| 609 | } |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 610 | |
Michael Ludwig | 4325270 | 2019-05-16 15:04:36 -0400 | [diff] [blame] | 611 | combinedRect = clipRRect.rect(); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 612 | } else { |
| 613 | // The clip is outside the render target, so the clip can be ignored |
| 614 | clipAA = GrAA::kNo; |
| 615 | } |
| 616 | |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 617 | GrQuadAAFlags edgeFlags; // To account for clip and draw mixing AA modes |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 618 | if (viewMatrix.rectStaysRect()) { |
| 619 | // Skip the extra overhead of inverting the view matrix to see if rtRect is contained in the |
| 620 | // drawn rectangle, and instead just intersect rtRect with the transformed rect. It will be |
| 621 | // the new clear region. |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 622 | SkRect drawRect = viewMatrix.mapRect(rect); |
| 623 | if (!combinedRect.intersect(drawRect)) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 624 | // No intersection means nothing should be drawn, so return true but don't add an op |
| 625 | return true; |
| 626 | } |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 627 | |
| 628 | // In this case, edge flags start based on draw's AA and then switch per-edge to the clip's |
| 629 | // AA setting if that edge was inset. |
| 630 | edgeFlags = aa == GrAA::kNo ? GrQuadAAFlags::kNone : GrQuadAAFlags::kAll; |
| 631 | if (combinedRect.fLeft > drawRect.fLeft) { |
| 632 | edgeFlags = set_edge_flag(edgeFlags, GrQuadAAFlags::kLeft, clipAA); |
| 633 | } |
| 634 | if (combinedRect.fTop > drawRect.fTop) { |
| 635 | edgeFlags = set_edge_flag(edgeFlags, GrQuadAAFlags::kTop, clipAA); |
| 636 | } |
| 637 | if (combinedRect.fRight < drawRect.fRight) { |
| 638 | edgeFlags = set_edge_flag(edgeFlags, GrQuadAAFlags::kRight, clipAA); |
| 639 | } |
| 640 | if (combinedRect.fBottom < drawRect.fBottom) { |
| 641 | edgeFlags = set_edge_flag(edgeFlags, GrQuadAAFlags::kBottom, clipAA); |
| 642 | } |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 643 | } else { |
| 644 | // If the transformed rectangle does not contain the combined rt and clip, the draw is too |
| 645 | // complex to be implemented as a clear |
| 646 | SkMatrix invM; |
| 647 | if (!viewMatrix.invert(&invM)) { |
| 648 | return false; |
| 649 | } |
| 650 | // The clip region in the rect's local space, so the test becomes the local rect containing |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 651 | // the quad's points. If clip is non-AA, test rounded out region to avoid the scenario where |
| 652 | // the draw contains the unrounded non-aa clip, but does not contain the rounded version. Be |
| 653 | // conservative since we don't know how the GPU would round. |
| 654 | SkRect conservative; |
| 655 | if (clipAA == GrAA::kNo) { |
| 656 | conservative = SkRect::Make(combinedRect.roundOut()); |
| 657 | } else { |
| 658 | conservative = combinedRect; |
| 659 | } |
| 660 | GrQuad quad = GrQuad::MakeFromRect(conservative, invM); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 661 | if (!rect_contains_inclusive(rect, quad.point(0)) || |
| 662 | !rect_contains_inclusive(rect, quad.point(1)) || |
| 663 | !rect_contains_inclusive(rect, quad.point(2)) || |
| 664 | !rect_contains_inclusive(rect, quad.point(3))) { |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 665 | // No containment, so combinedRect can't be filled by a solid color |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 666 | return false; |
| 667 | } |
| 668 | // combinedRect can be filled by a solid color but doesn't need to be modified since it's |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 669 | // inside the quad to be drawn, which also means the edge AA flags respect the clip AA |
| 670 | edgeFlags = clipAA == GrAA::kNo ? GrQuadAAFlags::kNone : GrQuadAAFlags::kAll; |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // Almost every condition is met; now it requires that the combined rect align with pixel |
| 674 | // boundaries in order for it to become a scissor-clear. Ignore the AA status in this case |
| 675 | // since non-AA with partial-pixel coordinates can be rounded differently on the GPU, |
| 676 | // leading to unexpected differences between a scissor test and a rasterized quad. |
| 677 | // Also skip very small rectangles since the scissor+clear doesn't by us much then. |
| 678 | if (combinedRect.contains(rtRect)) { |
| 679 | // Full screen clear |
| 680 | this->clear(nullptr, clearColor, CanClearFullscreen::kYes); |
| 681 | return true; |
| 682 | } else if (GrClip::IsPixelAligned(combinedRect) && |
| 683 | combinedRect.width() > 256 && combinedRect.height() > 256) { |
| 684 | // Scissor + clear (round shouldn't do anything since we are pixel aligned) |
| 685 | SkIRect scissorRect; |
| 686 | combinedRect.round(&scissorRect); |
| 687 | this->clear(&scissorRect, clearColor, CanClearFullscreen::kNo); |
| 688 | return true; |
| 689 | } |
| 690 | |
| 691 | // If we got here, we can't use a scissor + clear, but combinedRect represents the correct |
| 692 | // geometry combination of quad + clip so we can perform a simplified fill rect op. We do this |
| 693 | // mostly to avoid mismatches in rounding logic on the CPU vs. the GPU, which frequently appears |
| 694 | // when drawing and clipping something to the same non-AA rect that never-the-less has |
| 695 | // non-integer coordinates. |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 696 | aa = edgeFlags == GrQuadAAFlags::kNone ? GrAA::kNo : GrAA::kYes; |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 697 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 698 | this->addDrawOp(GrFixedClip::Disabled(), |
Michael Ludwig | 76ec80a | 2019-05-13 13:30:53 -0400 | [diff] [blame] | 699 | GrFillRectOp::MakePerEdge(fContext, std::move(paint), aaType, edgeFlags, |
| 700 | SkMatrix::I(), combinedRect)); |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 701 | return true; |
| 702 | } |
| 703 | |
| 704 | void GrRenderTargetContext::drawFilledRect(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& rect, |
| 709 | const GrUserStencilSettings* ss) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 710 | |
| 711 | if (!ss) { |
| 712 | if (this->drawFilledRectAsClear(clip, std::move(paint), aa, viewMatrix, rect)) { |
| 713 | return; |
| 714 | } |
| 715 | // Fall through to fill rect op |
| 716 | assert_alive(paint); |
| 717 | } |
| 718 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 719 | SkRect croppedRect = rect; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 720 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 721 | // The rectangle would not be drawn, so no need to add a draw op to the list |
| 722 | return; |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 723 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 724 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 725 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 726 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), aaType, viewMatrix, |
| 727 | croppedRect, ss)); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 730 | void GrRenderTargetContext::drawRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 731 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 732 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 733 | const SkMatrix& viewMatrix, |
| 734 | const SkRect& rect, |
| 735 | const GrStyle* style) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 736 | if (!style) { |
| 737 | style = &GrStyle::SimpleFill(); |
| 738 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 739 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 740 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 741 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 742 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRect", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 743 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 744 | // Path effects should've been devolved to a path in SkGpuDevice |
| 745 | SkASSERT(!style->pathEffect()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 746 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 747 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 748 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 749 | const SkStrokeRec& stroke = style->strokeRec(); |
Robert Phillips | 8c8b046 | 2018-08-24 16:18:03 -0400 | [diff] [blame] | 750 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 751 | this->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect); |
| 752 | return; |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 753 | } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 754 | stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
| 755 | if ((!rect.width() || !rect.height()) && |
| 756 | SkStrokeRec::kHairline_Style != stroke.getStyle()) { |
| 757 | SkScalar r = stroke.getWidth() / 2; |
| 758 | // TODO: Move these stroke->fill fallbacks to GrShape? |
| 759 | switch (stroke.getJoin()) { |
| 760 | case SkPaint::kMiter_Join: |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 761 | this->drawRect( |
| 762 | clip, std::move(paint), aa, viewMatrix, |
| 763 | {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, |
| 764 | &GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 765 | return; |
| 766 | case SkPaint::kRound_Join: |
| 767 | // Raster draws nothing when both dimensions are empty. |
| 768 | if (rect.width() || rect.height()){ |
| 769 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 770 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, |
| 771 | GrStyle::SimpleFill()); |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | case SkPaint::kBevel_Join: |
| 775 | if (!rect.width()) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 776 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 777 | {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, |
| 778 | &GrStyle::SimpleFill()); |
| 779 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 780 | this->drawRect(clip, std::move(paint), aa, viewMatrix, |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 781 | {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, |
| 782 | &GrStyle::SimpleFill()); |
| 783 | } |
| 784 | return; |
| 785 | } |
| 786 | } |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 787 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 788 | std::unique_ptr<GrDrawOp> op; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 789 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 790 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 791 | op = GrStrokeRectOp::Make(fContext, std::move(paint), aaType, viewMatrix, rect, stroke); |
| 792 | // op may be null if the stroke is not supported or if using coverage aa and the view matrix |
| 793 | // does not preserve rectangles. |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 794 | if (op) { |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 795 | this->addDrawOp(clip, std::move(op)); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 796 | return; |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 797 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 798 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 799 | assert_alive(paint); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 800 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(rect, *style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 803 | void GrRenderTargetContext::drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 804 | const SkMatrix& viewMatrix, const QuadSetEntry quads[], |
| 805 | int cnt) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 806 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 807 | this->addDrawOp(clip, GrFillRectOp::MakeSet(fContext, std::move(paint), aaType, viewMatrix, |
| 808 | quads, cnt)); |
| 809 | } |
| 810 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 811 | int GrRenderTargetContextPriv::maxWindowRectangles() const { |
| 812 | return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles( |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 813 | *fRenderTargetContext->caps()); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 814 | } |
| 815 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 816 | void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 817 | ASSERT_SINGLE_OWNER_PRIV |
| 818 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 819 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 820 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "clearStencilClip", |
| 821 | fRenderTargetContext->fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 822 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 823 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 824 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 825 | fRenderTargetContext->internalStencilClear(clip, insideStencilMask); |
| 826 | } |
| 827 | |
| 828 | void GrRenderTargetContext::internalStencilClear(const GrFixedClip& clip, bool insideStencilMask) { |
| 829 | if (this->caps()->performStencilClearsAsDraws()) { |
| 830 | const GrUserStencilSettings* ss = GrStencilSettings::SetClipBitSettings(insideStencilMask); |
| 831 | SkRect rtRect = SkRect::MakeWH(this->width(), this->height()); |
| 832 | |
| 833 | // Configure the paint to have no impact on the color buffer |
| 834 | GrPaint paint; |
| 835 | paint.setColor4f({0.f, 0.f, 0.f, 0.f}); |
| 836 | paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
| 837 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 838 | // Mark stencil usage here before addDrawOp() so that it doesn't try to re-call |
| 839 | // internalStencilClear() just because the op has stencil settings. |
| 840 | this->setNeedsStencil(); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 841 | this->addDrawOp(clip, GrFillRectOp::Make(fContext, std::move(paint), |
| 842 | GrAAType::kNone, SkMatrix::I(), rtRect, ss)); |
| 843 | } else { |
| 844 | std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(fContext, clip, insideStencilMask, |
| 845 | fRenderTargetProxy.get())); |
| 846 | if (!op) { |
| 847 | return; |
| 848 | } |
| 849 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 850 | } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 853 | void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 854 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 855 | const SkMatrix& viewMatrix, |
| 856 | const GrPath* path) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 857 | ASSERT_SINGLE_OWNER_PRIV |
| 858 | RETURN_IF_ABANDONED_PRIV |
| 859 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 860 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilPath", |
| 861 | fRenderTargetContext->fContext); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 862 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 863 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 864 | SkASSERT(path); |
| 865 | SkASSERT(fRenderTargetContext->caps()->shaderCaps()->pathRenderingSupport()); |
| 866 | |
| 867 | // FIXME: Use path bounds instead of this WAR once |
| 868 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
| 869 | SkRect bounds = SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height()); |
| 870 | |
| 871 | // Setup clip |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 872 | GrAppliedHardClip appliedClip; |
| 873 | if (!clip.apply(fRenderTargetContext->width(), fRenderTargetContext->height(), &appliedClip, |
| 874 | &bounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 875 | return; |
| 876 | } |
| 877 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 878 | fRenderTargetContext->setNeedsStencil(); |
| 879 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 880 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(fRenderTargetContext->fContext, |
| 881 | viewMatrix, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 882 | GrAA::kYes == doStencilMSAA, |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 883 | path->getFillType(), |
| 884 | appliedClip.hasStencilClip(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 885 | appliedClip.scissorState(), |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 886 | path); |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 887 | if (!op) { |
| 888 | return; |
| 889 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 890 | op->setClippedBounds(bounds); |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 891 | fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 894 | void GrRenderTargetContextPriv::stencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 895 | const GrUserStencilSettings* ss, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 896 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 897 | const SkMatrix& viewMatrix, |
| 898 | const SkRect& rect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 899 | ASSERT_SINGLE_OWNER_PRIV |
| 900 | RETURN_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 901 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 902 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "stencilRect", |
| 903 | fRenderTargetContext->fContext); |
| 904 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 905 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 906 | |
| 907 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 908 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 909 | auto aaType = (GrAA::kYes == doStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone; |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 910 | std::unique_ptr<GrDrawOp> op = GrFillRectOp::Make( |
| 911 | fRenderTargetContext->fContext, std::move(paint), aaType, viewMatrix, rect, ss); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 912 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 915 | bool GrRenderTargetContextPriv::drawAndStencilRect(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 916 | const GrUserStencilSettings* ss, |
| 917 | SkRegion::Op op, |
| 918 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 919 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 920 | const SkMatrix& viewMatrix, |
| 921 | const SkRect& rect) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 922 | ASSERT_SINGLE_OWNER_PRIV |
| 923 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 924 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 925 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilRect", |
| 926 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 927 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 928 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 929 | |
| 930 | GrPaint paint; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 931 | paint.setCoverageSetOpXPFactory(op, invert); |
| 932 | |
Michael Ludwig | 61a1651 | 2019-01-15 11:15:13 -0500 | [diff] [blame] | 933 | // This will always succeed to draw a rectangle |
| 934 | fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, viewMatrix, rect, ss); |
| 935 | return true; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 938 | void GrRenderTargetContext::fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 939 | GrQuadAAFlags edgeAA, const SkMatrix& viewMatrix, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 940 | const SkRect& rect, const SkRect* localRect) { |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 941 | ASSERT_SINGLE_OWNER |
| 942 | RETURN_IF_ABANDONED |
| 943 | SkDEBUGCODE(this->validate();) |
| 944 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithEdgeAA", fContext); |
| 945 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 946 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 947 | std::unique_ptr<GrDrawOp> op; |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 948 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 949 | if (localRect) { |
| 950 | // If local coordinates are provided, skip the optimization check to go through |
| 951 | // drawFilledRect, and also calculate clipped local coordinates |
| 952 | SkRect croppedRect = rect; |
| 953 | SkRect croppedLocalRect = *localRect; |
| 954 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect, |
| 955 | &croppedLocalRect)) { |
| 956 | return; |
| 957 | } |
| 958 | op = GrFillRectOp::MakePerEdgeWithLocalRect(fContext, std::move(paint), aaType, edgeAA, |
| 959 | viewMatrix, croppedRect, croppedLocalRect); |
| 960 | } else { |
| 961 | // If aaType turns into MSAA, make sure to keep quads with no AA edges as MSAA. Sending |
| 962 | // those to drawFilledRect() would have it turn off MSAA in that case, which breaks seaming |
| 963 | // with any partial AA edges that kept MSAA. |
| 964 | if (aaType != GrAAType::kMSAA && |
| 965 | (edgeAA == GrQuadAAFlags::kNone || edgeAA == GrQuadAAFlags::kAll)) { |
| 966 | // This is equivalent to a regular filled rect draw, so route through there to take |
| 967 | // advantage of draw->clear optimizations |
| 968 | this->drawFilledRect(clip, std::move(paint), GrAA(edgeAA == GrQuadAAFlags::kAll), |
| 969 | viewMatrix, rect); |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | SkRect croppedRect = rect; |
| 974 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
| 975 | return; |
| 976 | } |
| 977 | op = GrFillRectOp::MakePerEdge(fContext, std::move(paint), aaType, edgeAA, viewMatrix, |
| 978 | croppedRect); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | AutoCheckFlush acf(this->drawingManager()); |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 982 | this->addDrawOp(clip, std::move(op)); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 983 | } |
| 984 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 985 | void GrRenderTargetContext::fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, |
| 986 | GrQuadAAFlags edgeAA, const SkMatrix& viewMatrix, |
| 987 | const SkPoint quad[4], const SkPoint localQuad[4]) { |
| 988 | ASSERT_SINGLE_OWNER |
| 989 | RETURN_IF_ABANDONED |
| 990 | SkDEBUGCODE(this->validate();) |
| 991 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillQuadWithEdgeAA", fContext); |
| 992 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 993 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 994 | |
| 995 | AutoCheckFlush acf(this->drawingManager()); |
| 996 | // MakePerEdgeQuad automatically does the right thing if localQuad is null or not |
| 997 | this->addDrawOp(clip, GrFillRectOp::MakePerEdgeQuad(fContext, std::move(paint), aaType, edgeAA, |
| 998 | viewMatrix, quad, localQuad)); |
| 999 | } |
| 1000 | |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1001 | // Creates a paint for GrFillRectOp that matches behavior of GrTextureOp |
| 1002 | static void draw_texture_to_grpaint(sk_sp<GrTextureProxy> proxy, const SkRect* domain, |
| 1003 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 1004 | const SkPMColor4f& color, sk_sp<GrColorSpaceXform> csXform, |
| 1005 | GrPaint* paint) { |
| 1006 | paint->setColor4f(color); |
| 1007 | paint->setXPFactory(SkBlendMode_AsXPFactory(mode)); |
| 1008 | |
| 1009 | std::unique_ptr<GrFragmentProcessor> fp; |
| 1010 | if (domain) { |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1011 | SkRect correctedDomain = *domain; |
| 1012 | if (filter == GrSamplerState::Filter::kBilerp) { |
| 1013 | // Inset by 1/2 pixel, which GrTextureOp and GrTextureAdjuster handle automatically |
| 1014 | correctedDomain.inset(0.5f, 0.5f); |
| 1015 | } |
| 1016 | fp = GrTextureDomainEffect::Make(std::move(proxy), SkMatrix::I(), correctedDomain, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1017 | GrTextureDomain::kClamp_Mode, filter); |
| 1018 | } else { |
| 1019 | fp = GrSimpleTextureEffect::Make(std::move(proxy), SkMatrix::I(), filter); |
| 1020 | } |
| 1021 | |
| 1022 | fp = GrColorSpaceXformEffect::Make(std::move(fp), csXform); |
| 1023 | paint->addColorFragmentProcessor(std::move(fp)); |
| 1024 | } |
| 1025 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1026 | void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1027 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 1028 | const SkPMColor4f& color, const SkRect& srcRect, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 1029 | const SkRect& dstRect, GrAA aa, GrQuadAAFlags aaFlags, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 1030 | SkCanvas::SrcRectConstraint constraint, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1031 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 1032 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1033 | ASSERT_SINGLE_OWNER |
| 1034 | RETURN_IF_ABANDONED |
| 1035 | SkDEBUGCODE(this->validate();) |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1036 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexture", fContext); |
Brian Salomon | f170904 | 2018-10-03 11:57:00 -0400 | [diff] [blame] | 1037 | if (constraint == SkCanvas::kStrict_SrcRectConstraint && |
| 1038 | srcRect.contains(proxy->getWorstCaseBoundsRect())) { |
| 1039 | constraint = SkCanvas::kFast_SrcRectConstraint; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1040 | } |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1041 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1042 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | ff9d6d3 | 2017-08-30 10:27:49 -0400 | [diff] [blame] | 1043 | SkRect clippedDstRect = dstRect; |
| 1044 | SkRect clippedSrcRect = srcRect; |
| 1045 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect, |
| 1046 | &clippedSrcRect)) { |
| 1047 | return; |
| 1048 | } |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1049 | |
| 1050 | AutoCheckFlush acf(this->drawingManager()); |
| 1051 | |
| 1052 | std::unique_ptr<GrDrawOp> op; |
| 1053 | if (mode != SkBlendMode::kSrcOver) { |
| 1054 | // Emulation mode with GrPaint and GrFillRectOp |
| 1055 | if (filter != GrSamplerState::Filter::kNearest && |
| 1056 | !GrTextureOp::GetFilterHasEffect(viewMatrix, clippedSrcRect, clippedDstRect)) { |
| 1057 | filter = GrSamplerState::Filter::kNearest; |
| 1058 | } |
| 1059 | |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1060 | GrPaint paint; |
| 1061 | draw_texture_to_grpaint(std::move(proxy), |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1062 | constraint == SkCanvas::kStrict_SrcRectConstraint ? &srcRect : nullptr, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1063 | filter, mode, color, std::move(textureColorSpaceXform), &paint); |
| 1064 | op = GrFillRectOp::MakePerEdgeWithLocalRect(fContext, std::move(paint), aaType, aaFlags, |
| 1065 | viewMatrix, clippedDstRect, clippedSrcRect); |
| 1066 | } else { |
| 1067 | // Can use a lighter weight op that can chain across proxies |
| 1068 | op = GrTextureOp::Make(fContext, std::move(proxy), filter, color, clippedSrcRect, |
| 1069 | clippedDstRect, aaType, aaFlags, constraint, viewMatrix, |
| 1070 | std::move(textureColorSpaceXform)); |
| 1071 | } |
| 1072 | |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 1073 | this->addDrawOp(clip, std::move(op)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1076 | void GrRenderTargetContext::drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy> proxy, |
| 1077 | GrSamplerState::Filter filter, SkBlendMode mode, |
| 1078 | const SkPMColor4f& color, const SkPoint srcQuad[4], |
| 1079 | const SkPoint dstQuad[4], GrAA aa, |
| 1080 | GrQuadAAFlags aaFlags, const SkRect* domain, |
| 1081 | const SkMatrix& viewMatrix, |
| 1082 | sk_sp<GrColorSpaceXform> texXform) { |
| 1083 | ASSERT_SINGLE_OWNER |
| 1084 | RETURN_IF_ABANDONED |
| 1085 | SkDEBUGCODE(this->validate();) |
| 1086 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureQuad", fContext); |
| 1087 | if (domain && domain->contains(proxy->getWorstCaseBoundsRect())) { |
| 1088 | domain = nullptr; |
| 1089 | } |
| 1090 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1091 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1092 | |
| 1093 | // Unlike drawTexture(), don't bother cropping or optimizing the filter type since we're |
| 1094 | // sampling an arbitrary quad of the texture. |
| 1095 | AutoCheckFlush acf(this->drawingManager()); |
| 1096 | std::unique_ptr<GrDrawOp> op; |
| 1097 | if (mode != SkBlendMode::kSrcOver) { |
| 1098 | // Emulation mode, but don't bother converting to kNearest filter since it's an arbitrary |
| 1099 | // quad that is being drawn, which makes the tests too expensive here |
| 1100 | GrPaint paint; |
| 1101 | draw_texture_to_grpaint( |
| 1102 | std::move(proxy), domain, filter, mode, color, std::move(texXform), &paint); |
| 1103 | op = GrFillRectOp::MakePerEdgeQuad(fContext, std::move(paint), aaType, aaFlags, viewMatrix, |
| 1104 | dstQuad, srcQuad); |
| 1105 | } else { |
| 1106 | // Use lighter weight GrTextureOp |
| 1107 | op = GrTextureOp::MakeQuad(fContext, std::move(proxy), filter, color, srcQuad, dstQuad, |
| 1108 | aaType, aaFlags, domain, viewMatrix, std::move(texXform)); |
| 1109 | } |
| 1110 | |
| 1111 | this->addDrawOp(clip, std::move(op)); |
| 1112 | } |
| 1113 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1114 | void GrRenderTargetContext::drawTextureSet(const GrClip& clip, const TextureSetEntry set[], int cnt, |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1115 | GrSamplerState::Filter filter, SkBlendMode mode, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1116 | GrAA aa, SkCanvas::SrcRectConstraint constraint, |
| 1117 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 1118 | sk_sp<GrColorSpaceXform> texXform) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1119 | ASSERT_SINGLE_OWNER |
| 1120 | RETURN_IF_ABANDONED |
| 1121 | SkDEBUGCODE(this->validate();) |
| 1122 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureSet", fContext); |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1123 | |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1124 | if (mode != SkBlendMode::kSrcOver || |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1125 | !fContext->priv().caps()->dynamicStateArrayGeometryProcessorTextureSupport()) { |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1126 | // Draw one at a time with GrFillRectOp and a GrPaint that emulates what GrTextureOp does |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1127 | SkMatrix ctm; |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1128 | for (int i = 0; i < cnt; ++i) { |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1129 | float alpha = set[i].fAlpha; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1130 | ctm = viewMatrix; |
| 1131 | if (set[i].fPreViewMatrix) { |
| 1132 | ctm.preConcat(*set[i].fPreViewMatrix); |
| 1133 | } |
| 1134 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1135 | if (set[i].fDstClipQuad == nullptr) { |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1136 | // Stick with original rectangles, which allows the ops to know more about what's |
| 1137 | // being drawn. |
| 1138 | this->drawTexture(clip, set[i].fProxy, filter, mode, {alpha, alpha, alpha, alpha}, |
| 1139 | set[i].fSrcRect, set[i].fDstRect, aa, set[i].fAAFlags, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1140 | constraint, ctm, texXform); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1141 | } else { |
| 1142 | // Generate interpolated texture coordinates to match the dst clip |
| 1143 | SkPoint srcQuad[4]; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1144 | GrMapRectPoints(set[i].fDstRect, set[i].fSrcRect, set[i].fDstClipQuad, srcQuad, 4); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1145 | const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint |
| 1146 | ? &set[i].fSrcRect : nullptr; |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1147 | this->drawTextureQuad(clip, set[i].fProxy, filter, mode, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1148 | {alpha, alpha, alpha, alpha}, srcQuad, set[i].fDstClipQuad, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1149 | aa, set[i].fAAFlags, domain, ctm, texXform); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 1150 | } |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1151 | } |
| 1152 | } else { |
| 1153 | // Can use a single op, avoiding GrPaint creation, and can batch across proxies |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 1154 | AutoCheckFlush acf(this->drawingManager()); |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1155 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 1156 | auto op = GrTextureOp::MakeSet(fContext, set, cnt, filter, aaType, constraint, viewMatrix, |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 1157 | std::move(texXform)); |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 1158 | this->addDrawOp(clip, std::move(op)); |
| 1159 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1162 | void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1163 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1164 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1165 | const SkMatrix& viewMatrix, |
| 1166 | const SkRect& rectToDraw, |
| 1167 | const SkMatrix& localMatrix) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1168 | ASSERT_SINGLE_OWNER |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 1169 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1170 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1171 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "fillRectWithLocalMatrix", fContext); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 1172 | |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 1173 | SkRect croppedRect = rectToDraw; |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 1174 | if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 1175 | return; |
| 1176 | } |
| 1177 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1178 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1179 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1180 | GrAAType aaType = this->chooseAAType(aa); |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 1181 | this->addDrawOp(clip, GrFillRectOp::MakeWithLocalMatrix(fContext, std::move(paint), aaType, |
| 1182 | viewMatrix, localMatrix, croppedRect)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1185 | void GrRenderTargetContext::drawVertices(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1186 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1187 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1188 | sk_sp<SkVertices> vertices, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1189 | const SkVertices::Bone bones[], |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1190 | int boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1191 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1192 | ASSERT_SINGLE_OWNER |
| 1193 | RETURN_IF_ABANDONED |
| 1194 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1195 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawVertices", fContext); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1196 | |
| 1197 | AutoCheckFlush acf(this->drawingManager()); |
| 1198 | |
| 1199 | SkASSERT(vertices); |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1200 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1201 | std::unique_ptr<GrDrawOp> op = GrDrawVerticesOp::Make( |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1202 | fContext, std::move(paint), std::move(vertices), bones, boneCount, viewMatrix, aaType, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1203 | this->colorSpaceInfo().refColorSpaceXformFromSRGB(), overridePrimType); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 1204 | this->addDrawOp(clip, std::move(op)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /////////////////////////////////////////////////////////////////////////////// |
| 1208 | |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1209 | void GrRenderTargetContext::drawAtlas(const GrClip& clip, |
| 1210 | GrPaint&& paint, |
| 1211 | const SkMatrix& viewMatrix, |
| 1212 | int spriteCount, |
| 1213 | const SkRSXform xform[], |
| 1214 | const SkRect texRect[], |
| 1215 | const SkColor colors[]) { |
| 1216 | ASSERT_SINGLE_OWNER |
| 1217 | RETURN_IF_ABANDONED |
| 1218 | SkDEBUGCODE(this->validate();) |
| 1219 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawAtlas", fContext); |
| 1220 | |
| 1221 | AutoCheckFlush acf(this->drawingManager()); |
| 1222 | |
| 1223 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
| 1224 | std::unique_ptr<GrDrawOp> op = GrDrawAtlasOp::Make(fContext, std::move(paint), viewMatrix, |
| 1225 | aaType, spriteCount, xform, texRect, colors); |
| 1226 | this->addDrawOp(clip, std::move(op)); |
| 1227 | } |
| 1228 | |
| 1229 | /////////////////////////////////////////////////////////////////////////////// |
| 1230 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1231 | void GrRenderTargetContext::drawRRect(const GrClip& origClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1232 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1233 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1234 | const SkMatrix& viewMatrix, |
| 1235 | const SkRRect& rrect, |
| 1236 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1237 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1238 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1239 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1240 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRRect", fContext); |
Robert Phillips | 8529080 | 2018-07-02 13:14:28 -0400 | [diff] [blame] | 1241 | |
| 1242 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1243 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1244 | return; |
| 1245 | } |
| 1246 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1247 | GrNoClip noclip; |
| 1248 | const GrClip* clip = &origClip; |
| 1249 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 1250 | // 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] | 1251 | // 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] | 1252 | // doesn't detect that the clip can be ignored (modulo antialiasing). The following test |
| 1253 | // attempts to mitigate the stencil clip cost but will only help when the entire clip stack |
Michael Ludwig | 2839884 | 2019-03-25 10:24:24 -0400 | [diff] [blame] | 1254 | // can be ignored. We'd prefer to fix this in the framework by removing the clips calls. This |
| 1255 | // only works for filled rrects since the stroke width outsets beyond the rrect itself. |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1256 | SkRRect devRRect; |
Michael Ludwig | 2839884 | 2019-03-25 10:24:24 -0400 | [diff] [blame] | 1257 | if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.transform(viewMatrix, &devRRect) && |
| 1258 | clip->quickContains(devRRect)) { |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 1259 | clip = &noclip; |
| 1260 | } |
| 1261 | #endif |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 1262 | SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice |
ksakamoto | ec7f2ac | 2016-07-05 03:54:53 -0700 | [diff] [blame] | 1263 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1264 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1265 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1266 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 1267 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1268 | std::unique_ptr<GrDrawOp> op; |
| 1269 | if (style.isSimpleFill()) { |
| 1270 | assert_alive(paint); |
| 1271 | op = GrFillRRectOp::Make( |
| 1272 | fContext, aaType, viewMatrix, rrect, *this->caps(), std::move(paint)); |
| 1273 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1274 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1275 | assert_alive(paint); |
| 1276 | op = GrOvalOpFactory::MakeRRectOp( |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1277 | fContext, std::move(paint), viewMatrix, rrect, stroke, this->caps()->shaderCaps()); |
| 1278 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1279 | } |
| 1280 | if (op) { |
| 1281 | this->addDrawOp(*clip, std::move(op)); |
| 1282 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1283 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1284 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1285 | assert_alive(paint); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1286 | this->drawShapeUsingPathRenderer(*clip, std::move(paint), aa, viewMatrix, |
| 1287 | GrShape(rrect, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1290 | /////////////////////////////////////////////////////////////////////////////// |
| 1291 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1292 | static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { |
| 1293 | SkPoint3 result; |
| 1294 | m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX); |
| 1295 | result.fZ = pt.fZ; |
| 1296 | return result; |
| 1297 | } |
| 1298 | |
| 1299 | bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1300 | const SkMatrix& viewMatrix, |
| 1301 | const SkPath& path, |
| 1302 | const SkDrawShadowRec& rec) { |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1303 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1304 | if (fContext->priv().abandoned()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1305 | return true; |
| 1306 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1307 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1308 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawFastShadow", fContext); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1309 | |
| 1310 | // check z plane |
| 1311 | bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) || |
| 1312 | !SkScalarNearlyZero(rec.fZPlaneParams.fY)); |
| 1313 | bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); |
| 1314 | if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) { |
| 1315 | return false; |
| 1316 | } |
| 1317 | |
| 1318 | SkRRect rrect; |
| 1319 | SkRect rect; |
| 1320 | // we can only handle rects, circles, and rrects with circular corners |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1321 | bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsSimpleCircular(rrect) && |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1322 | rrect.radii(SkRRect::kUpperLeft_Corner).fX > SK_ScalarNearlyZero; |
| 1323 | if (!isRRect && |
| 1324 | path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) && |
| 1325 | rect.width() > SK_ScalarNearlyZero) { |
| 1326 | rrect.setOval(rect); |
| 1327 | isRRect = true; |
| 1328 | } |
| 1329 | if (!isRRect && path.isRect(&rect)) { |
| 1330 | rrect.setRect(rect); |
| 1331 | isRRect = true; |
| 1332 | } |
| 1333 | |
| 1334 | if (!isRRect) { |
| 1335 | return false; |
| 1336 | } |
| 1337 | |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1338 | if (rrect.isEmpty()) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1339 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1340 | } |
| 1341 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1342 | AutoCheckFlush acf(this->drawingManager()); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1343 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1344 | // transform light |
| 1345 | SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos); |
| 1346 | |
| 1347 | // 1/scale |
| 1348 | SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ? |
| 1349 | SkScalarInvert(viewMatrix[SkMatrix::kMScaleX]) : |
| 1350 | sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] + |
| 1351 | viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); |
| 1352 | |
| 1353 | SkScalar occluderHeight = rec.fZPlaneParams.fZ; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1354 | bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); |
| 1355 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1356 | if (SkColorGetA(rec.fAmbientColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1357 | SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight); |
| 1358 | const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight); |
| 1359 | const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1360 | |
| 1361 | // Outset the shadow rrect to the border of the penumbra |
| 1362 | SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale; |
| 1363 | SkRRect ambientRRect; |
| 1364 | SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset); |
| 1365 | // If the rrect was an oval then its outset will also be one. |
| 1366 | // We set it explicitly to avoid errors. |
| 1367 | if (rrect.isOval()) { |
| 1368 | ambientRRect = SkRRect::MakeOval(outsetRect); |
| 1369 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1370 | SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1371 | ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1372 | } |
| 1373 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1374 | GrColor ambientColor = SkColorToPremulGrColor(rec.fAmbientColor); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1375 | if (transparent) { |
| 1376 | // set a large inset to force a fill |
| 1377 | devSpaceInsetWidth = ambientRRect.width(); |
| 1378 | } |
Jim Van Verth | 39e7165 | 2018-04-23 18:08:45 +0000 | [diff] [blame] | 1379 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1380 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1381 | ambientColor, |
| 1382 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1383 | ambientRRect, |
| 1384 | devSpaceAmbientBlur, |
Jim Van Verth | fb18639 | 2018-09-11 11:37:46 -0400 | [diff] [blame] | 1385 | devSpaceInsetWidth); |
Robert Phillips | e576378 | 2019-04-17 14:38:24 -0400 | [diff] [blame] | 1386 | if (op) { |
| 1387 | this->addDrawOp(clip, std::move(op)); |
| 1388 | } |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1389 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1390 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1391 | if (SkColorGetA(rec.fSpotColor) > 0) { |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1392 | SkScalar devSpaceSpotBlur; |
| 1393 | SkScalar spotScale; |
| 1394 | SkVector spotOffset; |
| 1395 | SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY, |
| 1396 | devLightPos.fZ, rec.fLightRadius, |
| 1397 | &devSpaceSpotBlur, &spotScale, &spotOffset); |
| 1398 | // handle scale of radius due to CTM |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1399 | const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale; |
| 1400 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1401 | // Adjust translate for the effect of the scale. |
| 1402 | spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX]; |
| 1403 | spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY]; |
| 1404 | // This offset is in dev space, need to transform it into source space. |
| 1405 | SkMatrix ctmInverse; |
| 1406 | if (viewMatrix.invert(&ctmInverse)) { |
| 1407 | ctmInverse.mapPoints(&spotOffset, 1); |
| 1408 | } else { |
| 1409 | // Since the matrix is a similarity, this should never happen, but just in case... |
| 1410 | SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n"); |
| 1411 | SkASSERT(false); |
| 1412 | } |
| 1413 | |
| 1414 | // Compute the transformed shadow rrect |
| 1415 | SkRRect spotShadowRRect; |
| 1416 | SkMatrix shadowTransform; |
| 1417 | shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY); |
| 1418 | rrect.transform(shadowTransform, &spotShadowRRect); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1419 | SkScalar spotRadius = SkRRectPriv::GetSimpleRadii(spotShadowRRect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1420 | |
| 1421 | // Compute the insetWidth |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1422 | SkScalar blurOutset = srcSpaceSpotBlur; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1423 | SkScalar insetWidth = blurOutset; |
| 1424 | if (transparent) { |
| 1425 | // If transparent, just do a fill |
| 1426 | insetWidth += spotShadowRRect.width(); |
| 1427 | } else { |
| 1428 | // For shadows, instead of using a stroke we specify an inset from the penumbra |
| 1429 | // border. We want to extend this inset area so that it meets up with the caster |
| 1430 | // geometry. The inset geometry will by default already be inset by the blur width. |
| 1431 | // |
| 1432 | // We compare the min and max corners inset by the radius between the original |
| 1433 | // rrect and the shadow rrect. The distance between the two plus the difference |
| 1434 | // between the scaled radius and the original radius gives the distance from the |
| 1435 | // transformed shadow shape to the original shape in that corner. The max |
| 1436 | // of these gives the maximum distance we need to cover. |
| 1437 | // |
| 1438 | // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to |
| 1439 | // that to get the full insetWidth. |
| 1440 | SkScalar maxOffset; |
| 1441 | if (rrect.isRect()) { |
| 1442 | // Manhattan distance works better for rects |
| 1443 | maxOffset = SkTMax(SkTMax(SkTAbs(spotShadowRRect.rect().fLeft - |
| 1444 | rrect.rect().fLeft), |
| 1445 | SkTAbs(spotShadowRRect.rect().fTop - |
| 1446 | rrect.rect().fTop)), |
| 1447 | SkTMax(SkTAbs(spotShadowRRect.rect().fRight - |
| 1448 | rrect.rect().fRight), |
| 1449 | SkTAbs(spotShadowRRect.rect().fBottom - |
| 1450 | rrect.rect().fBottom))); |
| 1451 | } else { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 1452 | SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1453 | SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft - |
| 1454 | rrect.rect().fLeft + dr, |
| 1455 | spotShadowRRect.rect().fTop - |
| 1456 | rrect.rect().fTop + dr); |
| 1457 | SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight - |
| 1458 | rrect.rect().fRight - dr, |
| 1459 | spotShadowRRect.rect().fBottom - |
| 1460 | rrect.rect().fBottom - dr); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 1461 | maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset), |
| 1462 | SkPointPriv::LengthSqd(lowerRightOffset))) + dr; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1463 | } |
Jim Van Verth | 4c8c1e8 | 2018-04-23 17:14:48 -0400 | [diff] [blame] | 1464 | insetWidth += SkTMax(blurOutset, maxOffset); |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | // Outset the shadow rrect to the border of the penumbra |
| 1468 | SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset); |
| 1469 | if (spotShadowRRect.isOval()) { |
| 1470 | spotShadowRRect = SkRRect::MakeOval(outsetRect); |
| 1471 | } else { |
| 1472 | SkScalar outsetRad = spotRadius + blurOutset; |
| 1473 | spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad); |
| 1474 | } |
| 1475 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1476 | GrColor spotColor = SkColorToPremulGrColor(rec.fSpotColor); |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 1477 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1478 | std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(fContext, |
| 1479 | spotColor, |
| 1480 | viewMatrix, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1481 | spotShadowRRect, |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 1482 | 2.0f * devSpaceSpotBlur, |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 1483 | insetWidth); |
Robert Phillips | e576378 | 2019-04-17 14:38:24 -0400 | [diff] [blame] | 1484 | if (op) { |
| 1485 | this->addDrawOp(clip, std::move(op)); |
| 1486 | } |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | return true; |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /////////////////////////////////////////////////////////////////////////////// |
| 1493 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1494 | bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1495 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1496 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1497 | const SkMatrix& viewMatrix, |
| 1498 | const SkRRect& origOuter, |
| 1499 | const SkRRect& origInner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1500 | SkASSERT(!origInner.isEmpty()); |
| 1501 | SkASSERT(!origOuter.isEmpty()); |
| 1502 | |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1503 | SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 1504 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1505 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 45839f9 | 2017-12-04 09:02:35 -0500 | [diff] [blame] | 1506 | |
| 1507 | if (GrAAType::kMSAA == aaType) { |
| 1508 | return false; |
| 1509 | } |
| 1510 | |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1511 | if (GrAAType::kCoverage == aaType && SkRRectPriv::IsCircle(*inner) |
| 1512 | && SkRRectPriv::IsCircle(*outer)) { |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1513 | auto outerR = outer->width() / 2.f; |
| 1514 | auto innerR = inner->width() / 2.f; |
| 1515 | auto cx = outer->getBounds().fLeft + outerR; |
| 1516 | auto cy = outer->getBounds().fTop + outerR; |
| 1517 | if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && |
| 1518 | SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { |
| 1519 | auto avgR = (innerR + outerR) / 2.f; |
| 1520 | auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); |
| 1521 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1522 | stroke.setStrokeStyle(outerR - innerR); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1523 | auto op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1524 | circleBounds, GrStyle(stroke, nullptr), |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1525 | this->caps()->shaderCaps()); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1526 | if (op) { |
| 1527 | this->addDrawOp(clip, std::move(op)); |
| 1528 | return true; |
| 1529 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1530 | assert_alive(paint); |
Brian Salomon | 6574921 | 2017-12-01 16:01:47 -0500 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 1534 | GrClipEdgeType innerEdgeType, outerEdgeType; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1535 | if (GrAAType::kCoverage == aaType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1536 | innerEdgeType = GrClipEdgeType::kInverseFillAA; |
| 1537 | outerEdgeType = GrClipEdgeType::kFillAA; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1538 | } else { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1539 | innerEdgeType = GrClipEdgeType::kInverseFillBW; |
| 1540 | outerEdgeType = GrClipEdgeType::kFillBW; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1541 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1542 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1543 | SkMatrix inverseVM; |
| 1544 | if (!viewMatrix.isIdentity()) { |
| 1545 | if (!origInner.transform(viewMatrix, inner.writable())) { |
| 1546 | return false; |
| 1547 | } |
| 1548 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 1549 | return false; |
| 1550 | } |
| 1551 | if (!viewMatrix.invert(&inverseVM)) { |
| 1552 | return false; |
| 1553 | } |
| 1554 | } else { |
| 1555 | inverseVM.reset(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1556 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1557 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1558 | const auto& caps = *this->caps()->shaderCaps(); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1559 | // TODO these need to be a geometry processors |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1560 | auto innerEffect = GrRRectEffect::Make(innerEdgeType, *inner, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1561 | if (!innerEffect) { |
| 1562 | return false; |
| 1563 | } |
| 1564 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1565 | auto outerEffect = GrRRectEffect::Make(outerEdgeType, *outer, caps); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1566 | if (!outerEffect) { |
| 1567 | return false; |
| 1568 | } |
| 1569 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1570 | paint.addCoverageFragmentProcessor(std::move(innerEffect)); |
| 1571 | paint.addCoverageFragmentProcessor(std::move(outerEffect)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1572 | |
| 1573 | SkRect bounds = outer->getBounds(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1574 | if (GrAAType::kCoverage == aaType) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1575 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1576 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1577 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1578 | this->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds, |
| 1579 | inverseVM); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1580 | return true; |
| 1581 | } |
| 1582 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1583 | void GrRenderTargetContext::drawDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1584 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1585 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1586 | const SkMatrix& viewMatrix, |
| 1587 | const SkRRect& outer, |
| 1588 | const SkRRect& inner) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1589 | ASSERT_SINGLE_OWNER |
| 1590 | RETURN_IF_ABANDONED |
| 1591 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1592 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawDRRect", fContext); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1593 | |
| 1594 | SkASSERT(!outer.isEmpty()); |
| 1595 | SkASSERT(!inner.isEmpty()); |
| 1596 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1597 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1598 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1599 | if (this->drawFilledDRRect(clip, std::move(paint), aa, viewMatrix, outer, inner)) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1600 | return; |
| 1601 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1602 | assert_alive(paint); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1603 | |
| 1604 | SkPath path; |
| 1605 | path.setIsVolatile(true); |
| 1606 | path.addRRect(inner); |
| 1607 | path.addRRect(outer); |
| 1608 | path.setFillType(SkPath::kEvenOdd_FillType); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1609 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrShape(path)); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1612 | /////////////////////////////////////////////////////////////////////////////// |
| 1613 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1614 | void GrRenderTargetContext::drawRegion(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1615 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1616 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1617 | const SkMatrix& viewMatrix, |
| 1618 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1619 | const GrStyle& style, |
| 1620 | const GrUserStencilSettings* ss) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1621 | ASSERT_SINGLE_OWNER |
| 1622 | RETURN_IF_ABANDONED |
| 1623 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1624 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawRegion", fContext); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1625 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1626 | if (GrAA::kYes == aa) { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 1627 | // 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] | 1628 | // to see whether aa is really required. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1629 | if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1630 | SkScalarIsInt(viewMatrix.getTranslateX()) && |
| 1631 | SkScalarIsInt(viewMatrix.getTranslateY())) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1632 | aa = GrAA::kNo; |
| 1633 | } |
Brian Salomon | c57c7c9 | 2016-12-06 14:47:34 -0500 | [diff] [blame] | 1634 | } |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1635 | bool complexStyle = !style.isSimpleFill(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1636 | if (complexStyle || GrAA::kYes == aa) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1637 | SkPath path; |
| 1638 | region.getBoundaryPath(&path); |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 1639 | path.setIsVolatile(true); |
| 1640 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1641 | return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1644 | GrAAType aaType = this->chooseAAType(GrAA::kNo); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1645 | std::unique_ptr<GrDrawOp> op = GrRegionOp::Make(fContext, std::move(paint), viewMatrix, region, |
| 1646 | aaType, ss); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 1647 | this->addDrawOp(clip, std::move(op)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1650 | void GrRenderTargetContext::drawOval(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1651 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1652 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1653 | const SkMatrix& viewMatrix, |
| 1654 | const SkRect& oval, |
| 1655 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1656 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1657 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1658 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1659 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawOval", fContext); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1660 | |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1661 | const SkStrokeRec& stroke = style.strokeRec(); |
| 1662 | |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1663 | if (oval.isEmpty() && !style.pathEffect()) { |
Robert Phillips | 7484d20 | 2018-07-03 09:09:08 -0400 | [diff] [blame] | 1664 | if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
| 1665 | return; |
| 1666 | } |
| 1667 | |
| 1668 | this->drawRect(clip, std::move(paint), aa, viewMatrix, oval, &style); |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 1669 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1672 | AutoCheckFlush acf(this->drawingManager()); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 1673 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1674 | GrAAType aaType = this->chooseAAType(aa); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1675 | |
| 1676 | std::unique_ptr<GrDrawOp> op; |
| 1677 | if (style.isSimpleFill()) { |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 1678 | // GrFillRRectOp has special geometry and a fragment-shader branch to conditionally evaluate |
| 1679 | // the arc equation. This same special geometry and fragment branch also turn out to be a |
| 1680 | // substantial optimization for drawing ovals (namely, by not evaluating the arc equation |
| 1681 | // inside the oval's inner diamond). Given these optimizations, it's a clear win to draw |
| 1682 | // ovals the exact same way we do round rects. |
Chris Dalton | ebc38c9 | 2018-11-28 16:58:09 -0700 | [diff] [blame] | 1683 | // |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1684 | // However, we still don't draw true circles as round rects in coverage mode, because it can |
| 1685 | // cause perf regressions on some platforms as compared to the dedicated circle Op. |
| 1686 | if (GrAAType::kCoverage != aaType || oval.height() != oval.width()) { |
Chris Dalton | bf341ae | 2019-03-27 00:28:22 +0000 | [diff] [blame] | 1687 | assert_alive(paint); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1688 | op = GrFillRRectOp::Make(fContext, aaType, viewMatrix, SkRRect::MakeOval(oval), |
| 1689 | *this->caps(), std::move(paint)); |
Chris Dalton | bf341ae | 2019-03-27 00:28:22 +0000 | [diff] [blame] | 1690 | } |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1691 | } |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1692 | if (!op && GrAAType::kCoverage == aaType) { |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1693 | assert_alive(paint); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1694 | op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, oval, style, |
| 1695 | this->caps()->shaderCaps()); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 1696 | } |
| 1697 | if (op) { |
| 1698 | this->addDrawOp(clip, std::move(op)); |
| 1699 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1700 | } |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1701 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 1702 | assert_alive(paint); |
Brian Salomon | 5209d7f | 2018-04-20 16:52:42 -0400 | [diff] [blame] | 1703 | this->drawShapeUsingPathRenderer( |
| 1704 | clip, std::move(paint), aa, viewMatrix, |
| 1705 | GrShape(SkRRect::MakeOval(oval), SkPath::kCW_Direction, 2, false, style)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1708 | void GrRenderTargetContext::drawArc(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1709 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1710 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1711 | const SkMatrix& viewMatrix, |
| 1712 | const SkRect& oval, |
| 1713 | SkScalar startAngle, |
| 1714 | SkScalar sweepAngle, |
| 1715 | bool useCenter, |
| 1716 | const GrStyle& style) { |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1717 | ASSERT_SINGLE_OWNER |
| 1718 | RETURN_IF_ABANDONED |
| 1719 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1720 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawArc", fContext); |
Robert Phillips | f1d0ced | 2017-02-10 09:31:01 -0500 | [diff] [blame] | 1721 | |
| 1722 | AutoCheckFlush acf(this->drawingManager()); |
| 1723 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1724 | GrAAType aaType = this->chooseAAType(aa); |
Greg Daniel | 2655ede | 2019-04-10 00:49:28 +0000 | [diff] [blame] | 1725 | if (GrAAType::kCoverage == aaType) { |
| 1726 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
| 1727 | std::unique_ptr<GrDrawOp> op = GrOvalOpFactory::MakeArcOp(fContext, |
| 1728 | std::move(paint), |
| 1729 | viewMatrix, |
| 1730 | oval, |
| 1731 | startAngle, |
| 1732 | sweepAngle, |
| 1733 | useCenter, |
| 1734 | style, |
| 1735 | shaderCaps); |
| 1736 | if (op) { |
| 1737 | this->addDrawOp(clip, std::move(op)); |
| 1738 | return; |
| 1739 | } |
| 1740 | assert_alive(paint); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1741 | } |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 1742 | this->drawShapeUsingPathRenderer( |
| 1743 | clip, std::move(paint), aa, viewMatrix, |
| 1744 | GrShape::MakeArc(oval, startAngle, sweepAngle, useCenter, style)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1747 | void GrRenderTargetContext::drawImageLattice(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1748 | GrPaint&& paint, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1749 | const SkMatrix& viewMatrix, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1750 | sk_sp<GrTextureProxy> image, |
| 1751 | sk_sp<GrColorSpaceXform> csxf, |
| 1752 | GrSamplerState::Filter filter, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1753 | std::unique_ptr<SkLatticeIter> iter, |
| 1754 | const SkRect& dst) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1755 | ASSERT_SINGLE_OWNER |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1756 | RETURN_IF_ABANDONED |
| 1757 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1758 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawImageLattice", fContext); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1759 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1760 | AutoCheckFlush acf(this->drawingManager()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1761 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1762 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1763 | GrLatticeOp::MakeNonAA(fContext, std::move(paint), viewMatrix, std::move(image), |
| 1764 | std::move(csxf), filter, std::move(iter), dst); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 1765 | this->addDrawOp(clip, std::move(op)); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1768 | void GrRenderTargetContext::drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable, |
| 1769 | const SkRect& bounds) { |
| 1770 | std::unique_ptr<GrOp> op(GrDrawableOp::Make(fContext, std::move(drawable), bounds)); |
| 1771 | SkASSERT(op); |
| 1772 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1773 | } |
| 1774 | |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1775 | bool GrRenderTargetContext::asyncReadPixels(const SkImageInfo& info, int srcX, int srcY, |
| 1776 | ReadPixelsCallback callback, |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1777 | ReadPixelsContext context) { |
| 1778 | auto direct = fContext->priv().asDirectContext(); |
| 1779 | if (!direct) { |
| 1780 | return false; |
| 1781 | } |
| 1782 | if (!this->caps()->transferBufferSupport()) { |
| 1783 | return false; |
| 1784 | } |
| 1785 | if (fRenderTargetProxy->wrapsVkSecondaryCB()) { |
| 1786 | return false; |
| 1787 | } |
| 1788 | // We currently don't know our own alpha type, we assume it's premul if we have an alpha channel |
| 1789 | // and opaque otherwise. |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1790 | if (!GrPixelConfigIsAlphaOnly(fRenderTargetProxy->config()) && |
| 1791 | info.alphaType() != kPremul_SkAlphaType) { |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1794 | auto dstCT = SkColorTypeToGrColorType(info.colorType()); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1795 | auto readCT = this->caps()->supportedReadPixelsColorType(fRenderTargetProxy->config(), dstCT); |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1796 | // Fail if we can't do a CPU conversion from readCT to dstCT. |
| 1797 | if (GrColorTypeToSkColorType(readCT) == kUnknown_SkColorType) { |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1798 | return false; |
| 1799 | } |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1800 | // Fail if readCT does not have all of readCT's color channels. |
| 1801 | if (GrColorTypeComponentFlags(dstCT) & ~GrColorTypeComponentFlags(readCT)) { |
| 1802 | return false; |
| 1803 | } |
| 1804 | // Fail if readCT is not supported for transfer buffers. |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1805 | if (!this->caps()->transferFromOffsetAlignment(readCT)) { |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1809 | sk_sp<GrColorSpaceXform> xform = |
| 1810 | GrColorSpaceXform::Make(this->colorSpaceInfo().colorSpace(), kPremul_SkAlphaType, |
| 1811 | info.colorSpace(), info.alphaType()); |
| 1812 | const auto srcRect = SkIRect::MakeXYWH(srcX, srcY, info.width(), info.height()); |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1813 | // Insert a draw to a temporary surface if we need to do a y-flip or color space conversion. |
| 1814 | if (this->origin() == kBottomLeft_GrSurfaceOrigin || xform) { |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1815 | sk_sp<GrTextureProxy> texProxy = sk_ref_sp(fRenderTargetProxy->asTextureProxy()); |
| 1816 | const auto& backendFormat = fRenderTargetProxy->backendFormat(); |
| 1817 | SkRect srcRectToDraw = SkRect::Make(srcRect); |
| 1818 | // If the src is not texturable first try to make a copy to a texture. |
| 1819 | if (!texProxy) { |
| 1820 | GrSurfaceDesc desc; |
| 1821 | desc.fWidth = srcRect.width(); |
| 1822 | desc.fHeight = srcRect.height(); |
| 1823 | desc.fConfig = fRenderTargetProxy->config(); |
| 1824 | auto sContext = direct->priv().makeDeferredSurfaceContext( |
| 1825 | backendFormat, desc, this->origin(), GrMipMapped::kNo, SkBackingFit::kApprox, |
| 1826 | SkBudgeted::kNo, this->colorSpaceInfo().refColorSpace()); |
| 1827 | if (!sContext) { |
| 1828 | return false; |
| 1829 | } |
| 1830 | if (!sContext->copy(fRenderTargetProxy.get(), srcRect, {0, 0})) { |
| 1831 | return false; |
| 1832 | } |
| 1833 | texProxy = sk_ref_sp(sContext->asTextureProxy()); |
| 1834 | SkASSERT(texProxy); |
| 1835 | srcRectToDraw = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 1836 | } |
| 1837 | auto rtc = direct->priv().makeDeferredRenderTargetContext( |
| 1838 | backendFormat, SkBackingFit::kApprox, srcRect.width(), srcRect.height(), |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1839 | fRenderTargetProxy->config(), info.refColorSpace(), 1, GrMipMapped::kNo, |
| 1840 | kTopLeft_GrSurfaceOrigin); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1841 | if (!rtc) { |
| 1842 | return false; |
| 1843 | } |
| 1844 | rtc->drawTexture(GrNoClip(), std::move(texProxy), GrSamplerState::Filter::kNearest, |
| 1845 | SkBlendMode::kSrc, SK_PMColor4fWHITE, srcRectToDraw, |
| 1846 | SkRect::MakeWH(srcRect.width(), srcRect.height()), GrAA::kNo, |
| 1847 | GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1848 | std::move(xform)); |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1849 | return rtc->asyncReadPixels(info, 0, 0, callback, context); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1850 | } |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1851 | |
| 1852 | size_t rowBytes = GrColorTypeBytesPerPixel(readCT) * srcRect.width(); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1853 | size_t size = rowBytes * srcRect.height(); |
| 1854 | auto buffer = direct->priv().resourceProvider()->createBuffer( |
| 1855 | size, GrGpuBufferType::kXferGpuToCpu, GrAccessPattern::kStream_GrAccessPattern); |
| 1856 | if (!buffer) { |
| 1857 | return false; |
| 1858 | } |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1859 | this->getRTOpList()->addOp(GrTransferFromOp::Make(fContext, srcRect, readCT, buffer, 0), |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1860 | *this->caps()); |
| 1861 | struct FinishContext { |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1862 | SkImageInfo fReadInfo; |
| 1863 | SkImageInfo fDstInfo; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1864 | ReadPixelsCallback* fClientCallback; |
| 1865 | ReadPixelsContext fClientContext; |
| 1866 | sk_sp<GrGpuBuffer> fBuffer; |
| 1867 | size_t fRowBytes; |
| 1868 | }; |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1869 | const auto readInfo = info.makeColorType(GrColorTypeToSkColorType(readCT)); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1870 | // Assumption is that the caller would like to flush. We could take a parameter or require an |
| 1871 | // explicit flush from the caller. We'd have to have a way to defer attaching the finish |
| 1872 | // callback to GrGpu until after the next flush that flushes our op list, though. |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame^] | 1873 | auto* finishContext = new FinishContext{readInfo, info, callback, context, buffer, rowBytes}; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1874 | auto finishCallback = [](GrGpuFinishedContext c) { |
| 1875 | auto context = reinterpret_cast<const FinishContext*>(c); |
| 1876 | void* data = context->fBuffer->map(); |
Brian Salomon | cd734f6 | 2019-05-10 16:32:54 -0400 | [diff] [blame] | 1877 | if (!data) { |
| 1878 | (*context->fClientCallback)(context->fClientContext, nullptr, 0); |
| 1879 | delete context; |
| 1880 | return; |
| 1881 | } |
| 1882 | SkAutoPixmapStorage pm; |
| 1883 | const void* callbackData = data; |
| 1884 | size_t callbackRowBytes = context->fRowBytes; |
| 1885 | if (context->fDstInfo != context->fReadInfo) { |
| 1886 | pm.alloc(context->fDstInfo); |
| 1887 | SkConvertPixels(context->fDstInfo, pm.writable_addr(), pm.rowBytes(), |
| 1888 | context->fReadInfo, data, context->fRowBytes); |
| 1889 | callbackData = pm.addr(); |
| 1890 | callbackRowBytes = pm.rowBytes(); |
| 1891 | } |
| 1892 | (*context->fClientCallback)(context->fClientContext, callbackData, callbackRowBytes); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 1893 | if (data) { |
| 1894 | context->fBuffer->unmap(); |
| 1895 | } |
| 1896 | delete context; |
| 1897 | }; |
| 1898 | GrFlushInfo flushInfo; |
| 1899 | flushInfo.fFinishedContext = finishContext; |
| 1900 | flushInfo.fFinishedProc = finishCallback; |
| 1901 | this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo); |
| 1902 | return true; |
| 1903 | } |
| 1904 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1905 | GrSemaphoresSubmitted GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess access, |
| 1906 | const GrFlushInfo& info) { |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1907 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 1908 | if (fContext->priv().abandoned()) { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 1909 | return GrSemaphoresSubmitted::kNo; |
| 1910 | } |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1911 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 15c9142 | 2019-05-07 16:54:48 -0400 | [diff] [blame] | 1912 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1913 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1914 | return this->drawingManager()->flushSurface(fRenderTargetProxy.get(), access, info); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1917 | bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores, |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1918 | const GrBackendSemaphore waitSemaphores[]) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1919 | ASSERT_SINGLE_OWNER |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1920 | RETURN_FALSE_IF_ABANDONED |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1921 | SkDEBUGCODE(this->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 1922 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "waitOnSemaphores", fContext); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1923 | |
| 1924 | AutoCheckFlush acf(this->drawingManager()); |
| 1925 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 1926 | if (numSemaphores && !this->caps()->semaphoreSupport()) { |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1927 | return false; |
| 1928 | } |
| 1929 | |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1930 | auto direct = fContext->priv().asDirectContext(); |
| 1931 | if (!direct) { |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
| 1935 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1936 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1937 | for (int i = 0; i < numSemaphores; ++i) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 1938 | sk_sp<GrSemaphore> sema = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 1939 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 1940 | kAdopt_GrWrapOwnership); |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 1941 | std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(fContext, std::move(sema), |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1942 | fRenderTargetProxy.get())); |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 1943 | this->getRTOpList()->addWaitOp(std::move(waitOp), *this->caps()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1944 | } |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1945 | return true; |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 1946 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1947 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1948 | void GrRenderTargetContext::insertEventMarker(const SkString& str) { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 1949 | std::unique_ptr<GrOp> op(GrDebugMarkerOp::Make(fContext, fRenderTargetProxy.get(), str)); |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 1950 | this->getRTOpList()->addOp(std::move(op), *this->caps()); |
| 1951 | } |
| 1952 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 1953 | const GrCaps* GrRenderTargetContext::caps() const { |
| 1954 | return fContext->priv().caps(); |
| 1955 | } |
| 1956 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1957 | void GrRenderTargetContext::drawPath(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1958 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1959 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1960 | const SkMatrix& viewMatrix, |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1961 | const SkPath& path, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1962 | const GrStyle& style) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1963 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1964 | RETURN_IF_ABANDONED |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 1965 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1966 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPath", fContext); |
| 1967 | |
Brian Salomon | 40b77a6 | 2017-12-22 11:25:52 -0500 | [diff] [blame] | 1968 | GrShape shape(path, style); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1969 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 1970 | this->drawShape(clip, std::move(paint), aa, viewMatrix, shape); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void GrRenderTargetContext::drawShape(const GrClip& clip, |
| 1974 | GrPaint&& paint, |
| 1975 | GrAA aa, |
| 1976 | const SkMatrix& viewMatrix, |
| 1977 | const GrShape& shape) { |
| 1978 | ASSERT_SINGLE_OWNER |
| 1979 | RETURN_IF_ABANDONED |
| 1980 | SkDEBUGCODE(this->validate();) |
| 1981 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawShape", fContext); |
| 1982 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1983 | if (shape.isEmpty()) { |
| 1984 | if (shape.inverseFilled()) { |
| 1985 | this->drawPaint(clip, std::move(paint), viewMatrix); |
| 1986 | } |
| 1987 | return; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 1990 | AutoCheckFlush acf(this->drawingManager()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1991 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1992 | if (!shape.style().hasPathEffect()) { |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 1993 | GrAAType aaType = this->chooseAAType(aa); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1994 | SkRRect rrect; |
| 1995 | // We can ignore the starting point and direction since there is no path effect. |
| 1996 | bool inverted; |
| 1997 | if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) { |
| 1998 | if (rrect.isRect()) { |
| 1999 | this->drawRect(clip, std::move(paint), aa, viewMatrix, rrect.rect(), |
| 2000 | &shape.style()); |
| 2001 | return; |
| 2002 | } else if (rrect.isOval()) { |
| 2003 | this->drawOval(clip, std::move(paint), aa, viewMatrix, rrect.rect(), shape.style()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2004 | return; |
| 2005 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2006 | this->drawRRect(clip, std::move(paint), aa, viewMatrix, rrect, shape.style()); |
| 2007 | return; |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 2008 | } else if (GrAAType::kCoverage == aaType && shape.style().isSimpleFill() && |
| 2009 | viewMatrix.rectStaysRect()) { |
| 2010 | // TODO: the rectStaysRect restriction could be lifted if we were willing to apply |
| 2011 | // the matrix to all the points individually rather than just to the rect |
| 2012 | SkRect rects[2]; |
| 2013 | if (shape.asNestedRects(rects)) { |
| 2014 | // Concave AA paths are expensive - try to avoid them for special cases |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 2015 | std::unique_ptr<GrDrawOp> op = GrStrokeRectOp::MakeNested( |
Robert Phillips | 73653b4 | 2018-08-22 12:42:42 -0400 | [diff] [blame] | 2016 | fContext, std::move(paint), viewMatrix, rects); |
| 2017 | if (op) { |
| 2018 | this->addDrawOp(clip, std::move(op)); |
| 2019 | } |
| 2020 | // Returning here indicates that there is nothing to draw in this case. |
| 2021 | return; |
| 2022 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2023 | } |
| 2024 | } |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 2025 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2026 | this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, shape); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 2029 | bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2030 | const GrUserStencilSettings* ss, |
| 2031 | SkRegion::Op op, |
| 2032 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2033 | GrAA aa, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2034 | const SkMatrix& viewMatrix, |
| 2035 | const SkPath& path) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2036 | ASSERT_SINGLE_OWNER_PRIV |
| 2037 | RETURN_FALSE_IF_ABANDONED_PRIV |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2038 | SkDEBUGCODE(fRenderTargetContext->validate();) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2039 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContextPriv", "drawAndStencilPath", |
| 2040 | fRenderTargetContext->fContext); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2041 | |
| 2042 | if (path.isEmpty() && path.isInverseFillType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2043 | this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2044 | SkRect::MakeIWH(fRenderTargetContext->width(), |
| 2045 | fRenderTargetContext->height())); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2046 | return true; |
| 2047 | } |
| 2048 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2049 | AutoCheckFlush acf(fRenderTargetContext->drawingManager()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2050 | |
| 2051 | // An Assumption here is that path renderer would use some form of tweaking |
| 2052 | // the src color (either the input alpha or in the frag shader) to implement |
| 2053 | // aa. If we have some future driver-mojo path AA that can do the right |
| 2054 | // thing WRT to the blend then we'll need some query on the PR. |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2055 | auto aaTypeFlags = choose_path_aa_type_flags( |
| 2056 | aa, fRenderTargetContext->fsaaType(), *fRenderTargetContext->caps()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 2057 | bool hasUserStencilSettings = !ss->isUnused(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2058 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2059 | SkIRect clipConservativeBounds; |
| 2060 | clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 2061 | &clipConservativeBounds, nullptr); |
| 2062 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2063 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2064 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 2065 | canDrawArgs.fCaps = fRenderTargetContext->caps(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2066 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2067 | canDrawArgs.fShape = &shape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2068 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2069 | canDrawArgs.fAATypeFlags = aaTypeFlags; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2070 | SkASSERT(!fRenderTargetContext->wrapsVkSecondaryCB()); |
| 2071 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = false; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2072 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2073 | |
| 2074 | // Don't allow the SW renderer |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2075 | GrPathRenderer* pr = fRenderTargetContext->drawingManager()->getPathRenderer( |
Brian Salomon | 36aa176 | 2016-12-10 13:24:02 -0500 | [diff] [blame] | 2076 | canDrawArgs, false, GrPathRendererChain::DrawType::kStencilAndColor); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2077 | if (!pr) { |
| 2078 | return false; |
| 2079 | } |
| 2080 | |
| 2081 | GrPaint paint; |
| 2082 | paint.setCoverageSetOpXPFactory(op, invert); |
| 2083 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 2084 | GrPathRenderer::DrawPathArgs args{fRenderTargetContext->drawingManager()->getContext(), |
| 2085 | std::move(paint), |
| 2086 | ss, |
| 2087 | fRenderTargetContext, |
| 2088 | &clip, |
| 2089 | &clipConservativeBounds, |
| 2090 | &viewMatrix, |
| 2091 | &shape, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2092 | aaTypeFlags, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 2093 | fRenderTargetContext->colorSpaceInfo().isLinearlyBlended()}; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 2094 | pr->drawPath(args); |
| 2095 | return true; |
| 2096 | } |
| 2097 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2098 | SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2099 | ASSERT_SINGLE_OWNER_PRIV |
| 2100 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 2101 | if (fRenderTargetContext->fContext->priv().abandoned()) { |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2102 | return SkBudgeted::kNo; |
| 2103 | } |
| 2104 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 2105 | SkDEBUGCODE(fRenderTargetContext->validate();) |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2106 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 2107 | return fRenderTargetContext->fRenderTargetProxy->isBudgeted(); |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2110 | void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, |
| 2111 | GrPaint&& paint, |
| 2112 | GrAA aa, |
| 2113 | const SkMatrix& viewMatrix, |
| 2114 | const GrShape& originalShape) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2115 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2116 | RETURN_IF_ABANDONED |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2117 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "internalDrawPath", fContext); |
| 2118 | |
Jim Van Verth | f86073a | 2018-10-02 13:05:38 -0400 | [diff] [blame] | 2119 | if (!viewMatrix.isFinite() || !originalShape.bounds().isFinite()) { |
| 2120 | return; |
| 2121 | } |
| 2122 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2123 | SkIRect clipConservativeBounds; |
| 2124 | clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr); |
| 2125 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2126 | GrShape tempShape; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2127 | auto aaTypeFlags = choose_path_aa_type_flags(aa, this->fsaaType(), *this->caps()); |
| 2128 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2129 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 2130 | canDrawArgs.fCaps = this->caps(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2131 | canDrawArgs.fViewMatrix = &viewMatrix; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2132 | canDrawArgs.fShape = &originalShape; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2133 | canDrawArgs.fClipConservativeBounds = &clipConservativeBounds; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2134 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = this->wrapsVkSecondaryCB(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2135 | canDrawArgs.fHasUserStencilSettings = false; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 2136 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 2137 | GrPathRenderer* pr; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 2138 | static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2139 | if (originalShape.isEmpty() && !originalShape.inverseFilled()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2140 | return; |
| 2141 | } |
| 2142 | |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2143 | canDrawArgs.fAATypeFlags = aaTypeFlags; |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2144 | |
| 2145 | // Try a 1st time without applying any of the style to the geometry (and barring sw) |
| 2146 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
| 2147 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 2148 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2149 | if (!pr && originalShape.style().pathEffect()) { |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2150 | // 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] | 2151 | tempShape = originalShape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); |
| 2152 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2153 | return; |
| 2154 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2155 | canDrawArgs.fShape = &tempShape; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 2156 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType); |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2157 | } |
| 2158 | if (!pr) { |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2159 | if (canDrawArgs.fShape->style().applies()) { |
| 2160 | tempShape = canDrawArgs.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, |
| 2161 | styleScale); |
| 2162 | if (tempShape.isEmpty()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2163 | return; |
| 2164 | } |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2165 | canDrawArgs.fShape = &tempShape; |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 2166 | // This time, allow SW renderer |
| 2167 | pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType); |
| 2168 | } else { |
| 2169 | pr = this->drawingManager()->getSoftwarePathRenderer(); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 2170 | } |
Brian Salomon | 1e5d0ca | 2017-12-14 10:50:19 -0500 | [diff] [blame] | 2171 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2172 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 2173 | if (!pr) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2174 | #ifdef SK_DEBUG |
| 2175 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 2176 | #endif |
| 2177 | return; |
| 2178 | } |
| 2179 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 2180 | GrPathRenderer::DrawPathArgs args{this->drawingManager()->getContext(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2181 | std::move(paint), |
| 2182 | &GrUserStencilSettings::kUnused, |
| 2183 | this, |
| 2184 | &clip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 2185 | &clipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 2186 | &viewMatrix, |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 2187 | canDrawArgs.fShape, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 2188 | aaTypeFlags, |
Brian Osman | 34ec374 | 2018-07-03 10:40:57 -0400 | [diff] [blame] | 2189 | this->colorSpaceInfo().isLinearlyBlended()}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 2190 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2193 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 2194 | *bounds = op->bounds(); |
| 2195 | if (op->hasZeroArea()) { |
| 2196 | if (op->hasAABloat()) { |
| 2197 | bounds->outset(0.5f, 0.5f); |
| 2198 | } else { |
| 2199 | // We don't know which way the particular GPU will snap lines or points at integer |
| 2200 | // coords. So we ensure that the bounds is large enough for either snap. |
| 2201 | SkRect before = *bounds; |
| 2202 | bounds->roundOut(bounds); |
| 2203 | if (bounds->fLeft == before.fLeft) { |
| 2204 | bounds->fLeft -= 1; |
| 2205 | } |
| 2206 | if (bounds->fTop == before.fTop) { |
| 2207 | bounds->fTop -= 1; |
| 2208 | } |
| 2209 | if (bounds->fRight == before.fRight) { |
| 2210 | bounds->fRight += 1; |
| 2211 | } |
| 2212 | if (bounds->fBottom == before.fBottom) { |
| 2213 | bounds->fBottom += 1; |
| 2214 | } |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2219 | void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op, |
| 2220 | const std::function<WillAddOpFn>& willAddFn) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 2221 | ASSERT_SINGLE_OWNER |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 2222 | if (fContext->priv().abandoned()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2223 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2224 | return; |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 2225 | } |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 2226 | SkDEBUGCODE(this->validate();) |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 2227 | SkDEBUGCODE(op->fAddDrawOpCalled = true;) |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 2228 | GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "addDrawOp", fContext); |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 2229 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2230 | // Setup clip |
| 2231 | SkRect bounds; |
| 2232 | op_bounds(&bounds, op.get()); |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 2233 | GrAppliedClip appliedClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2234 | GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags(); |
| 2235 | if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA, |
| 2236 | fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip, |
| 2237 | &bounds)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2238 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2239 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2240 | } |
| 2241 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 2242 | if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil || |
| 2243 | appliedClip.hasStencilClip()) { |
| 2244 | if (this->caps()->performStencilClearsAsDraws()) { |
| 2245 | // Must use an op to perform the clear of the stencil buffer before this op, but only |
| 2246 | // have to clear the first time any draw needs it (this also ensures we don't loop |
| 2247 | // forever when the internal stencil clear adds a draw op that has stencil settings). |
| 2248 | if (!fRenderTargetProxy->needsStencil()) { |
| 2249 | // Send false so that the stencil buffer is fully cleared to 0 |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 2250 | this->internalStencilClear(GrFixedClip::Disabled(), /* inside mask */ false); |
| 2251 | } |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 2252 | } else { |
| 2253 | // Just make sure the stencil buffer is cleared before the draw op, easy to do it as |
| 2254 | // a load at the start |
| 2255 | this->getRTOpList()->setStencilLoadOp(GrLoadOp::kClear); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 2256 | } |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 2257 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 2258 | this->setNeedsStencil(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2259 | } |
| 2260 | |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 2261 | GrClampType clampType = GrPixelConfigClampType(this->colorSpaceInfo().config()); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2262 | GrXferProcessor::DstProxy dstProxy; |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 2263 | GrProcessorSet::Analysis analysis = op->finalize( |
| 2264 | *this->caps(), &appliedClip, this->fsaaType(), clampType); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 2265 | if (analysis.requiresDstTexture()) { |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2266 | if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, *op, &dstProxy)) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2267 | fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2268 | return; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | op->setClippedBounds(bounds); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 2273 | auto opList = this->getRTOpList(); |
| 2274 | if (willAddFn) { |
| 2275 | willAddFn(op.get(), opList->uniqueID()); |
| 2276 | } |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 2277 | opList->addDrawOp(std::move(op), analysis, std::move(appliedClip), dstProxy, *this->caps()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 2278 | } |
| 2279 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2280 | bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2281 | const GrOp& op, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 2282 | GrXferProcessor::DstProxy* dstProxy) { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 2283 | // If we are wrapping a vulkan secondary command buffer, we can't make a dst copy because we |
| 2284 | // don't actually have a VkImage to make a copy of. Additionally we don't have the power to |
| 2285 | // start and stop the render pass in order to make the copy. |
| 2286 | if (rtProxy->wrapsVkSecondaryCB()) { |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2290 | if (this->caps()->textureBarrierSupport()) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2291 | if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2292 | // The render target is a texture, so we can read from it directly in the shader. The XP |
| 2293 | // will be responsible to detect this situation and request a texture barrier. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2294 | dstProxy->setProxy(sk_ref_sp(texProxy)); |
| 2295 | dstProxy->setOffset(0, 0); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2296 | return true; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2297 | } |
| 2298 | } |
| 2299 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2300 | SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height()); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2301 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2302 | SkIRect clippedRect; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2303 | clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect); |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 2304 | SkRect opBounds = op.bounds(); |
| 2305 | // If the op has aa bloating or is a infinitely thin geometry (hairline) outset the bounds by |
| 2306 | // 0.5 pixels. |
| 2307 | if (op.hasAABloat() || op.hasZeroArea()) { |
| 2308 | opBounds.outset(0.5f, 0.5f); |
| 2309 | // An antialiased/hairline draw can sometimes bleed outside of the clips bounds. For |
| 2310 | // performance we may ignore the clip when the draw is entirely inside the clip is float |
| 2311 | // space but will hit pixels just outside the clip when actually rasterizing. |
| 2312 | clippedRect.outset(1, 1); |
| 2313 | clippedRect.intersect(SkIRect::MakeWH(rtProxy->width(), rtProxy->height())); |
| 2314 | } |
| 2315 | SkIRect opIBounds; |
| 2316 | opBounds.roundOut(&opIBounds); |
| 2317 | if (!clippedRect.intersect(opIBounds)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2318 | #ifdef SK_DEBUG |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2319 | GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw."); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2320 | #endif |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2321 | return false; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 2325 | // have per-sample dst values by making the copy multisampled. |
| 2326 | GrSurfaceDesc desc; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2327 | bool rectsMustMatch = false; |
| 2328 | bool disallowSubrect = false; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 2329 | GrSurfaceOrigin origin; |
| 2330 | if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &origin, &rectsMustMatch, |
| 2331 | &disallowSubrect)) { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2332 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2333 | desc.fConfig = rtProxy->config(); |
Greg Daniel | 1efe322 | 2018-04-04 14:02:51 -0400 | [diff] [blame] | 2334 | origin = rtProxy->origin(); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2337 | if (!disallowSubrect) { |
| 2338 | copyRect = clippedRect; |
| 2339 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2340 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2341 | SkIPoint dstPoint, dstOffset; |
| 2342 | SkBackingFit fit; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2343 | if (rectsMustMatch) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2344 | desc.fWidth = rtProxy->width(); |
| 2345 | desc.fHeight = rtProxy->height(); |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2346 | dstPoint = {copyRect.fLeft, copyRect.fTop}; |
| 2347 | dstOffset = {0, 0}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2348 | fit = SkBackingFit::kExact; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2349 | } else { |
| 2350 | desc.fWidth = copyRect.width(); |
| 2351 | desc.fHeight = copyRect.height(); |
| 2352 | dstPoint = {0, 0}; |
| 2353 | dstOffset = {copyRect.fLeft, copyRect.fTop}; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2354 | fit = SkBackingFit::kApprox; |
Eric Karl | 7448088 | 2017-04-03 14:49:05 -0700 | [diff] [blame] | 2355 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 2356 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 2357 | SkASSERT(rtProxy->backendFormat().textureType() == GrTextureType::k2D); |
| 2358 | const GrBackendFormat& format = rtProxy->backendFormat(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 2359 | sk_sp<GrSurfaceContext> sContext = fContext->priv().makeDeferredSurfaceContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 2360 | format, desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 2361 | sk_ref_sp(this->colorSpaceInfo().colorSpace())); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2362 | if (!sContext) { |
| 2363 | SkDebugf("setupDstTexture: surfaceContext creation failed.\n"); |
| 2364 | return false; |
| 2365 | } |
| 2366 | |
| 2367 | if (!sContext->copy(rtProxy, copyRect, dstPoint)) { |
| 2368 | SkDebugf("setupDstTexture: copy failed.\n"); |
| 2369 | return false; |
| 2370 | } |
| 2371 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 2372 | dstProxy->setProxy(sContext->asTextureProxyRef()); |
| 2373 | dstProxy->setOffset(dstOffset); |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 2374 | return true; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 2375 | } |