blob: 938fbbe8abf859469715058ee80f0934e8ef2709 [file] [log] [blame]
bsalomon@google.com30085192011-08-19 15:42:31 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ops/GrDefaultPathRenderer.h"
Robert Phillipsbe9aff22019-02-15 11:33:22 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkString.h"
11#include "include/core/SkStrokeRec.h"
12#include "src/core/SkGeometry.h"
Michael Ludwigfbe28592020-06-26 16:02:15 -040013#include "src/core/SkMatrixPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/core/SkTLazy.h"
15#include "src/core/SkTraceEvent.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040016#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrCaps.h"
Michael Ludwig58f569b2020-05-21 17:03:08 -040018#include "src/gpu/GrClip.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/GrDefaultGeoProcFactory.h"
20#include "src/gpu/GrDrawOpTest.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrOpFlushState.h"
Robert Phillips9028bac2020-03-10 16:19:27 -040022#include "src/gpu/GrProgramInfo.h"
Chris Daltoneb694b72020-03-16 09:25:50 -060023#include "src/gpu/GrSimpleMesh.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/GrStyle.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040025#include "src/gpu/geometry/GrPathUtils.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000026#include "src/gpu/geometry/GrStyledShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/ops/GrMeshDrawOp.h"
Robert Phillips55f681f2020-02-28 08:58:15 -050028#include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h"
joshualitt74417822015-08-07 11:42:16 -070029
Brian Salomon15b25092017-05-08 11:10:53 -040030GrDefaultPathRenderer::GrDefaultPathRenderer() {
bsalomon@google.com289533a2011-10-27 12:34:25 +000031}
32
bsalomon@google.com30085192011-08-19 15:42:31 +000033////////////////////////////////////////////////////////////////////////////////
34// Helpers for drawPath
35
bsalomon@google.com30085192011-08-19 15:42:31 +000036#define STENCIL_OFF 0 // Always disable stencil (even when needed)
37
Michael Ludwig2686d692020-04-17 20:21:37 +000038static inline bool single_pass_shape(const GrStyledShape& shape) {
bsalomon@google.com30085192011-08-19 15:42:31 +000039#if STENCIL_OFF
40 return true;
41#else
bsalomonee432412016-06-27 07:18:18 -070042 // Inverse fill is always two pass.
43 if (shape.inverseFilled()) {
44 return false;
45 }
46 // This path renderer only accepts simple fill paths or stroke paths that are either hairline
47 // or have a stroke width small enough to treat as hairline. Hairline paths are always single
48 // pass. Filled paths are single pass if they're convex.
49 if (shape.style().isSimpleFill()) {
bsalomon8acedde2016-06-24 10:42:16 -070050 return shape.knownToBeConvex();
bsalomon@google.com30085192011-08-19 15:42:31 +000051 }
bsalomonee432412016-06-27 07:18:18 -070052 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +000053#endif
54}
55
joshualitt9853cce2014-11-17 14:22:48 -080056GrPathRenderer::StencilSupport
Michael Ludwig2686d692020-04-17 20:21:37 +000057GrDefaultPathRenderer::onGetStencilSupport(const GrStyledShape& shape) const {
bsalomon8acedde2016-06-24 10:42:16 -070058 if (single_pass_shape(shape)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000059 return GrPathRenderer::kNoRestriction_StencilSupport;
60 } else {
61 return GrPathRenderer::kStencilOnly_StencilSupport;
62 }
bsalomon@google.com30085192011-08-19 15:42:31 +000063}
64
Brian Salomonee3e0ba2017-07-13 16:40:46 -040065namespace {
66
Brian Osman49b7b6f2017-06-20 14:43:58 -040067class PathGeoBuilder {
68public:
Robert Phillips9028bac2020-03-10 16:19:27 -040069 PathGeoBuilder(GrPrimitiveType primitiveType,
70 GrMeshDrawOp::Target* target,
Chris Daltoneb694b72020-03-16 09:25:50 -060071 SkTDArray<GrSimpleMesh*>* meshes)
Brian Salomon7eae3e02018-08-07 14:02:38 +000072 : fPrimitiveType(primitiveType)
Brian Osman49b7b6f2017-06-20 14:43:58 -040073 , fTarget(target)
74 , fVertexStride(sizeof(SkPoint))
Brian Osman49b7b6f2017-06-20 14:43:58 -040075 , fFirstIndex(0)
76 , fIndicesInChunk(0)
Robert Phillips9028bac2020-03-10 16:19:27 -040077 , fIndices(nullptr)
78 , fMeshes(meshes) {
Brian Osman49b7b6f2017-06-20 14:43:58 -040079 this->allocNewBuffers();
Brian Osmaneb86b702017-06-07 11:38:31 -040080 }
81
Brian Osman49b7b6f2017-06-20 14:43:58 -040082 ~PathGeoBuilder() {
Robert Phillips9028bac2020-03-10 16:19:27 -040083 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -040084 }
85
86 /**
87 * Path verbs
88 */
89 void moveTo(const SkPoint& p) {
Greg Daniel30b355a2021-02-03 16:22:49 +000090 needSpace(1);
Brian Osman49b7b6f2017-06-20 14:43:58 -040091
92 fSubpathIndexStart = this->currentIndex();
93 *(fCurVert++) = p;
94 }
95
Greg Daniel30b355a2021-02-03 16:22:49 +000096 void addLine(const SkPoint& p) {
97 needSpace(1, this->indexScale());
Brian Osman49b7b6f2017-06-20 14:43:58 -040098
Brian Salomon763abf02018-05-01 18:49:38 +000099 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400100 uint16_t prevIdx = this->currentIndex() - 1;
Greg Daniel30b355a2021-02-03 16:22:49 +0000101 appendCountourEdgeIndices(prevIdx);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400102 }
Greg Daniel30b355a2021-02-03 16:22:49 +0000103 *(fCurVert++) = p;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400104 }
105
106 void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
107 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel30b355a2021-02-03 16:22:49 +0000108 GrPathUtils::kMaxPointsPerCurve * this->indexScale());
Brian Osman49b7b6f2017-06-20 14:43:58 -0400109
110 // First pt of quad is the pt we ended on in previous step
111 uint16_t firstQPtIdx = this->currentIndex() - 1;
112 uint16_t numPts = (uint16_t)GrPathUtils::generateQuadraticPoints(
113 pts[0], pts[1], pts[2], srcSpaceTolSqd, &fCurVert,
114 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000115 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400116 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel30b355a2021-02-03 16:22:49 +0000117 appendCountourEdgeIndices(firstQPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400118 }
egdanielaf18a092015-01-05 10:22:28 -0800119 }
120 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400121
122 void addConic(SkScalar weight, const SkPoint pts[], SkScalar srcSpaceTolSqd,
123 SkScalar srcSpaceTol) {
124 SkAutoConicToQuads converter;
125 const SkPoint* quadPts = converter.computeQuads(pts, weight, srcSpaceTol);
126 for (int i = 0; i < converter.countQuads(); ++i) {
127 this->addQuad(quadPts + i * 2, srcSpaceTolSqd, srcSpaceTol);
128 }
129 }
130
131 void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
132 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel30b355a2021-02-03 16:22:49 +0000133 GrPathUtils::kMaxPointsPerCurve * this->indexScale());
Brian Osman49b7b6f2017-06-20 14:43:58 -0400134
135 // First pt of cubic is the pt we ended on in previous step
136 uint16_t firstCPtIdx = this->currentIndex() - 1;
137 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
138 pts[0], pts[1], pts[2], pts[3], srcSpaceTolSqd, &fCurVert,
139 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000140 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400141 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel30b355a2021-02-03 16:22:49 +0000142 appendCountourEdgeIndices(firstCPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400143 }
144 }
145 }
146
147 void addPath(const SkPath& path, SkScalar srcSpaceTol) {
148 SkScalar srcSpaceTolSqd = srcSpaceTol * srcSpaceTol;
149
150 SkPath::Iter iter(path, false);
151 SkPoint pts[4];
152
153 bool done = false;
154 while (!done) {
Mike Reedba7e9a62019-08-16 13:30:34 -0400155 SkPath::Verb verb = iter.next(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400156 switch (verb) {
157 case SkPath::kMove_Verb:
158 this->moveTo(pts[0]);
159 break;
160 case SkPath::kLine_Verb:
Greg Daniel30b355a2021-02-03 16:22:49 +0000161 this->addLine(pts[1]);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400162 break;
163 case SkPath::kConic_Verb:
164 this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol);
165 break;
166 case SkPath::kQuad_Verb:
167 this->addQuad(pts, srcSpaceTolSqd, srcSpaceTol);
168 break;
169 case SkPath::kCubic_Verb:
170 this->addCubic(pts, srcSpaceTolSqd, srcSpaceTol);
171 break;
172 case SkPath::kClose_Verb:
173 break;
174 case SkPath::kDone_Verb:
175 done = true;
176 }
177 }
178 }
179
180 static bool PathHasMultipleSubpaths(const SkPath& path) {
181 bool first = true;
182
183 SkPath::Iter iter(path, false);
184 SkPath::Verb verb;
185
186 SkPoint pts[4];
Mike Reedba7e9a62019-08-16 13:30:34 -0400187 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400188 if (SkPath::kMove_Verb == verb && !first) {
189 return true;
190 }
191 first = false;
192 }
193 return false;
194 }
195
196private:
197 /**
198 * Derived properties
199 * TODO: Cache some of these for better performance, rather than re-computing?
200 */
Brian Salomon763abf02018-05-01 18:49:38 +0000201 bool isIndexed() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000202 return GrPrimitiveType::kLines == fPrimitiveType ||
203 GrPrimitiveType::kTriangles == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400204 }
205 bool isHairline() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000206 return GrPrimitiveType::kLines == fPrimitiveType ||
207 GrPrimitiveType::kLineStrip == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400208 }
209 int indexScale() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000210 switch (fPrimitiveType) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400211 case GrPrimitiveType::kLines:
212 return 2;
213 case GrPrimitiveType::kTriangles:
214 return 3;
215 default:
216 return 0;
217 }
218 }
219
220 uint16_t currentIndex() const { return fCurVert - fVertices; }
221
Brian Osman49b7b6f2017-06-20 14:43:58 -0400222 // Allocate vertex and (possibly) index buffers
223 void allocNewBuffers() {
224 // Ensure that we always get enough verts for a worst-case quad/cubic, plus leftover points
225 // from previous mesh piece (up to two verts to continue fanning). If we can't get that
226 // many, ask for a much larger number. This needs to be fairly big to handle quads/cubics,
227 // which have a worst-case of 1k points.
228 static const int kMinVerticesPerChunk = GrPathUtils::kMaxPointsPerCurve + 2;
229 static const int kFallbackVerticesPerChunk = 16384;
230
231 fVertices = static_cast<SkPoint*>(fTarget->makeVertexSpaceAtLeast(fVertexStride,
232 kMinVerticesPerChunk,
233 kFallbackVerticesPerChunk,
234 &fVertexBuffer,
235 &fFirstVertex,
236 &fVerticesInChunk));
237
Brian Salomon763abf02018-05-01 18:49:38 +0000238 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400239 // Similar to above: Ensure we get enough indices for one worst-case quad/cubic.
240 // No extra indices are needed for stitching, though. If we can't get that many, ask
241 // for enough to match our large vertex request.
242 const int kMinIndicesPerChunk = GrPathUtils::kMaxPointsPerCurve * this->indexScale();
243 const int kFallbackIndicesPerChunk = kFallbackVerticesPerChunk * this->indexScale();
244
245 fIndices = fTarget->makeIndexSpaceAtLeast(kMinIndicesPerChunk, kFallbackIndicesPerChunk,
246 &fIndexBuffer, &fFirstIndex,
247 &fIndicesInChunk);
248 }
Brian Osman3902d402017-06-20 15:36:31 -0400249
250 fCurVert = fVertices;
251 fCurIdx = fIndices;
252 fSubpathIndexStart = 0;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400253 }
254
255 void appendCountourEdgeIndices(uint16_t edgeV0Idx) {
256 // When drawing lines we're appending line segments along the countour. When applying the
257 // other fill rules we're drawing triangle fans around the start of the current (sub)path.
258 if (!this->isHairline()) {
259 *(fCurIdx++) = fSubpathIndexStart;
260 }
261 *(fCurIdx++) = edgeV0Idx;
262 *(fCurIdx++) = edgeV0Idx + 1;
263 }
264
265 // Emits a single draw with all accumulated vertex/index data
Robert Phillips9028bac2020-03-10 16:19:27 -0400266 void createMeshAndPutBackReserve() {
Brian Osman3902d402017-06-20 15:36:31 -0400267 int vertexCount = fCurVert - fVertices;
268 int indexCount = fCurIdx - fIndices;
269 SkASSERT(vertexCount <= fVerticesInChunk);
270 SkASSERT(indexCount <= fIndicesInChunk);
271
Chris Daltoneb694b72020-03-16 09:25:50 -0600272 GrSimpleMesh* mesh = nullptr;
Brian Salomon763abf02018-05-01 18:49:38 +0000273 if (this->isIndexed() ? SkToBool(indexCount) : SkToBool(vertexCount)) {
Robert Phillips9028bac2020-03-10 16:19:27 -0400274 mesh = fTarget->allocMesh();
Brian Salomon763abf02018-05-01 18:49:38 +0000275 if (!this->isIndexed()) {
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600276 mesh->set(std::move(fVertexBuffer), vertexCount, fFirstVertex);
Brian Salomon763abf02018-05-01 18:49:38 +0000277 } else {
Brian Salomon12d22642019-01-29 14:38:50 -0500278 mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0,
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600279 vertexCount - 1, GrPrimitiveRestart::kNo, std::move(fVertexBuffer),
280 fFirstVertex);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400281 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400282 }
Brian Osman3902d402017-06-20 15:36:31 -0400283
284 fTarget->putBackIndices((size_t)(fIndicesInChunk - indexCount));
285 fTarget->putBackVertices((size_t)(fVerticesInChunk - vertexCount), fVertexStride);
Robert Phillips9028bac2020-03-10 16:19:27 -0400286
287 if (mesh) {
288 fMeshes->push_back(mesh);
289 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400290 }
291
Greg Daniel30b355a2021-02-03 16:22:49 +0000292 void needSpace(int vertsNeeded, int indicesNeeded = 0) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400293 if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk ||
294 fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) {
295 // We are about to run out of space (possibly)
296
297 // To maintain continuity, we need to remember one or two points from the current mesh.
298 // Lines only need the last point, fills need the first point from the current contour.
299 // We always grab both here, and append the ones we need at the end of this process.
Greg Daniel30b355a2021-02-03 16:22:49 +0000300 SkPoint lastPt = *(fCurVert - 1);
Brian Osman3902d402017-06-20 15:36:31 -0400301 SkASSERT(fSubpathIndexStart < fVerticesInChunk);
Greg Daniel30b355a2021-02-03 16:22:49 +0000302 SkPoint subpathStartPt = fVertices[fSubpathIndexStart];
Brian Osman49b7b6f2017-06-20 14:43:58 -0400303
Brian Osman3902d402017-06-20 15:36:31 -0400304 // Draw the mesh we've accumulated, and put back any unused space
Robert Phillips9028bac2020-03-10 16:19:27 -0400305 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -0400306
Brian Osman3902d402017-06-20 15:36:31 -0400307 // Get new buffers
Brian Osman49b7b6f2017-06-20 14:43:58 -0400308 this->allocNewBuffers();
309
Greg Daniel30b355a2021-02-03 16:22:49 +0000310 // Append copies of the points we saved so the two meshes will weld properly
311 if (!this->isHairline()) {
312 *(fCurVert++) = subpathStartPt;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400313 }
Greg Daniel30b355a2021-02-03 16:22:49 +0000314 *(fCurVert++) = lastPt;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400315 }
316 }
317
Brian Salomon7eae3e02018-08-07 14:02:38 +0000318 GrPrimitiveType fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400319 GrMeshDrawOp::Target* fTarget;
320 size_t fVertexStride;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400321
Brian Salomon12d22642019-01-29 14:38:50 -0500322 sk_sp<const GrBuffer> fVertexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400323 int fFirstVertex;
324 int fVerticesInChunk;
325 SkPoint* fVertices;
326 SkPoint* fCurVert;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400327
Brian Salomon12d22642019-01-29 14:38:50 -0500328 sk_sp<const GrBuffer> fIndexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400329 int fFirstIndex;
330 int fIndicesInChunk;
331 uint16_t* fIndices;
332 uint16_t* fCurIdx;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400333 uint16_t fSubpathIndexStart;
Robert Phillips9028bac2020-03-10 16:19:27 -0400334
Chris Daltoneb694b72020-03-16 09:25:50 -0600335 SkTDArray<GrSimpleMesh*>* fMeshes;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400336};
egdanielaf18a092015-01-05 10:22:28 -0800337
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400338class DefaultPathOp final : public GrMeshDrawOp {
339private:
340 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
341
joshualitt332c7292015-02-23 08:44:31 -0800342public:
Brian Salomon25a88092016-12-01 09:36:50 -0500343 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -0700344
Herb Derbyc76d4092020-10-07 16:46:15 -0400345 static GrOp::Owner Make(GrRecordingContext* context,
346 GrPaint&& paint,
347 const SkPath& path,
348 SkScalar tolerance,
349 uint8_t coverage,
350 const SkMatrix& viewMatrix,
351 bool isHairline,
352 GrAAType aaType,
353 const SkRect& devBounds,
354 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400355 return Helper::FactoryHelper<DefaultPathOp>(context, std::move(paint), path, tolerance,
356 coverage, viewMatrix, isHairline, aaType,
357 devBounds, stencilSettings);
bsalomon@google.com30085192011-08-19 15:42:31 +0000358 }
359
Brian Salomon780dad12016-12-15 18:08:40 -0500360 const char* name() const override { return "DefaultPathOp"; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000361
Chris Dalton1706cbf2019-05-21 19:35:29 -0600362 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400363 if (fProgramInfo) {
Chris Daltonbe457422020-03-16 18:05:03 -0600364 fProgramInfo->visitFPProxies(func);
Robert Phillips9028bac2020-03-10 16:19:27 -0400365 } else {
366 fHelper.visitProxies(func);
367 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400368 }
369
Herb Derbyc76d4092020-10-07 16:46:15 -0400370 DefaultPathOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkPath& path,
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400371 SkScalar tolerance, uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline,
372 GrAAType aaType, const SkRect& devBounds,
373 const GrUserStencilSettings* stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500374 : INHERITED(ClassID())
Herb Derbyc76d4092020-10-07 16:46:15 -0400375 , fHelper(processorSet, aaType, stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500376 , fColor(color)
377 , fCoverage(coverage)
378 , fViewMatrix(viewMatrix)
379 , fIsHairline(isHairline) {
380 fPaths.emplace_back(PathData{path, tolerance});
joshualitt332c7292015-02-23 08:44:31 -0800381
Greg Daniel5faf4742019-10-01 15:14:44 -0400382 HasAABloat aaBloat = (aaType == GrAAType::kNone) ? HasAABloat ::kNo : HasAABloat::kYes;
383 this->setBounds(devBounds, aaBloat,
384 isHairline ? IsHairline::kYes : IsHairline::kNo);
Brian Salomon780dad12016-12-15 18:08:40 -0500385 }
386
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400387 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
388
Chris Dalton6ce447a2019-06-23 18:07:38 -0600389 GrProcessorSet::Analysis finalize(
390 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
391 GrClampType clampType) override {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400392 GrProcessorAnalysisCoverage gpCoverage =
393 this->coverage() == 0xFF ? GrProcessorAnalysisCoverage::kNone
394 : GrProcessorAnalysisCoverage::kSingleChannel;
Brian Osman8fa7ab42019-03-18 10:22:42 -0400395 // This Op uses uniform (not vertex) color, so doesn't need to track wide color.
396 return fHelper.finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600397 caps, clip, hasMixedSampledCoverage, clampType, gpCoverage, &fColor, nullptr);
Brian Salomon92aee3d2016-12-21 09:20:25 -0500398 }
399
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400400private:
Robert Phillips9028bac2020-03-10 16:19:27 -0400401 GrPrimitiveType primType() const {
402 if (this->isHairline()) {
403 int instanceCount = fPaths.count();
404
405 // We avoid indices when we have a single hairline contour.
406 bool isIndexed = instanceCount > 1 ||
407 PathGeoBuilder::PathHasMultipleSubpaths(fPaths[0].fPath);
408
409 return isIndexed ? GrPrimitiveType::kLines : GrPrimitiveType::kLineStrip;
410 }
411
412 return GrPrimitiveType::kTriangles;
413 }
414
Robert Phillips2669a7b2020-03-12 12:07:19 -0400415 GrProgramInfo* programInfo() override { return fProgramInfo; }
416
Robert Phillips4133dc42020-03-11 15:55:55 -0400417 void onCreateProgramInfo(const GrCaps* caps,
418 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500419 const GrSurfaceProxyView& writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400420 GrAppliedClip&& appliedClip,
Greg Danield358cbe2020-09-11 09:33:54 -0400421 const GrXferProcessor::DstProxyView& dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500422 GrXferBarrierFlags renderPassXferBarriers,
423 GrLoadOp colorLoadOp) override {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500424 GrGeometryProcessor* gp;
joshualittdf0c5572015-08-03 11:35:28 -0700425 {
426 using namespace GrDefaultGeoProcFactory;
427 Color color(this->color());
428 Coverage coverage(this->coverage());
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400429 LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type
430 : LocalCoords::kUnused_Type);
Robert Phillips9028bac2020-03-10 16:19:27 -0400431 gp = GrDefaultGeoProcFactory::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400432 color,
433 coverage,
434 localCoords,
435 this->viewMatrix());
joshualittdf0c5572015-08-03 11:35:28 -0700436 }
joshualitt332c7292015-02-23 08:44:31 -0800437
Brian Osmanf04fb3c2018-11-12 15:34:00 -0500438 SkASSERT(gp->vertexStride() == sizeof(SkPoint));
joshualitt332c7292015-02-23 08:44:31 -0800439
Brian Salomon8afde5f2020-04-01 16:22:00 -0400440 fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400441 std::move(appliedClip),
Greg Danield358cbe2020-09-11 09:33:54 -0400442 dstProxyView, gp, this->primType(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500443 renderPassXferBarriers, colorLoadOp);
Brian Salomon763abf02018-05-01 18:49:38 +0000444
Robert Phillips9028bac2020-03-10 16:19:27 -0400445 }
Brian Osman7f95dfc2017-06-09 14:43:49 +0000446
Robert Phillips9028bac2020-03-10 16:19:27 -0400447 void onPrepareDraws(Target* target) override {
448 PathGeoBuilder pathGeoBuilder(this->primType(), target, &fMeshes);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000449
450 // fill buffers
Robert Phillips9028bac2020-03-10 16:19:27 -0400451 for (int i = 0; i < fPaths.count(); i++) {
Brian Salomon763abf02018-05-01 18:49:38 +0000452 const PathData& args = fPaths[i];
453 pathGeoBuilder.addPath(args.fPath, args.fTolerance);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000454 }
joshualitt332c7292015-02-23 08:44:31 -0800455 }
456
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700457 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400458 if (!fProgramInfo) {
Robert Phillips4133dc42020-03-11 15:55:55 -0400459 this->createProgramInfo(flushState);
Robert Phillips9028bac2020-03-10 16:19:27 -0400460 }
Robert Phillips3968fcb2019-12-05 16:40:31 -0500461
Robert Phillips9028bac2020-03-10 16:19:27 -0400462 if (!fProgramInfo || !fMeshes.count()) {
463 return;
464 }
465
Chris Dalton765ed362020-03-16 17:34:44 -0600466 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
467 flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline());
Robert Phillips9028bac2020-03-10 16:19:27 -0400468 for (int i = 0; i < fMeshes.count(); ++i) {
Chris Dalton765ed362020-03-16 17:34:44 -0600469 flushState->drawMesh(*fMeshes[i]);
Robert Phillips9028bac2020-03-10 16:19:27 -0400470 }
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700471 }
472
Herb Derbye25c3002020-10-27 15:57:27 -0400473 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500474 DefaultPathOp* that = t->cast<DefaultPathOp>();
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400475 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000476 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700477 }
478
joshualitt332c7292015-02-23 08:44:31 -0800479 if (this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000480 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800481 }
482
483 if (this->coverage() != that->coverage()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000484 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800485 }
486
Mike Reed2c383152019-12-18 16:47:47 -0500487 if (!SkMatrixPriv::CheapEqual(this->viewMatrix(), that->viewMatrix())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000488 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800489 }
490
491 if (this->isHairline() != that->isHairline()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000492 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800493 }
494
Brian Salomon780dad12016-12-15 18:08:40 -0500495 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000496 return CombineResult::kMerged;
joshualitt332c7292015-02-23 08:44:31 -0800497 }
498
John Stilesaf366522020-08-13 09:57:34 -0400499#if GR_TEST_UTILS
500 SkString onDumpInfo() const override {
501 SkString string = SkStringPrintf("Color: 0x%08x Count: %d\n",
502 fColor.toBytes_RGBA(), fPaths.count());
503 for (const auto& path : fPaths) {
504 string.appendf("Tolerance: %.2f\n", path.fTolerance);
505 }
506 string += fHelper.dumpInfo();
507 return string;
508 }
509#endif
510
Brian Osmancf860852018-10-31 14:04:39 -0400511 const SkPMColor4f& color() const { return fColor; }
Brian Salomon780dad12016-12-15 18:08:40 -0500512 uint8_t coverage() const { return fCoverage; }
Brian Salomon780dad12016-12-15 18:08:40 -0500513 const SkMatrix& viewMatrix() const { return fViewMatrix; }
514 bool isHairline() const { return fIsHairline; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000515
Brian Salomon780dad12016-12-15 18:08:40 -0500516 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700517 SkPath fPath;
518 SkScalar fTolerance;
519 };
520
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400521 SkSTArray<1, PathData, true> fPaths;
522 Helper fHelper;
Brian Osmancf860852018-10-31 14:04:39 -0400523 SkPMColor4f fColor;
Brian Salomon780dad12016-12-15 18:08:40 -0500524 uint8_t fCoverage;
525 SkMatrix fViewMatrix;
Brian Salomon780dad12016-12-15 18:08:40 -0500526 bool fIsHairline;
reed1b55a962015-09-17 20:16:13 -0700527
Chris Daltoneb694b72020-03-16 09:25:50 -0600528 SkTDArray<GrSimpleMesh*> fMeshes;
529 GrProgramInfo* fProgramInfo = nullptr;
Robert Phillips9028bac2020-03-10 16:19:27 -0400530
John Stiles7571f9e2020-09-02 22:42:33 -0400531 using INHERITED = GrMeshDrawOp;
joshualitt332c7292015-02-23 08:44:31 -0800532};
bsalomon@google.com30085192011-08-19 15:42:31 +0000533
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400534} // anonymous namespace
535
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500536bool GrDefaultPathRenderer::internalDrawPath(GrSurfaceDrawContext* surfaceDrawContext,
Brian Salomon82f44312017-01-11 13:42:54 -0500537 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500538 GrAAType aaType,
robertphillipsd2b6d642016-07-21 08:55:08 -0700539 const GrUserStencilSettings& userStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400540 const GrClip* clip,
joshualitt8059eb92014-12-29 15:10:07 -0800541 const SkMatrix& viewMatrix,
Michael Ludwig2686d692020-04-17 20:21:37 +0000542 const GrStyledShape& shape,
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000543 bool stencilOnly) {
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500544 auto context = surfaceDrawContext->recordingContext();
Robert Phillips7c525e62018-06-12 10:11:12 -0400545
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500546 SkASSERT(GrAAType::kCoverage != aaType);
bsalomon8acedde2016-06-24 10:42:16 -0700547 SkPath path;
548 shape.asPath(&path);
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000549
550 SkScalar hairlineCoverage;
joshualitt2e3b3e32014-12-09 13:31:14 -0800551 uint8_t newCoverage = 0xff;
bsalomon6663acf2016-05-10 09:14:17 -0700552 bool isHairline = false;
bsalomon8acedde2016-06-24 10:42:16 -0700553 if (IsStrokeHairlineOrEquivalent(shape.style(), viewMatrix, &hairlineCoverage)) {
joshualitt2e3b3e32014-12-09 13:31:14 -0800554 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
bsalomon6663acf2016-05-10 09:14:17 -0700555 isHairline = true;
556 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700557 SkASSERT(shape.style().isSimpleFill());
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000558 }
559
cdalton93a379b2016-05-11 13:58:08 -0700560 int passCount = 0;
Brian Salomonf0861672017-05-08 11:10:10 -0400561 const GrUserStencilSettings* passes[2];
cdalton93a379b2016-05-11 13:58:08 -0700562 bool reverse = false;
563 bool lastPassIsBounds;
bsalomon@google.com30085192011-08-19 15:42:31 +0000564
joshualitt332c7292015-02-23 08:44:31 -0800565 if (isHairline) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000566 passCount = 1;
567 if (stencilOnly) {
568 passes[0] = &gDirectToStencil;
569 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700570 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000571 }
572 lastPassIsBounds = false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000573 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700574 if (single_pass_shape(shape)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000575 passCount = 1;
576 if (stencilOnly) {
577 passes[0] = &gDirectToStencil;
578 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700579 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000580 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000581 lastPassIsBounds = false;
582 } else {
Mike Reedcf0e3c62019-12-03 16:26:15 -0500583 switch (path.getFillType()) {
Mike Reed7d34dc72019-11-26 12:17:17 -0500584 case SkPathFillType::kInverseEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000585 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400586 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500587 case SkPathFillType::kEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000588 passes[0] = &gEOStencilPass;
589 if (stencilOnly) {
590 passCount = 1;
591 lastPassIsBounds = false;
592 } else {
593 passCount = 2;
594 lastPassIsBounds = true;
595 if (reverse) {
596 passes[1] = &gInvEOColorPass;
597 } else {
598 passes[1] = &gEOColorPass;
599 }
600 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000601 break;
602
Mike Reed7d34dc72019-11-26 12:17:17 -0500603 case SkPathFillType::kInverseWinding:
bsalomon@google.com30085192011-08-19 15:42:31 +0000604 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400605 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500606 case SkPathFillType::kWinding:
Brian Salomon15b25092017-05-08 11:10:53 -0400607 passes[0] = &gWindStencilPass;
Brian Salomonf0861672017-05-08 11:10:10 -0400608 passCount = 2;
bsalomon@google.com30085192011-08-19 15:42:31 +0000609 if (stencilOnly) {
610 lastPassIsBounds = false;
611 --passCount;
612 } else {
613 lastPassIsBounds = true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000614 if (reverse) {
615 passes[passCount-1] = &gInvWindColorPass;
616 } else {
617 passes[passCount-1] = &gWindColorPass;
618 }
619 }
620 break;
621 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000622 SkDEBUGFAIL("Unknown path fFill!");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000623 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000624 }
625 }
626 }
627
senorblanco2b4bb072015-04-22 13:45:18 -0700628 SkScalar tol = GrPathUtils::kDefaultTolerance;
joshualitt332c7292015-02-23 08:44:31 -0800629 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds());
630
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000631 SkRect devBounds;
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500632 GetPathDevBounds(path, surfaceDrawContext->asRenderTargetProxy()->backingStoreDimensions(),
Robert Phillipsec325342017-10-30 18:02:48 +0000633 viewMatrix, &devBounds);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000634
bsalomon@google.com30085192011-08-19 15:42:31 +0000635 for (int p = 0; p < passCount; ++p) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000636 if (lastPassIsBounds && (p == passCount-1)) {
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000637 SkRect bounds;
joshualittd27f73e2014-12-29 07:43:36 -0800638 SkMatrix localMatrix = SkMatrix::I();
bsalomon@google.com30085192011-08-19 15:42:31 +0000639 if (reverse) {
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000640 // draw over the dev bounds (which will be the whole dst surface for inv fill).
641 bounds = devBounds;
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000642 SkMatrix vmi;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000643 // mapRect through persp matrix may not be correct
joshualitt8059eb92014-12-29 15:10:07 -0800644 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000645 vmi.mapRect(&bounds);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000646 } else {
joshualittd27f73e2014-12-29 07:43:36 -0800647 if (!viewMatrix.invert(&localMatrix)) {
648 return false;
649 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000650 }
651 } else {
robertphillips@google.come79f3202014-02-11 16:30:21 +0000652 bounds = path.getBounds();
bsalomon@google.com30085192011-08-19 15:42:31 +0000653 }
joshualitt8059eb92014-12-29 15:10:07 -0800654 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() :
655 viewMatrix;
Michael Ludwig72ab3462018-12-10 12:43:36 -0500656 // This is a non-coverage aa rect op since we assert aaType != kCoverage at the start
Mike Klein16885072018-12-11 09:54:31 -0500657 assert_alive(paint);
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500658 surfaceDrawContext->stencilRect(clip, passes[p], std::move(paint),
659 GrAA(aaType == GrAAType::kMSAA), viewM, bounds,
660 &localMatrix);
robertphillips976f5f02016-06-03 10:59:20 -0700661 } else {
Brian Salomond4652ca2017-01-13 12:11:36 -0500662 bool stencilPass = stencilOnly || passCount > 1;
Herb Derbyc76d4092020-10-07 16:46:15 -0400663 GrOp::Owner op;
Brian Salomond4652ca2017-01-13 12:11:36 -0500664 if (stencilPass) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400665 GrPaint stencilPaint;
666 stencilPaint.setXPFactory(GrDisableColorXPFactory::Get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400667 op = DefaultPathOp::Make(context, std::move(stencilPaint), path, srcSpaceTol,
668 newCoverage, viewMatrix, isHairline, aaType, devBounds,
669 passes[p]);
Brian Salomonb74ef032017-08-10 12:46:01 -0400670 } else {
Mike Klein16885072018-12-11 09:54:31 -0500671 assert_alive(paint);
Robert Phillips7c525e62018-06-12 10:11:12 -0400672 op = DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, newCoverage,
Brian Salomonb74ef032017-08-10 12:46:01 -0400673 viewMatrix, isHairline, aaType, devBounds, passes[p]);
Brian Salomond4652ca2017-01-13 12:11:36 -0500674 }
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500675 surfaceDrawContext->addDrawOp(clip, std::move(op));
bsalomon@google.com30085192011-08-19 15:42:31 +0000676 }
677 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000678 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000679}
680
Chris Dalton5ed44232017-09-07 13:22:46 -0600681GrPathRenderer::CanDrawPath
682GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Chris Dalton09e56892019-03-13 00:22:01 -0600683 bool isHairline = IsStrokeHairlineOrEquivalent(
684 args.fShape->style(), *args.fViewMatrix, nullptr);
Eric Karl5c779752017-05-08 12:02:07 -0700685 // If we aren't a single_pass_shape or hairline, we require stencil buffers.
Greg Danielbe7fc462019-01-03 16:40:42 -0500686 if (!(single_pass_shape(*args.fShape) || isHairline) &&
687 (args.fCaps->avoidStencilBuffers() || args.fTargetIsWrappedVkSecondaryCB)) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600688 return CanDrawPath::kNo;
Eric Karl5c779752017-05-08 12:02:07 -0700689 }
Chris Dalton09e56892019-03-13 00:22:01 -0600690 // If antialiasing is required, we only support MSAA.
Chris Dalton6ce447a2019-06-23 18:07:38 -0600691 if (GrAAType::kNone != args.fAAType && GrAAType::kMSAA != args.fAAType) {
Chris Dalton09e56892019-03-13 00:22:01 -0600692 return CanDrawPath::kNo;
693 }
694 // This can draw any path with any simple fill style.
695 if (!args.fShape->style().isSimpleFill() && !isHairline) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600696 return CanDrawPath::kNo;
697 }
698 // This is the fallback renderer for when a path is too complicated for the others to draw.
699 return CanDrawPath::kAsBackup;
bsalomon@google.com30085192011-08-19 15:42:31 +0000700}
701
bsalomon0aff2fa2015-07-31 06:48:27 -0700702bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400703 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700704 "GrDefaultPathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -0600705 GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone;
Chris Dalton09e56892019-03-13 00:22:01 -0600706
707 return this->internalDrawPath(
708 args.fRenderTargetContext, std::move(args.fPaint), aaType, *args.fUserStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400709 args.fClip, *args.fViewMatrix, *args.fShape, false);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000710}
711
bsalomon0aff2fa2015-07-31 06:48:27 -0700712void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400713 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700714 "GrDefaultPathRenderer::onStencilPath");
bsalomon8acedde2016-06-24 10:42:16 -0700715 SkASSERT(!args.fShape->inverseFilled());
robertphillips976f5f02016-06-03 10:59:20 -0700716
717 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500718 paint.setXPFactory(GrDisableColorXPFactory::Get());
robertphillips976f5f02016-06-03 10:59:20 -0700719
Chris Dalton09e56892019-03-13 00:22:01 -0600720 auto aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
721
722 this->internalDrawPath(
723 args.fRenderTargetContext, std::move(paint), aaType, GrUserStencilSettings::kUnused,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400724 args.fClip, *args.fViewMatrix, *args.fShape, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000725}
joshualitt622d3ad2015-05-07 08:13:11 -0700726
727///////////////////////////////////////////////////////////////////////////////////////////////////
728
Hal Canary6f6961e2017-01-31 13:50:44 -0500729#if GR_TEST_UTILS
joshualitt622d3ad2015-05-07 08:13:11 -0700730
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400731GR_DRAW_OP_TEST_DEFINE(DefaultPathOp) {
joshualitt622d3ad2015-05-07 08:13:11 -0700732 SkMatrix viewMatrix = GrTest::TestMatrix(random);
733
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500734 // For now just hairlines because the other types of draws require two ops.
735 // TODO we should figure out a way to combine the stencil and cover steps into one op.
bsalomon6663acf2016-05-10 09:14:17 -0700736 GrStyle style(SkStrokeRec::kHairline_InitStyle);
John Stiles31954bf2020-08-07 17:35:54 -0400737 const SkPath& path = GrTest::TestPath(random);
joshualitt622d3ad2015-05-07 08:13:11 -0700738
739 // Compute srcSpaceTol
740 SkRect bounds = path.getBounds();
741 SkScalar tol = GrPathUtils::kDefaultTolerance;
742 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds);
743
joshualitt622d3ad2015-05-07 08:13:11 -0700744 viewMatrix.mapRect(&bounds);
745 uint8_t coverage = GrRandomCoverage(random);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400746 GrAAType aaType = GrAAType::kNone;
Chris Dalton6ce447a2019-06-23 18:07:38 -0600747 if (numSamples > 1 && random->nextBool()) {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400748 aaType = GrAAType::kMSAA;
749 }
Robert Phillips7c525e62018-06-12 10:11:12 -0400750 return DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, coverage, viewMatrix,
751 true, aaType, bounds, GrGetRandomStencil(random, context));
joshualitt622d3ad2015-05-07 08:13:11 -0700752}
753
754#endif