blob: c2473535f7fc51b2b2e16f161da3ac4f0effdc91 [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"
9
10#include "GrAAConvexTessellator.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070011#include "GrBatchTest.h"
12#include "GrContext.h"
13#include "GrDefaultGeoProcFactory.h"
14#include "GrGeometryProcessor.h"
15#include "GrInvariantOutput.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050016#include "GrOpFlushState.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070017#include "GrPathUtils.h"
bsalomonbb243832016-07-22 07:10:19 -070018#include "GrPipelineBuilder.h"
Brian Salomondad29232016-12-01 16:40:24 -050019#include "GrProcessor.h"
bsalomon6663acf2016-05-10 09:14:17 -070020#include "GrStyle.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"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070027
fmalitabd5d7e72015-06-26 07:18:24 -070028static const int DEFAULT_BUFFER_SIZE = 100;
29
30// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For
31// the time being, we simply drop back to software rendering above this stroke width.
32static const SkScalar kMaxStrokeWidth = 20.0;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070033
34GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
35}
36
37///////////////////////////////////////////////////////////////////////////////
38
bsalomon0aff2fa2015-07-31 06:48:27 -070039bool GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050040 if (GrAAType::kCoverage != args.fAAType) {
fmalitabd5d7e72015-06-26 07:18:24 -070041 return false;
42 }
bsalomon8acedde2016-06-24 10:42:16 -070043 if (!args.fShape->knownToBeConvex()) {
fmalitabd5d7e72015-06-26 07:18:24 -070044 return false;
45 }
bsalomon8acedde2016-06-24 10:42:16 -070046 if (args.fShape->style().pathEffect()) {
fmalitabd5d7e72015-06-26 07:18:24 -070047 return false;
48 }
bsalomon8acedde2016-06-24 10:42:16 -070049 if (args.fShape->inverseFilled()) {
bsalomon6663acf2016-05-10 09:14:17 -070050 return false;
51 }
bsalomon8acedde2016-06-24 10:42:16 -070052 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
robertphillips8c170972016-09-22 12:42:30 -070053
54 if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
55 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
ethannicholasfea77632015-08-19 12:09:12 -070056 if (!args.fViewMatrix->isSimilarity()) {
57 return false;
58 }
bsalomon6663acf2016-05-10 09:14:17 -070059 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * stroke.getWidth();
robertphillips8c170972016-09-22 12:42:30 -070060 if (strokeWidth < 1.0f && stroke.getStyle() == SkStrokeRec::kStroke_Style) {
61 return false;
62 }
63 return strokeWidth <= kMaxStrokeWidth &&
bsalomon8acedde2016-06-24 10:42:16 -070064 args.fShape->knownToBeClosed() &&
bsalomon6663acf2016-05-10 09:14:17 -070065 stroke.getJoin() != SkPaint::Join::kRound_Join;
fmalitabd5d7e72015-06-26 07:18:24 -070066 }
bsalomon6663acf2016-05-10 09:14:17 -070067 return stroke.getStyle() == SkStrokeRec::kFill_Style;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070068}
69
70// extract the result vertices and indices from the GrAAConvexTessellator
71static void extract_verts(const GrAAConvexTessellator& tess,
72 void* vertices,
73 size_t vertexStride,
74 GrColor color,
75 uint16_t firstIndex,
76 uint16_t* idxs,
77 bool tweakAlphaForCoverage) {
78 intptr_t verts = reinterpret_cast<intptr_t>(vertices);
79
80 for (int i = 0; i < tess.numPts(); ++i) {
81 *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i);
82 }
83
84 // Make 'verts' point to the colors
85 verts += sizeof(SkPoint);
86 for (int i = 0; i < tess.numPts(); ++i) {
ethannicholas1a1b3ac2015-06-10 12:11:17 -070087 if (tweakAlphaForCoverage) {
fmalitabd5d7e72015-06-26 07:18:24 -070088 SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255);
89 unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
ethannicholas1a1b3ac2015-06-10 12:11:17 -070090 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
91 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
92 } else {
93 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
mtklein002c2ce2015-08-26 05:43:22 -070094 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
fmalitabd5d7e72015-06-26 07:18:24 -070095 tess.coverage(i);
ethannicholas1a1b3ac2015-06-10 12:11:17 -070096 }
97 }
98
99 for (int i = 0; i < tess.numIndices(); ++i) {
100 idxs[i] = tess.index(i) + firstIndex;
101 }
102}
103
bungeman06ca8ec2016-06-09 08:01:03 -0700104static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage,
joshualittdf0c5572015-08-03 11:35:28 -0700105 const SkMatrix& viewMatrix,
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700106 bool usesLocalCoords,
107 bool coverageIgnored) {
joshualittdf0c5572015-08-03 11:35:28 -0700108 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700109
joshualittdf0c5572015-08-03 11:35:28 -0700110 Color color(Color::kAttribute_Type);
111 Coverage::Type coverageType;
112 // TODO remove coverage if coverage is ignored
113 /*if (coverageIgnored) {
114 coverageType = Coverage::kNone_Type;
115 } else*/ if (tweakAlphaForCoverage) {
116 coverageType = Coverage::kSolid_Type;
117 } else {
118 coverageType = Coverage::kAttribute_Type;
119 }
120 Coverage coverage(coverageType);
121 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
122 LocalCoords::kUnused_Type);
bungeman06ca8ec2016-06-09 08:01:03 -0700123 return MakeForDeviceSpace(color, coverage, localCoords, viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700124}
125
Brian Salomon780dad12016-12-15 18:08:40 -0500126class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700127public:
Brian Salomon25a88092016-12-01 09:36:50 -0500128 DEFINE_OP_CLASS_ID
Brian Salomon780dad12016-12-15 18:08:40 -0500129 static sk_sp<GrDrawOp> Make(GrColor color,
bsalomon0432dd62016-06-30 07:19:27 -0700130 const SkMatrix& viewMatrix,
131 const SkPath& path,
132 SkScalar strokeWidth,
robertphillips8c170972016-09-22 12:42:30 -0700133 SkStrokeRec::Style style,
bsalomon0432dd62016-06-30 07:19:27 -0700134 SkPaint::Join join,
Brian Salomon780dad12016-12-15 18:08:40 -0500135 SkScalar miterLimit) {
136 return sk_sp<GrDrawOp>(new AAFlatteningConvexPathOp(color, viewMatrix, path, strokeWidth,
137 style, join, miterLimit));
138 }
139
140 const char* name() const override { return "AAFlatteningConvexPathOp"; }
141
142 SkString dumpInfo() const override {
143 SkString string;
144 for (const auto& path : fPaths) {
145 string.appendf(
146 "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
147 "MiterLimit: %.2f\n",
148 path.fColor, path.fStrokeWidth, path.fStyle, path.fJoin, path.fMiterLimit);
149 }
150 string.append(DumpPipelineInfo(*this->pipeline()));
151 string.append(INHERITED::dumpInfo());
152 return string;
153 }
154
155 void computePipelineOptimizations(GrInitInvariantOutput* color,
156 GrInitInvariantOutput* coverage,
157 GrBatchToXPOverrides* overrides) const override {
158 // When this is called there is only one path.
159 color->setKnownFourComponents(fPaths[0].fColor);
160 coverage->setUnknownSingleComponent();
161 }
162
163private:
164 AAFlatteningConvexPathOp(GrColor color,
165 const SkMatrix& viewMatrix,
166 const SkPath& path,
167 SkScalar strokeWidth,
168 SkStrokeRec::Style style,
169 SkPaint::Join join,
170 SkScalar miterLimit)
171 : INHERITED(ClassID()) {
172 fPaths.emplace_back(
173 PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700174
bsalomon0432dd62016-06-30 07:19:27 -0700175 // compute bounds
bsalomon88cf17d2016-07-08 06:40:56 -0700176 SkRect bounds = path.getBounds();
bsalomon0432dd62016-06-30 07:19:27 -0700177 SkScalar w = strokeWidth;
178 if (w > 0) {
179 w /= 2;
180 // If the half stroke width is < 1 then we effectively fallback to bevel joins.
181 if (SkPaint::kMiter_Join == join && w > 1.f) {
182 w *= miterLimit;
183 }
bsalomon88cf17d2016-07-08 06:40:56 -0700184 bounds.outset(w, w);
bsalomon0432dd62016-06-30 07:19:27 -0700185 }
bsalomon88cf17d2016-07-08 06:40:56 -0700186 this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700187 }
188
ethannicholasff210322015-11-24 12:10:10 -0800189 void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700190 // Handle any color overrides
ethannicholasff210322015-11-24 12:10:10 -0800191 if (!overrides.readsColor()) {
Brian Salomon780dad12016-12-15 18:08:40 -0500192 fPaths[0].fColor = GrColor_ILLEGAL;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700193 }
Brian Salomon780dad12016-12-15 18:08:40 -0500194 overrides.getOverrideColorIfSet(&fPaths[0].fColor);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700195
196 // setup batch properties
Brian Salomon780dad12016-12-15 18:08:40 -0500197 fColor = fPaths[0].fColor;
198 fUsesLocalCoords = overrides.readsLocalCoords();
199 fCoverageIgnored = !overrides.readsCoverage();
200 fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700201 }
202
Brian Salomondad29232016-12-01 16:40:24 -0500203 void draw(GrMeshDrawOp::Target* target, const GrGeometryProcessor* gp, int vertexCount,
joshualitt144c3c82015-11-30 12:30:13 -0800204 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 }
cdalton397536c2016-03-25 12:15:03 -0700208 const GrBuffer* vertexBuffer;
egdaniel0e1853c2016-03-17 11:35:45 -0700209 GrMesh mesh;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700210 int firstVertex;
mtklein002c2ce2015-08-26 05:43:22 -0700211 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
bsalomon75398562015-08-17 12:55:38 -0700212 &firstVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700213 if (!verts) {
214 SkDebugf("Could not allocate vertices\n");
215 return;
216 }
217 memcpy(verts, vertices, vertexCount * vertexStride);
218
cdalton397536c2016-03-25 12:15:03 -0700219 const GrBuffer* indexBuffer;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700220 int firstIndex;
bsalomon75398562015-08-17 12:55:38 -0700221 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700222 if (!idxs) {
223 SkDebugf("Could not allocate indices\n");
224 return;
225 }
226 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
egdaniel0e1853c2016-03-17 11:35:45 -0700227 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
228 firstIndex, vertexCount, indexCount);
bsalomon342bfc22016-04-01 06:06:20 -0700229 target->draw(gp, mesh);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700230 }
mtklein002c2ce2015-08-26 05:43:22 -0700231
joshualitt144c3c82015-11-30 12:30:13 -0800232 void onPrepareDraws(Target* target) const override {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700233 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
234
joshualittdf0c5572015-08-03 11:35:28 -0700235 // Setup GrGeometryProcessor
bungeman06ca8ec2016-06-09 08:01:03 -0700236 sk_sp<GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage,
237 this->viewMatrix(),
238 this->usesLocalCoords(),
239 this->coverageIgnored()));
joshualittdf0c5572015-08-03 11:35:28 -0700240 if (!gp) {
241 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700242 return;
243 }
244
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700245 size_t vertexStride = gp->getVertexStride();
246
247 SkASSERT(canTweakAlphaForCoverage ?
248 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
249 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
250
Brian Salomon780dad12016-12-15 18:08:40 -0500251 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700252
253 int vertexCount = 0;
254 int indexCount = 0;
255 int maxVertices = DEFAULT_BUFFER_SIZE;
256 int maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700257 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
258 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700259 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500260 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700261 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
262 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700263
264 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
265 continue;
266 }
267
268 int currentIndices = tess.numIndices();
269 SkASSERT(currentIndices <= UINT16_MAX);
270 if (indexCount + currentIndices > UINT16_MAX) {
mtklein002c2ce2015-08-26 05:43:22 -0700271 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700272 // uint16_t. Draw what we've got so far and reset.
bungeman06ca8ec2016-06-09 08:01:03 -0700273 this->draw(target, gp.get(),
274 vertexCount, vertexStride, vertices, indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700275 vertexCount = 0;
276 indexCount = 0;
277 }
278 int currentVertices = tess.numPts();
279 if (vertexCount + currentVertices > maxVertices) {
280 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700281 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700282 }
283 if (indexCount + currentIndices > maxIndices) {
284 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700285 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700286 }
287
mtklein002c2ce2015-08-26 05:43:22 -0700288 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor,
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700289 vertexCount, indices + indexCount, canTweakAlphaForCoverage);
290 vertexCount += currentVertices;
291 indexCount += currentIndices;
292 }
bungeman06ca8ec2016-06-09 08:01:03 -0700293 this->draw(target, gp.get(), vertexCount, vertexStride, vertices, indexCount, indices);
mtklein002c2ce2015-08-26 05:43:22 -0700294 sk_free(vertices);
295 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700296 }
297
Brian Salomon25a88092016-12-01 09:36:50 -0500298 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500299 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
bsalomonabd30f52015-08-13 13:34:48 -0700300 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
301 that->bounds(), caps)) {
joshualitt8cab9a72015-07-16 09:13:50 -0700302 return false;
303 }
304
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700305 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
306 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
307 return false;
308 }
309
Brian Salomon780dad12016-12-15 18:08:40 -0500310 // In the event of two ops, one who can tweak, one who cannot, we just fall back to not
311 // tweaking
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700312 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) {
Brian Salomon780dad12016-12-15 18:08:40 -0500313 fCanTweakAlphaForCoverage = false;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700314 }
315
Brian Salomon780dad12016-12-15 18:08:40 -0500316 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700317 this->joinBounds(*that);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700318 return true;
319 }
320
Brian Salomon780dad12016-12-15 18:08:40 -0500321 GrColor color() const { return fColor; }
322 bool usesLocalCoords() const { return fUsesLocalCoords; }
323 bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; }
324 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
325 bool coverageIgnored() const { return fCoverageIgnored; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700326
Brian Salomon780dad12016-12-15 18:08:40 -0500327 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700328 GrColor fColor;
329 SkMatrix fViewMatrix;
330 SkPath fPath;
331 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700332 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700333 SkPaint::Join fJoin;
334 SkScalar fMiterLimit;
335 };
336
Brian Salomon780dad12016-12-15 18:08:40 -0500337 GrColor fColor;
338 bool fUsesLocalCoords;
339 bool fCoverageIgnored;
340 bool fCanTweakAlphaForCoverage;
341 SkSTArray<1, PathData, true> fPaths;
reed1b55a962015-09-17 20:16:13 -0700342
Brian Salomondad29232016-12-01 16:40:24 -0500343 typedef GrMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700344};
345
bsalomon0aff2fa2015-07-31 06:48:27 -0700346bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400347 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800348 "GrAALinearizingConvexPathRenderer::onDrawPath");
Brian Osman11052242016-10-27 14:47:55 -0400349 SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
bsalomon8acedde2016-06-24 10:42:16 -0700350 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700351 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700352
bsalomon0432dd62016-06-30 07:19:27 -0700353 SkPath path;
354 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700355 bool fill = args.fShape->style().isSimpleFill();
356 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700357 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
358 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
359 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700360
Brian Salomon780dad12016-12-15 18:08:40 -0500361 sk_sp<GrDrawOp> op =
362 AAFlatteningConvexPathOp::Make(args.fPaint->getColor(), *args.fViewMatrix, path,
363 strokeWidth, stroke.getStyle(), join, miterLimit);
robertphillips976f5f02016-06-03 10:59:20 -0700364
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500365 GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
bsalomonbb243832016-07-22 07:10:19 -0700366 pipelineBuilder.setUserStencil(args.fUserStencilSettings);
367
Brian Salomon24f19782016-12-13 15:10:11 -0500368 args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
bsalomonbb243832016-07-22 07:10:19 -0700369
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700370 return true;
371}
372
373///////////////////////////////////////////////////////////////////////////////////////////////////
374
375#ifdef GR_TEST_UTILS
376
Brian Salomon780dad12016-12-15 18:08:40 -0500377DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathOp) {
bsalomon0432dd62016-06-30 07:19:27 -0700378 GrColor color = GrRandomColor(random);
Brian Salomon780dad12016-12-15 18:08:40 -0500379 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700380 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700381
382 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500383 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700384 SkStrokeRec::kStrokeAndFill_Style };
385
386 SkStrokeRec::Style style = styles[random->nextU() % 3];
387
388 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700389 SkPaint::Join join = SkPaint::kMiter_Join;
390 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700391
392 if (SkStrokeRec::kFill_Style != style) {
393 strokeWidth = random->nextRangeF(1.0f, 10.0f);
394 if (random->nextBool()) {
395 join = SkPaint::kMiter_Join;
396 } else {
397 join = SkPaint::kBevel_Join;
398 }
399 miterLimit = random->nextRangeF(0.5f, 2.0f);
400 }
401
Brian Salomon780dad12016-12-15 18:08:40 -0500402 return AAFlatteningConvexPathOp::Make(color, viewMatrix, path, strokeWidth, style, join,
403 miterLimit)
404 .release();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700405}
406
407#endif