blob: 03e5ce35221365317e60a8d8fe06d1d7522e4ec4 [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 "GrContext.h"
12#include "GrDefaultGeoProcFactory.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050013#include "GrDrawOpTest.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070014#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,
Brian Salomon8c852be2017-01-04 10:44:42 -0500106 bool usesLocalCoords) {
joshualittdf0c5572015-08-03 11:35:28 -0700107 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700108
joshualittdf0c5572015-08-03 11:35:28 -0700109 Coverage::Type coverageType;
Brian Salomon8c852be2017-01-04 10:44:42 -0500110 if (tweakAlphaForCoverage) {
joshualittdf0c5572015-08-03 11:35:28 -0700111 coverageType = Coverage::kSolid_Type;
112 } else {
113 coverageType = Coverage::kAttribute_Type;
114 }
Brian Salomon8c852be2017-01-04 10:44:42 -0500115 LocalCoords::Type localCoordsType =
116 usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
117 return MakeForDeviceSpace(Color::kAttribute_Type, coverageType, localCoordsType, viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700118}
119
Brian Salomon780dad12016-12-15 18:08:40 -0500120class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700121public:
Brian Salomon25a88092016-12-01 09:36:50 -0500122 DEFINE_OP_CLASS_ID
Brian Salomonf8334782017-01-03 09:42:58 -0500123 static std::unique_ptr<GrDrawOp> Make(GrColor color,
124 const SkMatrix& viewMatrix,
125 const SkPath& path,
126 SkScalar strokeWidth,
127 SkStrokeRec::Style style,
128 SkPaint::Join join,
129 SkScalar miterLimit) {
130 return std::unique_ptr<GrDrawOp>(new AAFlatteningConvexPathOp(
131 color, viewMatrix, path, strokeWidth, style, join, miterLimit));
Brian Salomon780dad12016-12-15 18:08:40 -0500132 }
133
134 const char* name() const override { return "AAFlatteningConvexPathOp"; }
135
136 SkString dumpInfo() const override {
137 SkString string;
138 for (const auto& path : fPaths) {
139 string.appendf(
140 "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
141 "MiterLimit: %.2f\n",
142 path.fColor, path.fStrokeWidth, path.fStyle, path.fJoin, path.fMiterLimit);
143 }
144 string.append(DumpPipelineInfo(*this->pipeline()));
145 string.append(INHERITED::dumpInfo());
146 return string;
147 }
148
Brian Salomon780dad12016-12-15 18:08:40 -0500149private:
150 AAFlatteningConvexPathOp(GrColor color,
151 const SkMatrix& viewMatrix,
152 const SkPath& path,
153 SkScalar strokeWidth,
154 SkStrokeRec::Style style,
155 SkPaint::Join join,
156 SkScalar miterLimit)
157 : INHERITED(ClassID()) {
158 fPaths.emplace_back(
159 PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700160
bsalomon0432dd62016-06-30 07:19:27 -0700161 // compute bounds
bsalomon88cf17d2016-07-08 06:40:56 -0700162 SkRect bounds = path.getBounds();
bsalomon0432dd62016-06-30 07:19:27 -0700163 SkScalar w = strokeWidth;
164 if (w > 0) {
165 w /= 2;
166 // If the half stroke width is < 1 then we effectively fallback to bevel joins.
167 if (SkPaint::kMiter_Join == join && w > 1.f) {
168 w *= miterLimit;
169 }
bsalomon88cf17d2016-07-08 06:40:56 -0700170 bounds.outset(w, w);
bsalomon0432dd62016-06-30 07:19:27 -0700171 }
bsalomon88cf17d2016-07-08 06:40:56 -0700172 this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700173 }
174
Brian Salomon92aee3d2016-12-21 09:20:25 -0500175 void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override {
176 input->pipelineColorInput()->setKnownFourComponents(fPaths[0].fColor);
177 input->pipelineCoverageInput()->setUnknownSingleComponent();
178 }
179
180 void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
181 if (!optimizations.readsColor()) {
Brian Salomon780dad12016-12-15 18:08:40 -0500182 fPaths[0].fColor = GrColor_ILLEGAL;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700183 }
Brian Salomon92aee3d2016-12-21 09:20:25 -0500184 optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700185
Brian Salomon780dad12016-12-15 18:08:40 -0500186 fColor = fPaths[0].fColor;
Brian Salomon92aee3d2016-12-21 09:20:25 -0500187 fUsesLocalCoords = optimizations.readsLocalCoords();
Brian Salomon92aee3d2016-12-21 09:20:25 -0500188 fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700189 }
190
Brian Salomondad29232016-12-01 16:40:24 -0500191 void draw(GrMeshDrawOp::Target* target, const GrGeometryProcessor* gp, int vertexCount,
joshualitt144c3c82015-11-30 12:30:13 -0800192 size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700193 if (vertexCount == 0 || indexCount == 0) {
194 return;
195 }
cdalton397536c2016-03-25 12:15:03 -0700196 const GrBuffer* vertexBuffer;
egdaniel0e1853c2016-03-17 11:35:45 -0700197 GrMesh mesh;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700198 int firstVertex;
mtklein002c2ce2015-08-26 05:43:22 -0700199 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
bsalomon75398562015-08-17 12:55:38 -0700200 &firstVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700201 if (!verts) {
202 SkDebugf("Could not allocate vertices\n");
203 return;
204 }
205 memcpy(verts, vertices, vertexCount * vertexStride);
206
cdalton397536c2016-03-25 12:15:03 -0700207 const GrBuffer* indexBuffer;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700208 int firstIndex;
bsalomon75398562015-08-17 12:55:38 -0700209 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700210 if (!idxs) {
211 SkDebugf("Could not allocate indices\n");
212 return;
213 }
214 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
egdaniel0e1853c2016-03-17 11:35:45 -0700215 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
216 firstIndex, vertexCount, indexCount);
bsalomon342bfc22016-04-01 06:06:20 -0700217 target->draw(gp, mesh);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700218 }
mtklein002c2ce2015-08-26 05:43:22 -0700219
joshualitt144c3c82015-11-30 12:30:13 -0800220 void onPrepareDraws(Target* target) const override {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700221 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
222
joshualittdf0c5572015-08-03 11:35:28 -0700223 // Setup GrGeometryProcessor
Brian Salomon8c852be2017-01-04 10:44:42 -0500224 sk_sp<GrGeometryProcessor> gp(create_fill_gp(
225 canTweakAlphaForCoverage, this->viewMatrix(), this->usesLocalCoords()));
joshualittdf0c5572015-08-03 11:35:28 -0700226 if (!gp) {
227 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700228 return;
229 }
230
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700231 size_t vertexStride = gp->getVertexStride();
232
233 SkASSERT(canTweakAlphaForCoverage ?
234 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
235 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
236
Brian Salomon780dad12016-12-15 18:08:40 -0500237 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700238
239 int vertexCount = 0;
240 int indexCount = 0;
241 int maxVertices = DEFAULT_BUFFER_SIZE;
242 int maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700243 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
244 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700245 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500246 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700247 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
248 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700249
250 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
251 continue;
252 }
253
254 int currentIndices = tess.numIndices();
255 SkASSERT(currentIndices <= UINT16_MAX);
256 if (indexCount + currentIndices > UINT16_MAX) {
mtklein002c2ce2015-08-26 05:43:22 -0700257 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700258 // uint16_t. Draw what we've got so far and reset.
bungeman06ca8ec2016-06-09 08:01:03 -0700259 this->draw(target, gp.get(),
260 vertexCount, vertexStride, vertices, indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700261 vertexCount = 0;
262 indexCount = 0;
263 }
264 int currentVertices = tess.numPts();
265 if (vertexCount + currentVertices > maxVertices) {
266 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700267 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700268 }
269 if (indexCount + currentIndices > maxIndices) {
270 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700271 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700272 }
273
mtklein002c2ce2015-08-26 05:43:22 -0700274 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor,
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700275 vertexCount, indices + indexCount, canTweakAlphaForCoverage);
276 vertexCount += currentVertices;
277 indexCount += currentIndices;
278 }
bungeman06ca8ec2016-06-09 08:01:03 -0700279 this->draw(target, gp.get(), vertexCount, vertexStride, vertices, indexCount, indices);
mtklein002c2ce2015-08-26 05:43:22 -0700280 sk_free(vertices);
281 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700282 }
283
Brian Salomon25a88092016-12-01 09:36:50 -0500284 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500285 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
bsalomonabd30f52015-08-13 13:34:48 -0700286 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
287 that->bounds(), caps)) {
joshualitt8cab9a72015-07-16 09:13:50 -0700288 return false;
289 }
290
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700291 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
292 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
293 return false;
294 }
295
Brian Salomon780dad12016-12-15 18:08:40 -0500296 // In the event of two ops, one who can tweak, one who cannot, we just fall back to not
297 // tweaking
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700298 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) {
Brian Salomon780dad12016-12-15 18:08:40 -0500299 fCanTweakAlphaForCoverage = false;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700300 }
301
Brian Salomon780dad12016-12-15 18:08:40 -0500302 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700303 this->joinBounds(*that);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700304 return true;
305 }
306
Brian Salomon780dad12016-12-15 18:08:40 -0500307 GrColor color() const { return fColor; }
308 bool usesLocalCoords() const { return fUsesLocalCoords; }
309 bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; }
310 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700311
Brian Salomon780dad12016-12-15 18:08:40 -0500312 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700313 GrColor fColor;
314 SkMatrix fViewMatrix;
315 SkPath fPath;
316 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700317 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700318 SkPaint::Join fJoin;
319 SkScalar fMiterLimit;
320 };
321
Brian Salomon780dad12016-12-15 18:08:40 -0500322 GrColor fColor;
323 bool fUsesLocalCoords;
Brian Salomon780dad12016-12-15 18:08:40 -0500324 bool fCanTweakAlphaForCoverage;
325 SkSTArray<1, PathData, true> fPaths;
reed1b55a962015-09-17 20:16:13 -0700326
Brian Salomondad29232016-12-01 16:40:24 -0500327 typedef GrMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700328};
329
bsalomon0aff2fa2015-07-31 06:48:27 -0700330bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400331 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800332 "GrAALinearizingConvexPathRenderer::onDrawPath");
Brian Osman11052242016-10-27 14:47:55 -0400333 SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
bsalomon8acedde2016-06-24 10:42:16 -0700334 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700335 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700336
bsalomon0432dd62016-06-30 07:19:27 -0700337 SkPath path;
338 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700339 bool fill = args.fShape->style().isSimpleFill();
340 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700341 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
342 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
343 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700344
Brian Salomonf8334782017-01-03 09:42:58 -0500345 std::unique_ptr<GrDrawOp> op =
Brian Salomon780dad12016-12-15 18:08:40 -0500346 AAFlatteningConvexPathOp::Make(args.fPaint->getColor(), *args.fViewMatrix, path,
347 strokeWidth, stroke.getStyle(), join, miterLimit);
robertphillips976f5f02016-06-03 10:59:20 -0700348
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500349 GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
bsalomonbb243832016-07-22 07:10:19 -0700350 pipelineBuilder.setUserStencil(args.fUserStencilSettings);
351
Brian Salomon24f19782016-12-13 15:10:11 -0500352 args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
bsalomonbb243832016-07-22 07:10:19 -0700353
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700354 return true;
355}
356
357///////////////////////////////////////////////////////////////////////////////////////////////////
358
359#ifdef GR_TEST_UTILS
360
Brian Salomon5ec9def2016-12-20 15:34:05 -0500361DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
bsalomon0432dd62016-06-30 07:19:27 -0700362 GrColor color = GrRandomColor(random);
Brian Salomon780dad12016-12-15 18:08:40 -0500363 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700364 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700365
366 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500367 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700368 SkStrokeRec::kStrokeAndFill_Style };
369
370 SkStrokeRec::Style style = styles[random->nextU() % 3];
371
372 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700373 SkPaint::Join join = SkPaint::kMiter_Join;
374 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700375
376 if (SkStrokeRec::kFill_Style != style) {
377 strokeWidth = random->nextRangeF(1.0f, 10.0f);
378 if (random->nextBool()) {
379 join = SkPaint::kMiter_Join;
380 } else {
381 join = SkPaint::kBevel_Join;
382 }
383 miterLimit = random->nextRangeF(0.5f, 2.0f);
384 }
385
Brian Salomon780dad12016-12-15 18:08:40 -0500386 return AAFlatteningConvexPathOp::Make(color, viewMatrix, path, strokeWidth, style, join,
Brian Salomon5ec9def2016-12-20 15:34:05 -0500387 miterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700388}
389
390#endif