blob: 6c94793a351ea4a0996ce7ad7c5f0c710ed8561e [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"
Brian Salomon742e31d2016-12-07 17:06:19 -050015#include "GrOpFlushState.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070016#include "GrPathUtils.h"
bsalomonbb243832016-07-22 07:10:19 -070017#include "GrPipelineBuilder.h"
Brian Salomondad29232016-12-01 16:40:24 -050018#include "GrProcessor.h"
bsalomon6663acf2016-05-10 09:14:17 -070019#include "GrStyle.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070020#include "SkGeometry.h"
Brian Salomondad29232016-12-01 16:40:24 -050021#include "SkPathPriv.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070022#include "SkString.h"
23#include "SkTraceEvent.h"
egdaniele659a582015-11-13 09:55:43 -080024#include "glsl/GrGLSLGeometryProcessor.h"
Brian Salomon89527432016-12-16 09:52:16 -050025#include "ops/GrMeshDrawOp.h"
ethannicholas1a1b3ac2015-06-10 12:11:17 -070026
fmalitabd5d7e72015-06-26 07:18:24 -070027static const int DEFAULT_BUFFER_SIZE = 100;
28
29// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For
30// the time being, we simply drop back to software rendering above this stroke width.
31static const SkScalar kMaxStrokeWidth = 20.0;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070032
33GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
34}
35
36///////////////////////////////////////////////////////////////////////////////
37
bsalomon0aff2fa2015-07-31 06:48:27 -070038bool GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050039 if (GrAAType::kCoverage != args.fAAType) {
fmalitabd5d7e72015-06-26 07:18:24 -070040 return false;
41 }
bsalomon8acedde2016-06-24 10:42:16 -070042 if (!args.fShape->knownToBeConvex()) {
fmalitabd5d7e72015-06-26 07:18:24 -070043 return false;
44 }
bsalomon8acedde2016-06-24 10:42:16 -070045 if (args.fShape->style().pathEffect()) {
fmalitabd5d7e72015-06-26 07:18:24 -070046 return false;
47 }
bsalomon8acedde2016-06-24 10:42:16 -070048 if (args.fShape->inverseFilled()) {
bsalomon6663acf2016-05-10 09:14:17 -070049 return false;
50 }
bsalomon8acedde2016-06-24 10:42:16 -070051 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
robertphillips8c170972016-09-22 12:42:30 -070052
53 if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
54 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
ethannicholasfea77632015-08-19 12:09:12 -070055 if (!args.fViewMatrix->isSimilarity()) {
56 return false;
57 }
bsalomon6663acf2016-05-10 09:14:17 -070058 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * stroke.getWidth();
robertphillips8c170972016-09-22 12:42:30 -070059 if (strokeWidth < 1.0f && stroke.getStyle() == SkStrokeRec::kStroke_Style) {
60 return false;
61 }
62 return strokeWidth <= kMaxStrokeWidth &&
bsalomon8acedde2016-06-24 10:42:16 -070063 args.fShape->knownToBeClosed() &&
bsalomon6663acf2016-05-10 09:14:17 -070064 stroke.getJoin() != SkPaint::Join::kRound_Join;
fmalitabd5d7e72015-06-26 07:18:24 -070065 }
bsalomon6663acf2016-05-10 09:14:17 -070066 return stroke.getStyle() == SkStrokeRec::kFill_Style;
ethannicholas1a1b3ac2015-06-10 12:11:17 -070067}
68
69// extract the result vertices and indices from the GrAAConvexTessellator
70static void extract_verts(const GrAAConvexTessellator& tess,
71 void* vertices,
72 size_t vertexStride,
73 GrColor color,
74 uint16_t firstIndex,
75 uint16_t* idxs,
76 bool tweakAlphaForCoverage) {
77 intptr_t verts = reinterpret_cast<intptr_t>(vertices);
78
79 for (int i = 0; i < tess.numPts(); ++i) {
80 *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i);
81 }
82
83 // Make 'verts' point to the colors
84 verts += sizeof(SkPoint);
85 for (int i = 0; i < tess.numPts(); ++i) {
ethannicholas1a1b3ac2015-06-10 12:11:17 -070086 if (tweakAlphaForCoverage) {
fmalitabd5d7e72015-06-26 07:18:24 -070087 SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255);
88 unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
ethannicholas1a1b3ac2015-06-10 12:11:17 -070089 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
90 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
91 } else {
92 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
mtklein002c2ce2015-08-26 05:43:22 -070093 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
fmalitabd5d7e72015-06-26 07:18:24 -070094 tess.coverage(i);
ethannicholas1a1b3ac2015-06-10 12:11:17 -070095 }
96 }
97
98 for (int i = 0; i < tess.numIndices(); ++i) {
99 idxs[i] = tess.index(i) + firstIndex;
100 }
101}
102
bungeman06ca8ec2016-06-09 08:01:03 -0700103static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage,
joshualittdf0c5572015-08-03 11:35:28 -0700104 const SkMatrix& viewMatrix,
Brian Salomon8c852be2017-01-04 10:44:42 -0500105 bool usesLocalCoords) {
joshualittdf0c5572015-08-03 11:35:28 -0700106 using namespace GrDefaultGeoProcFactory;
joshualitte494a582015-08-03 09:32:36 -0700107
joshualittdf0c5572015-08-03 11:35:28 -0700108 Coverage::Type coverageType;
Brian Salomon8c852be2017-01-04 10:44:42 -0500109 if (tweakAlphaForCoverage) {
joshualittdf0c5572015-08-03 11:35:28 -0700110 coverageType = Coverage::kSolid_Type;
111 } else {
112 coverageType = Coverage::kAttribute_Type;
113 }
Brian Salomon8c852be2017-01-04 10:44:42 -0500114 LocalCoords::Type localCoordsType =
115 usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500116 return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType,
117 viewMatrix);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700118}
119
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400120class AAFlatteningConvexPathOp final : public GrLegacyMeshDrawOp {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700121public:
Brian Salomon25a88092016-12-01 09:36:50 -0500122 DEFINE_OP_CLASS_ID
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400123 static std::unique_ptr<GrLegacyMeshDrawOp> 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<GrLegacyMeshDrawOp>(new AAFlatteningConvexPathOp(
Brian Salomonf8334782017-01-03 09:42:58 -0500131 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 Salomona811b122017-03-30 08:21:32 -0400175 void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
176 GrProcessorAnalysisCoverage* coverage) const override {
Brian Salomonc0b642c2017-03-27 13:09:36 -0400177 color->setToConstant(fPaths[0].fColor);
Brian Salomona811b122017-03-30 08:21:32 -0400178 *coverage = GrProcessorAnalysisCoverage::kSingleChannel;
Brian Salomon92aee3d2016-12-21 09:20:25 -0500179 }
180
Brian Salomone7d30482017-03-29 12:09:15 -0400181 void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
Brian Salomon92aee3d2016-12-21 09:20:25 -0500182 optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
Brian Salomon92aee3d2016-12-21 09:20:25 -0500183 fUsesLocalCoords = optimizations.readsLocalCoords();
Brian Salomon92aee3d2016-12-21 09:20:25 -0500184 fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700185 }
186
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400187 void draw(GrLegacyMeshDrawOp::Target* target, const GrGeometryProcessor* gp, int vertexCount,
joshualitt144c3c82015-11-30 12:30:13 -0800188 size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700189 if (vertexCount == 0 || indexCount == 0) {
190 return;
191 }
Chris Daltonff926502017-05-03 14:36:54 -0400192
egdaniel0e1853c2016-03-17 11:35:45 -0700193 GrMesh mesh;
Chris Daltonff926502017-05-03 14:36:54 -0400194 mesh.fPrimitiveType = kTriangles_GrPrimitiveType;
195 const GrBuffer* vertexBuffer;
mtklein002c2ce2015-08-26 05:43:22 -0700196 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
Chris Daltonff926502017-05-03 14:36:54 -0400197 &mesh.fBaseVertex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700198 if (!verts) {
199 SkDebugf("Could not allocate vertices\n");
200 return;
201 }
Chris Daltonff926502017-05-03 14:36:54 -0400202 mesh.fVertexBuffer.reset(vertexBuffer);
203 mesh.fVertexCount = vertexCount;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700204 memcpy(verts, vertices, vertexCount * vertexStride);
205
cdalton397536c2016-03-25 12:15:03 -0700206 const GrBuffer* indexBuffer;
Chris Daltonff926502017-05-03 14:36:54 -0400207 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &mesh.fBaseIndex);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700208 if (!idxs) {
209 SkDebugf("Could not allocate indices\n");
210 return;
211 }
Chris Daltonff926502017-05-03 14:36:54 -0400212 mesh.fIndexBuffer.reset(indexBuffer);
213 mesh.fIndexCount = indexCount;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700214 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
Chris Daltonff926502017-05-03 14:36:54 -0400215
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400216 target->draw(gp, this->pipeline(), mesh);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700217 }
mtklein002c2ce2015-08-26 05:43:22 -0700218
joshualitt144c3c82015-11-30 12:30:13 -0800219 void onPrepareDraws(Target* target) const override {
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700220 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
221
joshualittdf0c5572015-08-03 11:35:28 -0700222 // Setup GrGeometryProcessor
Brian Salomon8c852be2017-01-04 10:44:42 -0500223 sk_sp<GrGeometryProcessor> gp(create_fill_gp(
224 canTweakAlphaForCoverage, this->viewMatrix(), this->usesLocalCoords()));
joshualittdf0c5572015-08-03 11:35:28 -0700225 if (!gp) {
226 SkDebugf("Couldn't create a GrGeometryProcessor\n");
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700227 return;
228 }
229
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700230 size_t vertexStride = gp->getVertexStride();
231
232 SkASSERT(canTweakAlphaForCoverage ?
233 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
234 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
235
Brian Salomon780dad12016-12-15 18:08:40 -0500236 int instanceCount = fPaths.count();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700237
238 int vertexCount = 0;
239 int indexCount = 0;
240 int maxVertices = DEFAULT_BUFFER_SIZE;
241 int maxIndices = DEFAULT_BUFFER_SIZE;
mtklein002c2ce2015-08-26 05:43:22 -0700242 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
243 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700244 for (int i = 0; i < instanceCount; i++) {
Brian Salomon780dad12016-12-15 18:08:40 -0500245 const PathData& args = fPaths[i];
robertphillips8c170972016-09-22 12:42:30 -0700246 GrAAConvexTessellator tess(args.fStyle, args.fStrokeWidth,
247 args.fJoin, args.fMiterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700248
249 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
250 continue;
251 }
252
253 int currentIndices = tess.numIndices();
254 SkASSERT(currentIndices <= UINT16_MAX);
255 if (indexCount + currentIndices > UINT16_MAX) {
mtklein002c2ce2015-08-26 05:43:22 -0700256 // if we added the current instance, we would overflow the indices we can store in a
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700257 // uint16_t. Draw what we've got so far and reset.
bungeman06ca8ec2016-06-09 08:01:03 -0700258 this->draw(target, gp.get(),
259 vertexCount, vertexStride, vertices, indexCount, indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700260 vertexCount = 0;
261 indexCount = 0;
262 }
263 int currentVertices = tess.numPts();
264 if (vertexCount + currentVertices > maxVertices) {
265 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700266 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700267 }
268 if (indexCount + currentIndices > maxIndices) {
269 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2);
mtklein002c2ce2015-08-26 05:43:22 -0700270 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700271 }
272
mtklein002c2ce2015-08-26 05:43:22 -0700273 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor,
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700274 vertexCount, indices + indexCount, canTweakAlphaForCoverage);
275 vertexCount += currentVertices;
276 indexCount += currentIndices;
277 }
bungeman06ca8ec2016-06-09 08:01:03 -0700278 this->draw(target, gp.get(), vertexCount, vertexStride, vertices, indexCount, indices);
mtklein002c2ce2015-08-26 05:43:22 -0700279 sk_free(vertices);
280 sk_free(indices);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700281 }
282
Brian Salomon25a88092016-12-01 09:36:50 -0500283 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon780dad12016-12-15 18:08:40 -0500284 AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
bsalomonabd30f52015-08-13 13:34:48 -0700285 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
286 that->bounds(), caps)) {
joshualitt8cab9a72015-07-16 09:13:50 -0700287 return false;
288 }
289
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700290 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
291 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
292 return false;
293 }
294
Brian Salomon780dad12016-12-15 18:08:40 -0500295 // In the event of two ops, one who can tweak, one who cannot, we just fall back to not
296 // tweaking
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700297 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) {
Brian Salomon780dad12016-12-15 18:08:40 -0500298 fCanTweakAlphaForCoverage = false;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700299 }
300
Brian Salomon780dad12016-12-15 18:08:40 -0500301 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700302 this->joinBounds(*that);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700303 return true;
304 }
305
Brian Salomon780dad12016-12-15 18:08:40 -0500306 bool usesLocalCoords() const { return fUsesLocalCoords; }
307 bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; }
308 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700309
Brian Salomon780dad12016-12-15 18:08:40 -0500310 struct PathData {
bsalomon0432dd62016-06-30 07:19:27 -0700311 GrColor fColor;
312 SkMatrix fViewMatrix;
313 SkPath fPath;
314 SkScalar fStrokeWidth;
robertphillips8c170972016-09-22 12:42:30 -0700315 SkStrokeRec::Style fStyle;
bsalomon0432dd62016-06-30 07:19:27 -0700316 SkPaint::Join fJoin;
317 SkScalar fMiterLimit;
318 };
319
Brian Salomon780dad12016-12-15 18:08:40 -0500320 bool fUsesLocalCoords;
Brian Salomon780dad12016-12-15 18:08:40 -0500321 bool fCanTweakAlphaForCoverage;
322 SkSTArray<1, PathData, true> fPaths;
reed1b55a962015-09-17 20:16:13 -0700323
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400324 typedef GrLegacyMeshDrawOp INHERITED;
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700325};
326
bsalomon0aff2fa2015-07-31 06:48:27 -0700327bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400328 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
joshualittde83b412016-01-14 09:58:36 -0800329 "GrAALinearizingConvexPathRenderer::onDrawPath");
Brian Osman11052242016-10-27 14:47:55 -0400330 SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
bsalomon8acedde2016-06-24 10:42:16 -0700331 SkASSERT(!args.fShape->isEmpty());
robertphillips8c170972016-09-22 12:42:30 -0700332 SkASSERT(!args.fShape->style().pathEffect());
csmartdaltonecbc12b2016-06-08 10:08:43 -0700333
bsalomon0432dd62016-06-30 07:19:27 -0700334 SkPath path;
335 args.fShape->asPath(&path);
bsalomon8acedde2016-06-24 10:42:16 -0700336 bool fill = args.fShape->style().isSimpleFill();
337 const SkStrokeRec& stroke = args.fShape->style().strokeRec();
bsalomon0432dd62016-06-30 07:19:27 -0700338 SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
339 SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
340 SkScalar miterLimit = stroke.getMiter();
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700341
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400342 std::unique_ptr<GrLegacyMeshDrawOp> op =
Brian Salomon82f44312017-01-11 13:42:54 -0500343 AAFlatteningConvexPathOp::Make(args.fPaint.getColor(), *args.fViewMatrix, path,
Brian Salomon780dad12016-12-15 18:08:40 -0500344 strokeWidth, stroke.getStyle(), join, miterLimit);
robertphillips976f5f02016-06-03 10:59:20 -0700345
Brian Salomon82f44312017-01-11 13:42:54 -0500346 GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
bsalomonbb243832016-07-22 07:10:19 -0700347 pipelineBuilder.setUserStencil(args.fUserStencilSettings);
348
Brian Salomone14bd802017-04-04 15:13:25 -0400349 args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
350 std::move(op));
bsalomonbb243832016-07-22 07:10:19 -0700351
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 Salomon5ec9def2016-12-20 15:34:05 -0500359DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
bsalomon0432dd62016-06-30 07:19:27 -0700360 GrColor color = GrRandomColor(random);
Brian Salomon780dad12016-12-15 18:08:40 -0500361 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
bsalomon0432dd62016-06-30 07:19:27 -0700362 SkPath path = GrTest::TestPathConvex(random);
robertphillips8c170972016-09-22 12:42:30 -0700363
364 SkStrokeRec::Style styles[3] = { SkStrokeRec::kFill_Style,
Herb Derby60c05f92016-12-13 15:18:55 -0500365 SkStrokeRec::kStroke_Style,
robertphillips8c170972016-09-22 12:42:30 -0700366 SkStrokeRec::kStrokeAndFill_Style };
367
368 SkStrokeRec::Style style = styles[random->nextU() % 3];
369
370 SkScalar strokeWidth = -1.f;
bsalomon0432dd62016-06-30 07:19:27 -0700371 SkPaint::Join join = SkPaint::kMiter_Join;
372 SkScalar miterLimit = 0.5f;
robertphillips8c170972016-09-22 12:42:30 -0700373
374 if (SkStrokeRec::kFill_Style != style) {
375 strokeWidth = random->nextRangeF(1.0f, 10.0f);
376 if (random->nextBool()) {
377 join = SkPaint::kMiter_Join;
378 } else {
379 join = SkPaint::kBevel_Join;
380 }
381 miterLimit = random->nextRangeF(0.5f, 2.0f);
382 }
383
Brian Salomon780dad12016-12-15 18:08:40 -0500384 return AAFlatteningConvexPathOp::Make(color, viewMatrix, path, strokeWidth, style, join,
Brian Salomon5ec9def2016-12-20 15:34:05 -0500385 miterLimit);
ethannicholas1a1b3ac2015-06-10 12:11:17 -0700386}
387
388#endif