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