blob: e40ccc06b0e1c45e37fc17c4818f735d8f4abf35 [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 Daniel733ab112021-02-03 12:16:32 -050090 this->needSpace(1);
Brian Osman49b7b6f2017-06-20 14:43:58 -040091
Greg Daniel733ab112021-02-03 12:16:32 -050092 if (!this->isHairline()) {
93 fSubpathIndexStart = this->currentIndex();
94 fSubpathStartPoint = p;
Brian Osman49b7b6f2017-06-20 14:43:58 -040095 }
Greg Daniel30b355a2021-02-03 16:22:49 +000096 *(fCurVert++) = p;
Brian Osman49b7b6f2017-06-20 14:43:58 -040097 }
98
Greg Daniel733ab112021-02-03 12:16:32 -050099 void addLine(const SkPoint pts[]) {
100 this->needSpace(1, this->indexScale(), &pts[0]);
101
102 if (this->isIndexed()) {
103 uint16_t prevIdx = this->currentIndex() - 1;
104 this->appendCountourEdgeIndices(prevIdx);
105 }
106 *(fCurVert++) = pts[1];
107 }
108
Brian Osman49b7b6f2017-06-20 14:43:58 -0400109 void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
110 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel733ab112021-02-03 12:16:32 -0500111 GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
112 &pts[0]);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400113
114 // First pt of quad is the pt we ended on in previous step
115 uint16_t firstQPtIdx = this->currentIndex() - 1;
116 uint16_t numPts = (uint16_t)GrPathUtils::generateQuadraticPoints(
117 pts[0], pts[1], pts[2], srcSpaceTolSqd, &fCurVert,
118 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000119 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400120 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel733ab112021-02-03 12:16:32 -0500121 this->appendCountourEdgeIndices(firstQPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400122 }
egdanielaf18a092015-01-05 10:22:28 -0800123 }
124 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400125
126 void addConic(SkScalar weight, const SkPoint pts[], SkScalar srcSpaceTolSqd,
127 SkScalar srcSpaceTol) {
128 SkAutoConicToQuads converter;
129 const SkPoint* quadPts = converter.computeQuads(pts, weight, srcSpaceTol);
130 for (int i = 0; i < converter.countQuads(); ++i) {
131 this->addQuad(quadPts + i * 2, srcSpaceTolSqd, srcSpaceTol);
132 }
133 }
134
135 void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
136 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
Greg Daniel733ab112021-02-03 12:16:32 -0500137 GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
138 &pts[0]);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400139
140 // First pt of cubic is the pt we ended on in previous step
141 uint16_t firstCPtIdx = this->currentIndex() - 1;
142 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
143 pts[0], pts[1], pts[2], pts[3], srcSpaceTolSqd, &fCurVert,
144 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000145 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400146 for (uint16_t i = 0; i < numPts; ++i) {
Greg Daniel733ab112021-02-03 12:16:32 -0500147 this->appendCountourEdgeIndices(firstCPtIdx + i);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400148 }
149 }
150 }
151
152 void addPath(const SkPath& path, SkScalar srcSpaceTol) {
153 SkScalar srcSpaceTolSqd = srcSpaceTol * srcSpaceTol;
154
155 SkPath::Iter iter(path, false);
156 SkPoint pts[4];
157
158 bool done = false;
159 while (!done) {
Mike Reedba7e9a62019-08-16 13:30:34 -0400160 SkPath::Verb verb = iter.next(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400161 switch (verb) {
162 case SkPath::kMove_Verb:
163 this->moveTo(pts[0]);
164 break;
165 case SkPath::kLine_Verb:
Greg Daniel733ab112021-02-03 12:16:32 -0500166 this->addLine(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400167 break;
168 case SkPath::kConic_Verb:
169 this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol);
170 break;
171 case SkPath::kQuad_Verb:
172 this->addQuad(pts, srcSpaceTolSqd, srcSpaceTol);
173 break;
174 case SkPath::kCubic_Verb:
175 this->addCubic(pts, srcSpaceTolSqd, srcSpaceTol);
176 break;
177 case SkPath::kClose_Verb:
178 break;
179 case SkPath::kDone_Verb:
180 done = true;
181 }
182 }
183 }
184
185 static bool PathHasMultipleSubpaths(const SkPath& path) {
186 bool first = true;
187
188 SkPath::Iter iter(path, false);
189 SkPath::Verb verb;
190
191 SkPoint pts[4];
Mike Reedba7e9a62019-08-16 13:30:34 -0400192 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400193 if (SkPath::kMove_Verb == verb && !first) {
194 return true;
195 }
196 first = false;
197 }
198 return false;
199 }
200
201private:
202 /**
203 * Derived properties
204 * TODO: Cache some of these for better performance, rather than re-computing?
205 */
Brian Salomon763abf02018-05-01 18:49:38 +0000206 bool isIndexed() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000207 return GrPrimitiveType::kLines == fPrimitiveType ||
208 GrPrimitiveType::kTriangles == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400209 }
210 bool isHairline() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000211 return GrPrimitiveType::kLines == fPrimitiveType ||
212 GrPrimitiveType::kLineStrip == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400213 }
214 int indexScale() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000215 switch (fPrimitiveType) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400216 case GrPrimitiveType::kLines:
217 return 2;
218 case GrPrimitiveType::kTriangles:
219 return 3;
220 default:
221 return 0;
222 }
223 }
224
225 uint16_t currentIndex() const { return fCurVert - fVertices; }
226
Brian Osman49b7b6f2017-06-20 14:43:58 -0400227 // Allocate vertex and (possibly) index buffers
228 void allocNewBuffers() {
229 // Ensure that we always get enough verts for a worst-case quad/cubic, plus leftover points
230 // from previous mesh piece (up to two verts to continue fanning). If we can't get that
231 // many, ask for a much larger number. This needs to be fairly big to handle quads/cubics,
232 // which have a worst-case of 1k points.
233 static const int kMinVerticesPerChunk = GrPathUtils::kMaxPointsPerCurve + 2;
234 static const int kFallbackVerticesPerChunk = 16384;
235
236 fVertices = static_cast<SkPoint*>(fTarget->makeVertexSpaceAtLeast(fVertexStride,
237 kMinVerticesPerChunk,
238 kFallbackVerticesPerChunk,
239 &fVertexBuffer,
240 &fFirstVertex,
241 &fVerticesInChunk));
242
Brian Salomon763abf02018-05-01 18:49:38 +0000243 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400244 // Similar to above: Ensure we get enough indices for one worst-case quad/cubic.
245 // No extra indices are needed for stitching, though. If we can't get that many, ask
246 // for enough to match our large vertex request.
247 const int kMinIndicesPerChunk = GrPathUtils::kMaxPointsPerCurve * this->indexScale();
248 const int kFallbackIndicesPerChunk = kFallbackVerticesPerChunk * this->indexScale();
249
250 fIndices = fTarget->makeIndexSpaceAtLeast(kMinIndicesPerChunk, kFallbackIndicesPerChunk,
251 &fIndexBuffer, &fFirstIndex,
252 &fIndicesInChunk);
253 }
Brian Osman3902d402017-06-20 15:36:31 -0400254
255 fCurVert = fVertices;
256 fCurIdx = fIndices;
257 fSubpathIndexStart = 0;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400258 }
259
260 void appendCountourEdgeIndices(uint16_t edgeV0Idx) {
261 // When drawing lines we're appending line segments along the countour. When applying the
262 // other fill rules we're drawing triangle fans around the start of the current (sub)path.
263 if (!this->isHairline()) {
264 *(fCurIdx++) = fSubpathIndexStart;
265 }
266 *(fCurIdx++) = edgeV0Idx;
267 *(fCurIdx++) = edgeV0Idx + 1;
268 }
269
270 // Emits a single draw with all accumulated vertex/index data
Robert Phillips9028bac2020-03-10 16:19:27 -0400271 void createMeshAndPutBackReserve() {
Brian Osman3902d402017-06-20 15:36:31 -0400272 int vertexCount = fCurVert - fVertices;
273 int indexCount = fCurIdx - fIndices;
274 SkASSERT(vertexCount <= fVerticesInChunk);
275 SkASSERT(indexCount <= fIndicesInChunk);
276
Chris Daltoneb694b72020-03-16 09:25:50 -0600277 GrSimpleMesh* mesh = nullptr;
Brian Salomon763abf02018-05-01 18:49:38 +0000278 if (this->isIndexed() ? SkToBool(indexCount) : SkToBool(vertexCount)) {
Robert Phillips9028bac2020-03-10 16:19:27 -0400279 mesh = fTarget->allocMesh();
Brian Salomon763abf02018-05-01 18:49:38 +0000280 if (!this->isIndexed()) {
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600281 mesh->set(std::move(fVertexBuffer), vertexCount, fFirstVertex);
Brian Salomon763abf02018-05-01 18:49:38 +0000282 } else {
Brian Salomon12d22642019-01-29 14:38:50 -0500283 mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0,
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600284 vertexCount - 1, GrPrimitiveRestart::kNo, std::move(fVertexBuffer),
285 fFirstVertex);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400286 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400287 }
Brian Osman3902d402017-06-20 15:36:31 -0400288
289 fTarget->putBackIndices((size_t)(fIndicesInChunk - indexCount));
290 fTarget->putBackVertices((size_t)(fVerticesInChunk - vertexCount), fVertexStride);
Robert Phillips9028bac2020-03-10 16:19:27 -0400291
292 if (mesh) {
293 fMeshes->push_back(mesh);
294 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400295 }
296
Greg Daniel733ab112021-02-03 12:16:32 -0500297 void needSpace(int vertsNeeded, int indicesNeeded = 0, const SkPoint* lastPoint = nullptr) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400298 if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk ||
299 fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) {
300 // We are about to run out of space (possibly)
301
Greg Daniel733ab112021-02-03 12:16:32 -0500302#ifdef SK_DEBUG
Brian Osman49b7b6f2017-06-20 14:43:58 -0400303 // To maintain continuity, we need to remember one or two points from the current mesh.
304 // Lines only need the last point, fills need the first point from the current contour.
305 // We always grab both here, and append the ones we need at the end of this process.
Brian Osman3902d402017-06-20 15:36:31 -0400306 SkASSERT(fSubpathIndexStart < fVerticesInChunk);
Greg Daniel733ab112021-02-03 12:16:32 -0500307 // This assert is reading from the gpu buffer fVertices and will be slow, but for debug
308 // that is okay.
309 if (!this->isHairline()) {
310 SkASSERT(fSubpathStartPoint == fVertices[fSubpathIndexStart]);
311 }
312 if (lastPoint) {
313 SkASSERT(*(fCurVert - 1) == *lastPoint);
314 }
315#endif
Brian Osman49b7b6f2017-06-20 14:43:58 -0400316
Brian Osman3902d402017-06-20 15:36:31 -0400317 // Draw the mesh we've accumulated, and put back any unused space
Robert Phillips9028bac2020-03-10 16:19:27 -0400318 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -0400319
Brian Osman3902d402017-06-20 15:36:31 -0400320 // Get new buffers
Brian Osman49b7b6f2017-06-20 14:43:58 -0400321 this->allocNewBuffers();
322
Greg Daniel733ab112021-02-03 12:16:32 -0500323 // On moves we don't need to copy over any points to the new buffer and we pass in a
324 // null lastPoint.
325 if (lastPoint) {
326 // Append copies of the points we saved so the two meshes will weld properly
327 if (!this->isHairline()) {
328 *(fCurVert++) = fSubpathStartPoint;
329 }
330 *(fCurVert++) = *lastPoint;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400331 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400332 }
333 }
334
Brian Salomon7eae3e02018-08-07 14:02:38 +0000335 GrPrimitiveType fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400336 GrMeshDrawOp::Target* fTarget;
337 size_t fVertexStride;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400338
Brian Salomon12d22642019-01-29 14:38:50 -0500339 sk_sp<const GrBuffer> fVertexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400340 int fFirstVertex;
341 int fVerticesInChunk;
342 SkPoint* fVertices;
343 SkPoint* fCurVert;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400344
Brian Salomon12d22642019-01-29 14:38:50 -0500345 sk_sp<const GrBuffer> fIndexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400346 int fFirstIndex;
347 int fIndicesInChunk;
348 uint16_t* fIndices;
349 uint16_t* fCurIdx;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400350 uint16_t fSubpathIndexStart;
Greg Daniel733ab112021-02-03 12:16:32 -0500351 SkPoint fSubpathStartPoint;
Robert Phillips9028bac2020-03-10 16:19:27 -0400352
Chris Daltoneb694b72020-03-16 09:25:50 -0600353 SkTDArray<GrSimpleMesh*>* fMeshes;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400354};
egdanielaf18a092015-01-05 10:22:28 -0800355
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400356class DefaultPathOp final : public GrMeshDrawOp {
357private:
358 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
359
joshualitt332c7292015-02-23 08:44:31 -0800360public:
Brian Salomon25a88092016-12-01 09:36:50 -0500361 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -0700362
Herb Derbyc76d4092020-10-07 16:46:15 -0400363 static GrOp::Owner Make(GrRecordingContext* context,
364 GrPaint&& paint,
365 const SkPath& path,
366 SkScalar tolerance,
367 uint8_t coverage,
368 const SkMatrix& viewMatrix,
369 bool isHairline,
370 GrAAType aaType,
371 const SkRect& devBounds,
372 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400373 return Helper::FactoryHelper<DefaultPathOp>(context, std::move(paint), path, tolerance,
374 coverage, viewMatrix, isHairline, aaType,
375 devBounds, stencilSettings);
bsalomon@google.com30085192011-08-19 15:42:31 +0000376 }
377
Brian Salomon780dad12016-12-15 18:08:40 -0500378 const char* name() const override { return "DefaultPathOp"; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000379
Chris Dalton1706cbf2019-05-21 19:35:29 -0600380 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400381 if (fProgramInfo) {
Chris Daltonbe457422020-03-16 18:05:03 -0600382 fProgramInfo->visitFPProxies(func);
Robert Phillips9028bac2020-03-10 16:19:27 -0400383 } else {
384 fHelper.visitProxies(func);
385 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400386 }
387
Herb Derbyc76d4092020-10-07 16:46:15 -0400388 DefaultPathOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkPath& path,
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400389 SkScalar tolerance, uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline,
390 GrAAType aaType, const SkRect& devBounds,
391 const GrUserStencilSettings* stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500392 : INHERITED(ClassID())
Herb Derbyc76d4092020-10-07 16:46:15 -0400393 , fHelper(processorSet, aaType, stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500394 , fColor(color)
395 , fCoverage(coverage)
396 , fViewMatrix(viewMatrix)
397 , fIsHairline(isHairline) {
398 fPaths.emplace_back(PathData{path, tolerance});
joshualitt332c7292015-02-23 08:44:31 -0800399
Greg Daniel5faf4742019-10-01 15:14:44 -0400400 HasAABloat aaBloat = (aaType == GrAAType::kNone) ? HasAABloat ::kNo : HasAABloat::kYes;
401 this->setBounds(devBounds, aaBloat,
402 isHairline ? IsHairline::kYes : IsHairline::kNo);
Brian Salomon780dad12016-12-15 18:08:40 -0500403 }
404
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400405 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
406
Chris Dalton6ce447a2019-06-23 18:07:38 -0600407 GrProcessorSet::Analysis finalize(
408 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
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.
414 return fHelper.finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600415 caps, clip, hasMixedSampledCoverage, clampType, gpCoverage, &fColor, nullptr);
Brian Salomon92aee3d2016-12-21 09:20:25 -0500416 }
417
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400418private:
Robert Phillips9028bac2020-03-10 16:19:27 -0400419 GrPrimitiveType primType() const {
420 if (this->isHairline()) {
421 int instanceCount = fPaths.count();
422
423 // We avoid indices when we have a single hairline contour.
424 bool isIndexed = instanceCount > 1 ||
425 PathGeoBuilder::PathHasMultipleSubpaths(fPaths[0].fPath);
426
427 return isIndexed ? GrPrimitiveType::kLines : GrPrimitiveType::kLineStrip;
428 }
429
430 return GrPrimitiveType::kTriangles;
431 }
432
Robert Phillips2669a7b2020-03-12 12:07:19 -0400433 GrProgramInfo* programInfo() override { return fProgramInfo; }
434
Robert Phillips4133dc42020-03-11 15:55:55 -0400435 void onCreateProgramInfo(const GrCaps* caps,
436 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500437 const GrSurfaceProxyView& writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400438 GrAppliedClip&& appliedClip,
Greg Danield358cbe2020-09-11 09:33:54 -0400439 const GrXferProcessor::DstProxyView& dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500440 GrXferBarrierFlags renderPassXferBarriers,
441 GrLoadOp colorLoadOp) override {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500442 GrGeometryProcessor* gp;
joshualittdf0c5572015-08-03 11:35:28 -0700443 {
444 using namespace GrDefaultGeoProcFactory;
445 Color color(this->color());
446 Coverage coverage(this->coverage());
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400447 LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type
448 : LocalCoords::kUnused_Type);
Robert Phillips9028bac2020-03-10 16:19:27 -0400449 gp = GrDefaultGeoProcFactory::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400450 color,
451 coverage,
452 localCoords,
453 this->viewMatrix());
joshualittdf0c5572015-08-03 11:35:28 -0700454 }
joshualitt332c7292015-02-23 08:44:31 -0800455
Brian Osmanf04fb3c2018-11-12 15:34:00 -0500456 SkASSERT(gp->vertexStride() == sizeof(SkPoint));
joshualitt332c7292015-02-23 08:44:31 -0800457
Brian Salomon8afde5f2020-04-01 16:22:00 -0400458 fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400459 std::move(appliedClip),
Greg Danield358cbe2020-09-11 09:33:54 -0400460 dstProxyView, gp, this->primType(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500461 renderPassXferBarriers, colorLoadOp);
Brian Salomon763abf02018-05-01 18:49:38 +0000462
Robert Phillips9028bac2020-03-10 16:19:27 -0400463 }
Brian Osman7f95dfc2017-06-09 14:43:49 +0000464
Robert Phillips9028bac2020-03-10 16:19:27 -0400465 void onPrepareDraws(Target* target) override {
466 PathGeoBuilder pathGeoBuilder(this->primType(), target, &fMeshes);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000467
468 // fill buffers
Robert Phillips9028bac2020-03-10 16:19:27 -0400469 for (int i = 0; i < fPaths.count(); i++) {
Brian Salomon763abf02018-05-01 18:49:38 +0000470 const PathData& args = fPaths[i];
471 pathGeoBuilder.addPath(args.fPath, args.fTolerance);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000472 }
joshualitt332c7292015-02-23 08:44:31 -0800473 }
474
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700475 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400476 if (!fProgramInfo) {
Robert Phillips4133dc42020-03-11 15:55:55 -0400477 this->createProgramInfo(flushState);
Robert Phillips9028bac2020-03-10 16:19:27 -0400478 }
Robert Phillips3968fcb2019-12-05 16:40:31 -0500479
Robert Phillips9028bac2020-03-10 16:19:27 -0400480 if (!fProgramInfo || !fMeshes.count()) {
481 return;
482 }
483
Chris Dalton765ed362020-03-16 17:34:44 -0600484 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
Robert Phillips787fd9d2021-03-22 14:48:09 -0400485 flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline());
Robert Phillips9028bac2020-03-10 16:19:27 -0400486 for (int i = 0; i < fMeshes.count(); ++i) {
Chris Dalton765ed362020-03-16 17:34:44 -0600487 flushState->drawMesh(*fMeshes[i]);
Robert Phillips9028bac2020-03-10 16:19:27 -0400488 }
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700489 }
490
Herb Derbye25c3002020-10-27 15:57:27 -0400491 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500492 DefaultPathOp* that = t->cast<DefaultPathOp>();
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400493 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000494 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700495 }
496
joshualitt332c7292015-02-23 08:44:31 -0800497 if (this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000498 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800499 }
500
501 if (this->coverage() != that->coverage()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000502 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800503 }
504
Mike Reed2c383152019-12-18 16:47:47 -0500505 if (!SkMatrixPriv::CheapEqual(this->viewMatrix(), that->viewMatrix())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000506 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800507 }
508
509 if (this->isHairline() != that->isHairline()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000510 return CombineResult::kCannotCombine;
joshualitt332c7292015-02-23 08:44:31 -0800511 }
512
Brian Salomon780dad12016-12-15 18:08:40 -0500513 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000514 return CombineResult::kMerged;
joshualitt332c7292015-02-23 08:44:31 -0800515 }
516
John Stilesaf366522020-08-13 09:57:34 -0400517#if GR_TEST_UTILS
518 SkString onDumpInfo() const override {
519 SkString string = SkStringPrintf("Color: 0x%08x Count: %d\n",
520 fColor.toBytes_RGBA(), fPaths.count());
521 for (const auto& path : fPaths) {
522 string.appendf("Tolerance: %.2f\n", path.fTolerance);
523 }
524 string += fHelper.dumpInfo();
525 return string;
526 }
527#endif
528
Brian Osmancf860852018-10-31 14:04:39 -0400529 const SkPMColor4f& color() const { return fColor; }
Brian Salomon780dad12016-12-15 18:08:40 -0500530 uint8_t coverage() const { return fCoverage; }
Brian Salomon780dad12016-12-15 18:08:40 -0500531 const SkMatrix& viewMatrix() const { return fViewMatrix; }
532 bool isHairline() const { return fIsHairline; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000533
Brian Salomon780dad12016-12-15 18:08:40 -0500534 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700535 SkPath fPath;
536 SkScalar fTolerance;
537 };
538
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400539 SkSTArray<1, PathData, true> fPaths;
540 Helper fHelper;
Brian Osmancf860852018-10-31 14:04:39 -0400541 SkPMColor4f fColor;
Brian Salomon780dad12016-12-15 18:08:40 -0500542 uint8_t fCoverage;
543 SkMatrix fViewMatrix;
Brian Salomon780dad12016-12-15 18:08:40 -0500544 bool fIsHairline;
reed1b55a962015-09-17 20:16:13 -0700545
Chris Daltoneb694b72020-03-16 09:25:50 -0600546 SkTDArray<GrSimpleMesh*> fMeshes;
547 GrProgramInfo* fProgramInfo = nullptr;
Robert Phillips9028bac2020-03-10 16:19:27 -0400548
John Stiles7571f9e2020-09-02 22:42:33 -0400549 using INHERITED = GrMeshDrawOp;
joshualitt332c7292015-02-23 08:44:31 -0800550};
bsalomon@google.com30085192011-08-19 15:42:31 +0000551
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400552} // anonymous namespace
553
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500554bool GrDefaultPathRenderer::internalDrawPath(GrSurfaceDrawContext* surfaceDrawContext,
Brian Salomon82f44312017-01-11 13:42:54 -0500555 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500556 GrAAType aaType,
robertphillipsd2b6d642016-07-21 08:55:08 -0700557 const GrUserStencilSettings& userStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400558 const GrClip* clip,
joshualitt8059eb92014-12-29 15:10:07 -0800559 const SkMatrix& viewMatrix,
Michael Ludwig2686d692020-04-17 20:21:37 +0000560 const GrStyledShape& shape,
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000561 bool stencilOnly) {
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500562 auto context = surfaceDrawContext->recordingContext();
Robert Phillips7c525e62018-06-12 10:11:12 -0400563
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500564 SkASSERT(GrAAType::kCoverage != aaType);
bsalomon8acedde2016-06-24 10:42:16 -0700565 SkPath path;
566 shape.asPath(&path);
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000567
568 SkScalar hairlineCoverage;
joshualitt2e3b3e32014-12-09 13:31:14 -0800569 uint8_t newCoverage = 0xff;
bsalomon6663acf2016-05-10 09:14:17 -0700570 bool isHairline = false;
bsalomon8acedde2016-06-24 10:42:16 -0700571 if (IsStrokeHairlineOrEquivalent(shape.style(), viewMatrix, &hairlineCoverage)) {
joshualitt2e3b3e32014-12-09 13:31:14 -0800572 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
bsalomon6663acf2016-05-10 09:14:17 -0700573 isHairline = true;
574 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700575 SkASSERT(shape.style().isSimpleFill());
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000576 }
577
cdalton93a379b2016-05-11 13:58:08 -0700578 int passCount = 0;
Brian Salomonf0861672017-05-08 11:10:10 -0400579 const GrUserStencilSettings* passes[2];
cdalton93a379b2016-05-11 13:58:08 -0700580 bool reverse = false;
581 bool lastPassIsBounds;
bsalomon@google.com30085192011-08-19 15:42:31 +0000582
joshualitt332c7292015-02-23 08:44:31 -0800583 if (isHairline) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000584 passCount = 1;
585 if (stencilOnly) {
586 passes[0] = &gDirectToStencil;
587 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700588 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000589 }
590 lastPassIsBounds = false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000591 } else {
bsalomon8acedde2016-06-24 10:42:16 -0700592 if (single_pass_shape(shape)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000593 passCount = 1;
594 if (stencilOnly) {
595 passes[0] = &gDirectToStencil;
596 } else {
robertphillipsd2b6d642016-07-21 08:55:08 -0700597 passes[0] = &userStencilSettings;
bsalomon@google.com30085192011-08-19 15:42:31 +0000598 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000599 lastPassIsBounds = false;
600 } else {
Mike Reedcf0e3c62019-12-03 16:26:15 -0500601 switch (path.getFillType()) {
Mike Reed7d34dc72019-11-26 12:17:17 -0500602 case SkPathFillType::kInverseEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000603 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400604 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500605 case SkPathFillType::kEvenOdd:
bsalomon@google.com30085192011-08-19 15:42:31 +0000606 passes[0] = &gEOStencilPass;
607 if (stencilOnly) {
608 passCount = 1;
609 lastPassIsBounds = false;
610 } else {
611 passCount = 2;
612 lastPassIsBounds = true;
613 if (reverse) {
614 passes[1] = &gInvEOColorPass;
615 } else {
616 passes[1] = &gEOColorPass;
617 }
618 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000619 break;
620
Mike Reed7d34dc72019-11-26 12:17:17 -0500621 case SkPathFillType::kInverseWinding:
bsalomon@google.com30085192011-08-19 15:42:31 +0000622 reverse = true;
John Stiles30212b72020-06-11 17:55:07 -0400623 [[fallthrough]];
Mike Reed7d34dc72019-11-26 12:17:17 -0500624 case SkPathFillType::kWinding:
Brian Salomon15b25092017-05-08 11:10:53 -0400625 passes[0] = &gWindStencilPass;
Brian Salomonf0861672017-05-08 11:10:10 -0400626 passCount = 2;
bsalomon@google.com30085192011-08-19 15:42:31 +0000627 if (stencilOnly) {
628 lastPassIsBounds = false;
629 --passCount;
630 } else {
631 lastPassIsBounds = true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000632 if (reverse) {
633 passes[passCount-1] = &gInvWindColorPass;
634 } else {
635 passes[passCount-1] = &gWindColorPass;
636 }
637 }
638 break;
639 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000640 SkDEBUGFAIL("Unknown path fFill!");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000641 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000642 }
643 }
644 }
645
senorblanco2b4bb072015-04-22 13:45:18 -0700646 SkScalar tol = GrPathUtils::kDefaultTolerance;
joshualitt332c7292015-02-23 08:44:31 -0800647 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds());
648
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000649 SkRect devBounds;
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500650 GetPathDevBounds(path, surfaceDrawContext->asRenderTargetProxy()->backingStoreDimensions(),
Robert Phillipsec325342017-10-30 18:02:48 +0000651 viewMatrix, &devBounds);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000652
bsalomon@google.com30085192011-08-19 15:42:31 +0000653 for (int p = 0; p < passCount; ++p) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000654 if (lastPassIsBounds && (p == passCount-1)) {
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000655 SkRect bounds;
joshualittd27f73e2014-12-29 07:43:36 -0800656 SkMatrix localMatrix = SkMatrix::I();
bsalomon@google.com30085192011-08-19 15:42:31 +0000657 if (reverse) {
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000658 // draw over the dev bounds (which will be the whole dst surface for inv fill).
659 bounds = devBounds;
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000660 SkMatrix vmi;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000661 // mapRect through persp matrix may not be correct
joshualitt8059eb92014-12-29 15:10:07 -0800662 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000663 vmi.mapRect(&bounds);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000664 } else {
joshualittd27f73e2014-12-29 07:43:36 -0800665 if (!viewMatrix.invert(&localMatrix)) {
666 return false;
667 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000668 }
669 } else {
robertphillips@google.come79f3202014-02-11 16:30:21 +0000670 bounds = path.getBounds();
bsalomon@google.com30085192011-08-19 15:42:31 +0000671 }
joshualitt8059eb92014-12-29 15:10:07 -0800672 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() :
673 viewMatrix;
Michael Ludwig72ab3462018-12-10 12:43:36 -0500674 // This is a non-coverage aa rect op since we assert aaType != kCoverage at the start
Mike Klein16885072018-12-11 09:54:31 -0500675 assert_alive(paint);
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500676 surfaceDrawContext->stencilRect(clip, passes[p], std::move(paint),
677 GrAA(aaType == GrAAType::kMSAA), viewM, bounds,
678 &localMatrix);
robertphillips976f5f02016-06-03 10:59:20 -0700679 } else {
Brian Salomond4652ca2017-01-13 12:11:36 -0500680 bool stencilPass = stencilOnly || passCount > 1;
Herb Derbyc76d4092020-10-07 16:46:15 -0400681 GrOp::Owner op;
Brian Salomond4652ca2017-01-13 12:11:36 -0500682 if (stencilPass) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400683 GrPaint stencilPaint;
684 stencilPaint.setXPFactory(GrDisableColorXPFactory::Get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400685 op = DefaultPathOp::Make(context, std::move(stencilPaint), path, srcSpaceTol,
686 newCoverage, viewMatrix, isHairline, aaType, devBounds,
687 passes[p]);
Brian Salomonb74ef032017-08-10 12:46:01 -0400688 } else {
Mike Klein16885072018-12-11 09:54:31 -0500689 assert_alive(paint);
Robert Phillips7c525e62018-06-12 10:11:12 -0400690 op = DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, newCoverage,
Brian Salomonb74ef032017-08-10 12:46:01 -0400691 viewMatrix, isHairline, aaType, devBounds, passes[p]);
Brian Salomond4652ca2017-01-13 12:11:36 -0500692 }
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500693 surfaceDrawContext->addDrawOp(clip, std::move(op));
bsalomon@google.com30085192011-08-19 15:42:31 +0000694 }
695 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000696 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000697}
698
Chris Dalton5ed44232017-09-07 13:22:46 -0600699GrPathRenderer::CanDrawPath
700GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Chris Dalton09e56892019-03-13 00:22:01 -0600701 bool isHairline = IsStrokeHairlineOrEquivalent(
702 args.fShape->style(), *args.fViewMatrix, nullptr);
Eric Karl5c779752017-05-08 12:02:07 -0700703 // If we aren't a single_pass_shape or hairline, we require stencil buffers.
Greg Danielbe7fc462019-01-03 16:40:42 -0500704 if (!(single_pass_shape(*args.fShape) || isHairline) &&
705 (args.fCaps->avoidStencilBuffers() || args.fTargetIsWrappedVkSecondaryCB)) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600706 return CanDrawPath::kNo;
Eric Karl5c779752017-05-08 12:02:07 -0700707 }
Chris Dalton09e56892019-03-13 00:22:01 -0600708 // If antialiasing is required, we only support MSAA.
Chris Dalton6ce447a2019-06-23 18:07:38 -0600709 if (GrAAType::kNone != args.fAAType && GrAAType::kMSAA != args.fAAType) {
Chris Dalton09e56892019-03-13 00:22:01 -0600710 return CanDrawPath::kNo;
711 }
712 // This can draw any path with any simple fill style.
713 if (!args.fShape->style().isSimpleFill() && !isHairline) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600714 return CanDrawPath::kNo;
715 }
716 // This is the fallback renderer for when a path is too complicated for the others to draw.
717 return CanDrawPath::kAsBackup;
bsalomon@google.com30085192011-08-19 15:42:31 +0000718}
719
bsalomon0aff2fa2015-07-31 06:48:27 -0700720bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400721 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700722 "GrDefaultPathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -0600723 GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone;
Chris Dalton09e56892019-03-13 00:22:01 -0600724
725 return this->internalDrawPath(
726 args.fRenderTargetContext, std::move(args.fPaint), aaType, *args.fUserStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400727 args.fClip, *args.fViewMatrix, *args.fShape, false);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000728}
729
bsalomon0aff2fa2015-07-31 06:48:27 -0700730void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400731 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700732 "GrDefaultPathRenderer::onStencilPath");
bsalomon8acedde2016-06-24 10:42:16 -0700733 SkASSERT(!args.fShape->inverseFilled());
robertphillips976f5f02016-06-03 10:59:20 -0700734
735 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500736 paint.setXPFactory(GrDisableColorXPFactory::Get());
robertphillips976f5f02016-06-03 10:59:20 -0700737
Chris Dalton09e56892019-03-13 00:22:01 -0600738 auto aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
739
740 this->internalDrawPath(
741 args.fRenderTargetContext, std::move(paint), aaType, GrUserStencilSettings::kUnused,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400742 args.fClip, *args.fViewMatrix, *args.fShape, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000743}
joshualitt622d3ad2015-05-07 08:13:11 -0700744
745///////////////////////////////////////////////////////////////////////////////////////////////////
746
Hal Canary6f6961e2017-01-31 13:50:44 -0500747#if GR_TEST_UTILS
joshualitt622d3ad2015-05-07 08:13:11 -0700748
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400749GR_DRAW_OP_TEST_DEFINE(DefaultPathOp) {
joshualitt622d3ad2015-05-07 08:13:11 -0700750 SkMatrix viewMatrix = GrTest::TestMatrix(random);
751
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500752 // For now just hairlines because the other types of draws require two ops.
753 // TODO we should figure out a way to combine the stencil and cover steps into one op.
bsalomon6663acf2016-05-10 09:14:17 -0700754 GrStyle style(SkStrokeRec::kHairline_InitStyle);
John Stiles31954bf2020-08-07 17:35:54 -0400755 const SkPath& path = GrTest::TestPath(random);
joshualitt622d3ad2015-05-07 08:13:11 -0700756
757 // Compute srcSpaceTol
758 SkRect bounds = path.getBounds();
759 SkScalar tol = GrPathUtils::kDefaultTolerance;
760 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds);
761
joshualitt622d3ad2015-05-07 08:13:11 -0700762 viewMatrix.mapRect(&bounds);
763 uint8_t coverage = GrRandomCoverage(random);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400764 GrAAType aaType = GrAAType::kNone;
Chris Dalton6ce447a2019-06-23 18:07:38 -0600765 if (numSamples > 1 && random->nextBool()) {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400766 aaType = GrAAType::kMSAA;
767 }
Robert Phillips7c525e62018-06-12 10:11:12 -0400768 return DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, coverage, viewMatrix,
769 true, aaType, bounds, GrGetRandomStencil(random, context));
joshualitt622d3ad2015-05-07 08:13:11 -0700770}
771
772#endif