blob: c8c06f55756005a114681819c5eaa78c0c29f793 [file] [log] [blame]
Chris Daltonb832ce62020-01-06 19:49:37 -07001/*
2 * Copyright 2019 Google LLC.
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
Chris Dalton0a22b1e2020-03-26 11:52:15 -06008#include "src/gpu/tessellate/GrTessellationPathRenderer.h"
Chris Daltonb832ce62020-01-06 19:49:37 -07009
Chris Dalton50c3c242021-06-14 16:32:35 -060010#include "include/private/SkVx.h"
Chris Daltond2dc8dd2020-05-19 16:32:02 -060011#include "src/core/SkIPoint16.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070012#include "src/core/SkPathPriv.h"
13#include "src/gpu/GrClip.h"
14#include "src/gpu/GrMemoryPool.h"
15#include "src/gpu/GrRecordingContextPriv.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050016#include "src/gpu/GrSurfaceDrawContext.h"
Chris Dalton50c3c242021-06-14 16:32:35 -060017#include "src/gpu/GrVx.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000018#include "src/gpu/geometry/GrStyledShape.h"
Michael Ludwig4e9d5e22021-05-11 10:00:12 -040019#include "src/gpu/geometry/GrWangsFormula.h"
Chris Daltonc3b67eb2020-02-10 21:09:58 -070020#include "src/gpu/ops/GrFillRectOp.h"
Chris Dalton4e998532020-02-10 11:06:42 -070021#include "src/gpu/tessellate/GrDrawAtlasPathOp.h"
Chris Daltonebb37e72021-01-27 17:59:45 -070022#include "src/gpu/tessellate/GrPathInnerTriangulateOp.h"
Chris Dalton031d76b2021-06-08 16:32:00 -060023#include "src/gpu/tessellate/GrPathStencilCoverOp.h"
Chris Dalton7ae272f2021-06-10 11:45:14 -060024#include "src/gpu/tessellate/GrPathTessellateOp.h"
Chris Dalton05007df2021-02-04 00:24:52 -070025#include "src/gpu/tessellate/GrStrokeTessellateOp.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070026
Chris Dalton4e998532020-02-10 11:06:42 -070027constexpr static SkISize kAtlasInitialSize{512, 512};
28constexpr static int kMaxAtlasSize = 2048;
29
Chris Daltond72cb4c2020-07-16 17:50:17 -060030constexpr static auto kAtlasAlpha8Type = GrColorType::kAlpha_8;
31
Chris Daltond2dc8dd2020-05-19 16:32:02 -060032// The atlas is only used for small-area paths, which means at least one dimension of every path is
33// guaranteed to be quite small. So if we transpose tall paths, then every path will have a small
34// height, which lends very well to efficient pow2 atlas packing.
35constexpr static auto kAtlasAlgorithm = GrDynamicAtlas::RectanizerAlgorithm::kPow2;
36
37// Ensure every path in the atlas falls in or below the 128px high rectanizer band.
38constexpr static int kMaxAtlasPathHeight = 128;
39
Chris Dalton1413d112020-07-09 11:26:31 -060040bool GrTessellationPathRenderer::IsSupported(const GrCaps& caps) {
Chris Dalton8f282f52021-01-06 11:47:58 -070041 return !caps.avoidStencilBuffers() &&
42 caps.drawInstancedSupport() &&
Chris Daltoneae5c162020-12-29 10:18:21 -070043 caps.shaderCaps()->vertexIDSupport() &&
44 !caps.disableTessellationPathRenderer();
Chris Dalton1413d112020-07-09 11:26:31 -060045}
46
Chris Dalton9213e612020-10-09 17:22:43 -060047GrTessellationPathRenderer::GrTessellationPathRenderer(GrRecordingContext* rContext)
Chris Daltond72cb4c2020-07-16 17:50:17 -060048 : fAtlas(kAtlasAlpha8Type, GrDynamicAtlas::InternalMultisample::kYes, kAtlasInitialSize,
Chris Dalton31634282020-09-17 12:16:54 -060049 std::min(kMaxAtlasSize, rContext->priv().caps()->maxPreferredRenderTargetSize()),
50 *rContext->priv().caps(), kAtlasAlgorithm) {
Chris Dalton31634282020-09-17 12:16:54 -060051 const GrCaps& caps = *rContext->priv().caps();
Chris Dalton9213e612020-10-09 17:22:43 -060052 auto atlasFormat = caps.getDefaultBackendFormat(kAtlasAlpha8Type, GrRenderable::kYes);
Chris Dalton569c01b2021-05-25 10:11:46 -060053 if (rContext->asDirectContext() && // The atlas doesn't support DDL yet.
54 caps.internalMultisampleCount(atlasFormat) > 1) {
55 fMaxAtlasPathWidth = fAtlas.maxAtlasSize() / 2; // Enable the atlas.
Chris Dalton9213e612020-10-09 17:22:43 -060056 }
Chris Dalton4e998532020-02-10 11:06:42 -070057}
58
Chris Dalton7ae272f2021-06-10 11:45:14 -060059GrPathRenderer::StencilSupport GrTessellationPathRenderer::onGetStencilSupport(
60 const GrStyledShape& shape) const {
61 if (!shape.style().isSimpleFill()) {
62 // Don't bother with stroke stencilling yet. Skia probably shouldn't support this at all
63 // since you can't clip by a stroke.
64 return kNoSupport_StencilSupport;
65 }
66 return shape.knownToBeConvex() ? kNoRestriction_StencilSupport : kStencilOnly_StencilSupport;
67}
68
Chris Dalton0a22b1e2020-03-26 11:52:15 -060069GrPathRenderer::CanDrawPath GrTessellationPathRenderer::onCanDrawPath(
Chris Daltonb832ce62020-01-06 19:49:37 -070070 const CanDrawPathArgs& args) const {
Chris Dalton1c62a7b2020-06-29 22:01:14 -060071 const GrStyledShape& shape = *args.fShape;
Chris Dalton57ab06c2021-04-22 12:57:28 -060072 if (args.fAAType == GrAAType::kCoverage ||
73 shape.style().hasPathEffect() ||
Chris Dalton06b52ad2020-12-15 10:01:35 -070074 args.fViewMatrix->hasPerspective() ||
75 shape.style().strokeRec().getStyle() == SkStrokeRec::kStrokeAndFill_Style ||
Chris Dalton2078cbe2020-12-14 19:04:55 -070076 shape.inverseFilled() ||
Chris Dalton537293bf2021-05-03 15:54:24 -060077 !args.fProxy->canUseStencil(*args.fCaps)) {
Chris Daltonb832ce62020-01-06 19:49:37 -070078 return CanDrawPath::kNo;
79 }
Chris Dalton7ae272f2021-06-10 11:45:14 -060080 if (args.fHasUserStencilSettings) {
81 // Non-convex paths and strokes use the stencil buffer internally, so they can't support
82 // draws with stencil settings.
83 if (!shape.style().isSimpleFill() || !shape.knownToBeConvex()) {
84 return CanDrawPath::kNo;
85 }
86 }
Chris Daltonb832ce62020-01-06 19:49:37 -070087 return CanDrawPath::kYes;
88}
89
Chris Dalton7ae272f2021-06-10 11:45:14 -060090static GrOp::Owner make_non_convex_fill_op(GrRecordingContext* rContext,
91 GrTessellationPathRenderer::PathFlags pathFlags,
92 GrAAType aaType, const SkRect& pathDevBounds,
93 const SkMatrix& viewMatrix, const SkPath& path,
94 GrPaint&& paint) {
95 SkASSERT(!path.isConvex());
96 int numVerbs = path.countVerbs();
97 if (numVerbs > 0) {
98 // Check if the path is large and/or simple enough that we can triangulate the inner fan
99 // on the CPU. This is our fastest approach. It allows us to stencil only the curves,
100 // and then fill the inner fan directly to the final render target, thus drawing the
101 // majority of pixels in a single render pass.
102 float gpuFragmentWork = pathDevBounds.height() * pathDevBounds.width();
103 float cpuTessellationWork = numVerbs * SkNextLog2(numVerbs); // N log N.
104 constexpr static float kCpuWeight = 512;
105 constexpr static float kMinNumPixelsToTriangulate = 256 * 256;
106 if (cpuTessellationWork * kCpuWeight + kMinNumPixelsToTriangulate < gpuFragmentWork) {
107 return GrOp::Make<GrPathInnerTriangulateOp>(rContext, viewMatrix, path,
108 std::move(paint), aaType, pathFlags,
109 pathDevBounds);
Chris Dalton70a0d2c2021-01-26 12:01:21 -0700110 }
Chris Daltonc2a17462020-12-09 16:46:22 -0700111 }
Chris Dalton7ae272f2021-06-10 11:45:14 -0600112 return GrOp::Make<GrPathStencilCoverOp>(rContext, viewMatrix, path, std::move(paint), aaType,
113 pathFlags, pathDevBounds);
Chris Daltonc2a17462020-12-09 16:46:22 -0700114}
115
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600116bool GrTessellationPathRenderer::onDrawPath(const DrawPathArgs& args) {
John Stiles0fbc6a32021-06-04 14:40:57 -0400117 GrSurfaceDrawContext* surfaceDrawContext = args.fSurfaceDrawContext;
Chris Daltonb832ce62020-01-06 19:49:37 -0700118
Chris Dalton7ae272f2021-06-10 11:45:14 -0600119 SkPath path;
120 args.fShape->asPath(&path);
121
122 // Handle strokes first.
123 if (!args.fShape->style().isSimpleFill()) {
124 SkASSERT(args.fUserStencilSettings->isUnused());
125 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
126 SkASSERT(stroke.getStyle() != SkStrokeRec::kStrokeAndFill_Style);
127 auto op = GrOp::Make<GrStrokeTessellateOp>(args.fContext, args.fAAType, *args.fViewMatrix,
128 path, stroke, std::move(args.fPaint));
129 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
130 return true;
131 }
132
133 SkRect pathDevBounds;
134 args.fViewMatrix->mapRect(&pathDevBounds, args.fShape->bounds());
Chris Daltonb96995d2020-06-04 16:44:29 -0600135
Chris Dalton4e998532020-02-10 11:06:42 -0700136 // See if the path is small and simple enough to atlas instead of drawing directly.
137 //
138 // NOTE: The atlas uses alpha8 coverage even for msaa render targets. We could theoretically
139 // render the sample mask to an integer texture, but such a scheme would probably require
140 // GL_EXT_post_depth_coverage, which appears to have low adoption.
141 SkIRect devIBounds;
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600142 SkIPoint16 locationInAtlas;
143 bool transposedInAtlas;
Chris Dalton7ae272f2021-06-10 11:45:14 -0600144 if (args.fUserStencilSettings->isUnused() &&
145 this->tryAddPathToAtlas(*args.fContext->priv().caps(), *args.fViewMatrix, path,
Chris Dalton50c3c242021-06-14 16:32:35 -0600146 pathDevBounds, args.fAAType != GrAAType::kNone, &devIBounds,
147 &locationInAtlas, &transposedInAtlas)) {
Chris Dalton9213e612020-10-09 17:22:43 -0600148 // The atlas is not compatible with DDL. We should only be using it on direct contexts.
149 SkASSERT(args.fContext->asDirectContext());
Chris Dalton50c3c242021-06-14 16:32:35 -0600150 auto op = GrOp::Make<GrDrawAtlasPathOp>(args.fContext, surfaceDrawContext->numSamples(),
151 sk_ref_sp(fAtlas.textureProxy()), devIBounds,
152 locationInAtlas, transposedInAtlas,
153 *args.fViewMatrix, std::move(args.fPaint));
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500154 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700155 return true;
156 }
Chris Daltonb832ce62020-01-06 19:49:37 -0700157
Chris Dalton7ae272f2021-06-10 11:45:14 -0600158 // Handle convex paths only if we couldn't fit them in the atlas. We give the atlas priority in
159 // an effort to reduce DMSAA triggers.
160 if (args.fShape->knownToBeConvex()) {
161 auto op = GrOp::Make<GrPathTessellateOp>(args.fContext, *args.fViewMatrix, path,
162 std::move(args.fPaint), args.fAAType,
163 args.fUserStencilSettings, pathDevBounds);
Chris Daltonb0643342020-12-15 01:04:12 -0700164 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
Chris Dalton7ae272f2021-06-10 11:45:14 -0600165 return true;
Chris Daltonb96995d2020-06-04 16:44:29 -0600166 }
Chris Dalton7ae272f2021-06-10 11:45:14 -0600167
168 SkASSERT(args.fUserStencilSettings->isUnused()); // See onGetStencilSupport().
169 auto op = make_non_convex_fill_op(args.fContext, PathFlags::kNone, args.fAAType, pathDevBounds,
170 *args.fViewMatrix, path, std::move(args.fPaint));
171 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700172 return true;
173}
174
Chris Dalton7ae272f2021-06-10 11:45:14 -0600175void GrTessellationPathRenderer::onStencilPath(const StencilPathArgs& args) {
176 SkASSERT(args.fShape->style().isSimpleFill()); // See onGetStencilSupport().
177
178 GrSurfaceDrawContext* surfaceDrawContext = args.fSurfaceDrawContext;
179 GrAAType aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
180
181 SkRect pathDevBounds;
182 args.fViewMatrix->mapRect(&pathDevBounds, args.fShape->bounds());
183
184 SkPath path;
185 args.fShape->asPath(&path);
186
187 if (args.fShape->knownToBeConvex()) {
188 constexpr static GrUserStencilSettings kMarkStencil(
189 GrUserStencilSettings::StaticInit<
190 0x0001,
191 GrUserStencilTest::kAlways,
192 0xffff,
193 GrUserStencilOp::kReplace,
194 GrUserStencilOp::kKeep,
195 0xffff>());
196
197 GrPaint stencilPaint;
198 stencilPaint.setXPFactory(GrDisableColorXPFactory::Get());
199 auto op = GrOp::Make<GrPathTessellateOp>(args.fContext, *args.fViewMatrix, path,
200 std::move(stencilPaint), aaType, &kMarkStencil,
201 pathDevBounds);
202 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
203 return;
Chris Daltonb0643342020-12-15 01:04:12 -0700204 }
205
Chris Dalton7ae272f2021-06-10 11:45:14 -0600206 auto op = make_non_convex_fill_op(args.fContext, PathFlags::kStencilOnly, aaType, pathDevBounds,
207 *args.fViewMatrix, path, GrPaint());
208 surfaceDrawContext->addDrawOp(args.fClip, std::move(op));
209}
210
Chris Dalton50c3c242021-06-14 16:32:35 -0600211void GrTessellationPathRenderer::AtlasPathKey::set(const SkMatrix& m, bool antialias,
212 const SkPath& path) {
213 using grvx::float2;
214 fAffineMatrix[0] = m.getScaleX();
215 fAffineMatrix[1] = m.getSkewX();
216 fAffineMatrix[2] = m.getSkewY();
217 fAffineMatrix[3] = m.getScaleY();
218 float2 translate = {m.getTranslateX(), m.getTranslateY()};
219 float2 subpixelPosition = translate - skvx::floor(translate);
Robert Phillips62214f72021-06-15 10:12:51 -0400220 float2 subpixelPositionKey = skvx::trunc(subpixelPosition *
221 GrPathTessellator::kLinearizationPrecision);
Chris Dalton50c3c242021-06-14 16:32:35 -0600222 skvx::cast<uint8_t>(subpixelPositionKey).store(fSubpixelPositionKey);
223 fAntialias = antialias;
224 fFillRule = (uint8_t)GrFillRuleForSkPath(path); // Fill rule doesn't affect the path's genID.
225 fPathGenID = path.getGenerationID();
226}
227
Chris Dalton7ae272f2021-06-10 11:45:14 -0600228bool GrTessellationPathRenderer::tryAddPathToAtlas(const GrCaps& caps, const SkMatrix& viewMatrix,
229 const SkPath& path, const SkRect& pathDevBounds,
Chris Dalton50c3c242021-06-14 16:32:35 -0600230 bool antialias, SkIRect* devIBounds,
Chris Dalton7ae272f2021-06-10 11:45:14 -0600231 SkIPoint16* locationInAtlas,
232 bool* transposedInAtlas) {
Chris Dalton50c3c242021-06-14 16:32:35 -0600233 SkASSERT(!viewMatrix.hasPerspective()); // See onCanDrawPath().
234
Chris Daltond72cb4c2020-07-16 17:50:17 -0600235 if (!fMaxAtlasPathWidth) {
236 return false;
237 }
238
Chris Dalton50c3c242021-06-14 16:32:35 -0600239 if (!caps.multisampleDisableSupport() && !antialias) {
Chris Dalton4e998532020-02-10 11:06:42 -0700240 return false;
241 }
242
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600243 // Transpose tall paths in the atlas. Since we limit ourselves to small-area paths, this
244 // guarantees that every atlas entry has a small height, which lends very well to efficient pow2
245 // atlas packing.
Chris Dalton7ae272f2021-06-10 11:45:14 -0600246 pathDevBounds.roundOut(devIBounds);
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600247 int maxDimenstion = devIBounds->width();
248 int minDimension = devIBounds->height();
249 *transposedInAtlas = minDimension > maxDimenstion;
250 if (*transposedInAtlas) {
251 std::swap(minDimension, maxDimenstion);
252 }
253
Chris Dalton569c01b2021-05-25 10:11:46 -0600254 // Check if the path is too large for an atlas. Since we transpose paths in the atlas so height
255 // is always "minDimension", limiting to kMaxAtlasPathHeight^2 pixels guarantees height <=
256 // kMaxAtlasPathHeight, while also allowing paths that are very wide and short.
Chris Daltoneae5c162020-12-29 10:18:21 -0700257 if ((uint64_t)maxDimenstion * minDimension > kMaxAtlasPathHeight * kMaxAtlasPathHeight ||
Chris Daltonb96995d2020-06-04 16:44:29 -0600258 maxDimenstion > fMaxAtlasPathWidth) {
Chris Dalton4e998532020-02-10 11:06:42 -0700259 return false;
260 }
261
Chris Dalton50c3c242021-06-14 16:32:35 -0600262 // Check if this path is already in the atlas. This is mainly for clip paths.
263 AtlasPathKey atlasPathKey;
264 if (!path.isVolatile()) {
265 atlasPathKey.set(viewMatrix, antialias, path);
266 if (const SkIPoint16* existingLocation = fAtlasPathCache.find(atlasPathKey)) {
267 *locationInAtlas = *existingLocation;
268 return true;
269 }
270 }
271
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600272 if (!fAtlas.addRect(maxDimenstion, minDimension, locationInAtlas)) {
Chris Dalton4e998532020-02-10 11:06:42 -0700273 return false;
274 }
275
Chris Dalton50c3c242021-06-14 16:32:35 -0600276 // Remember this path's location in the atlas, in case it gets drawn again.
277 if (!path.isVolatile()) {
278 fAtlasPathCache.set(atlasPathKey, *locationInAtlas);
279 }
280
Chris Dalton4e998532020-02-10 11:06:42 -0700281 SkMatrix atlasMatrix = viewMatrix;
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600282 if (*transposedInAtlas) {
283 std::swap(atlasMatrix[0], atlasMatrix[3]);
284 std::swap(atlasMatrix[1], atlasMatrix[4]);
285 float tx=atlasMatrix.getTranslateX(), ty=atlasMatrix.getTranslateY();
286 atlasMatrix.setTranslateX(ty - devIBounds->y() + locationInAtlas->x());
287 atlasMatrix.setTranslateY(tx - devIBounds->x() + locationInAtlas->y());
288 } else {
289 atlasMatrix.postTranslate(locationInAtlas->x() - devIBounds->x(),
290 locationInAtlas->y() - devIBounds->y());
291 }
Chris Dalton4e998532020-02-10 11:06:42 -0700292
293 // Concatenate this path onto our uber path that matches its fill and AA types.
Chris Dalton50c3c242021-06-14 16:32:35 -0600294 SkPath* uberPath = this->getAtlasUberPath(path.getFillType(), antialias);
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600295 uberPath->moveTo(locationInAtlas->x(), locationInAtlas->y()); // Implicit moveTo(0,0).
Chris Dalton4e998532020-02-10 11:06:42 -0700296 uberPath->addPath(path, atlasMatrix);
Chris Daltonb832ce62020-01-06 19:49:37 -0700297 return true;
298}
299
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600300void GrTessellationPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP,
Adlai Holler9902cff2020-11-11 08:51:25 -0500301 SkSpan<const uint32_t> /* taskIDs */) {
Chris Dalton4e998532020-02-10 11:06:42 -0700302 if (!fAtlas.drawBounds().isEmpty()) {
303 this->renderAtlas(onFlushRP);
304 fAtlas.reset(kAtlasInitialSize, *onFlushRP->caps());
305 }
306 for (SkPath& path : fAtlasUberPaths) {
307 path.reset();
308 }
Chris Dalton50c3c242021-06-14 16:32:35 -0600309 fAtlasPathCache.reset();
Chris Dalton4e998532020-02-10 11:06:42 -0700310}
311
312constexpr static GrUserStencilSettings kTestStencil(
313 GrUserStencilSettings::StaticInit<
314 0x0000,
315 GrUserStencilTest::kNotEqual,
316 0xffff,
317 GrUserStencilOp::kKeep,
318 GrUserStencilOp::kKeep,
319 0xffff>());
320
321constexpr static GrUserStencilSettings kTestAndResetStencil(
322 GrUserStencilSettings::StaticInit<
323 0x0000,
324 GrUserStencilTest::kNotEqual,
325 0xffff,
326 GrUserStencilOp::kZero,
327 GrUserStencilOp::kKeep,
328 0xffff>());
329
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600330void GrTessellationPathRenderer::renderAtlas(GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton4e998532020-02-10 11:06:42 -0700331 auto rtc = fAtlas.instantiate(onFlushRP);
332 if (!rtc) {
333 return;
334 }
335
Chris Dalton569c01b2021-05-25 10:11:46 -0600336 SkRect atlasRect = SkRect::MakeIWH(fAtlas.drawBounds().width(), fAtlas.drawBounds().height());
337
Chris Dalton4e998532020-02-10 11:06:42 -0700338 // Add ops to stencil the atlas paths.
339 for (auto antialias : {false, true}) {
340 for (auto fillType : {SkPathFillType::kWinding, SkPathFillType::kEvenOdd}) {
341 SkPath* uberPath = this->getAtlasUberPath(fillType, antialias);
342 if (uberPath->isEmpty()) {
343 continue;
344 }
345 uberPath->setFillType(fillType);
346 GrAAType aaType = (antialias) ? GrAAType::kMSAA : GrAAType::kNone;
Chris Dalton031d76b2021-06-08 16:32:00 -0600347 auto op = GrOp::Make<GrPathStencilCoverOp>(onFlushRP->recordingContext(), SkMatrix::I(),
348 *uberPath, GrPaint(), aaType,
349 PathFlags::kStencilOnly, atlasRect);
Michael Ludwig7c12e282020-05-29 09:54:07 -0400350 rtc->addDrawOp(nullptr, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700351 }
352 }
353
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700354 // Finally, draw a fullscreen rect to convert our stencilled paths into alpha coverage masks.
Chris Dalton569c01b2021-05-25 10:11:46 -0600355 GrPaint paint;
356 paint.setColor4f(SK_PMColor4fWHITE);
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700357 const GrUserStencilSettings* stencil;
Chris Dalton57ab06c2021-04-22 12:57:28 -0600358 if (onFlushRP->caps()->discardStencilValuesAfterRenderPass()) {
359 // This is the final op in the surfaceDrawContext. Since Ganesh is planning to discard the
360 // stencil values anyway, there is no need to reset the stencil values back to 0.
361 stencil = &kTestStencil;
362 } else {
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700363 // Outset the cover rect in case there are T-junctions in the path bounds.
Chris Dalton569c01b2021-05-25 10:11:46 -0600364 atlasRect.outset(1, 1);
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700365 stencil = &kTestAndResetStencil;
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700366 }
Chris Dalton569c01b2021-05-25 10:11:46 -0600367 rtc->stencilRect(nullptr, stencil, std::move(paint), GrAA::kYes, SkMatrix::I(), atlasRect);
Chris Dalton4e998532020-02-10 11:06:42 -0700368
369 if (rtc->asSurfaceProxy()->requiresManualMSAAResolve()) {
370 onFlushRP->addTextureResolveTask(sk_ref_sp(rtc->asTextureProxy()),
371 GrSurfaceProxy::ResolveFlags::kMSAA);
372 }
373}