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