blob: b007245b43089e4361ddd46df1b419af79f99a97 [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
8#include "GrAALinearizingConvexPathRenderer.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -07009#include "GrAAConvexTessellator.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070010#include "GrContext.h"
11#include "GrDefaultGeoProcFactory.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050012#include "GrDrawOpTest.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070013#include "GrGeometryProcessor.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050014#include "GrOpFlushState.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070015#include "GrPathUtils.h"
Brian Salomondad29232016-12-01 16:40:24 -050016#include "GrProcessor.h"
Brian Salomon653f42f2018-07-10 10:07:31 -040017#include "GrRenderTargetContext.h"
18#include "GrShape.h"
bsalomon6663acf2016-05-10 09:14:17 -070019#include "GrStyle.h"
Brian Osmanf9aabff2018-11-13 16:11:38 -050020#include "GrVertexWriter.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070021#include "SkGeometry.h"
Brian Salomondad29232016-12-01 16:40:24 -050022#include "SkPathPriv.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070023#include "SkString.h"
24#include "SkTraceEvent.h"
egdaniele659a582015-11-13 09:55:43 -080025#include "glsl/GrGLSLGeometryProcessor.h"
Brian Salomon89527432016-12-16 09:52:16 -050026#include "ops/GrMeshDrawOp.h"
Brian Salomonb2955732017-07-13 16:42:55 -040027#include "ops/GrSimpleMeshDrawOpHelper.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070028
fmalitabd5d7e72015-06-26 07:18:24 -070029static const int DEFAULT_BUFFER_SIZE = 100;
30
31// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For
32// the time being, we simply drop back to software rendering above this stroke width.
33static const SkScalar kMaxStrokeWidth = 20.0;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070034
35GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
36}
37
38///////////////////////////////////////////////////////////////////////////////
39
Chris Dalton5ed44232017-09-07 13:22:46 -060040GrPathRenderer::CanDrawPath
41GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050042 if (GrAAType::kCoverage != args.fAAType) {
Chris Dalton5ed44232017-09-07 13:22:46 -060043 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070044 }
bsalomon8acedde2016-06-24 10:42:16 -070045 if (!args.fShape->knownToBeConvex()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060046 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070047 }
bsalomon8acedde2016-06-24 10:42:16 -070048 if (args.fShape->style().pathEffect()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060049 return CanDrawPath::kNo;
fmalitabd5d7e72015-06-26 07:18:24 -070050 }
bsalomon8acedde2016-06-24 10:42:16 -070051 if (args.fShape->inverseFilled()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060052 return CanDrawPath::kNo;
bsalomon6663acf2016-05-10 09:14:17 -070053 }
Brian Osmana98e3992017-06-26 15:14:53 -040054 if (args.fShape->bounds().width() <= 0 && args.fShape->bounds().height() <= 0) {
55 // Stroked zero length lines should draw, but this PR doesn't handle that case
Chris Dalton5ed44232017-09-07 13:22:46 -060056 return CanDrawPath::kNo;
Brian Osmana98e3992017-06-26 15:14:53 -040057 }
bsalomon8acedde2016-06-24 10:42:16 -070058 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
robertphillips8c170972016-09-22 12:42:30 -070059
60 if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
61 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
ethannicholasfea77632015-08-19 12:09:12 -070062 if (!args.fViewMatrix->isSimilarity()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060063 return CanDrawPath::kNo;
ethannicholasfea77632015-08-19 12:09:12 -070064 }
bsalomon6663acf2016-05-10 09:14:17 -070065 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * stroke.getWidth();
robertphillips8c170972016-09-22 12:42:30 -070066 if (strokeWidth < 1.0f && stroke.getStyle() == SkStrokeRec::kStroke_Style) {
Chris Dalton5ed44232017-09-07 13:22:46 -060067 return CanDrawPath::kNo;
robertphillips8c170972016-09-22 12:42:30 -070068 }
Chris Dalton5ed44232017-09-07 13:22:46 -060069 if (strokeWidth > kMaxStrokeWidth ||
70 !args.fShape->knownToBeClosed() ||
71 stroke.getJoin() == SkPaint::Join::kRound_Join) {
72 return CanDrawPath::kNo;
73 }
74 return CanDrawPath::kYes;
fmalitabd5d7e72015-06-26 07:18:24 -070075 }
Chris Dalton5ed44232017-09-07 13:22:46 -060076 if (stroke.getStyle() != SkStrokeRec::kFill_Style) {
77 return CanDrawPath::kNo;
78 }
79 return CanDrawPath::kYes;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070080}
81
82// extract the result vertices and indices from the GrAAConvexTessellator
83static void extract_verts(const GrAAConvexTessellator& tess,
Brian Osmanf9aabff2018-11-13 16:11:38 -050084 void* vertData,
Brian Osman80879d42019-01-07 16:15:27 -050085 const GrVertexColor& color,
ethannicholas1a1b3ac2015-06-10 12:11:17 -070086 uint16_t firstIndex,
Brian Osman0995fd52019-01-09 09:52:25 -050087 uint16_t* idxs) {
Brian Osmanf9aabff2018-11-13 16:11:38 -050088 GrVertexWriter verts{vertData};
Brian Osmanf3e6b902018-12-28 17:43:50 +000089 for (int i = 0; i < tess.numPts(); ++i) {
Brian Osman80879d42019-01-07 16:15:27 -050090 verts.write(tess.point(i), color, tess.coverage(i));
ethannicholas1a1b3ac2015-06-10 12:11:17 -070091 }
92
93 for (int i = 0; i < tess.numIndices(); ++i) {
94 idxs[i] = tess.index(i) + firstIndex;
95 }
96}
97
Ruiqi Maob609e6d2018-07-17 10:19:38 -040098static sk_sp<GrGeometryProcessor> create_lines_only_gp(const GrShaderCaps* shaderCaps,
99 bool tweakAlphaForCoverage,
Brian Salomon60fb0b22017-06-15 17:09:36 -0400100 const SkMatrix& viewMatrix,
Brian Osman80879d42019-01-07 16:15:27 -0500101 bool usesLocalCoords,
102 bool wideColor) {
joshualittdf0c5572015-08-03 11:35:28 -0700103 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700104
Brian Osman80879d42019-01-07 16:15:27 -0500105 Coverage::Type coverageType =
106 tweakAlphaForCoverage ? Coverage::kAttributeTweakAlpha_Type : Coverage::kAttribute_Type;
Brian Salomon8c852be2017-01-04 10:44:42 -0500107 LocalCoords::Type localCoordsType =
Brian Osman80879d42019-01-07 16:15:27 -0500108 usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
109 Color::Type colorType =
110 wideColor ? Color::kPremulWideColorAttribute_Type : Color::kPremulGrColorAttribute_Type;
111
112 return MakeForDeviceSpace(shaderCaps, colorType, coverageType, localCoordsType, viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700113}
114
Brian Salomonb2955732017-07-13 16:42:55 -0400115namespace {
116
117class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
118private:
119 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
120
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700121public:
Brian Salomon25a88092016-12-01 09:36:50 -0500122 DEFINE_OP_CLASS_ID
Robert Phillips7c525e62018-06-12 10:11:12 -0400123 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
124 GrPaint&& paint,
Brian Salomonb2955732017-07-13 16:42:55 -0400125 const SkMatrix& viewMatrix,
126 const SkPath& path,
127 SkScalar strokeWidth,
128 SkStrokeRec::Style style,
129 SkPaint::Join join,
130 SkScalar miterLimit,
131 const GrUserStencilSettings* stencilSettings) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400132 return Helper::FactoryHelper<AAFlatteningConvexPathOp>(context, std::move(paint),
133 viewMatrix, path,
Brian Salomonb2955732017-07-13 16:42:55 -0400134 strokeWidth, style, join, miterLimit,
135 stencilSettings);
Brian Salomon780dad12016-12-15 18:08:40 -0500136 }
137
Brian Salomonb2955732017-07-13 16:42:55 -0400138 AAFlatteningConvexPathOp(const Helper::MakeArgs& helperArgs,
Brian Osmancf860852018-10-31 14:04:39 -0400139 const SkPMColor4f& color,
Brian Salomon780dad12016-12-15 18:08:40 -0500140 const SkMatrix& viewMatrix,
141 const SkPath& path,
142 SkScalar strokeWidth,
143 SkStrokeRec::Style style,
144 SkPaint::Join join,
Brian Salomonb2955732017-07-13 16:42:55 -0400145 SkScalar miterLimit,
146 const GrUserStencilSettings* stencilSettings)
147 : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) {
Brian Salomon780dad12016-12-15 18:08:40 -0500148 fPaths.emplace_back(
149 PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700150
bsalomon0432dd62016-06-30 07:19:27 -0700151 // compute bounds
bsalomon88cf17d2016-07-08 06:40:56 -0700152 SkRect bounds = path.getBounds();
bsalomon0432dd62016-06-30 07:19:27 -0700153 SkScalar w = strokeWidth;
154 if (w > 0) {
155 w /= 2;
156 // If the half stroke width is < 1 then we effectively fallback to bevel joins.
157 if (SkPaint::kMiter_Join == join && w > 1.f) {
158 w *= miterLimit;
159 }
bsalomon88cf17d2016-07-08 06:40:56 -0700160 bounds.outset(w, w);
bsalomon0432dd62016-06-30 07:19:27 -0700161 }
bsalomon88cf17d2016-07-08 06:40:56 -0700162 this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
Brian Osman80879d42019-01-07 16:15:27 -0500163 fWideColor = !SkPMColor4fFitsInBytes(color);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700164 }
165
Brian Salomonb2955732017-07-13 16:42:55 -0400166 const char* name() const override { return "AAFlatteningConvexPathOp"; }
167
Brian Salomon7d94bb52018-10-12 14:37:19 -0400168 void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400169 fHelper.visitProxies(func);
170 }
171
Brian Osman9a390ac2018-11-12 09:47:48 -0500172#ifdef SK_DEBUG
Brian Salomonb2955732017-07-13 16:42:55 -0400173 SkString dumpInfo() const override {
174 SkString string;
175 for (const auto& path : fPaths) {
176 string.appendf(
177 "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
178 "MiterLimit: %.2f\n",
Brian Osmancf860852018-10-31 14:04:39 -0400179 path.fColor.toBytes_RGBA(), path.fStrokeWidth, path.fStyle, path.fJoin,
Brian Osman1be2b7c2018-10-29 16:07:15 -0400180 path.fMiterLimit);
Brian Salomonb2955732017-07-13 16:42:55 -0400181 }
182 string += fHelper.dumpInfo();
183 string += INHERITED::dumpInfo();
184 return string;
Brian Salomon92aee3d2016-12-21 09:20:25 -0500185 }
Brian Osman9a390ac2018-11-12 09:47:48 -0500186#endif
Brian Salomon92aee3d2016-12-21 09:20:25 -0500187
Brian Salomonb2955732017-07-13 16:42:55 -0400188 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
189
Brian Osman532b3f92018-07-11 10:02:07 -0400190 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
191 return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel,
Brian Salomonb2955732017-07-13 16:42:55 -0400192 &fPaths.back().fColor);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700193 }
194
Brian Salomonb2955732017-07-13 16:42:55 -0400195private:
Brian Salomon7eae3e02018-08-07 14:02:38 +0000196 void draw(Target* target, sk_sp<const GrGeometryProcessor> gp, const GrPipeline* pipeline,
Brian Salomon49348902018-06-26 09:12:38 -0400197 const GrPipeline::FixedDynamicState* fixedDynamicState, int vertexCount,
198 size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700199 if (vertexCount == 0 || indexCount == 0) {
200 return;
201 }
Chris Daltonff926502017-05-03 14:36:54 -0400202 const GrBuffer* vertexBuffer;
Chris Daltonbca46e22017-05-15 11:03:26 -0600203 int firstVertex;
mtklein002c2ce2015-08-26 05:43:22 -0700204 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
Chris Daltonbca46e22017-05-15 11:03:26 -0600205 &firstVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700206 if (!verts) {
207 SkDebugf("Could not allocate vertices\n");
208 return;
209 }
210 memcpy(verts, vertices, vertexCount * vertexStride);
211
cdalton397536c2016-03-25 12:15:03 -0700212 const GrBuffer* indexBuffer;
Chris Daltonbca46e22017-05-15 11:03:26 -0600213 int firstIndex;
214 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700215 if (!idxs) {
216 SkDebugf("Could not allocate indices\n");
217 return;
218 }
219 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
Brian Salomon7eae3e02018-08-07 14:02:38 +0000220 GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
221 mesh->setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
222 GrPrimitiveRestart::kNo);
223 mesh->setVertexData(vertexBuffer, firstVertex);
224 target->draw(std::move(gp), pipeline, fixedDynamicState, mesh);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700225 }
mtklein002c2ce2015-08-26 05:43:22 -0700226
Brian Salomon91326c32017-08-09 16:02:19 -0400227 void onPrepareDraws(Target* target) override {
Brian Salomon49348902018-06-26 09:12:38 -0400228 auto pipe = fHelper.makePipeline(target);
joshualittdf0c5572015-08-03 11:35:28 -0700229 // Setup GrGeometryProcessor
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400230 sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(target->caps().shaderCaps(),
231 fHelper.compatibleWithAlphaAsCoverage(),
Brian Salomonb2955732017-07-13 16:42:55 -0400232 this->viewMatrix(),
Brian Osman80879d42019-01-07 16:15:27 -0500233 fHelper.usesLocalCoords(),
234 fWideColor));
joshualittdf0c5572015-08-03 11:35:28 -0700235 if (!gp) {
236 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700237 return;
238 }
239
Brian Osmanf04fb3c2018-11-12 15:34:00 -0500240 size_t vertexStride = gp->vertexStride();
Brian Salomon780dad12016-12-15 18:08:40 -0500241 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700242
Greg Danield5b45932018-06-07 13:15:10 -0400243 int64_t vertexCount = 0;
244 int64_t indexCount = 0;
245 int64_t maxVertices = DEFAULT_BUFFER_SIZE;
246 int64_t maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700247 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
248 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700249 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500250 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700251 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
252 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700253
254 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
255 continue;
256 }
257
Greg Danield5b45932018-06-07 13:15:10 -0400258 int currentVertices = tess.numPts();
259 if (vertexCount + currentVertices > static_cast<int>(UINT16_MAX)) {
mtklein002c2ce2015-08-26 05:43:22 -0700260 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700261 // uint16_t. Draw what we've got so far and reset.
Brian Salomon7eae3e02018-08-07 14:02:38 +0000262 this->draw(target, gp, pipe.fPipeline, pipe.fFixedDynamicState, vertexCount,
Brian Salomon49348902018-06-26 09:12:38 -0400263 vertexStride, vertices, indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700264 vertexCount = 0;
265 indexCount = 0;
266 }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700267 if (vertexCount + currentVertices > maxVertices) {
268 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
Greg Danield5b45932018-06-07 13:15:10 -0400269 if (maxVertices * vertexStride > SK_MaxS32) {
270 sk_free(vertices);
271 sk_free(indices);
272 return;
273 }
mtklein002c2ce2015-08-26 05:43:22 -0700274 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700275 }
Greg Danield5b45932018-06-07 13:15:10 -0400276 int currentIndices = tess.numIndices();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700277 if (indexCount + currentIndices > maxIndices) {
278 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
Greg Danield5b45932018-06-07 13:15:10 -0400279 if (maxIndices * sizeof(uint16_t) > SK_MaxS32) {
280 sk_free(vertices);
281 sk_free(indices);
282 return;
283 }
mtklein002c2ce2015-08-26 05:43:22 -0700284 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700285 }
286
Brian Osman80879d42019-01-07 16:15:27 -0500287 extract_verts(tess, vertices + vertexStride * vertexCount,
Brian Osman0995fd52019-01-09 09:52:25 -0500288 GrVertexColor(args.fColor, fWideColor), vertexCount,
289 indices + indexCount);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700290 vertexCount += currentVertices;
291 indexCount += currentIndices;
292 }
Greg Danield5b45932018-06-07 13:15:10 -0400293 if (vertexCount <= SK_MaxS32 && indexCount <= SK_MaxS32) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000294 this->draw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, vertexCount,
Brian Salomon49348902018-06-26 09:12:38 -0400295 vertexStride, vertices, indexCount, indices);
Greg Danield5b45932018-06-07 13:15:10 -0400296 }
mtklein002c2ce2015-08-26 05:43:22 -0700297 sk_free(vertices);
298 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700299 }
300
Brian Salomon7eae3e02018-08-07 14:02:38 +0000301 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500302 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
Brian Salomonb2955732017-07-13 16:42:55 -0400303 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000304 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700305 }
306
Brian Salomon780dad12016-12-15 18:08:40 -0500307 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
Brian Osman80879d42019-01-07 16:15:27 -0500308 fWideColor |= that->fWideColor;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000309 return CombineResult::kMerged;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700310 }
311
Brian Salomon780dad12016-12-15 18:08:40 -0500312 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700313
Brian Salomon780dad12016-12-15 18:08:40 -0500314 struct PathData {
Brian Osmancf860852018-10-31 14:04:39 -0400315 SkPMColor4f fColor;
bsalomon0432dd62016-06-30 07:19:27 -0700316 SkMatrix fViewMatrix;
317 SkPath fPath;
318 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700319 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700320 SkPaint::Join fJoin;
321 SkScalar fMiterLimit;
322 };
323
Brian Salomon780dad12016-12-15 18:08:40 -0500324 SkSTArray<1, PathData, true> fPaths;
Brian Salomonb2955732017-07-13 16:42:55 -0400325 Helper fHelper;
Brian Osman80879d42019-01-07 16:15:27 -0500326 bool fWideColor;
reed1b55a962015-09-17 20:16:13 -0700327
Brian Salomonb2955732017-07-13 16:42:55 -0400328 typedef GrMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700329};
330
Brian Salomonb2955732017-07-13 16:42:55 -0400331} // anonymous namespace
332
bsalomon0aff2fa2015-07-31 06:48:27 -0700333bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400334 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800335 "GrAALinearizingConvexPathRenderer::onDrawPath");
Brian Salomon7c8460e2017-05-12 11:36:10 -0400336 SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType());
bsalomon8acedde2016-06-24 10:42:16 -0700337 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700338 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700339
bsalomon0432dd62016-06-30 07:19:27 -0700340 SkPath path;
341 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700342 bool fill = args.fShape->style().isSimpleFill();
343 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700344 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
345 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
346 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700347
Brian Salomonb2955732017-07-13 16:42:55 -0400348 std::unique_ptr<GrDrawOp> op = AAFlatteningConvexPathOp::Make(
Robert Phillips7c525e62018-06-12 10:11:12 -0400349 args.fContext, std::move(args.fPaint), *args.fViewMatrix, path, strokeWidth,
350 stroke.getStyle(), join, miterLimit, args.fUserStencilSettings);
Brian Salomonb2955732017-07-13 16:42:55 -0400351 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700352 return true;
353}
354
355///////////////////////////////////////////////////////////////////////////////////////////////////
356
Hal Canary6f6961e2017-01-31 13:50:44 -0500357#if GR_TEST_UTILS
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700358
Brian Salomonb2955732017-07-13 16:42:55 -0400359GR_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
Brian Salomon780dad12016-12-15 18:08:40 -0500360 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700361 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700362
363 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500364 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700365 SkStrokeRec::kStrokeAndFill_Style };
366
367 SkStrokeRec::Style style = styles[random->nextU() % 3];
368
369 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700370 SkPaint::Join join = SkPaint::kMiter_Join;
371 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700372
373 if (SkStrokeRec::kFill_Style != style) {
374 strokeWidth = random->nextRangeF(1.0f, 10.0f);
375 if (random->nextBool()) {
376 join = SkPaint::kMiter_Join;
377 } else {
378 join = SkPaint::kBevel_Join;
379 }
380 miterLimit = random->nextRangeF(0.5f, 2.0f);
381 }
Brian Salomonb2955732017-07-13 16:42:55 -0400382 const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context);
Robert Phillips7c525e62018-06-12 10:11:12 -0400383 return AAFlatteningConvexPathOp::Make(context, std::move(paint), viewMatrix, path, strokeWidth,
384 style, join, miterLimit, stencilSettings);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700385}
386
387#endif