blob: 9d928ae13cfb892da4634840c0038c9c7e3b41cd [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"
Michael Ludwigaa1b6b32019-05-29 14:43:13 -040023#include "src/gpu/GrRenderTargetContextPriv.h"
Chris Daltoneb694b72020-03-16 09:25:50 -060024#include "src/gpu/GrSimpleMesh.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrStyle.h"
26#include "src/gpu/GrSurfaceContextPriv.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040027#include "src/gpu/geometry/GrPathUtils.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000028#include "src/gpu/geometry/GrStyledShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "src/gpu/ops/GrMeshDrawOp.h"
Robert Phillips55f681f2020-02-28 08:58:15 -050030#include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h"
joshualitt74417822015-08-07 11:42:16 -070031
Brian Salomon15b25092017-05-08 11:10:53 -040032GrDefaultPathRenderer::GrDefaultPathRenderer() {
bsalomon@google.com289533a2011-10-27 12:34:25 +000033}
34
bsalomon@google.com30085192011-08-19 15:42:31 +000035////////////////////////////////////////////////////////////////////////////////
36// Helpers for drawPath
37
bsalomon@google.com30085192011-08-19 15:42:31 +000038#define STENCIL_OFF 0 // Always disable stencil (even when needed)
39
Michael Ludwig2686d692020-04-17 20:21:37 +000040static inline bool single_pass_shape(const GrStyledShape& shape) {
bsalomon@google.com30085192011-08-19 15:42:31 +000041#if STENCIL_OFF
42 return true;
43#else
bsalomonee432412016-06-27 07:18:18 -070044 // Inverse fill is always two pass.
45 if (shape.inverseFilled()) {
46 return false;
47 }
48 // This path renderer only accepts simple fill paths or stroke paths that are either hairline
49 // or have a stroke width small enough to treat as hairline. Hairline paths are always single
50 // pass. Filled paths are single pass if they're convex.
51 if (shape.style().isSimpleFill()) {
bsalomon8acedde2016-06-24 10:42:16 -070052 return shape.knownToBeConvex();
bsalomon@google.com30085192011-08-19 15:42:31 +000053 }
bsalomonee432412016-06-27 07:18:18 -070054 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +000055#endif
56}
57
joshualitt9853cce2014-11-17 14:22:48 -080058GrPathRenderer::StencilSupport
Michael Ludwig2686d692020-04-17 20:21:37 +000059GrDefaultPathRenderer::onGetStencilSupport(const GrStyledShape& shape) const {
bsalomon8acedde2016-06-24 10:42:16 -070060 if (single_pass_shape(shape)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000061 return GrPathRenderer::kNoRestriction_StencilSupport;
62 } else {
63 return GrPathRenderer::kStencilOnly_StencilSupport;
64 }
bsalomon@google.com30085192011-08-19 15:42:31 +000065}
66
Brian Salomonee3e0ba2017-07-13 16:40:46 -040067namespace {
68
Brian Osman49b7b6f2017-06-20 14:43:58 -040069class PathGeoBuilder {
70public:
Robert Phillips9028bac2020-03-10 16:19:27 -040071 PathGeoBuilder(GrPrimitiveType primitiveType,
72 GrMeshDrawOp::Target* target,
Chris Daltoneb694b72020-03-16 09:25:50 -060073 SkTDArray<GrSimpleMesh*>* meshes)
Brian Salomon7eae3e02018-08-07 14:02:38 +000074 : fPrimitiveType(primitiveType)
Brian Osman49b7b6f2017-06-20 14:43:58 -040075 , fTarget(target)
76 , fVertexStride(sizeof(SkPoint))
Brian Osman49b7b6f2017-06-20 14:43:58 -040077 , fFirstIndex(0)
78 , fIndicesInChunk(0)
Robert Phillips9028bac2020-03-10 16:19:27 -040079 , fIndices(nullptr)
80 , fMeshes(meshes) {
Brian Osman49b7b6f2017-06-20 14:43:58 -040081 this->allocNewBuffers();
Brian Osmaneb86b702017-06-07 11:38:31 -040082 }
83
Brian Osman49b7b6f2017-06-20 14:43:58 -040084 ~PathGeoBuilder() {
Robert Phillips9028bac2020-03-10 16:19:27 -040085 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -040086 }
87
88 /**
89 * Path verbs
90 */
91 void moveTo(const SkPoint& p) {
92 needSpace(1);
93
94 fSubpathIndexStart = this->currentIndex();
95 *(fCurVert++) = p;
96 }
97
98 void addLine(const SkPoint& p) {
99 needSpace(1, this->indexScale());
100
Brian Salomon763abf02018-05-01 18:49:38 +0000101 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400102 uint16_t prevIdx = this->currentIndex() - 1;
103 appendCountourEdgeIndices(prevIdx);
104 }
105 *(fCurVert++) = p;
106 }
107
108 void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
109 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
110 GrPathUtils::kMaxPointsPerCurve * this->indexScale());
111
112 // First pt of quad is the pt we ended on in previous step
113 uint16_t firstQPtIdx = this->currentIndex() - 1;
114 uint16_t numPts = (uint16_t)GrPathUtils::generateQuadraticPoints(
115 pts[0], pts[1], pts[2], srcSpaceTolSqd, &fCurVert,
116 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000117 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400118 for (uint16_t i = 0; i < numPts; ++i) {
119 appendCountourEdgeIndices(firstQPtIdx + i);
120 }
egdanielaf18a092015-01-05 10:22:28 -0800121 }
122 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400123
124 void addConic(SkScalar weight, const SkPoint pts[], SkScalar srcSpaceTolSqd,
125 SkScalar srcSpaceTol) {
126 SkAutoConicToQuads converter;
127 const SkPoint* quadPts = converter.computeQuads(pts, weight, srcSpaceTol);
128 for (int i = 0; i < converter.countQuads(); ++i) {
129 this->addQuad(quadPts + i * 2, srcSpaceTolSqd, srcSpaceTol);
130 }
131 }
132
133 void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
134 this->needSpace(GrPathUtils::kMaxPointsPerCurve,
135 GrPathUtils::kMaxPointsPerCurve * this->indexScale());
136
137 // First pt of cubic is the pt we ended on in previous step
138 uint16_t firstCPtIdx = this->currentIndex() - 1;
139 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
140 pts[0], pts[1], pts[2], pts[3], srcSpaceTolSqd, &fCurVert,
141 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
Brian Salomon763abf02018-05-01 18:49:38 +0000142 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400143 for (uint16_t i = 0; i < numPts; ++i) {
144 appendCountourEdgeIndices(firstCPtIdx + i);
145 }
146 }
147 }
148
149 void addPath(const SkPath& path, SkScalar srcSpaceTol) {
150 SkScalar srcSpaceTolSqd = srcSpaceTol * srcSpaceTol;
151
152 SkPath::Iter iter(path, false);
153 SkPoint pts[4];
154
155 bool done = false;
156 while (!done) {
Mike Reedba7e9a62019-08-16 13:30:34 -0400157 SkPath::Verb verb = iter.next(pts);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400158 switch (verb) {
159 case SkPath::kMove_Verb:
160 this->moveTo(pts[0]);
161 break;
162 case SkPath::kLine_Verb:
163 this->addLine(pts[1]);
164 break;
165 case SkPath::kConic_Verb:
166 this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol);
167 break;
168 case SkPath::kQuad_Verb:
169 this->addQuad(pts, srcSpaceTolSqd, srcSpaceTol);
170 break;
171 case SkPath::kCubic_Verb:
172 this->addCubic(pts, srcSpaceTolSqd, srcSpaceTol);
173 break;
174 case SkPath::kClose_Verb:
175 break;
176 case SkPath::kDone_Verb:
177 done = true;
178 }
179 }
180 }
181
182 static bool PathHasMultipleSubpaths(const SkPath& path) {
183 bool first = true;
184
185 SkPath::Iter iter(path, false);
186 SkPath::Verb verb;
187
188 SkPoint pts[4];
Mike Reedba7e9a62019-08-16 13:30:34 -0400189 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400190 if (SkPath::kMove_Verb == verb && !first) {
191 return true;
192 }
193 first = false;
194 }
195 return false;
196 }
197
198private:
199 /**
200 * Derived properties
201 * TODO: Cache some of these for better performance, rather than re-computing?
202 */
Brian Salomon763abf02018-05-01 18:49:38 +0000203 bool isIndexed() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000204 return GrPrimitiveType::kLines == fPrimitiveType ||
205 GrPrimitiveType::kTriangles == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400206 }
207 bool isHairline() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000208 return GrPrimitiveType::kLines == fPrimitiveType ||
209 GrPrimitiveType::kLineStrip == fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400210 }
211 int indexScale() const {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000212 switch (fPrimitiveType) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400213 case GrPrimitiveType::kLines:
214 return 2;
215 case GrPrimitiveType::kTriangles:
216 return 3;
217 default:
218 return 0;
219 }
220 }
221
222 uint16_t currentIndex() const { return fCurVert - fVertices; }
223
Brian Osman49b7b6f2017-06-20 14:43:58 -0400224 // Allocate vertex and (possibly) index buffers
225 void allocNewBuffers() {
226 // Ensure that we always get enough verts for a worst-case quad/cubic, plus leftover points
227 // from previous mesh piece (up to two verts to continue fanning). If we can't get that
228 // many, ask for a much larger number. This needs to be fairly big to handle quads/cubics,
229 // which have a worst-case of 1k points.
230 static const int kMinVerticesPerChunk = GrPathUtils::kMaxPointsPerCurve + 2;
231 static const int kFallbackVerticesPerChunk = 16384;
232
233 fVertices = static_cast<SkPoint*>(fTarget->makeVertexSpaceAtLeast(fVertexStride,
234 kMinVerticesPerChunk,
235 kFallbackVerticesPerChunk,
236 &fVertexBuffer,
237 &fFirstVertex,
238 &fVerticesInChunk));
239
Brian Salomon763abf02018-05-01 18:49:38 +0000240 if (this->isIndexed()) {
Brian Osman49b7b6f2017-06-20 14:43:58 -0400241 // Similar to above: Ensure we get enough indices for one worst-case quad/cubic.
242 // No extra indices are needed for stitching, though. If we can't get that many, ask
243 // for enough to match our large vertex request.
244 const int kMinIndicesPerChunk = GrPathUtils::kMaxPointsPerCurve * this->indexScale();
245 const int kFallbackIndicesPerChunk = kFallbackVerticesPerChunk * this->indexScale();
246
247 fIndices = fTarget->makeIndexSpaceAtLeast(kMinIndicesPerChunk, kFallbackIndicesPerChunk,
248 &fIndexBuffer, &fFirstIndex,
249 &fIndicesInChunk);
250 }
Brian Osman3902d402017-06-20 15:36:31 -0400251
252 fCurVert = fVertices;
253 fCurIdx = fIndices;
254 fSubpathIndexStart = 0;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400255 }
256
257 void appendCountourEdgeIndices(uint16_t edgeV0Idx) {
258 // When drawing lines we're appending line segments along the countour. When applying the
259 // other fill rules we're drawing triangle fans around the start of the current (sub)path.
260 if (!this->isHairline()) {
261 *(fCurIdx++) = fSubpathIndexStart;
262 }
263 *(fCurIdx++) = edgeV0Idx;
264 *(fCurIdx++) = edgeV0Idx + 1;
265 }
266
267 // Emits a single draw with all accumulated vertex/index data
Robert Phillips9028bac2020-03-10 16:19:27 -0400268 void createMeshAndPutBackReserve() {
Brian Osman3902d402017-06-20 15:36:31 -0400269 int vertexCount = fCurVert - fVertices;
270 int indexCount = fCurIdx - fIndices;
271 SkASSERT(vertexCount <= fVerticesInChunk);
272 SkASSERT(indexCount <= fIndicesInChunk);
273
Chris Daltoneb694b72020-03-16 09:25:50 -0600274 GrSimpleMesh* mesh = nullptr;
Brian Salomon763abf02018-05-01 18:49:38 +0000275 if (this->isIndexed() ? SkToBool(indexCount) : SkToBool(vertexCount)) {
Robert Phillips9028bac2020-03-10 16:19:27 -0400276 mesh = fTarget->allocMesh();
Brian Salomon763abf02018-05-01 18:49:38 +0000277 if (!this->isIndexed()) {
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600278 mesh->set(std::move(fVertexBuffer), vertexCount, fFirstVertex);
Brian Salomon763abf02018-05-01 18:49:38 +0000279 } else {
Brian Salomon12d22642019-01-29 14:38:50 -0500280 mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0,
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600281 vertexCount - 1, GrPrimitiveRestart::kNo, std::move(fVertexBuffer),
282 fFirstVertex);
Brian Osman49b7b6f2017-06-20 14:43:58 -0400283 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400284 }
Brian Osman3902d402017-06-20 15:36:31 -0400285
286 fTarget->putBackIndices((size_t)(fIndicesInChunk - indexCount));
287 fTarget->putBackVertices((size_t)(fVerticesInChunk - vertexCount), fVertexStride);
Robert Phillips9028bac2020-03-10 16:19:27 -0400288
289 if (mesh) {
290 fMeshes->push_back(mesh);
291 }
Brian Osman49b7b6f2017-06-20 14:43:58 -0400292 }
293
294 void needSpace(int vertsNeeded, int indicesNeeded = 0) {
295 if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk ||
296 fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) {
297 // We are about to run out of space (possibly)
298
299 // To maintain continuity, we need to remember one or two points from the current mesh.
300 // Lines only need the last point, fills need the first point from the current contour.
301 // We always grab both here, and append the ones we need at the end of this process.
302 SkPoint lastPt = *(fCurVert - 1);
Brian Osman3902d402017-06-20 15:36:31 -0400303 SkASSERT(fSubpathIndexStart < fVerticesInChunk);
304 SkPoint subpathStartPt = fVertices[fSubpathIndexStart];
Brian Osman49b7b6f2017-06-20 14:43:58 -0400305
Brian Osman3902d402017-06-20 15:36:31 -0400306 // Draw the mesh we've accumulated, and put back any unused space
Robert Phillips9028bac2020-03-10 16:19:27 -0400307 this->createMeshAndPutBackReserve();
Brian Osman49b7b6f2017-06-20 14:43:58 -0400308
Brian Osman3902d402017-06-20 15:36:31 -0400309 // Get new buffers
Brian Osman49b7b6f2017-06-20 14:43:58 -0400310 this->allocNewBuffers();
311
Brian Osman49b7b6f2017-06-20 14:43:58 -0400312 // Append copies of the points we saved so the two meshes will weld properly
313 if (!this->isHairline()) {
314 *(fCurVert++) = subpathStartPt;
315 }
316 *(fCurVert++) = lastPt;
317 }
318 }
319
Brian Salomon7eae3e02018-08-07 14:02:38 +0000320 GrPrimitiveType fPrimitiveType;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400321 GrMeshDrawOp::Target* fTarget;
322 size_t fVertexStride;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400323
Brian Salomon12d22642019-01-29 14:38:50 -0500324 sk_sp<const GrBuffer> fVertexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400325 int fFirstVertex;
326 int fVerticesInChunk;
327 SkPoint* fVertices;
328 SkPoint* fCurVert;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400329
Brian Salomon12d22642019-01-29 14:38:50 -0500330 sk_sp<const GrBuffer> fIndexBuffer;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400331 int fFirstIndex;
332 int fIndicesInChunk;
333 uint16_t* fIndices;
334 uint16_t* fCurIdx;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400335 uint16_t fSubpathIndexStart;
Robert Phillips9028bac2020-03-10 16:19:27 -0400336
Chris Daltoneb694b72020-03-16 09:25:50 -0600337 SkTDArray<GrSimpleMesh*>* fMeshes;
Brian Osman49b7b6f2017-06-20 14:43:58 -0400338};
egdanielaf18a092015-01-05 10:22:28 -0800339
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400340class DefaultPathOp final : public GrMeshDrawOp {
341private:
342 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
343
joshualitt332c7292015-02-23 08:44:31 -0800344public:
Brian Salomon25a88092016-12-01 09:36:50 -0500345 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -0700346
Robert Phillipsb97da532019-02-12 15:24:12 -0500347 static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -0400348 GrPaint&& paint,
349 const SkPath& path,
350 SkScalar tolerance,
351 uint8_t coverage,
352 const SkMatrix& viewMatrix,
353 bool isHairline,
354 GrAAType aaType,
355 const SkRect& devBounds,
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400356 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400357 return Helper::FactoryHelper<DefaultPathOp>(context, std::move(paint), path, tolerance,
358 coverage, viewMatrix, isHairline, aaType,
359 devBounds, stencilSettings);
bsalomon@google.com30085192011-08-19 15:42:31 +0000360 }
361
Brian Salomon780dad12016-12-15 18:08:40 -0500362 const char* name() const override { return "DefaultPathOp"; }
bsalomon@google.com30085192011-08-19 15:42:31 +0000363
Chris Dalton1706cbf2019-05-21 19:35:29 -0600364 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400365 if (fProgramInfo) {
Chris Daltonbe457422020-03-16 18:05:03 -0600366 fProgramInfo->visitFPProxies(func);
Robert Phillips9028bac2020-03-10 16:19:27 -0400367 } else {
368 fHelper.visitProxies(func);
369 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400370 }
371
Brian Osmancf860852018-10-31 14:04:39 -0400372 DefaultPathOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, const SkPath& path,
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400373 SkScalar tolerance, uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline,
374 GrAAType aaType, const SkRect& devBounds,
375 const GrUserStencilSettings* stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500376 : INHERITED(ClassID())
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400377 , fHelper(helperArgs, aaType, stencilSettings)
Brian Salomon780dad12016-12-15 18:08:40 -0500378 , fColor(color)
379 , fCoverage(coverage)
380 , fViewMatrix(viewMatrix)
381 , fIsHairline(isHairline) {
382 fPaths.emplace_back(PathData{path, tolerance});
joshualitt332c7292015-02-23 08:44:31 -0800383
Greg Daniel5faf4742019-10-01 15:14:44 -0400384 HasAABloat aaBloat = (aaType == GrAAType::kNone) ? HasAABloat ::kNo : HasAABloat::kYes;
385 this->setBounds(devBounds, aaBloat,
386 isHairline ? IsHairline::kYes : IsHairline::kNo);
Brian Salomon780dad12016-12-15 18:08:40 -0500387 }
388
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400389 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
390
Chris Dalton6ce447a2019-06-23 18:07:38 -0600391 GrProcessorSet::Analysis finalize(
392 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
393 GrClampType clampType) override {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400394 GrProcessorAnalysisCoverage gpCoverage =
395 this->coverage() == 0xFF ? GrProcessorAnalysisCoverage::kNone
396 : GrProcessorAnalysisCoverage::kSingleChannel;
Brian Osman8fa7ab42019-03-18 10:22:42 -0400397 // This Op uses uniform (not vertex) color, so doesn't need to track wide color.
398 return fHelper.finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600399 caps, clip, hasMixedSampledCoverage, clampType, gpCoverage, &fColor, nullptr);
Brian Salomon92aee3d2016-12-21 09:20:25 -0500400 }
401
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400402private:
Robert Phillips9028bac2020-03-10 16:19:27 -0400403 GrPrimitiveType primType() const {
404 if (this->isHairline()) {
405 int instanceCount = fPaths.count();
406
407 // We avoid indices when we have a single hairline contour.
408 bool isIndexed = instanceCount > 1 ||
409 PathGeoBuilder::PathHasMultipleSubpaths(fPaths[0].fPath);
410
411 return isIndexed ? GrPrimitiveType::kLines : GrPrimitiveType::kLineStrip;
412 }
413
414 return GrPrimitiveType::kTriangles;
415 }
416
Robert Phillips2669a7b2020-03-12 12:07:19 -0400417 GrProgramInfo* programInfo() override { return fProgramInfo; }
418
Robert Phillips4133dc42020-03-11 15:55:55 -0400419 void onCreateProgramInfo(const GrCaps* caps,
420 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400421 const GrSurfaceProxyView* writeView,
Robert Phillips4133dc42020-03-11 15:55:55 -0400422 GrAppliedClip&& appliedClip,
423 const GrXferProcessor::DstProxyView& dstProxyView) 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),
442 dstProxyView, gp, this->primType());
Brian Salomon763abf02018-05-01 18:49:38 +0000443
Robert Phillips9028bac2020-03-10 16:19:27 -0400444 }
Brian Osman7f95dfc2017-06-09 14:43:49 +0000445
Robert Phillips9028bac2020-03-10 16:19:27 -0400446 void onPrepareDraws(Target* target) override {
447 PathGeoBuilder pathGeoBuilder(this->primType(), target, &fMeshes);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000448
449 // fill buffers
Robert Phillips9028bac2020-03-10 16:19:27 -0400450 for (int i = 0; i < fPaths.count(); i++) {
Brian Salomon763abf02018-05-01 18:49:38 +0000451 const PathData& args = fPaths[i];
452 pathGeoBuilder.addPath(args.fPath, args.fTolerance);
Brian Osman7f95dfc2017-06-09 14:43:49 +0000453 }
joshualitt332c7292015-02-23 08:44:31 -0800454 }
455
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700456 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
Robert Phillips9028bac2020-03-10 16:19:27 -0400457 if (!fProgramInfo) {
Robert Phillips4133dc42020-03-11 15:55:55 -0400458 this->createProgramInfo(flushState);
Robert Phillips9028bac2020-03-10 16:19:27 -0400459 }
Robert Phillips3968fcb2019-12-05 16:40:31 -0500460
Robert Phillips9028bac2020-03-10 16:19:27 -0400461 if (!fProgramInfo || !fMeshes.count()) {
462 return;
463 }
464
Chris Dalton765ed362020-03-16 17:34:44 -0600465 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
466 flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline());
Robert Phillips9028bac2020-03-10 16:19:27 -0400467 for (int i = 0; i < fMeshes.count(); ++i) {
Chris Dalton765ed362020-03-16 17:34:44 -0600468 flushState->drawMesh(*fMeshes[i]);
Robert Phillips9028bac2020-03-10 16:19:27 -0400469 }
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700470 }
471
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500472 CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
473 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
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400531 typedef GrMeshDrawOp INHERITED;
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 Osman11052242016-10-27 14:47:55 -0400536bool GrDefaultPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetContext,
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) {
Robert Phillipsb97da532019-02-12 15:24:12 -0500544 auto context = renderTargetContext->surfPriv().getContext();
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;
Robert Phillipse9462dd2019-10-23 12:41:29 -0400632 GetPathDevBounds(path, renderTargetContext->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);
Michael Ludwigaa1b6b32019-05-29 14:43:13 -0400658 renderTargetContext->priv().stencilRect(clip, passes[p], std::move(paint),
659 GrAA(aaType == GrAAType::kMSAA), viewM, bounds, &localMatrix);
robertphillips976f5f02016-06-03 10:59:20 -0700660 } else {
Brian Salomond4652ca2017-01-13 12:11:36 -0500661 bool stencilPass = stencilOnly || passCount > 1;
Brian Salomonb74ef032017-08-10 12:46:01 -0400662 std::unique_ptr<GrDrawOp> op;
Brian Salomond4652ca2017-01-13 12:11:36 -0500663 if (stencilPass) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400664 GrPaint stencilPaint;
665 stencilPaint.setXPFactory(GrDisableColorXPFactory::Get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400666 op = DefaultPathOp::Make(context, std::move(stencilPaint), path, srcSpaceTol,
667 newCoverage, viewMatrix, isHairline, aaType, devBounds,
668 passes[p]);
Brian Salomonb74ef032017-08-10 12:46:01 -0400669 } else {
Mike Klein16885072018-12-11 09:54:31 -0500670 assert_alive(paint);
Robert Phillips7c525e62018-06-12 10:11:12 -0400671 op = DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, newCoverage,
Brian Salomonb74ef032017-08-10 12:46:01 -0400672 viewMatrix, isHairline, aaType, devBounds, passes[p]);
Brian Salomond4652ca2017-01-13 12:11:36 -0500673 }
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400674 renderTargetContext->addDrawOp(clip, std::move(op));
bsalomon@google.com30085192011-08-19 15:42:31 +0000675 }
676 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000677 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000678}
679
Chris Dalton5ed44232017-09-07 13:22:46 -0600680GrPathRenderer::CanDrawPath
681GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Chris Dalton09e56892019-03-13 00:22:01 -0600682 bool isHairline = IsStrokeHairlineOrEquivalent(
683 args.fShape->style(), *args.fViewMatrix, nullptr);
Eric Karl5c779752017-05-08 12:02:07 -0700684 // If we aren't a single_pass_shape or hairline, we require stencil buffers.
Greg Danielbe7fc462019-01-03 16:40:42 -0500685 if (!(single_pass_shape(*args.fShape) || isHairline) &&
686 (args.fCaps->avoidStencilBuffers() || args.fTargetIsWrappedVkSecondaryCB)) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600687 return CanDrawPath::kNo;
Eric Karl5c779752017-05-08 12:02:07 -0700688 }
Chris Dalton09e56892019-03-13 00:22:01 -0600689 // If antialiasing is required, we only support MSAA.
Chris Dalton6ce447a2019-06-23 18:07:38 -0600690 if (GrAAType::kNone != args.fAAType && GrAAType::kMSAA != args.fAAType) {
Chris Dalton09e56892019-03-13 00:22:01 -0600691 return CanDrawPath::kNo;
692 }
693 // This can draw any path with any simple fill style.
694 if (!args.fShape->style().isSimpleFill() && !isHairline) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600695 return CanDrawPath::kNo;
696 }
697 // This is the fallback renderer for when a path is too complicated for the others to draw.
698 return CanDrawPath::kAsBackup;
bsalomon@google.com30085192011-08-19 15:42:31 +0000699}
700
bsalomon0aff2fa2015-07-31 06:48:27 -0700701bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400702 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700703 "GrDefaultPathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -0600704 GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone;
Chris Dalton09e56892019-03-13 00:22:01 -0600705
706 return this->internalDrawPath(
707 args.fRenderTargetContext, std::move(args.fPaint), aaType, *args.fUserStencilSettings,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400708 args.fClip, *args.fViewMatrix, *args.fShape, false);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000709}
710
bsalomon0aff2fa2015-07-31 06:48:27 -0700711void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400712 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700713 "GrDefaultPathRenderer::onStencilPath");
bsalomon8acedde2016-06-24 10:42:16 -0700714 SkASSERT(!args.fShape->inverseFilled());
robertphillips976f5f02016-06-03 10:59:20 -0700715
716 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500717 paint.setXPFactory(GrDisableColorXPFactory::Get());
robertphillips976f5f02016-06-03 10:59:20 -0700718
Chris Dalton09e56892019-03-13 00:22:01 -0600719 auto aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
720
721 this->internalDrawPath(
722 args.fRenderTargetContext, std::move(paint), aaType, GrUserStencilSettings::kUnused,
Michael Ludwig7c12e282020-05-29 09:54:07 -0400723 args.fClip, *args.fViewMatrix, *args.fShape, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000724}
joshualitt622d3ad2015-05-07 08:13:11 -0700725
726///////////////////////////////////////////////////////////////////////////////////////////////////
727
Hal Canary6f6961e2017-01-31 13:50:44 -0500728#if GR_TEST_UTILS
joshualitt622d3ad2015-05-07 08:13:11 -0700729
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400730GR_DRAW_OP_TEST_DEFINE(DefaultPathOp) {
joshualitt622d3ad2015-05-07 08:13:11 -0700731 SkMatrix viewMatrix = GrTest::TestMatrix(random);
732
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500733 // For now just hairlines because the other types of draws require two ops.
734 // TODO we should figure out a way to combine the stencil and cover steps into one op.
bsalomon6663acf2016-05-10 09:14:17 -0700735 GrStyle style(SkStrokeRec::kHairline_InitStyle);
John Stiles31954bf2020-08-07 17:35:54 -0400736 const SkPath& path = GrTest::TestPath(random);
joshualitt622d3ad2015-05-07 08:13:11 -0700737
738 // Compute srcSpaceTol
739 SkRect bounds = path.getBounds();
740 SkScalar tol = GrPathUtils::kDefaultTolerance;
741 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds);
742
joshualitt622d3ad2015-05-07 08:13:11 -0700743 viewMatrix.mapRect(&bounds);
744 uint8_t coverage = GrRandomCoverage(random);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400745 GrAAType aaType = GrAAType::kNone;
Chris Dalton6ce447a2019-06-23 18:07:38 -0600746 if (numSamples > 1 && random->nextBool()) {
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400747 aaType = GrAAType::kMSAA;
748 }
Robert Phillips7c525e62018-06-12 10:11:12 -0400749 return DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, coverage, viewMatrix,
750 true, aaType, bounds, GrGetRandomStencil(random, context));
joshualitt622d3ad2015-05-07 08:13:11 -0700751}
752
753#endif