blob: c1fd4f7e65d9edca0ff84e851483c9a316b570b5 [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"
bsalomon6663acf2016-05-10 09:14:17 -070017#include "GrStyle.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070018#include "SkGeometry.h"
Brian Salomondad29232016-12-01 16:40:24 -050019#include "SkPathPriv.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070020#include "SkString.h"
21#include "SkTraceEvent.h"
egdaniele659a582015-11-13 09:55:43 -080022#include "glsl/GrGLSLGeometryProcessor.h"
Brian Salomon89527432016-12-16 09:52:16 -050023#include "ops/GrMeshDrawOp.h"
Brian Salomonb2955732017-07-13 16:42:55 -040024#include "ops/GrSimpleMeshDrawOpHelper.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070025
fmalitabd5d7e72015-06-26 07:18:24 -070026static const int DEFAULT_BUFFER_SIZE = 100;
27
28// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For
29// the time being, we simply drop back to software rendering above this stroke width.
30static const SkScalar kMaxStrokeWidth = 20.0;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070031
32GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
33}
34
35///////////////////////////////////////////////////////////////////////////////
36
bsalomon0aff2fa2015-07-31 06:48:27 -070037bool GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050038 if (GrAAType::kCoverage != args.fAAType) {
fmalitabd5d7e72015-06-26 07:18:24 -070039 return false;
40 }
bsalomon8acedde2016-06-24 10:42:16 -070041 if (!args.fShape->knownToBeConvex()) {
fmalitabd5d7e72015-06-26 07:18:24 -070042 return false;
43 }
bsalomon8acedde2016-06-24 10:42:16 -070044 if (args.fShape->style().pathEffect()) {
fmalitabd5d7e72015-06-26 07:18:24 -070045 return false;
46 }
bsalomon8acedde2016-06-24 10:42:16 -070047 if (args.fShape->inverseFilled()) {
bsalomon6663acf2016-05-10 09:14:17 -070048 return false;
49 }
Brian Osmana98e3992017-06-26 15:14:53 -040050 if (args.fShape->bounds().width() <= 0 && args.fShape->bounds().height() <= 0) {
51 // Stroked zero length lines should draw, but this PR doesn't handle that case
52 return false;
53 }
bsalomon8acedde2016-06-24 10:42:16 -070054 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
robertphillips8c170972016-09-22 12:42:30 -070055
56 if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
57 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
ethannicholasfea77632015-08-19 12:09:12 -070058 if (!args.fViewMatrix->isSimilarity()) {
59 return false;
60 }
bsalomon6663acf2016-05-10 09:14:17 -070061 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * stroke.getWidth();
robertphillips8c170972016-09-22 12:42:30 -070062 if (strokeWidth < 1.0f && stroke.getStyle() == SkStrokeRec::kStroke_Style) {
63 return false;
64 }
65 return strokeWidth <= kMaxStrokeWidth &&
bsalomon8acedde2016-06-24 10:42:16 -070066 args.fShape->knownToBeClosed() &&
bsalomon6663acf2016-05-10 09:14:17 -070067 stroke.getJoin() != SkPaint::Join::kRound_Join;
fmalitabd5d7e72015-06-26 07:18:24 -070068 }
bsalomon6663acf2016-05-10 09:14:17 -070069 return stroke.getStyle() == SkStrokeRec::kFill_Style;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070070}
71
72// extract the result vertices and indices from the GrAAConvexTessellator
73static void extract_verts(const GrAAConvexTessellator& tess,
74 void* vertices,
75 size_t vertexStride,
76 GrColor color,
77 uint16_t firstIndex,
78 uint16_t* idxs,
79 bool tweakAlphaForCoverage) {
80 intptr_t verts = reinterpret_cast<intptr_t>(vertices);
81
82 for (int i = 0; i < tess.numPts(); ++i) {
83 *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i);
84 }
85
86 // Make 'verts' point to the colors
87 verts += sizeof(SkPoint);
88 for (int i = 0; i < tess.numPts(); ++i) {
ethannicholas1a1b3ac2015-06-10 12:11:17 -070089 if (tweakAlphaForCoverage) {
fmalitabd5d7e72015-06-26 07:18:24 -070090 SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255);
91 unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
ethannicholas1a1b3ac2015-06-10 12:11:17 -070092 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
93 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
94 } else {
95 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
mtklein002c2ce2015-08-26 05:43:22 -070096 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
fmalitabd5d7e72015-06-26 07:18:24 -070097 tess.coverage(i);
ethannicholas1a1b3ac2015-06-10 12:11:17 -070098 }
99 }
100
101 for (int i = 0; i < tess.numIndices(); ++i) {
102 idxs[i] = tess.index(i) + firstIndex;
103 }
104}
105
Brian Salomon60fb0b22017-06-15 17:09:36 -0400106static sk_sp<GrGeometryProcessor> create_lines_only_gp(bool tweakAlphaForCoverage,
107 const SkMatrix& viewMatrix,
108 bool usesLocalCoords) {
joshualittdf0c5572015-08-03 11:35:28 -0700109 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700110
joshualittdf0c5572015-08-03 11:35:28 -0700111 Coverage::Type coverageType;
Brian Salomon8c852be2017-01-04 10:44:42 -0500112 if (tweakAlphaForCoverage) {
joshualittdf0c5572015-08-03 11:35:28 -0700113 coverageType = Coverage::kSolid_Type;
114 } else {
115 coverageType = Coverage::kAttribute_Type;
116 }
Brian Salomon8c852be2017-01-04 10:44:42 -0500117 LocalCoords::Type localCoordsType =
118 usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500119 return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType,
120 viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700121}
122
Brian Salomonb2955732017-07-13 16:42:55 -0400123namespace {
124
125class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
126private:
127 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
128
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700129public:
Brian Salomon25a88092016-12-01 09:36:50 -0500130 DEFINE_OP_CLASS_ID
Brian Salomonb2955732017-07-13 16:42:55 -0400131 static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint,
132 const SkMatrix& viewMatrix,
133 const SkPath& path,
134 SkScalar strokeWidth,
135 SkStrokeRec::Style style,
136 SkPaint::Join join,
137 SkScalar miterLimit,
138 const GrUserStencilSettings* stencilSettings) {
139 return Helper::FactoryHelper<AAFlatteningConvexPathOp>(std::move(paint), viewMatrix, path,
140 strokeWidth, style, join, miterLimit,
141 stencilSettings);
Brian Salomon780dad12016-12-15 18:08:40 -0500142 }
143
Brian Salomonb2955732017-07-13 16:42:55 -0400144 AAFlatteningConvexPathOp(const Helper::MakeArgs& helperArgs,
145 GrColor color,
Brian Salomon780dad12016-12-15 18:08:40 -0500146 const SkMatrix& viewMatrix,
147 const SkPath& path,
148 SkScalar strokeWidth,
149 SkStrokeRec::Style style,
150 SkPaint::Join join,
Brian Salomonb2955732017-07-13 16:42:55 -0400151 SkScalar miterLimit,
152 const GrUserStencilSettings* stencilSettings)
153 : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) {
Brian Salomon780dad12016-12-15 18:08:40 -0500154 fPaths.emplace_back(
155 PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700156
bsalomon0432dd62016-06-30 07:19:27 -0700157 // compute bounds
bsalomon88cf17d2016-07-08 06:40:56 -0700158 SkRect bounds = path.getBounds();
bsalomon0432dd62016-06-30 07:19:27 -0700159 SkScalar w = strokeWidth;
160 if (w > 0) {
161 w /= 2;
162 // If the half stroke width is < 1 then we effectively fallback to bevel joins.
163 if (SkPaint::kMiter_Join == join && w > 1.f) {
164 w *= miterLimit;
165 }
bsalomon88cf17d2016-07-08 06:40:56 -0700166 bounds.outset(w, w);
bsalomon0432dd62016-06-30 07:19:27 -0700167 }
bsalomon88cf17d2016-07-08 06:40:56 -0700168 this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700169 }
170
Brian Salomonb2955732017-07-13 16:42:55 -0400171 const char* name() const override { return "AAFlatteningConvexPathOp"; }
172
173 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",
179 path.fColor, path.fStrokeWidth, path.fStyle, path.fJoin, path.fMiterLimit);
180 }
181 string += fHelper.dumpInfo();
182 string += INHERITED::dumpInfo();
183 return string;
Brian Salomon92aee3d2016-12-21 09:20:25 -0500184 }
185
Brian Salomonb2955732017-07-13 16:42:55 -0400186 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
187
188 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
189 return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel,
190 &fPaths.back().fColor);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700191 }
192
Brian Salomonb2955732017-07-13 16:42:55 -0400193private:
194 void draw(GrMeshDrawOp::Target* target, const GrGeometryProcessor* gp,
195 const GrPipeline* pipeline, int vertexCount, size_t vertexStride, void* vertices,
196 int indexCount, uint16_t* indices) const {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700197 if (vertexCount == 0 || indexCount == 0) {
198 return;
199 }
Chris Daltonff926502017-05-03 14:36:54 -0400200 const GrBuffer* vertexBuffer;
Chris Dalton3809bab2017-06-13 10:55:06 -0600201 GrMesh mesh(GrPrimitiveType::kTriangles);
Chris Daltonbca46e22017-05-15 11:03:26 -0600202 int firstVertex;
mtklein002c2ce2015-08-26 05:43:22 -0700203 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
Chris Daltonbca46e22017-05-15 11:03:26 -0600204 &firstVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700205 if (!verts) {
206 SkDebugf("Could not allocate vertices\n");
207 return;
208 }
209 memcpy(verts, vertices, vertexCount * vertexStride);
210
cdalton397536c2016-03-25 12:15:03 -0700211 const GrBuffer* indexBuffer;
Chris Daltonbca46e22017-05-15 11:03:26 -0600212 int firstIndex;
213 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700214 if (!idxs) {
215 SkDebugf("Could not allocate indices\n");
216 return;
217 }
218 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
Chris Dalton114a3c02017-05-26 15:17:19 -0600219 mesh.setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1);
220 mesh.setVertexData(vertexBuffer, firstVertex);
Brian Salomonb2955732017-07-13 16:42:55 -0400221 target->draw(gp, pipeline, mesh);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700222 }
mtklein002c2ce2015-08-26 05:43:22 -0700223
Brian Salomon91326c32017-08-09 16:02:19 -0400224 void onPrepareDraws(Target* target) override {
Brian Salomonb2955732017-07-13 16:42:55 -0400225 const GrPipeline* pipeline = fHelper.makePipeline(target);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700226
joshualittdf0c5572015-08-03 11:35:28 -0700227 // Setup GrGeometryProcessor
Brian Salomonb2955732017-07-13 16:42:55 -0400228 sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(fHelper.compatibleWithAlphaAsCoverage(),
229 this->viewMatrix(),
230 fHelper.usesLocalCoords()));
joshualittdf0c5572015-08-03 11:35:28 -0700231 if (!gp) {
232 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700233 return;
234 }
235
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700236 size_t vertexStride = gp->getVertexStride();
237
Brian Salomonb2955732017-07-13 16:42:55 -0400238 SkASSERT(fHelper.compatibleWithAlphaAsCoverage()
239 ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
240 : vertexStride ==
241 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700242
Brian Salomon780dad12016-12-15 18:08:40 -0500243 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700244
245 int vertexCount = 0;
246 int indexCount = 0;
247 int maxVertices = DEFAULT_BUFFER_SIZE;
248 int maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700249 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
250 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700251 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500252 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700253 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
254 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700255
256 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
257 continue;
258 }
259
260 int currentIndices = tess.numIndices();
261 SkASSERT(currentIndices <= UINT16_MAX);
262 if (indexCount + currentIndices > UINT16_MAX) {
mtklein002c2ce2015-08-26 05:43:22 -0700263 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700264 // uint16_t. Draw what we've got so far and reset.
Brian Salomonb2955732017-07-13 16:42:55 -0400265 this->draw(target, gp.get(), pipeline, vertexCount, vertexStride, vertices,
266 indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700267 vertexCount = 0;
268 indexCount = 0;
269 }
270 int currentVertices = tess.numPts();
271 if (vertexCount + currentVertices > maxVertices) {
272 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700273 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700274 }
275 if (indexCount + currentIndices > maxIndices) {
276 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700277 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700278 }
279
mtklein002c2ce2015-08-26 05:43:22 -0700280 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor,
Brian Salomonb2955732017-07-13 16:42:55 -0400281 vertexCount, indices + indexCount,
282 fHelper.compatibleWithAlphaAsCoverage());
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700283 vertexCount += currentVertices;
284 indexCount += currentIndices;
285 }
Brian Salomonb2955732017-07-13 16:42:55 -0400286 this->draw(target, gp.get(), pipeline, vertexCount, vertexStride, vertices, indexCount,
287 indices);
mtklein002c2ce2015-08-26 05:43:22 -0700288 sk_free(vertices);
289 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700290 }
291
Brian Salomon25a88092016-12-01 09:36:50 -0500292 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500293 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
Brian Salomonb2955732017-07-13 16:42:55 -0400294 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
joshualitt8cab9a72015-07-16 09:13:50 -0700295 return false;
296 }
297
Brian Salomon780dad12016-12-15 18:08:40 -0500298 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700299 this->joinBounds(*that);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700300 return true;
301 }
302
Brian Salomon780dad12016-12-15 18:08:40 -0500303 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700304
Brian Salomon780dad12016-12-15 18:08:40 -0500305 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700306 GrColor fColor;
307 SkMatrix fViewMatrix;
308 SkPath fPath;
309 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700310 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700311 SkPaint::Join fJoin;
312 SkScalar fMiterLimit;
313 };
314
Brian Salomon780dad12016-12-15 18:08:40 -0500315 SkSTArray<1, PathData, true> fPaths;
Brian Salomonb2955732017-07-13 16:42:55 -0400316 Helper fHelper;
reed1b55a962015-09-17 20:16:13 -0700317
Brian Salomonb2955732017-07-13 16:42:55 -0400318 typedef GrMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700319};
320
Brian Salomonb2955732017-07-13 16:42:55 -0400321} // anonymous namespace
322
bsalomon0aff2fa2015-07-31 06:48:27 -0700323bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400324 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800325 "GrAALinearizingConvexPathRenderer::onDrawPath");
Brian Salomon7c8460e2017-05-12 11:36:10 -0400326 SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType());
bsalomon8acedde2016-06-24 10:42:16 -0700327 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700328 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700329
bsalomon0432dd62016-06-30 07:19:27 -0700330 SkPath path;
331 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700332 bool fill = args.fShape->style().isSimpleFill();
333 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700334 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
335 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
336 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700337
Brian Salomonb2955732017-07-13 16:42:55 -0400338 std::unique_ptr<GrDrawOp> op = AAFlatteningConvexPathOp::Make(
339 std::move(args.fPaint), *args.fViewMatrix, path, strokeWidth, stroke.getStyle(), join,
340 miterLimit, args.fUserStencilSettings);
341 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700342 return true;
343}
344
345///////////////////////////////////////////////////////////////////////////////////////////////////
346
Hal Canary6f6961e2017-01-31 13:50:44 -0500347#if GR_TEST_UTILS
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700348
Brian Salomonb2955732017-07-13 16:42:55 -0400349GR_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
Brian Salomon780dad12016-12-15 18:08:40 -0500350 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700351 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700352
353 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500354 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700355 SkStrokeRec::kStrokeAndFill_Style };
356
357 SkStrokeRec::Style style = styles[random->nextU() % 3];
358
359 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700360 SkPaint::Join join = SkPaint::kMiter_Join;
361 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700362
363 if (SkStrokeRec::kFill_Style != style) {
364 strokeWidth = random->nextRangeF(1.0f, 10.0f);
365 if (random->nextBool()) {
366 join = SkPaint::kMiter_Join;
367 } else {
368 join = SkPaint::kBevel_Join;
369 }
370 miterLimit = random->nextRangeF(0.5f, 2.0f);
371 }
Brian Salomonb2955732017-07-13 16:42:55 -0400372 const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context);
373 return AAFlatteningConvexPathOp::Make(std::move(paint), viewMatrix, path, strokeWidth, style,
374 join, miterLimit, stencilSettings);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700375}
376
377#endif