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