blob: 0f3508ba48c4481b1b3e35359ae6a90583045312 [file] [log] [blame]
ethannicholas1a1b3ac2015-06-10 12:11:17 -07001/*
2 * Copyright 2015 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 "include/core/SkString.h"
9#include "src/core/SkGeometry.h"
10#include "src/core/SkPathPriv.h"
11#include "src/core/SkTraceEvent.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrCaps.h"
14#include "src/gpu/GrDefaultGeoProcFactory.h"
15#include "src/gpu/GrDrawOpTest.h"
16#include "src/gpu/GrGeometryProcessor.h"
17#include "src/gpu/GrOpFlushState.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrProcessor.h"
19#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrStyle.h"
21#include "src/gpu/GrVertexWriter.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040022#include "src/gpu/geometry/GrPathUtils.h"
23#include "src/gpu/geometry/GrShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
25#include "src/gpu/ops/GrAAConvexTessellator.h"
26#include "src/gpu/ops/GrAALinearizingConvexPathRenderer.h"
27#include "src/gpu/ops/GrMeshDrawOp.h"
28#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070029
fmalitabd5d7e72015-06-26 07:18:24 -070030static const int DEFAULT_BUFFER_SIZE = 100;
31
32// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For
33// the time being, we simply drop back to software rendering above this stroke width.
34static const SkScalar kMaxStrokeWidth = 20.0;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070035
36GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
37}
38
39///////////////////////////////////////////////////////////////////////////////
40
Chris Dalton5ed44232017-09-07 13:22:46 -060041GrPathRenderer::CanDrawPath
42GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Chris Dalton6ce447a2019-06-23 18:07:38 -060043 if (GrAAType::kCoverage != args.fAAType) {
Chris Dalton5ed44232017-09-07 13:22:46 -060044 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070045 }
bsalomon8acedde2016-06-24 10:42:16 -070046 if (!args.fShape->knownToBeConvex()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060047 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070048 }
bsalomon8acedde2016-06-24 10:42:16 -070049 if (args.fShape->style().pathEffect()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060050 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070051 }
bsalomon8acedde2016-06-24 10:42:16 -070052 if (args.fShape->inverseFilled()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060053 return CanDrawPath::kNo;
bsalomon6663acf2016-05-10 09:14:17 -070054 }
Brian Osmana98e3992017-06-26 15:14:53 -040055 if (args.fShape->bounds().width() <= 0 && args.fShape->bounds().height() <= 0) {
56 // Stroked zero length lines should draw, but this PR doesn't handle that case
Chris Dalton5ed44232017-09-07 13:22:46 -060057 return CanDrawPath::kNo;
Brian Osmana98e3992017-06-26 15:14:53 -040058 }
bsalomon8acedde2016-06-24 10:42:16 -070059 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
robertphillips8c170972016-09-22 12:42:30 -070060
61 if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
62 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
ethannicholasfea77632015-08-19 12:09:12 -070063 if (!args.fViewMatrix->isSimilarity()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060064 return CanDrawPath::kNo;
ethannicholasfea77632015-08-19 12:09:12 -070065 }
bsalomon6663acf2016-05-10 09:14:17 -070066 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * stroke.getWidth();
robertphillips8c170972016-09-22 12:42:30 -070067 if (strokeWidth < 1.0f && stroke.getStyle() == SkStrokeRec::kStroke_Style) {
Chris Dalton5ed44232017-09-07 13:22:46 -060068 return CanDrawPath::kNo;
robertphillips8c170972016-09-22 12:42:30 -070069 }
Chris Dalton5ed44232017-09-07 13:22:46 -060070 if (strokeWidth > kMaxStrokeWidth ||
71 !args.fShape->knownToBeClosed() ||
72 stroke.getJoin() == SkPaint::Join::kRound_Join) {
73 return CanDrawPath::kNo;
74 }
75 return CanDrawPath::kYes;
fmalitabd5d7e72015-06-26 07:18:24 -070076 }
Chris Dalton5ed44232017-09-07 13:22:46 -060077 if (stroke.getStyle() != SkStrokeRec::kFill_Style) {
78 return CanDrawPath::kNo;
79 }
80 return CanDrawPath::kYes;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070081}
82
83// extract the result vertices and indices from the GrAAConvexTessellator
84static void extract_verts(const GrAAConvexTessellator& tess,
Brian Osmanf9aabff2018-11-13 16:11:38 -050085 void* vertData,
Brian Osman80879d42019-01-07 16:15:27 -050086 const GrVertexColor& color,
ethannicholas1a1b3ac2015-06-10 12:11:17 -070087 uint16_t firstIndex,
Brian Osman0995fd52019-01-09 09:52:25 -050088 uint16_t* idxs) {
Brian Osmanf9aabff2018-11-13 16:11:38 -050089 GrVertexWriter verts{vertData};
Brian Osmanf3e6b902018-12-28 17:43:50 +000090 for (int i = 0; i < tess.numPts(); ++i) {
Brian Osman80879d42019-01-07 16:15:27 -050091 verts.write(tess.point(i), color, tess.coverage(i));
ethannicholas1a1b3ac2015-06-10 12:11:17 -070092 }
93
94 for (int i = 0; i < tess.numIndices(); ++i) {
95 idxs[i] = tess.index(i) + firstIndex;
96 }
97}
98
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050099static GrGeometryProcessor* create_lines_only_gp(SkArenaAlloc* arena,
100 const GrShaderCaps* shaderCaps,
101 bool tweakAlphaForCoverage,
102 const SkMatrix& viewMatrix,
103 bool usesLocalCoords,
104 bool wideColor) {
joshualittdf0c5572015-08-03 11:35:28 -0700105 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700106
Brian Osman80879d42019-01-07 16:15:27 -0500107 Coverage::Type coverageType =
108 tweakAlphaForCoverage ? Coverage::kAttributeTweakAlpha_Type : Coverage::kAttribute_Type;
Brian Salomon8c852be2017-01-04 10:44:42 -0500109 LocalCoords::Type localCoordsType =
Brian Osman80879d42019-01-07 16:15:27 -0500110 usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
111 Color::Type colorType =
112 wideColor ? Color::kPremulWideColorAttribute_Type : Color::kPremulGrColorAttribute_Type;
113
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500114 return MakeForDeviceSpace(arena, shaderCaps, colorType, coverageType,
115 localCoordsType, viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700116}
117
Brian Salomonb2955732017-07-13 16:42:55 -0400118namespace {
119
120class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
121private:
122 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
123
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700124public:
Brian Salomon25a88092016-12-01 09:36:50 -0500125 DEFINE_OP_CLASS_ID
Robert Phillipsb97da532019-02-12 15:24:12 -0500126 static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -0400127 GrPaint&& paint,
Brian Salomonb2955732017-07-13 16:42:55 -0400128 const SkMatrix& viewMatrix,
129 const SkPath& path,
130 SkScalar strokeWidth,
131 SkStrokeRec::Style style,
132 SkPaint::Join join,
133 SkScalar miterLimit,
134 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400135 return Helper::FactoryHelper<AAFlatteningConvexPathOp>(context, std::move(paint),
136 viewMatrix, path,
Brian Salomonb2955732017-07-13 16:42:55 -0400137 strokeWidth, style, join, miterLimit,
138 stencilSettings);
Brian Salomon780dad12016-12-15 18:08:40 -0500139 }
140
Brian Salomonb2955732017-07-13 16:42:55 -0400141 AAFlatteningConvexPathOp(const Helper::MakeArgs& helperArgs,
Brian Osmancf860852018-10-31 14:04:39 -0400142 const SkPMColor4f& color,
Brian Salomon780dad12016-12-15 18:08:40 -0500143 const SkMatrix& viewMatrix,
144 const SkPath& path,
145 SkScalar strokeWidth,
146 SkStrokeRec::Style style,
147 SkPaint::Join join,
Brian Salomonb2955732017-07-13 16:42:55 -0400148 SkScalar miterLimit,
149 const GrUserStencilSettings* stencilSettings)
150 : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) {
Brian Salomon780dad12016-12-15 18:08:40 -0500151 fPaths.emplace_back(
152 PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700153
bsalomon0432dd62016-06-30 07:19:27 -0700154 // compute bounds
bsalomon88cf17d2016-07-08 06:40:56 -0700155 SkRect bounds = path.getBounds();
bsalomon0432dd62016-06-30 07:19:27 -0700156 SkScalar w = strokeWidth;
157 if (w > 0) {
158 w /= 2;
Greg Daniel55e5be32019-09-30 12:23:26 -0400159 SkScalar maxScale = viewMatrix.getMaxScale();
160 // We should not have a perspective matrix, thus we should have a valid scale.
161 SkASSERT(maxScale != -1);
162 if (SkPaint::kMiter_Join == join && w * maxScale > 1.f) {
bsalomon0432dd62016-06-30 07:19:27 -0700163 w *= miterLimit;
164 }
bsalomon88cf17d2016-07-08 06:40:56 -0700165 bounds.outset(w, w);
bsalomon0432dd62016-06-30 07:19:27 -0700166 }
Greg Daniel5faf4742019-10-01 15:14:44 -0400167 this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsHairline::kNo);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700168 }
169
Brian Salomonb2955732017-07-13 16:42:55 -0400170 const char* name() const override { return "AAFlatteningConvexPathOp"; }
171
Chris Dalton1706cbf2019-05-21 19:35:29 -0600172 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400173 fHelper.visitProxies(func);
174 }
175
Brian Osman9a390ac2018-11-12 09:47:48 -0500176#ifdef SK_DEBUG
Brian Salomonb2955732017-07-13 16:42:55 -0400177 SkString dumpInfo() const override {
178 SkString string;
179 for (const auto& path : fPaths) {
180 string.appendf(
181 "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
182 "MiterLimit: %.2f\n",
Brian Osmancf860852018-10-31 14:04:39 -0400183 path.fColor.toBytes_RGBA(), path.fStrokeWidth, path.fStyle, path.fJoin,
Brian Osman1be2b7c2018-10-29 16:07:15 -0400184 path.fMiterLimit);
Brian Salomonb2955732017-07-13 16:42:55 -0400185 }
186 string += fHelper.dumpInfo();
187 string += INHERITED::dumpInfo();
188 return string;
Brian Salomon92aee3d2016-12-21 09:20:25 -0500189 }
Brian Osman9a390ac2018-11-12 09:47:48 -0500190#endif
Brian Salomon92aee3d2016-12-21 09:20:25 -0500191
Brian Salomonb2955732017-07-13 16:42:55 -0400192 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
193
Chris Dalton6ce447a2019-06-23 18:07:38 -0600194 GrProcessorSet::Analysis finalize(
195 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
196 GrClampType clampType) override {
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700197 return fHelper.finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600198 caps, clip, hasMixedSampledCoverage, clampType,
199 GrProcessorAnalysisCoverage::kSingleChannel, &fPaths.back().fColor, &fWideColor);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700200 }
201
Brian Salomonb2955732017-07-13 16:42:55 -0400202private:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500203 void recordDraw(Target* target, const GrGeometryProcessor* gp, int vertexCount,
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700204 size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700205 if (vertexCount == 0 || indexCount == 0) {
206 return;
207 }
Brian Salomon12d22642019-01-29 14:38:50 -0500208 sk_sp<const GrBuffer> vertexBuffer;
Chris Daltonbca46e22017-05-15 11:03:26 -0600209 int firstVertex;
mtklein002c2ce2015-08-26 05:43:22 -0700210 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
Chris Daltonbca46e22017-05-15 11:03:26 -0600211 &firstVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700212 if (!verts) {
213 SkDebugf("Could not allocate vertices\n");
214 return;
215 }
216 memcpy(verts, vertices, vertexCount * vertexStride);
217
Brian Salomon12d22642019-01-29 14:38:50 -0500218 sk_sp<const GrBuffer> indexBuffer;
Chris Daltonbca46e22017-05-15 11:03:26 -0600219 int firstIndex;
220 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700221 if (!idxs) {
222 SkDebugf("Could not allocate indices\n");
223 return;
224 }
225 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
Brian Salomon7eae3e02018-08-07 14:02:38 +0000226 GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
Brian Salomon12d22642019-01-29 14:38:50 -0500227 mesh->setIndexed(std::move(indexBuffer), indexCount, firstIndex, 0, vertexCount - 1,
Brian Salomon7eae3e02018-08-07 14:02:38 +0000228 GrPrimitiveRestart::kNo);
Brian Salomon12d22642019-01-29 14:38:50 -0500229 mesh->setVertexData(std::move(vertexBuffer), firstVertex);
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500230 target->recordDraw(gp, mesh, 1, GrPrimitiveType::kTriangles);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700231 }
mtklein002c2ce2015-08-26 05:43:22 -0700232
Brian Salomon91326c32017-08-09 16:02:19 -0400233 void onPrepareDraws(Target* target) override {
joshualittdf0c5572015-08-03 11:35:28 -0700234 // Setup GrGeometryProcessor
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500235 GrGeometryProcessor* gp = create_lines_only_gp(target->allocator(),
236 target->caps().shaderCaps(),
237 fHelper.compatibleWithCoverageAsAlpha(),
238 this->viewMatrix(),
239 fHelper.usesLocalCoords(),
240 fWideColor);
joshualittdf0c5572015-08-03 11:35:28 -0700241 if (!gp) {
242 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700243 return;
244 }
245
Brian Osmanf04fb3c2018-11-12 15:34:00 -0500246 size_t vertexStride = gp->vertexStride();
Brian Salomon780dad12016-12-15 18:08:40 -0500247 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700248
Greg Danield5b45932018-06-07 13:15:10 -0400249 int64_t vertexCount = 0;
250 int64_t indexCount = 0;
251 int64_t maxVertices = DEFAULT_BUFFER_SIZE;
252 int64_t maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700253 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
254 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700255 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500256 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700257 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
258 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700259
260 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
261 continue;
262 }
263
Greg Danield5b45932018-06-07 13:15:10 -0400264 int currentVertices = tess.numPts();
265 if (vertexCount + currentVertices > static_cast<int>(UINT16_MAX)) {
mtklein002c2ce2015-08-26 05:43:22 -0700266 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700267 // uint16_t. Draw what we've got so far and reset.
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700268 this->recordDraw(
269 target, gp, vertexCount, vertexStride, vertices, indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700270 vertexCount = 0;
271 indexCount = 0;
272 }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700273 if (vertexCount + currentVertices > maxVertices) {
274 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
Greg Danield5b45932018-06-07 13:15:10 -0400275 if (maxVertices * vertexStride > SK_MaxS32) {
276 sk_free(vertices);
277 sk_free(indices);
278 return;
279 }
mtklein002c2ce2015-08-26 05:43:22 -0700280 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700281 }
Greg Danield5b45932018-06-07 13:15:10 -0400282 int currentIndices = tess.numIndices();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700283 if (indexCount + currentIndices > maxIndices) {
284 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
Greg Danield5b45932018-06-07 13:15:10 -0400285 if (maxIndices * sizeof(uint16_t) > SK_MaxS32) {
286 sk_free(vertices);
287 sk_free(indices);
288 return;
289 }
mtklein002c2ce2015-08-26 05:43:22 -0700290 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700291 }
292
Brian Osman80879d42019-01-07 16:15:27 -0500293 extract_verts(tess, vertices + vertexStride * vertexCount,
Brian Osman0995fd52019-01-09 09:52:25 -0500294 GrVertexColor(args.fColor, fWideColor), vertexCount,
295 indices + indexCount);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700296 vertexCount += currentVertices;
297 indexCount += currentIndices;
298 }
Greg Danield5b45932018-06-07 13:15:10 -0400299 if (vertexCount <= SK_MaxS32 && indexCount <= SK_MaxS32) {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500300 this->recordDraw(target, gp, vertexCount, vertexStride, vertices, indexCount, indices);
Greg Danield5b45932018-06-07 13:15:10 -0400301 }
mtklein002c2ce2015-08-26 05:43:22 -0700302 sk_free(vertices);
303 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700304 }
305
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700306 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
307 fHelper.executeDrawsAndUploads(this, flushState, chainBounds);
308 }
309
Brian Salomon7eae3e02018-08-07 14:02:38 +0000310 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500311 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
Brian Salomonb2955732017-07-13 16:42:55 -0400312 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000313 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700314 }
315
Brian Salomon780dad12016-12-15 18:08:40 -0500316 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
Brian Osman80879d42019-01-07 16:15:27 -0500317 fWideColor |= that->fWideColor;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000318 return CombineResult::kMerged;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700319 }
320
Brian Salomon780dad12016-12-15 18:08:40 -0500321 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700322
Brian Salomon780dad12016-12-15 18:08:40 -0500323 struct PathData {
Brian Osmancf860852018-10-31 14:04:39 -0400324 SkPMColor4f fColor;
bsalomon0432dd62016-06-30 07:19:27 -0700325 SkMatrix fViewMatrix;
326 SkPath fPath;
327 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700328 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700329 SkPaint::Join fJoin;
330 SkScalar fMiterLimit;
331 };
332
Brian Salomon780dad12016-12-15 18:08:40 -0500333 SkSTArray<1, PathData, true> fPaths;
Brian Salomonb2955732017-07-13 16:42:55 -0400334 Helper fHelper;
Brian Osman80879d42019-01-07 16:15:27 -0500335 bool fWideColor;
reed1b55a962015-09-17 20:16:13 -0700336
Brian Salomonb2955732017-07-13 16:42:55 -0400337 typedef GrMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700338};
339
Brian Salomonb2955732017-07-13 16:42:55 -0400340} // anonymous namespace
341
bsalomon0aff2fa2015-07-31 06:48:27 -0700342bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400343 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800344 "GrAALinearizingConvexPathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -0600345 SkASSERT(args.fRenderTargetContext->numSamples() <= 1);
bsalomon8acedde2016-06-24 10:42:16 -0700346 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700347 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700348
bsalomon0432dd62016-06-30 07:19:27 -0700349 SkPath path;
350 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700351 bool fill = args.fShape->style().isSimpleFill();
352 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700353 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
354 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
355 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700356
Brian Salomonb2955732017-07-13 16:42:55 -0400357 std::unique_ptr<GrDrawOp> op = AAFlatteningConvexPathOp::Make(
Robert Phillips7c525e62018-06-12 10:11:12 -0400358 args.fContext, std::move(args.fPaint), *args.fViewMatrix, path, strokeWidth,
359 stroke.getStyle(), join, miterLimit, args.fUserStencilSettings);
Brian Salomonb2955732017-07-13 16:42:55 -0400360 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700361 return true;
362}
363
364///////////////////////////////////////////////////////////////////////////////////////////////////
365
Hal Canary6f6961e2017-01-31 13:50:44 -0500366#if GR_TEST_UTILS
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700367
Brian Salomonb2955732017-07-13 16:42:55 -0400368GR_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
Brian Salomon780dad12016-12-15 18:08:40 -0500369 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700370 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700371
372 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500373 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700374 SkStrokeRec::kStrokeAndFill_Style };
375
376 SkStrokeRec::Style style = styles[random->nextU() % 3];
377
378 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700379 SkPaint::Join join = SkPaint::kMiter_Join;
380 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700381
382 if (SkStrokeRec::kFill_Style != style) {
383 strokeWidth = random->nextRangeF(1.0f, 10.0f);
384 if (random->nextBool()) {
385 join = SkPaint::kMiter_Join;
386 } else {
387 join = SkPaint::kBevel_Join;
388 }
389 miterLimit = random->nextRangeF(0.5f, 2.0f);
390 }
Brian Salomonb2955732017-07-13 16:42:55 -0400391 const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context);
Robert Phillips7c525e62018-06-12 10:11:12 -0400392 return AAFlatteningConvexPathOp::Make(context, std::move(paint), viewMatrix, path, strokeWidth,
393 style, join, miterLimit, stencilSettings);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700394}
395
396#endif