blob: 519a83b0a4192daff55e6e13790a84b03dfc223d [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 Daltonb96995d2020-06-04 16:44:29 -060010#include "include/pathops/SkPathOps.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"
16#include "src/gpu/GrRenderTargetContext.h"
Chris Daltonc3b67eb2020-02-10 21:09:58 -070017#include "src/gpu/GrSurfaceContextPriv.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000018#include "src/gpu/geometry/GrStyledShape.h"
Chris Daltonc3b67eb2020-02-10 21:09:58 -070019#include "src/gpu/ops/GrFillRectOp.h"
Chris Dalton4e998532020-02-10 11:06:42 -070020#include "src/gpu/tessellate/GrDrawAtlasPathOp.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070021#include "src/gpu/tessellate/GrTessellatePathOp.h"
Chris Dalton1c62a7b2020-06-29 22:01:14 -060022#include "src/gpu/tessellate/GrTessellateStrokeOp.h"
Chris Daltonb96995d2020-06-04 16:44:29 -060023#include "src/gpu/tessellate/GrWangsFormula.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070024
Chris Dalton4e998532020-02-10 11:06:42 -070025constexpr static SkISize kAtlasInitialSize{512, 512};
26constexpr static int kMaxAtlasSize = 2048;
27
Chris Daltond2dc8dd2020-05-19 16:32:02 -060028// The atlas is only used for small-area paths, which means at least one dimension of every path is
29// guaranteed to be quite small. So if we transpose tall paths, then every path will have a small
30// height, which lends very well to efficient pow2 atlas packing.
31constexpr static auto kAtlasAlgorithm = GrDynamicAtlas::RectanizerAlgorithm::kPow2;
32
33// Ensure every path in the atlas falls in or below the 128px high rectanizer band.
34constexpr static int kMaxAtlasPathHeight = 128;
35
Chris Daltonb96995d2020-06-04 16:44:29 -060036GrTessellationPathRenderer::GrTessellationPathRenderer(const GrCaps& caps)
37 : fAtlas(GrColorType::kAlpha_8, GrDynamicAtlas::InternalMultisample::kYes,
38 kAtlasInitialSize, std::min(kMaxAtlasSize, caps.maxPreferredRenderTargetSize()),
39 caps, kAtlasAlgorithm) {
40 this->initAtlasFlags(*caps.shaderCaps());
41}
42
43void GrTessellationPathRenderer::initAtlasFlags(const GrShaderCaps& shaderCaps) {
44 fStencilAtlasFlags = OpFlags::kStencilOnly | OpFlags::kDisableHWTessellation;
45 fMaxAtlasPathWidth = fAtlas.maxAtlasSize() / 2;
46 // The atlas usually does better with hardware tessellation. If hardware tessellation is
47 // supported, we choose a max atlas path width that is guaranteed to never require more
48 // tessellation segments than are supported by the hardware.
49 if (!shaderCaps.tessellationSupport()) {
50 return;
51 }
52 // Since we limit the area of paths in the atlas to kMaxAtlasPathHeight^2, taller paths can't
53 // get very wide anyway. Find the tallest path whose width is limited by
54 // GrWangsFormula::worst_case_cubic() rather than the max area constraint, and use that for our
55 // max atlas path width.
56 //
57 // Solve the following equation for w:
58 //
59 // GrWangsFormula::worst_case_cubic(kLinearizationIntolerance, w, kMaxAtlasPathHeight^2 / w)
60 // == maxTessellationSegments
61 //
62 float k = GrWangsFormula::cubic_k(kLinearizationIntolerance);
63 float h = kMaxAtlasPathHeight;
64 float s = shaderCaps.maxTessellationSegments();
65 // Quadratic formula from Numerical Recipes in C:
66 //
67 // q = -1/2 [b + sign(b) sqrt(b*b - 4*a*c)]
68 // x1 = q/a
69 // x2 = c/q
70 //
71 // float a = 1; // 'a' is always 1 in our specific equation.
72 float b = -s*s*s*s / (4*k*k); // Always negative.
73 float c = h*h*h*h; // Always positive.
74 float det = b*b - 4*1*c;
75 if (det <= 0) {
76 // maxTessellationSegments is too small for any path whose area == kMaxAtlasPathHeight^2.
77 // (This is unexpected because the GL spec mandates a minimum of 64 segments.)
78 SkDebugf("WARNING: maxTessellationSegments seems too low. (%i)\n",
79 shaderCaps.maxTessellationSegments());
80 return;
81 }
82 float q = -.5f * (b - std::sqrt(det)); // Always positive.
83 // The two roots represent the width^2 and height^2 of the tallest rectangle that is limited by
84 // GrWangsFormula::worst_case_cubic().
85 float r0 = q; // Always positive.
86 float r1 = c/q; // Always positive.
87 float worstCaseWidth = std::sqrt(std::max(r0, r1));
88#ifdef SK_DEBUG
89 float worstCaseHeight = std::sqrt(std::min(r0, r1));
90 // Verify the above equation worked as expected. It should have found a width and height whose
91 // area == kMaxAtlasPathHeight^2.
92 SkASSERT(SkScalarNearlyEqual(worstCaseHeight * worstCaseWidth, h*h, 1));
93 // Verify GrWangsFormula::worst_case_cubic() still works as we expect. The worst case number of
94 // segments for this bounding box should be maxTessellationSegments.
95 SkASSERT(SkScalarNearlyEqual(GrWangsFormula::worst_case_cubic(
96 kLinearizationIntolerance, worstCaseWidth, worstCaseHeight), s, 1));
97#endif
98 fStencilAtlasFlags &= ~OpFlags::kDisableHWTessellation;
99 fMaxAtlasPathWidth = std::min(fMaxAtlasPathWidth, (int)worstCaseWidth);
Chris Dalton4e998532020-02-10 11:06:42 -0700100}
101
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600102GrPathRenderer::CanDrawPath GrTessellationPathRenderer::onCanDrawPath(
Chris Daltonb832ce62020-01-06 19:49:37 -0700103 const CanDrawPathArgs& args) const {
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600104 const GrStyledShape& shape = *args.fShape;
105 if (shape.inverseFilled() || shape.style().hasPathEffect() ||
Chris Dalton0f6bb8a2020-01-15 09:40:54 -0700106 args.fViewMatrix->hasPerspective()) {
Chris Daltonb832ce62020-01-06 19:49:37 -0700107 return CanDrawPath::kNo;
108 }
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600109
Chris Daltonb832ce62020-01-06 19:49:37 -0700110 if (GrAAType::kCoverage == args.fAAType) {
111 SkASSERT(1 == args.fProxy->numSamples());
112 if (!args.fProxy->canUseMixedSamples(*args.fCaps)) {
113 return CanDrawPath::kNo;
114 }
115 }
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600116
Chris Daltonb832ce62020-01-06 19:49:37 -0700117 SkPath path;
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600118 shape.asPath(&path);
Chris Daltonb832ce62020-01-06 19:49:37 -0700119 if (SkPathPriv::ConicWeightCnt(path)) {
120 return CanDrawPath::kNo;
121 }
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600122
123 if (!shape.style().isSimpleFill()) {
124 SkPMColor4f constantColor;
125 // These are only temporary restrictions while we bootstrap tessellated stroking. Every one
126 // of them will eventually go away.
127 if (shape.style().strokeRec().getStyle() == SkStrokeRec::kStrokeAndFill_Style ||
128 !args.fCaps->shaderCaps()->tessellationSupport() ||
129 GrAAType::kCoverage == args.fAAType || !args.fViewMatrix->isSimilarity() ||
130 !args.fPaint->isConstantBlendedColor(&constantColor) ||
131 args.fPaint->numCoverageFragmentProcessors()) {
132 return CanDrawPath::kNo;
133 }
134 }
135
Chris Daltonb832ce62020-01-06 19:49:37 -0700136 return CanDrawPath::kYes;
137}
138
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600139bool GrTessellationPathRenderer::onDrawPath(const DrawPathArgs& args) {
Chris Dalton4e998532020-02-10 11:06:42 -0700140 GrRenderTargetContext* renderTargetContext = args.fRenderTargetContext;
141 GrOpMemoryPool* pool = args.fContext->priv().opMemoryPool();
Chris Daltonb96995d2020-06-04 16:44:29 -0600142 const GrShaderCaps& shaderCaps = *args.fContext->priv().caps()->shaderCaps();
143
Chris Daltonb832ce62020-01-06 19:49:37 -0700144 SkPath path;
145 args.fShape->asPath(&path);
146
Chris Daltonb96995d2020-06-04 16:44:29 -0600147 SkRect devBounds;
148 args.fViewMatrix->mapRect(&devBounds, path.getBounds());
149
Chris Dalton4e998532020-02-10 11:06:42 -0700150 // See if the path is small and simple enough to atlas instead of drawing directly.
151 //
152 // NOTE: The atlas uses alpha8 coverage even for msaa render targets. We could theoretically
153 // render the sample mask to an integer texture, but such a scheme would probably require
154 // GL_EXT_post_depth_coverage, which appears to have low adoption.
155 SkIRect devIBounds;
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600156 SkIPoint16 locationInAtlas;
157 bool transposedInAtlas;
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600158 if (args.fShape->style().isSimpleFill() &&
159 this->tryAddPathToAtlas(*args.fContext->priv().caps(), *args.fViewMatrix, path, devBounds,
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600160 args.fAAType, &devIBounds, &locationInAtlas, &transposedInAtlas)) {
Chris Daltonb96995d2020-06-04 16:44:29 -0600161#ifdef SK_DEBUG
162 // If using hardware tessellation in the atlas, make sure the max number of segments is
163 // sufficient for this path. fMaxAtlasPathWidth should have been tuned for this to always be
164 // the case.
165 if (!(fStencilAtlasFlags & OpFlags::kDisableHWTessellation)) {
166 int worstCaseNumSegments = GrWangsFormula::worst_case_cubic(kLinearizationIntolerance,
167 devIBounds.width(),
168 devIBounds.height());
169 SkASSERT(worstCaseNumSegments <= shaderCaps.maxTessellationSegments());
170 }
171#endif
Chris Dalton4e998532020-02-10 11:06:42 -0700172 auto op = pool->allocate<GrDrawAtlasPathOp>(
173 renderTargetContext->numSamples(), sk_ref_sp(fAtlas.textureProxy()),
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600174 devIBounds, locationInAtlas, transposedInAtlas, *args.fViewMatrix,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400175 std::move(args.fPaint));
176 renderTargetContext->addDrawOp(args.fClip, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700177 return true;
178 }
Chris Daltonb832ce62020-01-06 19:49:37 -0700179
Chris Daltonb96995d2020-06-04 16:44:29 -0600180 // Find the worst-case log2 number of line segments that a curve in this path might need to be
181 // divided into.
182 int worstCaseResolveLevel = GrWangsFormula::worst_case_cubic_log2(kLinearizationIntolerance,
183 devBounds.width(),
184 devBounds.height());
185 if (worstCaseResolveLevel > kMaxResolveLevel) {
186 // The path is too large for our internal indirect draw shaders. Crop it to the viewport.
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600187 auto viewport = SkRect::MakeIWH(renderTargetContext->width(),
188 renderTargetContext->height());
189 float inflationRadius = 1;
190 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
191 if (stroke.getStyle() == SkStrokeRec::kHairline_Style) {
192 inflationRadius += SkStrokeRec::GetInflationRadius(stroke.getJoin(), stroke.getMiter(),
193 stroke.getCap(), 1);
194 } else if (stroke.getStyle() != SkStrokeRec::kFill_Style) {
195 inflationRadius += stroke.getInflationRadius() * args.fViewMatrix->getMaxScale();
196 }
197 viewport.outset(inflationRadius, inflationRadius);
198
199 SkPath viewportPath;
200 viewportPath.addRect(viewport);
Chris Daltonb96995d2020-06-04 16:44:29 -0600201 // Perform the crop in device space so it's a simple rect-path intersection.
202 path.transform(*args.fViewMatrix);
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600203 if (!Op(viewportPath, path, kIntersect_SkPathOp, &path)) {
Chris Daltonb96995d2020-06-04 16:44:29 -0600204 // The crop can fail if the PathOps encounter NaN or infinities. Return true
205 // because drawing nothing is acceptable behavior for FP overflow.
206 return true;
207 }
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600208
Chris Daltonb96995d2020-06-04 16:44:29 -0600209 // Transform the path back to its own local space.
210 SkMatrix inverse;
211 if (!args.fViewMatrix->invert(&inverse)) {
212 return true; // Singular view matrix. Nothing would have drawn anyway. Return true.
213 }
214 path.transform(inverse);
215 path.setIsVolatile(true);
216 args.fViewMatrix->mapRect(&devBounds, path.getBounds());
217 worstCaseResolveLevel = GrWangsFormula::worst_case_cubic_log2(kLinearizationIntolerance,
218 devBounds.width(),
219 devBounds.height());
220 // kMaxResolveLevel should be large enough to tessellate paths the size of any screen we
221 // might encounter.
222 SkASSERT(worstCaseResolveLevel <= kMaxResolveLevel);
223 }
224
Chris Dalton1c62a7b2020-06-29 22:01:14 -0600225 if (!args.fShape->style().isSimpleFill()) {
226 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
227 SkASSERT(stroke.getStyle() != SkStrokeRec::kStrokeAndFill_Style);
228 auto op = pool->allocate<GrTessellateStrokeOp>(*args.fViewMatrix, path, stroke,
229 std::move(args.fPaint), args.fAAType);
230 renderTargetContext->addDrawOp(args.fClip, std::move(op));
231 return true;
232 }
233
234 auto drawPathFlags = OpFlags::kNone;
Chris Daltonb96995d2020-06-04 16:44:29 -0600235 if ((1 << worstCaseResolveLevel) > shaderCaps.maxTessellationSegments()) {
236 // The path is too large for hardware tessellation; a curve in this bounding box could
237 // potentially require more segments than are supported by the hardware. Fall back on
238 // indirect draws.
239 drawPathFlags |= OpFlags::kDisableHWTessellation;
240 }
241
242 auto op = pool->allocate<GrTessellatePathOp>(*args.fViewMatrix, path, std::move(args.fPaint),
243 args.fAAType, drawPathFlags);
Michael Ludwig7c12e282020-05-29 09:54:07 -0400244 renderTargetContext->addDrawOp(args.fClip, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700245 return true;
246}
247
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600248bool GrTessellationPathRenderer::tryAddPathToAtlas(
Chris Daltonb96995d2020-06-04 16:44:29 -0600249 const GrCaps& caps, const SkMatrix& viewMatrix, const SkPath& path, const SkRect& devBounds,
250 GrAAType aaType, SkIRect* devIBounds, SkIPoint16* locationInAtlas,
251 bool* transposedInAtlas) {
Chris Dalton4e998532020-02-10 11:06:42 -0700252 if (!caps.multisampleDisableSupport() && GrAAType::kNone == aaType) {
253 return false;
254 }
255
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600256 // Atlas paths require their points to be transformed on the CPU and copied into an "uber path".
257 // Check if this path has too many points to justify this extra work.
258 if (path.countPoints() > 200) {
Chris Dalton4e998532020-02-10 11:06:42 -0700259 return false;
260 }
261
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600262 // Transpose tall paths in the atlas. Since we limit ourselves to small-area paths, this
263 // guarantees that every atlas entry has a small height, which lends very well to efficient pow2
264 // atlas packing.
Chris Daltonb96995d2020-06-04 16:44:29 -0600265 devBounds.roundOut(devIBounds);
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600266 int maxDimenstion = devIBounds->width();
267 int minDimension = devIBounds->height();
268 *transposedInAtlas = minDimension > maxDimenstion;
269 if (*transposedInAtlas) {
270 std::swap(minDimension, maxDimenstion);
271 }
272
273 // Check if the path is too large for an atlas. Since we use "minDimension" for height in the
274 // atlas, limiting to kMaxAtlasPathHeight^2 pixels guarantees height <= kMaxAtlasPathHeight.
275 if (maxDimenstion * minDimension > kMaxAtlasPathHeight * kMaxAtlasPathHeight ||
Chris Daltonb96995d2020-06-04 16:44:29 -0600276 maxDimenstion > fMaxAtlasPathWidth) {
Chris Dalton4e998532020-02-10 11:06:42 -0700277 return false;
278 }
279
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600280 if (!fAtlas.addRect(maxDimenstion, minDimension, locationInAtlas)) {
Chris Dalton4e998532020-02-10 11:06:42 -0700281 return false;
282 }
283
284 SkMatrix atlasMatrix = viewMatrix;
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600285 if (*transposedInAtlas) {
286 std::swap(atlasMatrix[0], atlasMatrix[3]);
287 std::swap(atlasMatrix[1], atlasMatrix[4]);
288 float tx=atlasMatrix.getTranslateX(), ty=atlasMatrix.getTranslateY();
289 atlasMatrix.setTranslateX(ty - devIBounds->y() + locationInAtlas->x());
290 atlasMatrix.setTranslateY(tx - devIBounds->x() + locationInAtlas->y());
291 } else {
292 atlasMatrix.postTranslate(locationInAtlas->x() - devIBounds->x(),
293 locationInAtlas->y() - devIBounds->y());
294 }
Chris Dalton4e998532020-02-10 11:06:42 -0700295
296 // Concatenate this path onto our uber path that matches its fill and AA types.
297 SkPath* uberPath = this->getAtlasUberPath(path.getFillType(), GrAAType::kNone != aaType);
Chris Daltond2dc8dd2020-05-19 16:32:02 -0600298 uberPath->moveTo(locationInAtlas->x(), locationInAtlas->y()); // Implicit moveTo(0,0).
Chris Dalton4e998532020-02-10 11:06:42 -0700299 uberPath->addPath(path, atlasMatrix);
Chris Daltonb832ce62020-01-06 19:49:37 -0700300 return true;
301}
302
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600303void GrTessellationPathRenderer::onStencilPath(const StencilPathArgs& args) {
Chris Daltonb832ce62020-01-06 19:49:37 -0700304 SkPath path;
305 args.fShape->asPath(&path);
306
307 GrAAType aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
308
Chris Daltonf9aea7f2020-01-21 11:19:26 -0700309 auto op = args.fContext->priv().opMemoryPool()->allocate<GrTessellatePathOp>(
Chris Daltonb96995d2020-06-04 16:44:29 -0600310 *args.fViewMatrix, path, GrPaint(), aaType, OpFlags::kStencilOnly);
Michael Ludwig7c12e282020-05-29 09:54:07 -0400311 args.fRenderTargetContext->addDrawOp(args.fClip, std::move(op));
Chris Daltonb832ce62020-01-06 19:49:37 -0700312}
Chris Dalton4e998532020-02-10 11:06:42 -0700313
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600314void GrTessellationPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP,
315 const uint32_t* opsTaskIDs, int numOpsTaskIDs) {
Chris Dalton4e998532020-02-10 11:06:42 -0700316 if (!fAtlas.drawBounds().isEmpty()) {
317 this->renderAtlas(onFlushRP);
318 fAtlas.reset(kAtlasInitialSize, *onFlushRP->caps());
319 }
320 for (SkPath& path : fAtlasUberPaths) {
321 path.reset();
322 }
323}
324
325constexpr static GrUserStencilSettings kTestStencil(
326 GrUserStencilSettings::StaticInit<
327 0x0000,
328 GrUserStencilTest::kNotEqual,
329 0xffff,
330 GrUserStencilOp::kKeep,
331 GrUserStencilOp::kKeep,
332 0xffff>());
333
334constexpr static GrUserStencilSettings kTestAndResetStencil(
335 GrUserStencilSettings::StaticInit<
336 0x0000,
337 GrUserStencilTest::kNotEqual,
338 0xffff,
339 GrUserStencilOp::kZero,
340 GrUserStencilOp::kKeep,
341 0xffff>());
342
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600343void GrTessellationPathRenderer::renderAtlas(GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton4e998532020-02-10 11:06:42 -0700344 auto rtc = fAtlas.instantiate(onFlushRP);
345 if (!rtc) {
346 return;
347 }
348
349 // Add ops to stencil the atlas paths.
350 for (auto antialias : {false, true}) {
351 for (auto fillType : {SkPathFillType::kWinding, SkPathFillType::kEvenOdd}) {
352 SkPath* uberPath = this->getAtlasUberPath(fillType, antialias);
353 if (uberPath->isEmpty()) {
354 continue;
355 }
356 uberPath->setFillType(fillType);
357 GrAAType aaType = (antialias) ? GrAAType::kMSAA : GrAAType::kNone;
358 auto op = onFlushRP->opMemoryPool()->allocate<GrTessellatePathOp>(
Chris Daltonb96995d2020-06-04 16:44:29 -0600359 SkMatrix::I(), *uberPath, GrPaint(), aaType, fStencilAtlasFlags);
Michael Ludwig7c12e282020-05-29 09:54:07 -0400360 rtc->addDrawOp(nullptr, std::move(op));
Chris Dalton4e998532020-02-10 11:06:42 -0700361 }
362 }
363
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700364 // Finally, draw a fullscreen rect to convert our stencilled paths into alpha coverage masks.
365 auto fillRectFlags = GrFillRectOp::InputFlags::kNone;
Chris Dalton4e998532020-02-10 11:06:42 -0700366
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700367 // This will be the final op in the renderTargetContext. So if Ganesh is planning to discard the
368 // stencil values anyway, then we might not actually need to reset the stencil values back to 0.
369 bool mustResetStencil = !onFlushRP->caps()->discardStencilValuesAfterRenderPass();
370
371 if (rtc->numSamples() <= 1) {
372 // We are mixed sampled. We need to enable conservative raster and ensure stencil values get
373 // reset in order to avoid artifacts along the diagonal of the atlas.
374 fillRectFlags |= GrFillRectOp::InputFlags::kConservativeRaster;
375 mustResetStencil = true;
376 }
377
378 SkRect coverRect = SkRect::MakeIWH(fAtlas.drawBounds().width(), fAtlas.drawBounds().height());
379 const GrUserStencilSettings* stencil;
380 if (mustResetStencil) {
381 // Outset the cover rect in case there are T-junctions in the path bounds.
382 coverRect.outset(1, 1);
383 stencil = &kTestAndResetStencil;
384 } else {
385 stencil = &kTestStencil;
386 }
387
388 GrQuad coverQuad(coverRect);
389 DrawQuad drawQuad{coverQuad, coverQuad, GrQuadAAFlags::kAll};
390
Chris Dalton4e998532020-02-10 11:06:42 -0700391 GrPaint paint;
392 paint.setColor4f(SK_PMColor4fWHITE);
Chris Daltonc3b67eb2020-02-10 21:09:58 -0700393
394 auto coverOp = GrFillRectOp::Make(rtc->surfPriv().getContext(), std::move(paint),
395 GrAAType::kMSAA, &drawQuad, stencil, fillRectFlags);
Michael Ludwig7c12e282020-05-29 09:54:07 -0400396 rtc->addDrawOp(nullptr, std::move(coverOp));
Chris Dalton4e998532020-02-10 11:06:42 -0700397
398 if (rtc->asSurfaceProxy()->requiresManualMSAAResolve()) {
399 onFlushRP->addTextureResolveTask(sk_ref_sp(rtc->asTextureProxy()),
400 GrSurfaceProxy::ResolveFlags::kMSAA);
401 }
402}