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