blob: f9ced0500f65dd10c1cebeb76daac745dadf4dc9 [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"
Robert Phillips62214f72021-06-15 10:12:51 -040025#include "src/gpu/GrUtil.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040026#include "src/gpu/geometry/GrPathUtils.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000027#include "src/gpu/geometry/GrStyledShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "src/gpu/ops/GrMeshDrawOp.h"
Robert Phillips55f681f2020-02-28 08:58:15 -050029#include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h"
joshualitt74417822015-08-07 11:42:16 -070030
Brian Salomon15b25092017-05-08 11:10:53 -040031GrDefaultPathRenderer::GrDefaultPathRenderer() {
bsalomon@google.com289533a2011-10-27 12:34:25 +000032}
33
bsalomon@google.com30085192011-08-19 15:42:31 +000034////////////////////////////////////////////////////////////////////////////////
35// Helpers for drawPath
36
bsalomon@google.com30085192011-08-19 15:42:31 +000037#define STENCIL_OFF 0 // Always disable stencil (even when needed)
38
Michael Ludwig2686d692020-04-17 20:21:37 +000039static inline bool single_pass_shape(const GrStyledShape& shape) {
bsalomon@google.com30085192011-08-19 15:42:31 +000040#if STENCIL_OFF
41 return true;
42#else
bsalomonee432412016-06-27 07:18:18 -070043 // Inverse fill is always two pass.
44 if (shape.inverseFilled()) {
45 return false;
46 }
47 // This path renderer only accepts simple fill paths or stroke paths that are either hairline
48 // or have a stroke width small enough to treat as hairline. Hairline paths are always single
49 // pass. Filled paths are single pass if they're convex.
50 if (shape.style().isSimpleFill()) {
bsalomon8acedde2016-06-24 10:42:16 -070051 return shape.knownToBeConvex();
bsalomon@google.com30085192011-08-19 15:42:31 +000052 }
bsalomonee432412016-06-27 07:18:18 -070053 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +000054#endif
55}
56
joshualitt9853cce2014-11-17 14:22:48 -080057GrPathRenderer::StencilSupport
Michael Ludwig2686d692020-04-17 20:21:37 +000058GrDefaultPathRenderer::onGetStencilSupport(const GrStyledShape& shape) const {
bsalomon8acedde2016-06-24 10:42:16 -070059 if (single_pass_shape(shape)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000060 return GrPathRenderer::kNoRestriction_StencilSupport;
61 } else {
62 return GrPathRenderer::kStencilOnly_StencilSupport;
63 }
bsalomon@google.com30085192011-08-19 15:42:31 +000064}
65
Brian Salomonee3e0ba2017-07-13 16:40:46 -040066namespace {
67
Brian Osman49b7b6f2017-06-20 14:43:58 -040068class PathGeoBuilder {
69public:
Robert Phillips9028bac2020-03-10 16:19:27 -040070 PathGeoBuilder(GrPrimitiveType primitiveType,
Robert Phillips71143952021-06-17 14:55:07 -040071 GrMeshDrawTarget* target,
Chris Daltoneb694b72020-03-16 09:25:50 -060072 SkTDArray<GrSimpleMesh*>* meshes)
Brian Salomon7eae3e02018-08-07 14:02:38 +000073 : fPrimitiveType(primitiveType)
Brian Osman49b7b6f2017-06-20 14:43:58 -040074 , fTarget(target)
75 , fVertexStride(sizeof(SkPoint))
Brian Osman49b7b6f2017-06-20 14:43:58 -040076 , fFirstIndex(0)
77 , fIndicesInChunk(0)
Robert Phillips9028bac2020-03-10 16:19:27 -040078 , fIndices(nullptr)
79 , fMeshes(meshes) {
Brian Osman49b7b6f2017-06-20 14:43:58 -040080 this->allocNewBuffers();
Brian Osmaneb86b702017-06-07 11:38:31 -040081 }
82
Brian Osman49b7b6f2017-06-20 14:43:58 -040083 ~PathGeoBuilder() {
Robert Phillips9028bac2020-03-10 16:19:27 -040084 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -040085 }
86
87 /**
88 * Path verbs
89 */
90 void moveTo(const SkPoint& p) {
Greg Daniel733ab112021-02-03 12:16:32 -050091 this->needSpace(1);
Brian Osman49b7b6f2017-06-20 14:43:58 -040092
Greg Daniel733ab112021-02-03 12:16:32 -050093 if (!this->isHairline()) {
94 fSubpathIndexStart = this->currentIndex();
95 fSubpathStartPoint = p;
Brian Osman49b7b6f2017-06-20 14:43:58 -040096 }
Greg Daniel30b355a2021-02-03 16:22:49 +000097 *(fCurVert++) = p;
Brian Osman49b7b6f2017-06-20 14:43:58 -040098 }
99
Greg Daniel733ab112021-02-03 12:16:32 -0500100 void addLine(const SkPoint pts[]) {
101 this->needSpace(1, this->indexScale(), &pts[0]);
102
103 if (this->isIndexed()) {
104 uint16_t prevIdx = this->currentIndex() - 1;
105 this->appendCountourEdgeIndices(prevIdx);
106 }
107 *(fCurVert++) = pts[1];
108 }
109
Brian Osman49b7b6f2017-06-20 14:43:58 -0400110 void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
111 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel733ab112021-02-03 12:16:32 -0500112 GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
113 &pts[0]);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400114
115 // First pt of quad is the pt we ended on in previous step
116 uint16_t firstQPtIdx = this->currentIndex() - 1;
117 uint16_t numPts = (uint16_t)GrPathUtils::generateQuadraticPoints(
118 pts[0], pts[1], pts[2], srcSpaceTolSqd, &fCurVert,
119 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000120 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400121 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel733ab112021-02-03 12:16:32 -0500122 this->appendCountourEdgeIndices(firstQPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400123 }
egdanielaf18a092015-01-05 10:22:28 -0800124 }
125 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400126
127 void addConic(SkScalar weight, const SkPoint pts[], SkScalar srcSpaceTolSqd,
128 SkScalar srcSpaceTol) {
129 SkAutoConicToQuads converter;
130 const SkPoint* quadPts = converter.computeQuads(pts, weight, srcSpaceTol);
131 for (int i = 0; i < converter.countQuads(); ++i) {
132 this->addQuad(quadPts + i * 2, srcSpaceTolSqd, srcSpaceTol);
133 }
134 }
135
136 void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
137 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel733ab112021-02-03 12:16:32 -0500138 GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
139 &pts[0]);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400140
141 // First pt of cubic is the pt we ended on in previous step
142 uint16_t firstCPtIdx = this->currentIndex() - 1;
143 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
144 pts[0], pts[1], pts[2], pts[3], srcSpaceTolSqd, &fCurVert,
145 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000146 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400147 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel733ab112021-02-03 12:16:32 -0500148 this->appendCountourEdgeIndices(firstCPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400149 }
150 }
151 }
152
153 void addPath(const SkPath& path, SkScalar srcSpaceTol) {
154 SkScalar srcSpaceTolSqd = srcSpaceTol * srcSpaceTol;
155
156 SkPath::Iter iter(path, false);
157 SkPoint pts[4];
158
159 bool done = false;
160 while (!done) {
Mike Reedba7e9a62019-08-16 13:30:34 -0400161 SkPath::Verb verb = iter.next(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400162 switch (verb) {
163 case SkPath::kMove_Verb:
164 this->moveTo(pts[0]);
165 break;
166 case SkPath::kLine_Verb:
Greg Daniel733ab112021-02-03 12:16:32 -0500167 this->addLine(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400168 break;
169 case SkPath::kConic_Verb:
170 this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol);
171 break;
172 case SkPath::kQuad_Verb:
173 this->addQuad(pts, srcSpaceTolSqd, srcSpaceTol);
174 break;
175 case SkPath::kCubic_Verb:
176 this->addCubic(pts, srcSpaceTolSqd, srcSpaceTol);
177 break;
178 case SkPath::kClose_Verb:
179 break;
180 case SkPath::kDone_Verb:
181 done = true;
182 }
183 }
184 }
185
186 static bool PathHasMultipleSubpaths(const SkPath& path) {
187 bool first = true;
188
189 SkPath::Iter iter(path, false);
190 SkPath::Verb verb;
191
192 SkPoint pts[4];
Mike Reedba7e9a62019-08-16 13:30:34 -0400193 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400194 if (SkPath::kMove_Verb == verb && !first) {
195 return true;
196 }
197 first = false;
198 }
199 return false;
200 }
201
202private:
203 /**
204 * Derived properties
205 * TODO: Cache some of these for better performance, rather than re-computing?
206 */
Brian Salomon763abf02018-05-01 18:49:38 +0000207 bool isIndexed() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000208 return GrPrimitiveType::kLines == fPrimitiveType ||
209 GrPrimitiveType::kTriangles == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400210 }
211 bool isHairline() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000212 return GrPrimitiveType::kLines == fPrimitiveType ||
213 GrPrimitiveType::kLineStrip == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400214 }
215 int indexScale() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000216 switch (fPrimitiveType) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400217 case GrPrimitiveType::kLines:
218 return 2;
219 case GrPrimitiveType::kTriangles:
220 return 3;
221 default:
222 return 0;
223 }
224 }
225
226 uint16_t currentIndex() const { return fCurVert - fVertices; }
227
Brian Osman49b7b6f2017-06-20 14:43:58 -0400228 // Allocate vertex and (possibly) index buffers
229 void allocNewBuffers() {
230 // Ensure that we always get enough verts for a worst-case quad/cubic, plus leftover points
231 // from previous mesh piece (up to two verts to continue fanning). If we can't get that
232 // many, ask for a much larger number. This needs to be fairly big to handle quads/cubics,
233 // which have a worst-case of 1k points.
234 static const int kMinVerticesPerChunk = GrPathUtils::kMaxPointsPerCurve + 2;
235 static const int kFallbackVerticesPerChunk = 16384;
236
237 fVertices = static_cast<SkPoint*>(fTarget->makeVertexSpaceAtLeast(fVertexStride,
238 kMinVerticesPerChunk,
239 kFallbackVerticesPerChunk,
240 &fVertexBuffer,
241 &fFirstVertex,
242 &fVerticesInChunk));
243
Brian Salomon763abf02018-05-01 18:49:38 +0000244 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400245 // Similar to above: Ensure we get enough indices for one worst-case quad/cubic.
246 // No extra indices are needed for stitching, though. If we can't get that many, ask
247 // for enough to match our large vertex request.
248 const int kMinIndicesPerChunk = GrPathUtils::kMaxPointsPerCurve * this->indexScale();
249 const int kFallbackIndicesPerChunk = kFallbackVerticesPerChunk * this->indexScale();
250
251 fIndices = fTarget->makeIndexSpaceAtLeast(kMinIndicesPerChunk, kFallbackIndicesPerChunk,
252 &fIndexBuffer, &fFirstIndex,
253 &fIndicesInChunk);
254 }
Brian Osman3902d402017-06-20 15:36:31 -0400255
256 fCurVert = fVertices;
257 fCurIdx = fIndices;
258 fSubpathIndexStart = 0;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400259 }
260
261 void appendCountourEdgeIndices(uint16_t edgeV0Idx) {
262 // When drawing lines we're appending line segments along the countour. When applying the
263 // other fill rules we're drawing triangle fans around the start of the current (sub)path.
264 if (!this->isHairline()) {
265 *(fCurIdx++) = fSubpathIndexStart;
266 }
267 *(fCurIdx++) = edgeV0Idx;
268 *(fCurIdx++) = edgeV0Idx + 1;
269 }
270
271 // Emits a single draw with all accumulated vertex/index data
Robert Phillips9028bac2020-03-10 16:19:27 -0400272 void createMeshAndPutBackReserve() {
Brian Osman3902d402017-06-20 15:36:31 -0400273 int vertexCount = fCurVert - fVertices;
274 int indexCount = fCurIdx - fIndices;
275 SkASSERT(vertexCount <= fVerticesInChunk);
276 SkASSERT(indexCount <= fIndicesInChunk);
277
Chris Daltoneb694b72020-03-16 09:25:50 -0600278 GrSimpleMesh* mesh = nullptr;
Brian Salomon763abf02018-05-01 18:49:38 +0000279 if (this->isIndexed() ? SkToBool(indexCount) : SkToBool(vertexCount)) {
Robert Phillips9028bac2020-03-10 16:19:27 -0400280 mesh = fTarget->allocMesh();
Brian Salomon763abf02018-05-01 18:49:38 +0000281 if (!this->isIndexed()) {
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600282 mesh->set(std::move(fVertexBuffer), vertexCount, fFirstVertex);
Brian Salomon763abf02018-05-01 18:49:38 +0000283 } else {
Brian Salomon12d22642019-01-29 14:38:50 -0500284 mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0,
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600285 vertexCount - 1, GrPrimitiveRestart::kNo, std::move(fVertexBuffer),
286 fFirstVertex);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400287 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400288 }
Brian Osman3902d402017-06-20 15:36:31 -0400289
290 fTarget->putBackIndices((size_t)(fIndicesInChunk - indexCount));
291 fTarget->putBackVertices((size_t)(fVerticesInChunk - vertexCount), fVertexStride);
Robert Phillips9028bac2020-03-10 16:19:27 -0400292
293 if (mesh) {
294 fMeshes->push_back(mesh);
295 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400296 }
297
Greg Daniel733ab112021-02-03 12:16:32 -0500298 void needSpace(int vertsNeeded, int indicesNeeded = 0, const SkPoint* lastPoint = nullptr) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400299 if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk ||
300 fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) {
301 // We are about to run out of space (possibly)
302
Greg Daniel733ab112021-02-03 12:16:32 -0500303#ifdef SK_DEBUG
Brian Osman49b7b6f2017-06-20 14:43:58 -0400304 // To maintain continuity, we need to remember one or two points from the current mesh.
305 // Lines only need the last point, fills need the first point from the current contour.
306 // We always grab both here, and append the ones we need at the end of this process.
Brian Osman3902d402017-06-20 15:36:31 -0400307 SkASSERT(fSubpathIndexStart < fVerticesInChunk);
Greg Daniel733ab112021-02-03 12:16:32 -0500308 // This assert is reading from the gpu buffer fVertices and will be slow, but for debug
309 // that is okay.
310 if (!this->isHairline()) {
311 SkASSERT(fSubpathStartPoint == fVertices[fSubpathIndexStart]);
312 }
313 if (lastPoint) {
314 SkASSERT(*(fCurVert - 1) == *lastPoint);
315 }
316#endif
Brian Osman49b7b6f2017-06-20 14:43:58 -0400317
Brian Osman3902d402017-06-20 15:36:31 -0400318 // Draw the mesh we've accumulated, and put back any unused space
Robert Phillips9028bac2020-03-10 16:19:27 -0400319 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -0400320
Brian Osman3902d402017-06-20 15:36:31 -0400321 // Get new buffers
Brian Osman49b7b6f2017-06-20 14:43:58 -0400322 this->allocNewBuffers();
323
Greg Daniel733ab112021-02-03 12:16:32 -0500324 // On moves we don't need to copy over any points to the new buffer and we pass in a
325 // null lastPoint.
326 if (lastPoint) {
327 // Append copies of the points we saved so the two meshes will weld properly
328 if (!this->isHairline()) {
329 *(fCurVert++) = fSubpathStartPoint;
330 }
331 *(fCurVert++) = *lastPoint;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400332 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400333 }
334 }
335
Brian Salomon7eae3e02018-08-07 14:02:38 +0000336 GrPrimitiveType fPrimitiveType;
Robert Phillips71143952021-06-17 14:55:07 -0400337 GrMeshDrawTarget* fTarget;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400338 size_t fVertexStride;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400339
Brian Salomon12d22642019-01-29 14:38:50 -0500340 sk_sp<const GrBuffer> fVertexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400341 int fFirstVertex;
342 int fVerticesInChunk;
343 SkPoint* fVertices;
344 SkPoint* fCurVert;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400345
Brian Salomon12d22642019-01-29 14:38:50 -0500346 sk_sp<const GrBuffer> fIndexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400347 int fFirstIndex;
348 int fIndicesInChunk;
349 uint16_t* fIndices;
350 uint16_t* fCurIdx;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400351 uint16_t fSubpathIndexStart;
Greg Daniel733ab112021-02-03 12:16:32 -0500352 SkPoint fSubpathStartPoint;
Robert Phillips9028bac2020-03-10 16:19:27 -0400353
Chris Daltoneb694b72020-03-16 09:25:50 -0600354 SkTDArray<GrSimpleMesh*>* fMeshes;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400355};
egdanielaf18a092015-01-05 10:22:28 -0800356
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400357class DefaultPathOp final : public GrMeshDrawOp {
358private:
359 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
360
joshualitt332c7292015-02-23 08:44:31 -0800361public:
Brian Salomon25a88092016-12-01 09:36:50 -0500362 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -0700363
Herb Derbyc76d4092020-10-07 16:46:15 -0400364 static GrOp::Owner Make(GrRecordingContext* context,
365 GrPaint&& paint,
366 const SkPath& path,
367 SkScalar tolerance,
368 uint8_t coverage,
369 const SkMatrix& viewMatrix,
370 bool isHairline,
371 GrAAType aaType,
372 const SkRect& devBounds,
373 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400374 return Helper::FactoryHelper<DefaultPathOp>(context, std::move(paint), path, tolerance,
375 coverage, viewMatrix, isHairline, aaType,
376 devBounds, stencilSettings);
bsalomon@google.com30085192011-08-19 15:42:31 +0000377 }
378
Brian Salomon780dad12016-12-15 18:08:40 -0500379 const char* name() const override { return "DefaultPathOp"; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000380
Robert Phillips294723d2021-06-17 09:23:58 -0400381 void visitProxies(const GrVisitProxyFunc& func) const override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400382 if (fProgramInfo) {
Chris Daltonbe457422020-03-16 18:05:03 -0600383 fProgramInfo->visitFPProxies(func);
Robert Phillips9028bac2020-03-10 16:19:27 -0400384 } else {
385 fHelper.visitProxies(func);
386 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400387 }
388
Herb Derbyc76d4092020-10-07 16:46:15 -0400389 DefaultPathOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkPath& path,
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400390 SkScalar tolerance, uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline,
391 GrAAType aaType, const SkRect& devBounds,
392 const GrUserStencilSettings* stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500393 : INHERITED(ClassID())
Herb Derbyc76d4092020-10-07 16:46:15 -0400394 , fHelper(processorSet, aaType, stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500395 , fColor(color)
396 , fCoverage(coverage)
397 , fViewMatrix(viewMatrix)
398 , fIsHairline(isHairline) {
399 fPaths.emplace_back(PathData{path, tolerance});
joshualitt332c7292015-02-23 08:44:31 -0800400
Greg Daniel5faf4742019-10-01 15:14:44 -0400401 HasAABloat aaBloat = (aaType == GrAAType::kNone) ? HasAABloat ::kNo : HasAABloat::kYes;
402 this->setBounds(devBounds, aaBloat,
403 isHairline ? IsHairline::kYes : IsHairline::kNo);
Brian Salomon780dad12016-12-15 18:08:40 -0500404 }
405
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400406 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
407
Chris Dalton57ab06c2021-04-22 12:57:28 -0600408 GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip,
409 GrClampType clampType) override {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400410 GrProcessorAnalysisCoverage gpCoverage =
411 this->coverage() == 0xFF ? GrProcessorAnalysisCoverage::kNone
412 : GrProcessorAnalysisCoverage::kSingleChannel;
Brian Osman8fa7ab42019-03-18 10:22:42 -0400413 // This Op uses uniform (not vertex) color, so doesn't need to track wide color.
Chris Dalton57ab06c2021-04-22 12:57:28 -0600414 return fHelper.finalizeProcessors(caps, clip, clampType, gpCoverage, &fColor, nullptr);
Brian Salomon92aee3d2016-12-21 09:20:25 -0500415 }
416
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400417private:
Robert Phillips9028bac2020-03-10 16:19:27 -0400418 GrPrimitiveType primType() const {
419 if (this->isHairline()) {
420 int instanceCount = fPaths.count();
421
422 // We avoid indices when we have a single hairline contour.
423 bool isIndexed = instanceCount > 1 ||
424 PathGeoBuilder::PathHasMultipleSubpaths(fPaths[0].fPath);
425
426 return isIndexed ? GrPrimitiveType::kLines : GrPrimitiveType::kLineStrip;
427 }
428
429 return GrPrimitiveType::kTriangles;
430 }
431
Robert Phillips2669a7b2020-03-12 12:07:19 -0400432 GrProgramInfo* programInfo() override { return fProgramInfo; }
433
Robert Phillips4133dc42020-03-11 15:55:55 -0400434 void onCreateProgramInfo(const GrCaps* caps,
435 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500436 const GrSurfaceProxyView& writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400437 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400438 const GrDstProxyView& dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500439 GrXferBarrierFlags renderPassXferBarriers,
440 GrLoadOp colorLoadOp) override {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500441 GrGeometryProcessor* gp;
joshualittdf0c5572015-08-03 11:35:28 -0700442 {
443 using namespace GrDefaultGeoProcFactory;
444 Color color(this->color());
445 Coverage coverage(this->coverage());
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400446 LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type
447 : LocalCoords::kUnused_Type);
Robert Phillips9028bac2020-03-10 16:19:27 -0400448 gp = GrDefaultGeoProcFactory::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400449 color,
450 coverage,
451 localCoords,
452 this->viewMatrix());
joshualittdf0c5572015-08-03 11:35:28 -0700453 }
joshualitt332c7292015-02-23 08:44:31 -0800454
Brian Osmanf04fb3c2018-11-12 15:34:00 -0500455 SkASSERT(gp->vertexStride() == sizeof(SkPoint));
joshualitt332c7292015-02-23 08:44:31 -0800456
Brian Salomon8afde5f2020-04-01 16:22:00 -0400457 fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400458 std::move(appliedClip),
Greg Danield358cbe2020-09-11 09:33:54 -0400459 dstProxyView, gp, this->primType(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500460 renderPassXferBarriers, colorLoadOp);
Brian Salomon763abf02018-05-01 18:49:38 +0000461
Robert Phillips9028bac2020-03-10 16:19:27 -0400462 }
Brian Osman7f95dfc2017-06-09 14:43:49 +0000463
Robert Phillips71143952021-06-17 14:55:07 -0400464 void onPrepareDraws(GrMeshDrawTarget* target) override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400465 PathGeoBuilder pathGeoBuilder(this->primType(), target, &fMeshes);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000466
467 // fill buffers
Robert Phillips9028bac2020-03-10 16:19:27 -0400468 for (int i = 0; i < fPaths.count(); i++) {
Brian Salomon763abf02018-05-01 18:49:38 +0000469 const PathData& args = fPaths[i];
470 pathGeoBuilder.addPath(args.fPath, args.fTolerance);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000471 }
joshualitt332c7292015-02-23 08:44:31 -0800472 }
473
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700474 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400475 if (!fProgramInfo) {
Robert Phillips4133dc42020-03-11 15:55:55 -0400476 this->createProgramInfo(flushState);
Robert Phillips9028bac2020-03-10 16:19:27 -0400477 }
Robert Phillips3968fcb2019-12-05 16:40:31 -0500478
Robert Phillips9028bac2020-03-10 16:19:27 -0400479 if (!fProgramInfo || !fMeshes.count()) {
480 return;
481 }
482
Chris Dalton765ed362020-03-16 17:34:44 -0600483 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
Robert Phillips787fd9d2021-03-22 14:48:09 -0400484 flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline());
Robert Phillips9028bac2020-03-10 16:19:27 -0400485 for (int i = 0; i < fMeshes.count(); ++i) {
Chris Dalton765ed362020-03-16 17:34:44 -0600486 flushState->drawMesh(*fMeshes[i]);
Robert Phillips9028bac2020-03-10 16:19:27 -0400487 }
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700488 }
489
Herb Derbye25c3002020-10-27 15:57:27 -0400490 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500491 DefaultPathOp* that = t->cast<DefaultPathOp>();
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400492 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000493 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700494 }
495
joshualitt332c7292015-02-23 08:44:31 -0800496 if (this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000497 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800498 }
499
500 if (this->coverage() != that->coverage()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000501 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800502 }
503
Mike Reed2c383152019-12-18 16:47:47 -0500504 if (!SkMatrixPriv::CheapEqual(this->viewMatrix(), that->viewMatrix())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000505 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800506 }
507
508 if (this->isHairline() != that->isHairline()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000509 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800510 }
511
Brian Salomon780dad12016-12-15 18:08:40 -0500512 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000513 return CombineResult::kMerged;
joshualitt332c7292015-02-23 08:44:31 -0800514 }
515
John Stilesaf366522020-08-13 09:57:34 -0400516#if GR_TEST_UTILS
517 SkString onDumpInfo() const override {
518 SkString string = SkStringPrintf("Color: 0x%08x Count: %d\n",
519 fColor.toBytes_RGBA(), fPaths.count());
520 for (const auto& path : fPaths) {
521 string.appendf("Tolerance: %.2f\n", path.fTolerance);
522 }
523 string += fHelper.dumpInfo();
524 return string;
525 }
526#endif
527
Brian Osmancf860852018-10-31 14:04:39 -0400528 const SkPMColor4f& color() const { return fColor; }
Brian Salomon780dad12016-12-15 18:08:40 -0500529 uint8_t coverage() const { return fCoverage; }
Brian Salomon780dad12016-12-15 18:08:40 -0500530 const SkMatrix& viewMatrix() const { return fViewMatrix; }
531 bool isHairline() const { return fIsHairline; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000532
Brian Salomon780dad12016-12-15 18:08:40 -0500533 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700534 SkPath fPath;
535 SkScalar fTolerance;
536 };
537
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400538 SkSTArray<1, PathData, true> fPaths;
539 Helper fHelper;
Brian Osmancf860852018-10-31 14:04:39 -0400540 SkPMColor4f fColor;
Brian Salomon780dad12016-12-15 18:08:40 -0500541 uint8_t fCoverage;
542 SkMatrix fViewMatrix;
Brian Salomon780dad12016-12-15 18:08:40 -0500543 bool fIsHairline;
reed1b55a962015-09-17 20:16:13 -0700544
Chris Daltoneb694b72020-03-16 09:25:50 -0600545 SkTDArray<GrSimpleMesh*> fMeshes;
546 GrProgramInfo* fProgramInfo = nullptr;
Robert Phillips9028bac2020-03-10 16:19:27 -0400547
John Stiles7571f9e2020-09-02 22:42:33 -0400548 using INHERITED = GrMeshDrawOp;
joshualitt332c7292015-02-23 08:44:31 -0800549};
bsalomon@google.com30085192011-08-19 15:42:31 +0000550
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400551} // anonymous namespace
552
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500553bool GrDefaultPathRenderer::internalDrawPath(GrSurfaceDrawContext* surfaceDrawContext,
Brian Salomon82f44312017-01-11 13:42:54 -0500554 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500555 GrAAType aaType,
robertphillipsd2b6d642016-07-21 08:55:08 -0700556 const GrUserStencilSettings& userStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400557 const GrClip* clip,
joshualitt8059eb92014-12-29 15:10:07 -0800558 const SkMatrix& viewMatrix,
Michael Ludwig2686d692020-04-17 20:21:37 +0000559 const GrStyledShape& shape,
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000560 bool stencilOnly) {
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500561 auto context = surfaceDrawContext->recordingContext();
Robert Phillips7c525e62018-06-12 10:11:12 -0400562
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500563 SkASSERT(GrAAType::kCoverage != aaType);
bsalomon8acedde2016-06-24 10:42:16 -0700564 SkPath path;
565 shape.asPath(&path);
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000566
567 SkScalar hairlineCoverage;
joshualitt2e3b3e32014-12-09 13:31:14 -0800568 uint8_t newCoverage = 0xff;
bsalomon6663acf2016-05-10 09:14:17 -0700569 bool isHairline = false;
Robert Phillips62214f72021-06-15 10:12:51 -0400570 if (GrIsStrokeHairlineOrEquivalent(shape.style(), viewMatrix, &hairlineCoverage)) {
joshualitt2e3b3e32014-12-09 13:31:14 -0800571 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
bsalomon6663acf2016-05-10 09:14:17 -0700572 isHairline = true;
573 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700574 SkASSERT(shape.style().isSimpleFill());
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000575 }
576
cdalton93a379b2016-05-11 13:58:08 -0700577 int passCount = 0;
Brian Salomonf0861672017-05-08 11:10:10 -0400578 const GrUserStencilSettings* passes[2];
cdalton93a379b2016-05-11 13:58:08 -0700579 bool reverse = false;
580 bool lastPassIsBounds;
bsalomon@google.com30085192011-08-19 15:42:31 +0000581
joshualitt332c7292015-02-23 08:44:31 -0800582 if (isHairline) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000583 passCount = 1;
584 if (stencilOnly) {
585 passes[0] = &gDirectToStencil;
586 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700587 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000588 }
589 lastPassIsBounds = false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000590 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700591 if (single_pass_shape(shape)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000592 passCount = 1;
593 if (stencilOnly) {
594 passes[0] = &gDirectToStencil;
595 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700596 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000597 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000598 lastPassIsBounds = false;
599 } else {
Mike Reedcf0e3c62019-12-03 16:26:15 -0500600 switch (path.getFillType()) {
Mike Reed7d34dc72019-11-26 12:17:17 -0500601 case SkPathFillType::kInverseEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000602 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400603 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500604 case SkPathFillType::kEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000605 passes[0] = &gEOStencilPass;
606 if (stencilOnly) {
607 passCount = 1;
608 lastPassIsBounds = false;
609 } else {
610 passCount = 2;
611 lastPassIsBounds = true;
612 if (reverse) {
613 passes[1] = &gInvEOColorPass;
614 } else {
615 passes[1] = &gEOColorPass;
616 }
617 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000618 break;
619
Mike Reed7d34dc72019-11-26 12:17:17 -0500620 case SkPathFillType::kInverseWinding:
bsalomon@google.com30085192011-08-19 15:42:31 +0000621 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400622 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500623 case SkPathFillType::kWinding:
Brian Salomon15b25092017-05-08 11:10:53 -0400624 passes[0] = &gWindStencilPass;
Brian Salomonf0861672017-05-08 11:10:10 -0400625 passCount = 2;
bsalomon@google.com30085192011-08-19 15:42:31 +0000626 if (stencilOnly) {
627 lastPassIsBounds = false;
628 --passCount;
629 } else {
630 lastPassIsBounds = true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000631 if (reverse) {
632 passes[passCount-1] = &gInvWindColorPass;
633 } else {
634 passes[passCount-1] = &gWindColorPass;
635 }
636 }
637 break;
638 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000639 SkDEBUGFAIL("Unknown path fFill!");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000640 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000641 }
642 }
643 }
644
senorblanco2b4bb072015-04-22 13:45:18 -0700645 SkScalar tol = GrPathUtils::kDefaultTolerance;
joshualitt332c7292015-02-23 08:44:31 -0800646 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds());
647
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000648 SkRect devBounds;
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500649 GetPathDevBounds(path, surfaceDrawContext->asRenderTargetProxy()->backingStoreDimensions(),
Robert Phillipsec325342017-10-30 18:02:48 +0000650 viewMatrix, &devBounds);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000651
bsalomon@google.com30085192011-08-19 15:42:31 +0000652 for (int p = 0; p < passCount; ++p) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000653 if (lastPassIsBounds && (p == passCount-1)) {
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000654 SkRect bounds;
joshualittd27f73e2014-12-29 07:43:36 -0800655 SkMatrix localMatrix = SkMatrix::I();
bsalomon@google.com30085192011-08-19 15:42:31 +0000656 if (reverse) {
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000657 // draw over the dev bounds (which will be the whole dst surface for inv fill).
658 bounds = devBounds;
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000659 SkMatrix vmi;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000660 // mapRect through persp matrix may not be correct
joshualitt8059eb92014-12-29 15:10:07 -0800661 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000662 vmi.mapRect(&bounds);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000663 } else {
joshualittd27f73e2014-12-29 07:43:36 -0800664 if (!viewMatrix.invert(&localMatrix)) {
665 return false;
666 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000667 }
668 } else {
robertphillips@google.come79f3202014-02-11 16:30:21 +0000669 bounds = path.getBounds();
bsalomon@google.com30085192011-08-19 15:42:31 +0000670 }
joshualitt8059eb92014-12-29 15:10:07 -0800671 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() :
672 viewMatrix;
Michael Ludwig72ab3462018-12-10 12:43:36 -0500673 // This is a non-coverage aa rect op since we assert aaType != kCoverage at the start
Mike Klein16885072018-12-11 09:54:31 -0500674 assert_alive(paint);
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500675 surfaceDrawContext->stencilRect(clip, passes[p], std::move(paint),
676 GrAA(aaType == GrAAType::kMSAA), viewM, bounds,
677 &localMatrix);
robertphillips976f5f02016-06-03 10:59:20 -0700678 } else {
Brian Salomond4652ca2017-01-13 12:11:36 -0500679 bool stencilPass = stencilOnly || passCount > 1;
Herb Derbyc76d4092020-10-07 16:46:15 -0400680 GrOp::Owner op;
Brian Salomond4652ca2017-01-13 12:11:36 -0500681 if (stencilPass) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400682 GrPaint stencilPaint;
683 stencilPaint.setXPFactory(GrDisableColorXPFactory::Get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400684 op = DefaultPathOp::Make(context, std::move(stencilPaint), path, srcSpaceTol,
685 newCoverage, viewMatrix, isHairline, aaType, devBounds,
686 passes[p]);
Brian Salomonb74ef032017-08-10 12:46:01 -0400687 } else {
Mike Klein16885072018-12-11 09:54:31 -0500688 assert_alive(paint);
Robert Phillips7c525e62018-06-12 10:11:12 -0400689 op = DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, newCoverage,
Brian Salomonb74ef032017-08-10 12:46:01 -0400690 viewMatrix, isHairline, aaType, devBounds, passes[p]);
Brian Salomond4652ca2017-01-13 12:11:36 -0500691 }
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500692 surfaceDrawContext->addDrawOp(clip, std::move(op));
bsalomon@google.com30085192011-08-19 15:42:31 +0000693 }
694 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000695 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000696}
697
Chris Dalton5ed44232017-09-07 13:22:46 -0600698GrPathRenderer::CanDrawPath
699GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Robert Phillips62214f72021-06-15 10:12:51 -0400700 bool isHairline = GrIsStrokeHairlineOrEquivalent(
Chris Dalton09e56892019-03-13 00:22:01 -0600701 args.fShape->style(), *args.fViewMatrix, nullptr);
Eric Karl5c779752017-05-08 12:02:07 -0700702 // If we aren't a single_pass_shape or hairline, we require stencil buffers.
Greg Danielbe7fc462019-01-03 16:40:42 -0500703 if (!(single_pass_shape(*args.fShape) || isHairline) &&
Chris Dalton537293bf2021-05-03 15:54:24 -0600704 !args.fProxy->canUseStencil(*args.fCaps)) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600705 return CanDrawPath::kNo;
Eric Karl5c779752017-05-08 12:02:07 -0700706 }
Chris Dalton09e56892019-03-13 00:22:01 -0600707 // If antialiasing is required, we only support MSAA.
Chris Dalton6ce447a2019-06-23 18:07:38 -0600708 if (GrAAType::kNone != args.fAAType && GrAAType::kMSAA != args.fAAType) {
Chris Dalton09e56892019-03-13 00:22:01 -0600709 return CanDrawPath::kNo;
710 }
711 // This can draw any path with any simple fill style.
712 if (!args.fShape->style().isSimpleFill() && !isHairline) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600713 return CanDrawPath::kNo;
714 }
715 // This is the fallback renderer for when a path is too complicated for the others to draw.
716 return CanDrawPath::kAsBackup;
bsalomon@google.com30085192011-08-19 15:42:31 +0000717}
718
bsalomon0aff2fa2015-07-31 06:48:27 -0700719bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
John Stiles0fbc6a32021-06-04 14:40:57 -0400720 GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700721 "GrDefaultPathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -0600722 GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone;
Chris Dalton09e56892019-03-13 00:22:01 -0600723
724 return this->internalDrawPath(
John Stiles0fbc6a32021-06-04 14:40:57 -0400725 args.fSurfaceDrawContext, std::move(args.fPaint), aaType, *args.fUserStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400726 args.fClip, *args.fViewMatrix, *args.fShape, false);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000727}
728
bsalomon0aff2fa2015-07-31 06:48:27 -0700729void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
John Stiles0fbc6a32021-06-04 14:40:57 -0400730 GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700731 "GrDefaultPathRenderer::onStencilPath");
bsalomon8acedde2016-06-24 10:42:16 -0700732 SkASSERT(!args.fShape->inverseFilled());
robertphillips976f5f02016-06-03 10:59:20 -0700733
734 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500735 paint.setXPFactory(GrDisableColorXPFactory::Get());
robertphillips976f5f02016-06-03 10:59:20 -0700736
Chris Dalton09e56892019-03-13 00:22:01 -0600737 auto aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
738
739 this->internalDrawPath(
John Stiles0fbc6a32021-06-04 14:40:57 -0400740 args.fSurfaceDrawContext, std::move(paint), aaType, GrUserStencilSettings::kUnused,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400741 args.fClip, *args.fViewMatrix, *args.fShape, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000742}
joshualitt622d3ad2015-05-07 08:13:11 -0700743
744///////////////////////////////////////////////////////////////////////////////////////////////////
745
Hal Canary6f6961e2017-01-31 13:50:44 -0500746#if GR_TEST_UTILS
joshualitt622d3ad2015-05-07 08:13:11 -0700747
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400748GR_DRAW_OP_TEST_DEFINE(DefaultPathOp) {
joshualitt622d3ad2015-05-07 08:13:11 -0700749 SkMatrix viewMatrix = GrTest::TestMatrix(random);
750
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500751 // For now just hairlines because the other types of draws require two ops.
752 // TODO we should figure out a way to combine the stencil and cover steps into one op.
bsalomon6663acf2016-05-10 09:14:17 -0700753 GrStyle style(SkStrokeRec::kHairline_InitStyle);
John Stiles31954bf2020-08-07 17:35:54 -0400754 const SkPath& path = GrTest::TestPath(random);
joshualitt622d3ad2015-05-07 08:13:11 -0700755
756 // Compute srcSpaceTol
757 SkRect bounds = path.getBounds();
758 SkScalar tol = GrPathUtils::kDefaultTolerance;
759 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds);
760
joshualitt622d3ad2015-05-07 08:13:11 -0700761 viewMatrix.mapRect(&bounds);
762 uint8_t coverage = GrRandomCoverage(random);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400763 GrAAType aaType = GrAAType::kNone;
Chris Dalton6ce447a2019-06-23 18:07:38 -0600764 if (numSamples > 1 && random->nextBool()) {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400765 aaType = GrAAType::kMSAA;
766 }
Robert Phillips7c525e62018-06-12 10:11:12 -0400767 return DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, coverage, viewMatrix,
768 true, aaType, bounds, GrGetRandomStencil(random, context));
joshualitt622d3ad2015-05-07 08:13:11 -0700769}
770
771#endif