blob: 5e2a3bec48ba0e9d1ad87955f6d2a77c90762726 [file] [log] [blame]
bsalomon@google.comf75b84e2011-09-29 14:58:28 +00001/*
2 * Copyright 2011 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
bsalomon@google.comaeb21602011-08-30 18:13:44 +00008#include "GrAAHairLinePathRenderer.h"
cdalton397536c2016-03-25 12:15:03 -07009#include "GrBuffer.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070010#include "GrCaps.h"
Brian Salomonc65aec92017-03-09 09:03:58 -050011#include "GrClip.h"
bsalomon@google.comaeb21602011-08-30 18:13:44 +000012#include "GrContext.h"
joshualitt5478d422014-11-14 16:00:38 -080013#include "GrDefaultGeoProcFactory.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050014#include "GrDrawOpTest.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050015#include "GrOpFlushState.h"
bsalomon@google.comdbeeac32011-09-12 14:59:34 +000016#include "GrPathUtils.h"
joshualitt5478d422014-11-14 16:00:38 -080017#include "GrProcessor.h"
bsalomoned0bcad2015-05-04 10:36:42 -070018#include "GrResourceProvider.h"
Brian Salomon653f42f2018-07-10 10:07:31 -040019#include "GrShape.h"
Brian Salomona531f252017-07-07 13:29:28 -040020#include "GrSimpleMeshDrawOpHelper.h"
Brian Salomon653f42f2018-07-10 10:07:31 -040021#include "GrStyle.h"
bsalomon@google.comaeb21602011-08-30 18:13:44 +000022#include "SkGeometry.h"
Brian Salomonfa3783f2018-01-05 13:49:07 -050023#include "SkMatrixPriv.h"
Cary Clarke4442cb2017-10-18 11:46:18 -040024#include "SkPoint3.h"
Cary Clarkdf429f32017-11-08 11:44:31 -050025#include "SkPointPriv.h"
Mike Reed185ffe92018-01-08 17:09:54 -050026#include "SkRectPriv.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000027#include "SkStroke.h"
bsalomon@google.comaeb21602011-08-30 18:13:44 +000028#include "SkTemplates.h"
commit-bot@chromium.org07e1c3f2013-08-22 20:41:15 +000029#include "effects/GrBezierEffect.h"
Brian Salomonc65aec92017-03-09 09:03:58 -050030#include "ops/GrMeshDrawOp.h"
bsalomon@google.com4647f902013-03-26 14:45:27 +000031
bsalomoned0bcad2015-05-04 10:36:42 -070032#define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true>
33
bsalomon@google.comaeb21602011-08-30 18:13:44 +000034// quadratics are rendered as 5-sided polys in order to bound the
35// AA stroke around the center-curve. See comments in push_quad_index_buffer and
egdaniel@google.com5383a752013-07-12 20:15:34 +000036// bloat_quad. Quadratics and conics share an index buffer
bsalomon@google.comaeb21602011-08-30 18:13:44 +000037
robertphillips@google.comada90da2013-09-18 22:14:49 +000038// lines are rendered as:
39// *______________*
40// |\ -_______ /|
41// | \ \ / |
42// | *--------* |
43// | / ______/ \ |
44// */_-__________\*
45// For: 6 vertices and 18 indices (for 6 triangles)
bsalomon@google.comaeb21602011-08-30 18:13:44 +000046
joshualitt5ead6da2014-10-22 16:00:29 -070047// Each quadratic is rendered as a five sided polygon. This poly bounds
48// the quadratic's bounding triangle but has been expanded so that the
49// 1-pixel wide area around the curve is inside the poly.
50// If a,b,c are the original control points then the poly a0,b0,c0,c1,a1
51// that is rendered would look like this:
52// b0
53// b
54//
55// a0 c0
56// a c
57// a1 c1
egdaniel14afb432014-12-22 10:57:08 -080058// Each is drawn as three triangles ((a0,a1,b0), (b0,c1,c0), (a1,c1,b0))
59// specified by these 9 indices:
joshualitt5ead6da2014-10-22 16:00:29 -070060static const uint16_t kQuadIdxBufPattern[] = {
61 0, 1, 2,
62 2, 4, 3,
63 1, 4, 2
64};
bsalomon@google.comaeb21602011-08-30 18:13:44 +000065
joshualitt5ead6da2014-10-22 16:00:29 -070066static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern);
67static const int kQuadNumVertices = 5;
68static const int kQuadsNumInIdxBuffer = 256;
bsalomoned0bcad2015-05-04 10:36:42 -070069GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
70
Brian Salomond28a79d2017-10-16 13:01:07 -040071static sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) {
bsalomoned0bcad2015-05-04 10:36:42 -070072 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
Chris Daltonff926502017-05-03 14:36:54 -040073 return resourceProvider->findOrCreatePatternedIndexBuffer(
bsalomoned0bcad2015-05-04 10:36:42 -070074 kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices,
75 gQuadsIndexBufferKey);
76}
jvanverth@google.com681ccf02013-08-16 14:51:51 +000077
bsalomon@google.comaeb21602011-08-30 18:13:44 +000078
joshualitt5ead6da2014-10-22 16:00:29 -070079// Each line segment is rendered as two quads and two triangles.
80// p0 and p1 have alpha = 1 while all other points have alpha = 0.
81// The four external points are offset 1 pixel perpendicular to the
82// line and half a pixel parallel to the line.
83//
84// p4 p5
85// p0 p1
86// p2 p3
87//
88// Each is drawn as six triangles specified by these 18 indices:
jvanverth@google.com681ccf02013-08-16 14:51:51 +000089
joshualitt5ead6da2014-10-22 16:00:29 -070090static const uint16_t kLineSegIdxBufPattern[] = {
91 0, 1, 3,
92 0, 3, 2,
93 0, 4, 5,
94 0, 5, 1,
95 0, 2, 4,
96 1, 5, 3
97};
skia.committer@gmail.com74758112013-08-17 07:01:54 +000098
joshualitt5ead6da2014-10-22 16:00:29 -070099static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern);
100static const int kLineSegNumVertices = 6;
101static const int kLineSegsNumInIdxBuffer = 256;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000102
bsalomoned0bcad2015-05-04 10:36:42 -0700103GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
104
Brian Salomond28a79d2017-10-16 13:01:07 -0400105static sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) {
bsalomoned0bcad2015-05-04 10:36:42 -0700106 GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
Chris Daltonff926502017-05-03 14:36:54 -0400107 return resourceProvider->findOrCreatePatternedIndexBuffer(
bsalomoned0bcad2015-05-04 10:36:42 -0700108 kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices,
109 gLinesIndexBufferKey);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000110}
111
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000112// Takes 178th time of logf on Z600 / VC2010
bsalomoned0bcad2015-05-04 10:36:42 -0700113static int get_float_exp(float x) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000114 GR_STATIC_ASSERT(sizeof(int) == sizeof(float));
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000115#ifdef SK_DEBUG
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000116 static bool tested;
117 if (!tested) {
118 tested = true;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000119 SkASSERT(get_float_exp(0.25f) == -2);
120 SkASSERT(get_float_exp(0.3f) == -2);
121 SkASSERT(get_float_exp(0.5f) == -1);
122 SkASSERT(get_float_exp(1.f) == 0);
123 SkASSERT(get_float_exp(2.f) == 1);
124 SkASSERT(get_float_exp(2.5f) == 1);
125 SkASSERT(get_float_exp(8.f) == 3);
126 SkASSERT(get_float_exp(100.f) == 6);
127 SkASSERT(get_float_exp(1000.f) == 9);
128 SkASSERT(get_float_exp(1024.f) == 10);
129 SkASSERT(get_float_exp(3000000.f) == 21);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000130 }
131#endif
bsalomon@google.com2ec72802011-09-21 21:46:03 +0000132 const int* iptr = (const int*)&x;
133 return (((*iptr) & 0x7f800000) >> 23) - 127;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000134}
135
egdaniel@google.com5383a752013-07-12 20:15:34 +0000136// Uses the max curvature function for quads to estimate
137// where to chop the conic. If the max curvature is not
138// found along the curve segment it will return 1 and
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000139// dst[0] is the original conic. If it returns 2 the dst[0]
egdaniel@google.com5383a752013-07-12 20:15:34 +0000140// and dst[1] are the two new conics.
bsalomoned0bcad2015-05-04 10:36:42 -0700141static int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) {
egdaniel@google.com5383a752013-07-12 20:15:34 +0000142 SkScalar t = SkFindQuadMaxCurvature(src);
Chris Dalton1d474dd2018-07-24 01:08:31 -0600143 if (t == 0 || t == 1) {
egdaniel@google.com5383a752013-07-12 20:15:34 +0000144 if (dst) {
145 dst[0].set(src, weight);
146 }
147 return 1;
148 } else {
149 if (dst) {
150 SkConic conic;
151 conic.set(src, weight);
caryclark414c4292016-09-26 11:03:54 -0700152 if (!conic.chopAt(t, dst)) {
153 dst[0].set(src, weight);
154 return 1;
155 }
egdaniel@google.com5383a752013-07-12 20:15:34 +0000156 }
157 return 2;
158 }
159}
160
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000161// Calls split_conic on the entire conic and then once more on each subsection.
162// Most cases will result in either 1 conic (chop point is not within t range)
163// or 3 points (split once and then one subsection is split again).
bsalomoned0bcad2015-05-04 10:36:42 -0700164static int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) {
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000165 SkConic dstTemp[2];
166 int conicCnt = split_conic(src, dstTemp, weight);
167 if (2 == conicCnt) {
168 int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW);
169 conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW);
170 } else {
171 dst[0] = dstTemp[0];
172 }
173 return conicCnt;
174}
175
egdaniel@google.com5383a752013-07-12 20:15:34 +0000176// returns 0 if quad/conic is degen or close to it
177// in this case approx the path with lines
178// otherwise returns 1
bsalomoned0bcad2015-05-04 10:36:42 -0700179static int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) {
jvanverthcfeb85f2016-04-29 07:38:10 -0700180 static const SkScalar gDegenerateToLineTol = GrPathUtils::kDefaultTolerance;
egdaniel@google.com5383a752013-07-12 20:15:34 +0000181 static const SkScalar gDegenerateToLineTolSqd =
Mike Reed8be952a2017-02-13 20:44:33 -0500182 gDegenerateToLineTol * gDegenerateToLineTol;
egdaniel@google.com5383a752013-07-12 20:15:34 +0000183
Cary Clarkdf429f32017-11-08 11:44:31 -0500184 if (SkPointPriv::DistanceToSqd(p[0], p[1]) < gDegenerateToLineTolSqd ||
185 SkPointPriv::DistanceToSqd(p[1], p[2]) < gDegenerateToLineTolSqd) {
egdaniel@google.com5383a752013-07-12 20:15:34 +0000186 return 1;
187 }
188
Cary Clarkdf429f32017-11-08 11:44:31 -0500189 *dsqd = SkPointPriv::DistanceToLineBetweenSqd(p[1], p[0], p[2]);
joshualitt63648072015-02-19 10:25:21 -0800190 if (*dsqd < gDegenerateToLineTolSqd) {
egdaniel@google.com5383a752013-07-12 20:15:34 +0000191 return 1;
192 }
193
Cary Clarkdf429f32017-11-08 11:44:31 -0500194 if (SkPointPriv::DistanceToLineBetweenSqd(p[2], p[1], p[0]) < gDegenerateToLineTolSqd) {
egdaniel@google.com5383a752013-07-12 20:15:34 +0000195 return 1;
196 }
197 return 0;
198}
199
bsalomoned0bcad2015-05-04 10:36:42 -0700200static int is_degen_quad_or_conic(const SkPoint p[3]) {
joshualitt63648072015-02-19 10:25:21 -0800201 SkScalar dsqd;
202 return is_degen_quad_or_conic(p, &dsqd);
203}
204
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000205// we subdivide the quads to avoid huge overfill
206// if it returns -1 then should be drawn as lines
bsalomoned0bcad2015-05-04 10:36:42 -0700207static int num_quad_subdivs(const SkPoint p[3]) {
joshualitt63648072015-02-19 10:25:21 -0800208 SkScalar dsqd;
209 if (is_degen_quad_or_conic(p, &dsqd)) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000210 return -1;
211 }
212
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000213 // tolerance of triangle height in pixels
214 // tuned on windows Quadro FX 380 / Z600
215 // trade off of fill vs cpu time on verts
216 // maybe different when do this using gpu (geo or tess shaders)
217 static const SkScalar gSubdivTol = 175 * SK_Scalar1;
218
Mike Reed8be952a2017-02-13 20:44:33 -0500219 if (dsqd <= gSubdivTol * gSubdivTol) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000220 return 0;
221 } else {
robertphillips@google.com87379e12013-03-29 12:11:10 +0000222 static const int kMaxSub = 4;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000223 // subdividing the quad reduces d by 4. so we want x = log4(d/tol)
224 // = log4(d*d/tol*tol)/2
225 // = log2(d*d/tol*tol)
226
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000227 // +1 since we're ignoring the mantissa contribution.
228 int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1;
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000229 log = SkTMin(SkTMax(0, log), kMaxSub);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000230 return log;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000231 }
232}
233
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000234/**
235 * Generates the lines and quads to be rendered. Lines are always recorded in
236 * device space. We will do a device space bloat to account for the 1pixel
237 * thickness.
238 * Quads are recorded in device space unless m contains
239 * perspective, then in they are in src space. We do this because we will
240 * subdivide large quads to reduce over-fill. This subdivision has to be
241 * performed before applying the perspective matrix.
242 */
bsalomoned0bcad2015-05-04 10:36:42 -0700243static int gather_lines_and_quads(const SkPath& path,
244 const SkMatrix& m,
245 const SkIRect& devClipBounds,
Brian Osmancf3dc292017-06-28 16:45:32 -0400246 SkScalar capLength,
Brian Salomon969a7382018-05-09 13:28:44 -0400247 bool convertConicsToQuads,
bsalomoned0bcad2015-05-04 10:36:42 -0700248 GrAAHairLinePathRenderer::PtArray* lines,
249 GrAAHairLinePathRenderer::PtArray* quads,
250 GrAAHairLinePathRenderer::PtArray* conics,
251 GrAAHairLinePathRenderer::IntArray* quadSubdivCnts,
252 GrAAHairLinePathRenderer::FloatArray* conicWeights) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000253 SkPath::Iter iter(path, false);
254
255 int totalQuadCount = 0;
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000256 SkRect bounds;
257 SkIRect ibounds;
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000258
259 bool persp = m.hasPerspective();
260
Brian Osmancf3dc292017-06-28 16:45:32 -0400261 // Whenever a degenerate, zero-length contour is encountered, this code will insert a
262 // 'capLength' x-aligned line segment. Since this is rendering hairlines it is hoped this will
263 // suffice for AA square & circle capping.
264 int verbsInContour = 0; // Does not count moves
265 bool seenZeroLengthVerb = false;
266 SkPoint zeroVerbPt;
267
Brian Salomon969a7382018-05-09 13:28:44 -0400268 // Adds a quad that has already been chopped to the list and checks for quads that are close to
269 // lines. Also does a bounding box check. It takes points that are in src space and device
270 // space. The src points are only required if the view matrix has perspective.
271 auto addChoppedQuad = [&](const SkPoint srcPts[3], const SkPoint devPts[4],
272 bool isContourStart) {
273 SkRect bounds;
274 SkIRect ibounds;
275 bounds.setBounds(devPts, 3);
276 bounds.outset(SK_Scalar1, SK_Scalar1);
277 bounds.roundOut(&ibounds);
278 // We only need the src space space pts when not in perspective.
279 SkASSERT(srcPts || !persp);
280 if (SkIRect::Intersects(devClipBounds, ibounds)) {
281 int subdiv = num_quad_subdivs(devPts);
282 SkASSERT(subdiv >= -1);
283 if (-1 == subdiv) {
284 SkPoint* pts = lines->push_back_n(4);
285 pts[0] = devPts[0];
286 pts[1] = devPts[1];
287 pts[2] = devPts[1];
288 pts[3] = devPts[2];
289 if (isContourStart && pts[0] == pts[1] && pts[2] == pts[3]) {
290 seenZeroLengthVerb = true;
291 zeroVerbPt = pts[0];
292 }
293 } else {
294 // when in perspective keep quads in src space
295 const SkPoint* qPts = persp ? srcPts : devPts;
296 SkPoint* pts = quads->push_back_n(3);
297 pts[0] = qPts[0];
298 pts[1] = qPts[1];
299 pts[2] = qPts[2];
300 quadSubdivCnts->push_back() = subdiv;
301 totalQuadCount += 1 << subdiv;
302 }
303 }
304 };
305
306 // Applies the view matrix to quad src points and calls the above helper.
307 auto addSrcChoppedQuad = [&](const SkPoint srcSpaceQuadPts[3], bool isContourStart) {
308 SkPoint devPts[3];
309 m.mapPoints(devPts, srcSpaceQuadPts, 3);
310 addChoppedQuad(srcSpaceQuadPts, devPts, isContourStart);
311 };
312
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000313 for (;;) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000314 SkPoint pathPts[4];
Brian Osmancf3dc292017-06-28 16:45:32 -0400315 SkPath::Verb verb = iter.next(pathPts, false);
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000316 switch (verb) {
Brian Salomon969a7382018-05-09 13:28:44 -0400317 case SkPath::kConic_Verb:
318 if (convertConicsToQuads) {
319 SkScalar weight = iter.conicWeight();
320 SkAutoConicToQuads converter;
321 const SkPoint* quadPts = converter.computeQuads(pathPts, weight, 0.5f);
322 for (int i = 0; i < converter.countQuads(); ++i) {
323 addSrcChoppedQuad(quadPts + 2 * i, !verbsInContour && 0 == i);
324 }
325 } else {
326 SkConic dst[4];
327 // We chop the conics to create tighter clipping to hide error
328 // that appears near max curvature of very thin conics. Thin
329 // hyperbolas with high weight still show error.
330 int conicCnt = chop_conic(pathPts, dst, iter.conicWeight());
331 for (int i = 0; i < conicCnt; ++i) {
332 SkPoint devPts[4];
333 SkPoint* chopPnts = dst[i].fPts;
334 m.mapPoints(devPts, chopPnts, 3);
335 bounds.setBounds(devPts, 3);
336 bounds.outset(SK_Scalar1, SK_Scalar1);
337 bounds.roundOut(&ibounds);
338 if (SkIRect::Intersects(devClipBounds, ibounds)) {
339 if (is_degen_quad_or_conic(devPts)) {
340 SkPoint* pts = lines->push_back_n(4);
341 pts[0] = devPts[0];
342 pts[1] = devPts[1];
343 pts[2] = devPts[1];
344 pts[3] = devPts[2];
345 if (verbsInContour == 0 && i == 0 && pts[0] == pts[1] &&
346 pts[2] == pts[3]) {
347 seenZeroLengthVerb = true;
348 zeroVerbPt = pts[0];
349 }
350 } else {
351 // when in perspective keep conics in src space
352 SkPoint* cPts = persp ? chopPnts : devPts;
353 SkPoint* pts = conics->push_back_n(3);
354 pts[0] = cPts[0];
355 pts[1] = cPts[1];
356 pts[2] = cPts[2];
357 conicWeights->push_back() = dst[i].fW;
Brian Osmancf3dc292017-06-28 16:45:32 -0400358 }
egdaniel@google.com5383a752013-07-12 20:15:34 +0000359 }
360 }
361 }
Brian Osmancf3dc292017-06-28 16:45:32 -0400362 verbsInContour++;
reed@google.com277c3f82013-05-31 15:17:50 +0000363 break;
egdaniel@google.com5383a752013-07-12 20:15:34 +0000364 case SkPath::kMove_Verb:
Brian Osmancf3dc292017-06-28 16:45:32 -0400365 // New contour (and last one was unclosed). If it was just a zero length drawing
366 // operation, and we're supposed to draw caps, then add a tiny line.
367 if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) {
368 SkPoint* pts = lines->push_back_n(2);
369 pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
370 pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
371 }
372 verbsInContour = 0;
373 seenZeroLengthVerb = false;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000374 break;
Brian Salomon969a7382018-05-09 13:28:44 -0400375 case SkPath::kLine_Verb: {
376 SkPoint devPts[2];
commit-bot@chromium.org912e68e2013-05-24 18:51:55 +0000377 m.mapPoints(devPts, pathPts, 2);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000378 bounds.setBounds(devPts, 2);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000379 bounds.outset(SK_Scalar1, SK_Scalar1);
380 bounds.roundOut(&ibounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000381 if (SkIRect::Intersects(devClipBounds, ibounds)) {
bsalomon@google.coma996fec2011-09-13 18:49:13 +0000382 SkPoint* pts = lines->push_back_n(2);
383 pts[0] = devPts[0];
384 pts[1] = devPts[1];
Brian Osmancf3dc292017-06-28 16:45:32 -0400385 if (verbsInContour == 0 && pts[0] == pts[1]) {
386 seenZeroLengthVerb = true;
387 zeroVerbPt = pts[0];
388 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000389 }
Brian Osmancf3dc292017-06-28 16:45:32 -0400390 verbsInContour++;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000391 break;
Brian Salomon969a7382018-05-09 13:28:44 -0400392 }
commit-bot@chromium.org912e68e2013-05-24 18:51:55 +0000393 case SkPath::kQuad_Verb: {
394 SkPoint choppedPts[5];
395 // Chopping the quad helps when the quad is either degenerate or nearly degenerate.
396 // When it is degenerate it allows the approximation with lines to work since the
397 // chop point (if there is one) will be at the parabola's vertex. In the nearly
398 // degenerate the QuadUVMatrix computed for the points is almost singular which
399 // can cause rendering artifacts.
400 int n = SkChopQuadAtMaxCurvature(pathPts, choppedPts);
401 for (int i = 0; i < n; ++i) {
Brian Salomon969a7382018-05-09 13:28:44 -0400402 addSrcChoppedQuad(choppedPts + i * 2, !verbsInContour && 0 == i);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000403 }
Brian Osmancf3dc292017-06-28 16:45:32 -0400404 verbsInContour++;
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000405 break;
commit-bot@chromium.org912e68e2013-05-24 18:51:55 +0000406 }
Brian Salomon969a7382018-05-09 13:28:44 -0400407 case SkPath::kCubic_Verb: {
408 SkPoint devPts[4];
commit-bot@chromium.org912e68e2013-05-24 18:51:55 +0000409 m.mapPoints(devPts, pathPts, 4);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000410 bounds.setBounds(devPts, 4);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000411 bounds.outset(SK_Scalar1, SK_Scalar1);
412 bounds.roundOut(&ibounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000413 if (SkIRect::Intersects(devClipBounds, ibounds)) {
bsalomon@google.com92669012011-09-27 19:10:05 +0000414 PREALLOC_PTARRAY(32) q;
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000415 // We convert cubics to quadratics (for now).
416 // In perspective have to do conversion in src space.
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000417 if (persp) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000418 SkScalar tolScale =
bsalomon18fab302016-02-16 08:00:05 -0800419 GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, path.getBounds());
420 GrPathUtils::convertCubicToQuads(pathPts, tolScale, &q);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000421 } else {
bsalomon18fab302016-02-16 08:00:05 -0800422 GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, &q);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000423 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000424 for (int i = 0; i < q.count(); i += 3) {
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000425 if (persp) {
Brian Salomon969a7382018-05-09 13:28:44 -0400426 addSrcChoppedQuad(&q[i], !verbsInContour && 0 == i);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000427 } else {
Brian Salomon969a7382018-05-09 13:28:44 -0400428 addChoppedQuad(nullptr, &q[i], !verbsInContour && 0 == i);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000429 }
430 }
431 }
Brian Osmancf3dc292017-06-28 16:45:32 -0400432 verbsInContour++;
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000433 break;
Brian Salomon969a7382018-05-09 13:28:44 -0400434 }
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000435 case SkPath::kClose_Verb:
Brian Osmancf3dc292017-06-28 16:45:32 -0400436 // Contour is closed, so we don't need to grow the starting line, unless it's
437 // *just* a zero length subpath. (SVG Spec 11.4, 'stroke').
438 if (capLength > 0) {
439 if (seenZeroLengthVerb && verbsInContour == 1) {
440 SkPoint* pts = lines->push_back_n(2);
441 pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
442 pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
443 } else if (verbsInContour == 0) {
444 // Contour was (moveTo, close). Add a line.
Brian Salomon969a7382018-05-09 13:28:44 -0400445 SkPoint devPts[2];
Brian Osmancf3dc292017-06-28 16:45:32 -0400446 m.mapPoints(devPts, pathPts, 1);
447 devPts[1] = devPts[0];
448 bounds.setBounds(devPts, 2);
449 bounds.outset(SK_Scalar1, SK_Scalar1);
450 bounds.roundOut(&ibounds);
451 if (SkIRect::Intersects(devClipBounds, ibounds)) {
452 SkPoint* pts = lines->push_back_n(2);
453 pts[0] = SkPoint::Make(devPts[0].fX - capLength, devPts[0].fY);
454 pts[1] = SkPoint::Make(devPts[1].fX + capLength, devPts[1].fY);
455 }
456 }
457 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000458 break;
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000459 case SkPath::kDone_Verb:
Brian Osmancf3dc292017-06-28 16:45:32 -0400460 if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) {
461 // Path ended with a dangling (moveTo, line|quad|etc). If the final verb is
462 // degenerate, we need to draw a line.
463 SkPoint* pts = lines->push_back_n(2);
464 pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
465 pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
466 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000467 return totalQuadCount;
468 }
469 }
470}
471
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000472struct LineVertex {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000473 SkPoint fPos;
egdaniele27065a2014-11-06 08:00:48 -0800474 float fCoverage;
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000475};
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000476
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000477struct BezierVertex {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000478 SkPoint fPos;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000479 union {
480 struct {
csmartdaltoncc261272017-03-23 13:38:45 -0600481 SkScalar fKLM[3];
egdaniel@google.com5383a752013-07-12 20:15:34 +0000482 } fConic;
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000483 SkVector fQuadCoord;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000484 struct {
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000485 SkScalar fBogus[4];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000486 };
487 };
488};
egdaniel@google.com5383a752013-07-12 20:15:34 +0000489
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000490GR_STATIC_ASSERT(sizeof(BezierVertex) == 3 * sizeof(SkPoint));
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000491
bsalomoned0bcad2015-05-04 10:36:42 -0700492static void intersect_lines(const SkPoint& ptA, const SkVector& normA,
493 const SkPoint& ptB, const SkVector& normB,
494 SkPoint* result) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000495
496 SkScalar lineAW = -normA.dot(ptA);
497 SkScalar lineBW = -normB.dot(ptB);
498
Mike Reed8be952a2017-02-13 20:44:33 -0500499 SkScalar wInv = normA.fX * normB.fY - normA.fY * normB.fX;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000500 wInv = SkScalarInvert(wInv);
501
Mike Reed8be952a2017-02-13 20:44:33 -0500502 result->fX = normA.fY * lineBW - lineAW * normB.fY;
503 result->fX *= wInv;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000504
Mike Reed8be952a2017-02-13 20:44:33 -0500505 result->fY = lineAW * normB.fX - normA.fX * lineBW;
506 result->fY *= wInv;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000507}
508
bsalomoned0bcad2015-05-04 10:36:42 -0700509static void set_uv_quad(const SkPoint qpts[3], BezierVertex verts[kQuadNumVertices]) {
egdaniel@google.com34b05ca2013-08-05 20:43:12 +0000510 // this should be in the src space, not dev coords, when we have perspective
511 GrPathUtils::QuadUVMatrix DevToUV(qpts);
joshualitt5ead6da2014-10-22 16:00:29 -0700512 DevToUV.apply<kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint)>(verts);
egdaniel@google.com34b05ca2013-08-05 20:43:12 +0000513}
514
bsalomoned0bcad2015-05-04 10:36:42 -0700515static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice,
516 const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices]) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000517 SkASSERT(!toDevice == !toSrc);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000518 // original quad is specified by tri a,b,c
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000519 SkPoint a = qpts[0];
520 SkPoint b = qpts[1];
521 SkPoint c = qpts[2];
522
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000523 if (toDevice) {
524 toDevice->mapPoints(&a, 1);
525 toDevice->mapPoints(&b, 1);
526 toDevice->mapPoints(&c, 1);
527 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000528 // make a new poly where we replace a and c by a 1-pixel wide edges orthog
529 // to edges ab and bc:
530 //
531 // before | after
532 // | b0
533 // b |
534 // |
535 // | a0 c0
536 // a c | a1 c1
537 //
538 // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c,
539 // respectively.
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000540 BezierVertex& a0 = verts[0];
541 BezierVertex& a1 = verts[1];
542 BezierVertex& b0 = verts[2];
543 BezierVertex& c0 = verts[3];
544 BezierVertex& c1 = verts[4];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000545
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000546 SkVector ab = b;
547 ab -= a;
548 SkVector ac = c;
549 ac -= a;
550 SkVector cb = b;
551 cb -= c;
552
553 // We should have already handled degenerates
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000554 SkASSERT(ab.length() > 0 && cb.length() > 0);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000555
556 ab.normalize();
Brian Salomon0235c642018-08-31 12:04:18 -0400557 SkVector abN = SkPointPriv::MakeOrthog(ab, SkPointPriv::kLeft_Side);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000558 if (abN.dot(ac) > 0) {
559 abN.negate();
560 }
561
562 cb.normalize();
Brian Salomon0235c642018-08-31 12:04:18 -0400563 SkVector cbN = SkPointPriv::MakeOrthog(cb, SkPointPriv::kLeft_Side);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000564 if (cbN.dot(ac) < 0) {
565 cbN.negate();
566 }
567
568 a0.fPos = a;
569 a0.fPos += abN;
570 a1.fPos = a;
571 a1.fPos -= abN;
572
573 c0.fPos = c;
574 c0.fPos += cbN;
575 c1.fPos = c;
576 c1.fPos -= cbN;
577
578 intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos);
579
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000580 if (toSrc) {
Brian Salomonfa3783f2018-01-05 13:49:07 -0500581 SkMatrixPriv::MapPointsWithStride(*toSrc, &verts[0].fPos, sizeof(BezierVertex),
582 kQuadNumVertices);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000583 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000584}
585
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000586// Equations based off of Loop-Blinn Quadratic GPU Rendering
egdaniel@google.com5383a752013-07-12 20:15:34 +0000587// Input Parametric:
588// P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2)
589// Output Implicit:
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000590// f(x, y, w) = f(P) = K^2 - LM
591// K = dot(k, P), L = dot(l, P), M = dot(m, P)
commit-bot@chromium.org13948402013-08-20 17:55:43 +0000592// k, l, m are calculated in function GrPathUtils::getConicKLM
bsalomoned0bcad2015-05-04 10:36:42 -0700593static void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices],
594 const SkScalar weight) {
csmartdaltoncc261272017-03-23 13:38:45 -0600595 SkMatrix klm;
egdaniel@google.com3f2a2d52013-08-01 17:09:11 +0000596
csmartdaltoncc261272017-03-23 13:38:45 -0600597 GrPathUtils::getConicKLM(p, weight, &klm);
egdaniel@google.com5383a752013-07-12 20:15:34 +0000598
joshualitt5ead6da2014-10-22 16:00:29 -0700599 for (int i = 0; i < kQuadNumVertices; ++i) {
Cary Clarke4442cb2017-10-18 11:46:18 -0400600 const SkPoint3 pt3 = {verts[i].fPos.x(), verts[i].fPos.y(), 1.f};
601 klm.mapHomogeneousPoints((SkPoint3* ) verts[i].fConic.fKLM, &pt3, 1);
egdaniel@google.com5383a752013-07-12 20:15:34 +0000602 }
603}
604
bsalomoned0bcad2015-05-04 10:36:42 -0700605static void add_conics(const SkPoint p[3],
606 const SkScalar weight,
607 const SkMatrix* toDevice,
608 const SkMatrix* toSrc,
609 BezierVertex** vert) {
joshualitt7bc18b72015-02-03 16:41:41 -0800610 bloat_quad(p, toDevice, toSrc, *vert);
egdaniel@google.com5383a752013-07-12 20:15:34 +0000611 set_conic_coeffs(p, *vert, weight);
joshualitt5ead6da2014-10-22 16:00:29 -0700612 *vert += kQuadNumVertices;
egdaniel@google.com5383a752013-07-12 20:15:34 +0000613}
614
bsalomoned0bcad2015-05-04 10:36:42 -0700615static void add_quads(const SkPoint p[3],
616 int subdiv,
617 const SkMatrix* toDevice,
618 const SkMatrix* toSrc,
619 BezierVertex** vert) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000620 SkASSERT(subdiv >= 0);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000621 if (subdiv) {
622 SkPoint newP[5];
623 SkChopQuadAtHalf(p, newP);
joshualitt7bc18b72015-02-03 16:41:41 -0800624 add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert);
625 add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert);
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000626 } else {
joshualitt7bc18b72015-02-03 16:41:41 -0800627 bloat_quad(p, toDevice, toSrc, *vert);
egdaniel@google.com34b05ca2013-08-05 20:43:12 +0000628 set_uv_quad(p, *vert);
joshualitt5ead6da2014-10-22 16:00:29 -0700629 *vert += kQuadNumVertices;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000630 }
631}
632
bsalomoned0bcad2015-05-04 10:36:42 -0700633static void add_line(const SkPoint p[2],
634 const SkMatrix* toSrc,
635 uint8_t coverage,
636 LineVertex** vert) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000637 const SkPoint& a = p[0];
638 const SkPoint& b = p[1];
639
robertphillips@google.comada90da2013-09-18 22:14:49 +0000640 SkVector ortho, vec = b;
641 vec -= a;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000642
Cary Clarkdf429f32017-11-08 11:44:31 -0500643 SkScalar lengthSqd = SkPointPriv::LengthSqd(vec);
Greg Daniel2e67dea2017-10-12 15:14:41 -0400644
robertphillips@google.comada90da2013-09-18 22:14:49 +0000645 if (vec.setLength(SK_ScalarHalf)) {
646 // Create a vector orthogonal to 'vec' and of unit length
647 ortho.fX = 2.0f * vec.fY;
648 ortho.fY = -2.0f * vec.fX;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000649
egdaniele27065a2014-11-06 08:00:48 -0800650 float floatCoverage = GrNormalizeByteToFloat(coverage);
651
Greg Daniel2e67dea2017-10-12 15:14:41 -0400652 if (lengthSqd >= 1.0f) {
653 // Relative to points a and b:
654 // The inner vertices are inset half a pixel along the line a,b
655 (*vert)[0].fPos = a + vec;
656 (*vert)[0].fCoverage = floatCoverage;
657 (*vert)[1].fPos = b - vec;
658 (*vert)[1].fCoverage = floatCoverage;
659 } else {
660 // The inner vertices are inset a distance of length(a,b) from the outer edge of
661 // geometry. For the "a" inset this is the same as insetting from b by half a pixel.
662 // The coverage is then modulated by the length. This gives us the correct
663 // coverage for rects shorter than a pixel as they get translated subpixel amounts
664 // inside of a pixel.
665 SkScalar length = SkScalarSqrt(lengthSqd);
666 (*vert)[0].fPos = b - vec;
667 (*vert)[0].fCoverage = floatCoverage * length;
668 (*vert)[1].fPos = a + vec;
669 (*vert)[1].fCoverage = floatCoverage * length;
670 }
671 // Relative to points a and b:
672 // The outer vertices are outset half a pixel along the line a,b and then a whole pixel
673 // orthogonally.
robertphillips@google.comada90da2013-09-18 22:14:49 +0000674 (*vert)[2].fPos = a - vec + ortho;
675 (*vert)[2].fCoverage = 0;
676 (*vert)[3].fPos = b + vec + ortho;
677 (*vert)[3].fCoverage = 0;
678 (*vert)[4].fPos = a - vec - ortho;
679 (*vert)[4].fCoverage = 0;
680 (*vert)[5].fPos = b + vec - ortho;
681 (*vert)[5].fCoverage = 0;
682
bsalomon49f085d2014-09-05 13:34:00 -0700683 if (toSrc) {
Brian Salomonfa3783f2018-01-05 13:49:07 -0500684 SkMatrixPriv::MapPointsWithStride(*toSrc, &(*vert)->fPos, sizeof(LineVertex),
685 kLineSegNumVertices);
bsalomon@google.comdbeeac32011-09-12 14:59:34 +0000686 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000687 } else {
688 // just make it degenerate and likely offscreen
joshualitt5ead6da2014-10-22 16:00:29 -0700689 for (int i = 0; i < kLineSegNumVertices; ++i) {
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000690 (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax);
691 }
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000692 }
693
joshualitt5ead6da2014-10-22 16:00:29 -0700694 *vert += kLineSegNumVertices;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000695}
696
commit-bot@chromium.org90c240a2013-04-02 17:57:21 +0000697///////////////////////////////////////////////////////////////////////////////
698
Chris Dalton5ed44232017-09-07 13:22:46 -0600699GrPathRenderer::CanDrawPath
700GrAAHairLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500701 if (GrAAType::kCoverage != args.fAAType) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600702 return CanDrawPath::kNo;
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +0000703 }
704
bsalomon8acedde2016-06-24 10:42:16 -0700705 if (!IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr)) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600706 return CanDrawPath::kNo;
bsalomon6663acf2016-05-10 09:14:17 -0700707 }
708
709 // We don't currently handle dashing in this class though perhaps we should.
bsalomon8acedde2016-06-24 10:42:16 -0700710 if (args.fShape->style().pathEffect()) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600711 return CanDrawPath::kNo;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000712 }
713
bsalomon8acedde2016-06-24 10:42:16 -0700714 if (SkPath::kLine_SegmentMask == args.fShape->segmentMask() ||
Eric Karl5c779752017-05-08 12:02:07 -0700715 args.fCaps->shaderCaps()->shaderDerivativeSupport()) {
Chris Dalton5ed44232017-09-07 13:22:46 -0600716 return CanDrawPath::kYes;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000717 }
bsalomon8acedde2016-06-24 10:42:16 -0700718
Chris Dalton5ed44232017-09-07 13:22:46 -0600719 return CanDrawPath::kNo;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000720}
721
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000722template <class VertexType>
joshualitt8059eb92014-12-29 15:10:07 -0800723bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* vertices, int vCount)
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000724{
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000725 SkRect tolDevBounds = devBounds;
commit-bot@chromium.orgb8bd6cb2013-09-03 14:56:17 +0000726 // The bounds ought to be tight, but in perspective the below code runs the verts
727 // through the view matrix to get back to dev coords, which can introduce imprecision.
joshualitt8059eb92014-12-29 15:10:07 -0800728 if (viewMatrix.hasPerspective()) {
commit-bot@chromium.orgb8bd6cb2013-09-03 14:56:17 +0000729 tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
730 } else {
731 // Non-persp matrices cause this path renderer to draw in device space.
joshualitt8059eb92014-12-29 15:10:07 -0800732 SkASSERT(viewMatrix.isIdentity());
commit-bot@chromium.orgb8bd6cb2013-09-03 14:56:17 +0000733 }
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000734 SkRect actualBounds;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000735
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000736 VertexType* verts = reinterpret_cast<VertexType*>(vertices);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000737 bool first = true;
738 for (int i = 0; i < vCount; ++i) {
739 SkPoint pos = verts[i].fPos;
740 // This is a hack to workaround the fact that we move some degenerate segments offscreen.
741 if (SK_ScalarMax == pos.fX) {
742 continue;
743 }
joshualitt8059eb92014-12-29 15:10:07 -0800744 viewMatrix.mapPoints(&pos, 1);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000745 if (first) {
746 actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY);
747 first = false;
748 } else {
Mike Reed185ffe92018-01-08 17:09:54 -0500749 SkRectPriv::GrowToInclude(&actualBounds, pos);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000750 }
751 }
752 if (!first) {
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000753 return tolDevBounds.contains(actualBounds);
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000754 }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000755
jvanverth@google.com681ccf02013-08-16 14:51:51 +0000756 return true;
757}
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +0000758
Brian Salomona531f252017-07-07 13:29:28 -0400759namespace {
760
761class AAHairlineOp final : public GrMeshDrawOp {
762private:
763 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
764
joshualitt7bc18b72015-02-03 16:41:41 -0800765public:
Brian Salomon25a88092016-12-01 09:36:50 -0500766 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -0700767
Robert Phillips7c525e62018-06-12 10:11:12 -0400768 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
769 GrPaint&& paint,
Brian Salomona531f252017-07-07 13:29:28 -0400770 const SkMatrix& viewMatrix,
771 const SkPath& path,
772 const GrStyle& style,
773 const SkIRect& devClipBounds,
774 const GrUserStencilSettings* stencilSettings) {
Brian Salomond0a0a652016-12-15 15:25:22 -0500775 SkScalar hairlineCoverage;
776 uint8_t newCoverage = 0xff;
777 if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) {
778 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
779 }
joshualitt7bc18b72015-02-03 16:41:41 -0800780
Brian Osmancf3dc292017-06-28 16:45:32 -0400781 const SkStrokeRec& stroke = style.strokeRec();
782 SkScalar capLength = SkPaint::kButt_Cap != stroke.getCap() ? hairlineCoverage * 0.5f : 0.0f;
783
Robert Phillips7c525e62018-06-12 10:11:12 -0400784 return Helper::FactoryHelper<AAHairlineOp>(context, std::move(paint), newCoverage,
785 viewMatrix, path,
Brian Salomona531f252017-07-07 13:29:28 -0400786 devClipBounds, capLength, stencilSettings);
787 }
788
789 AAHairlineOp(const Helper::MakeArgs& helperArgs,
790 GrColor color,
791 uint8_t coverage,
792 const SkMatrix& viewMatrix,
793 const SkPath& path,
794 SkIRect devClipBounds,
795 SkScalar capLength,
796 const GrUserStencilSettings* stencilSettings)
797 : INHERITED(ClassID())
798 , fHelper(helperArgs, GrAAType::kCoverage, stencilSettings)
799 , fColor(color)
800 , fCoverage(coverage) {
801 fPaths.emplace_back(PathData{viewMatrix, path, devClipBounds, capLength});
802
803 this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes,
804 IsZeroArea::kYes);
bsalomonf1703092016-06-29 18:41:53 -0700805 }
joshualitt7bc18b72015-02-03 16:41:41 -0800806
Brian Salomond0a0a652016-12-15 15:25:22 -0500807 const char* name() const override { return "AAHairlineOp"; }
joshualitt7bc18b72015-02-03 16:41:41 -0800808
Robert Phillipsf1748f52017-09-14 14:11:24 -0400809 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400810 fHelper.visitProxies(func);
811 }
812
Brian Salomon7c3e7182016-12-01 09:35:30 -0500813 SkString dumpInfo() const override {
814 SkString string;
Brian Salomond0a0a652016-12-15 15:25:22 -0500815 string.appendf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n", fColor, fCoverage,
816 fPaths.count());
Brian Salomona531f252017-07-07 13:29:28 -0400817 string += INHERITED::dumpInfo();
818 string += fHelper.dumpInfo();
Brian Salomon7c3e7182016-12-01 09:35:30 -0500819 return string;
820 }
821
Brian Salomona531f252017-07-07 13:29:28 -0400822 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
823
Brian Osman532b3f92018-07-11 10:02:07 -0400824 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
825 return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel,
826 &fColor);
Brian Salomona531f252017-07-07 13:29:28 -0400827 }
828
bsalomone46f9fe2015-08-18 06:05:14 -0700829private:
Brian Salomon91326c32017-08-09 16:02:19 -0400830 void onPrepareDraws(Target*) override;
bsalomon75398562015-08-17 12:55:38 -0700831
joshualitt7bc18b72015-02-03 16:41:41 -0800832 typedef SkTArray<SkPoint, true> PtArray;
833 typedef SkTArray<int, true> IntArray;
834 typedef SkTArray<float, true> FloatArray;
835
Brian Salomon7eae3e02018-08-07 14:02:38 +0000836 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomond0a0a652016-12-15 15:25:22 -0500837 AAHairlineOp* that = t->cast<AAHairlineOp>();
bsalomonabd30f52015-08-13 13:34:48 -0700838
Brian Salomona531f252017-07-07 13:29:28 -0400839 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000840 return CombineResult::kCannotCombine;
joshualitt8cab9a72015-07-16 09:13:50 -0700841 }
842
joshualitt7bc18b72015-02-03 16:41:41 -0800843 if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000844 return CombineResult::kCannotCombine;
joshualitt7bc18b72015-02-03 16:41:41 -0800845 }
846
847 // We go to identity if we don't have perspective
848 if (this->viewMatrix().hasPerspective() &&
849 !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000850 return CombineResult::kCannotCombine;
joshualitt7bc18b72015-02-03 16:41:41 -0800851 }
852
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500853 // TODO we can actually combine hairlines if they are the same color in a kind of bulk
854 // method but we haven't implemented this yet
joshualitt7bc18b72015-02-03 16:41:41 -0800855 // TODO investigate going to vertex color and coverage?
856 if (this->coverage() != that->coverage()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000857 return CombineResult::kCannotCombine;
joshualitt7bc18b72015-02-03 16:41:41 -0800858 }
859
860 if (this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000861 return CombineResult::kCannotCombine;
joshualitt7bc18b72015-02-03 16:41:41 -0800862 }
863
Brian Salomona531f252017-07-07 13:29:28 -0400864 if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000865 return CombineResult::kCannotCombine;
joshualitt7bc18b72015-02-03 16:41:41 -0800866 }
867
Brian Salomond0a0a652016-12-15 15:25:22 -0500868 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700869 this->joinBounds(*that);
Brian Salomon7eae3e02018-08-07 14:02:38 +0000870 return CombineResult::kMerged;
joshualitt7bc18b72015-02-03 16:41:41 -0800871 }
872
Brian Salomond0a0a652016-12-15 15:25:22 -0500873 GrColor color() const { return fColor; }
874 uint8_t coverage() const { return fCoverage; }
Brian Salomond0a0a652016-12-15 15:25:22 -0500875 const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
joshualitt7bc18b72015-02-03 16:41:41 -0800876
Brian Salomond0a0a652016-12-15 15:25:22 -0500877 struct PathData {
bsalomonf1703092016-06-29 18:41:53 -0700878 SkMatrix fViewMatrix;
879 SkPath fPath;
880 SkIRect fDevClipBounds;
Brian Osmancf3dc292017-06-28 16:45:32 -0400881 SkScalar fCapLength;
bsalomonf1703092016-06-29 18:41:53 -0700882 };
883
Brian Salomona531f252017-07-07 13:29:28 -0400884 SkSTArray<1, PathData, true> fPaths;
885 Helper fHelper;
Brian Salomond0a0a652016-12-15 15:25:22 -0500886 GrColor fColor;
887 uint8_t fCoverage;
joshualitt7bc18b72015-02-03 16:41:41 -0800888
Brian Salomona531f252017-07-07 13:29:28 -0400889 typedef GrMeshDrawOp INHERITED;
joshualitt7bc18b72015-02-03 16:41:41 -0800890};
891
Brian Salomona531f252017-07-07 13:29:28 -0400892} // anonymous namespace
893
Brian Salomon91326c32017-08-09 16:02:19 -0400894void AAHairlineOp::onPrepareDraws(Target* target) {
joshualitt7bc18b72015-02-03 16:41:41 -0800895 // Setup the viewmatrix and localmatrix for the GrGeometryProcessor.
896 SkMatrix invert;
897 if (!this->viewMatrix().invert(&invert)) {
898 return;
899 }
900
901 // we will transform to identity space if the viewmatrix does not have perspective
902 bool hasPerspective = this->viewMatrix().hasPerspective();
903 const SkMatrix* geometryProcessorViewM = &SkMatrix::I();
904 const SkMatrix* geometryProcessorLocalM = &invert;
halcanary96fcdcc2015-08-27 07:41:13 -0700905 const SkMatrix* toDevice = nullptr;
906 const SkMatrix* toSrc = nullptr;
joshualitt7bc18b72015-02-03 16:41:41 -0800907 if (hasPerspective) {
908 geometryProcessorViewM = &this->viewMatrix();
909 geometryProcessorLocalM = &SkMatrix::I();
910 toDevice = &this->viewMatrix();
911 toSrc = &invert;
912 }
913
joshualitt7bc18b72015-02-03 16:41:41 -0800914 // This is hand inlined for maximum performance.
915 PREALLOC_PTARRAY(128) lines;
916 PREALLOC_PTARRAY(128) quads;
917 PREALLOC_PTARRAY(128) conics;
918 IntArray qSubdivs;
919 FloatArray cWeights;
joshualitt351ba1b2015-02-16 08:33:19 -0800920 int quadCount = 0;
joshualitt7bc18b72015-02-03 16:41:41 -0800921
Brian Salomond0a0a652016-12-15 15:25:22 -0500922 int instanceCount = fPaths.count();
Brian Salomon969a7382018-05-09 13:28:44 -0400923 bool convertConicsToQuads = !target->caps().shaderCaps()->floatIs32Bits();
joshualitt7bc18b72015-02-03 16:41:41 -0800924 for (int i = 0; i < instanceCount; i++) {
Brian Salomond0a0a652016-12-15 15:25:22 -0500925 const PathData& args = fPaths[i];
joshualitt351ba1b2015-02-16 08:33:19 -0800926 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds,
Brian Salomon969a7382018-05-09 13:28:44 -0400927 args.fCapLength, convertConicsToQuads, &lines, &quads,
928 &conics, &qSubdivs, &cWeights);
joshualitt7bc18b72015-02-03 16:41:41 -0800929 }
930
joshualitt7bc18b72015-02-03 16:41:41 -0800931 int lineCount = lines.count() / 2;
932 int conicCount = conics.count() / 3;
Brian Salomon296de502018-03-13 12:26:55 -0400933 int quadAndConicCount = conicCount + quadCount;
934
935 static constexpr int kMaxLines = SK_MaxS32 / kLineSegNumVertices;
936 static constexpr int kMaxQuadsAndConics = SK_MaxS32 / kQuadNumVertices;
937 if (lineCount > kMaxLines || quadAndConicCount > kMaxQuadsAndConics) {
938 return;
939 }
joshualitt7bc18b72015-02-03 16:41:41 -0800940
Brian Salomon49348902018-06-26 09:12:38 -0400941 auto pipe = fHelper.makePipeline(target);
joshualitt7bc18b72015-02-03 16:41:41 -0800942 // do lines first
943 if (lineCount) {
bungeman06ca8ec2016-06-09 08:01:03 -0700944 sk_sp<GrGeometryProcessor> lineGP;
bsalomon342bfc22016-04-01 06:06:20 -0700945 {
946 using namespace GrDefaultGeoProcFactory;
947
948 Color color(this->color());
Brian Salomona531f252017-07-07 13:29:28 -0400949 LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type
950 : LocalCoords::kUnused_Type);
bsalomon342bfc22016-04-01 06:06:20 -0700951 localCoords.fMatrix = geometryProcessorLocalM;
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400952 lineGP = GrDefaultGeoProcFactory::Make(target->caps().shaderCaps(),
953 color, Coverage::kAttribute_Type, localCoords,
bungeman06ca8ec2016-06-09 08:01:03 -0700954 *geometryProcessorViewM);
bsalomon342bfc22016-04-01 06:06:20 -0700955 }
956
Brian Salomond28a79d2017-10-16 13:01:07 -0400957 sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider());
joshualitt7bc18b72015-02-03 16:41:41 -0800958
cdalton397536c2016-03-25 12:15:03 -0700959 const GrBuffer* vertexBuffer;
joshualitt7bc18b72015-02-03 16:41:41 -0800960 int firstVertex;
961
Brian Salomon92be2f72018-06-19 14:33:47 -0400962 SkASSERT(sizeof(LineVertex) == lineGP->debugOnly_vertexStride());
joshualitt7bc18b72015-02-03 16:41:41 -0800963 int vertexCount = kLineSegNumVertices * lineCount;
Brian Salomon92be2f72018-06-19 14:33:47 -0400964 LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace(
965 sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex));
joshualitt7bc18b72015-02-03 16:41:41 -0800966
bsalomone64eb572015-05-07 11:35:55 -0700967 if (!verts|| !linesIndexBuffer) {
joshualitt4b31de82015-03-05 14:33:41 -0800968 SkDebugf("Could not allocate vertices\n");
969 return;
970 }
971
joshualitt7bc18b72015-02-03 16:41:41 -0800972 for (int i = 0; i < lineCount; ++i) {
973 add_line(&lines[2*i], toSrc, this->coverage(), &verts);
974 }
975
Brian Salomon7eae3e02018-08-07 14:02:38 +0000976 GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
977 mesh->setIndexedPatterned(linesIndexBuffer.get(), kIdxsPerLineSeg, kLineSegNumVertices,
978 lineCount, kLineSegsNumInIdxBuffer);
979 mesh->setVertexData(vertexBuffer, firstVertex);
980 target->draw(std::move(lineGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
joshualitt7bc18b72015-02-03 16:41:41 -0800981 }
982
983 if (quadCount || conicCount) {
Brian Salomona531f252017-07-07 13:29:28 -0400984 sk_sp<GrGeometryProcessor> quadGP(GrQuadEffect::Make(this->color(),
985 *geometryProcessorViewM,
Ethan Nicholas1706f842017-11-10 11:58:19 -0500986 GrClipEdgeType::kHairlineAA,
Brian Salomona531f252017-07-07 13:29:28 -0400987 target->caps(),
988 *geometryProcessorLocalM,
989 fHelper.usesLocalCoords(),
990 this->coverage()));
bsalomon342bfc22016-04-01 06:06:20 -0700991
Brian Salomona531f252017-07-07 13:29:28 -0400992 sk_sp<GrGeometryProcessor> conicGP(GrConicEffect::Make(this->color(),
993 *geometryProcessorViewM,
Ethan Nicholas1706f842017-11-10 11:58:19 -0500994 GrClipEdgeType::kHairlineAA,
Brian Salomona531f252017-07-07 13:29:28 -0400995 target->caps(),
996 *geometryProcessorLocalM,
997 fHelper.usesLocalCoords(),
998 this->coverage()));
bsalomon342bfc22016-04-01 06:06:20 -0700999
cdalton397536c2016-03-25 12:15:03 -07001000 const GrBuffer* vertexBuffer;
joshualitt7bc18b72015-02-03 16:41:41 -08001001 int firstVertex;
1002
Brian Salomond28a79d2017-10-16 13:01:07 -04001003 sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
bsalomoned0bcad2015-05-04 10:36:42 -07001004
Brian Salomon92be2f72018-06-19 14:33:47 -04001005 SkASSERT(sizeof(BezierVertex) == quadGP->debugOnly_vertexStride());
1006 SkASSERT(sizeof(BezierVertex) == conicGP->debugOnly_vertexStride());
Brian Salomon296de502018-03-13 12:26:55 -04001007 int vertexCount = kQuadNumVertices * quadAndConicCount;
Brian Salomon92be2f72018-06-19 14:33:47 -04001008 void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer,
1009 &firstVertex);
joshualitt7bc18b72015-02-03 16:41:41 -08001010
bsalomoned0bcad2015-05-04 10:36:42 -07001011 if (!vertices || !quadsIndexBuffer) {
joshualitt4b31de82015-03-05 14:33:41 -08001012 SkDebugf("Could not allocate vertices\n");
1013 return;
1014 }
1015
joshualitt7bc18b72015-02-03 16:41:41 -08001016 // Setup vertices
robertphillips44c31282015-09-03 12:58:48 -07001017 BezierVertex* bezVerts = reinterpret_cast<BezierVertex*>(vertices);
joshualitt7bc18b72015-02-03 16:41:41 -08001018
joshualitt7bc18b72015-02-03 16:41:41 -08001019 int unsubdivQuadCnt = quads.count() / 3;
1020 for (int i = 0; i < unsubdivQuadCnt; ++i) {
1021 SkASSERT(qSubdivs[i] >= 0);
robertphillips44c31282015-09-03 12:58:48 -07001022 add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts);
joshualitt7bc18b72015-02-03 16:41:41 -08001023 }
1024
1025 // Start Conics
1026 for (int i = 0; i < conicCount; ++i) {
robertphillips44c31282015-09-03 12:58:48 -07001027 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts);
joshualitt7bc18b72015-02-03 16:41:41 -08001028 }
1029
1030 if (quadCount > 0) {
Brian Salomon7eae3e02018-08-07 14:02:38 +00001031 GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
1032 mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
1033 quadCount, kQuadsNumInIdxBuffer);
1034 mesh->setVertexData(vertexBuffer, firstVertex);
1035 target->draw(std::move(quadGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
bsalomon342bfc22016-04-01 06:06:20 -07001036 firstVertex += quadCount * kQuadNumVertices;
joshualitt7bc18b72015-02-03 16:41:41 -08001037 }
1038
1039 if (conicCount > 0) {
Brian Salomon7eae3e02018-08-07 14:02:38 +00001040 GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
1041 mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
1042 conicCount, kQuadsNumInIdxBuffer);
1043 mesh->setVertexData(vertexBuffer, firstVertex);
1044 target->draw(std::move(conicGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
joshualitt7bc18b72015-02-03 16:41:41 -08001045 }
1046 }
1047}
1048
bsalomon0aff2fa2015-07-31 06:48:27 -07001049bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -04001050 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -07001051 "GrAAHairlinePathRenderer::onDrawPath");
Brian Salomon7c8460e2017-05-12 11:36:10 -04001052 SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType());
csmartdaltonecbc12b2016-06-08 10:08:43 -07001053
jvanverth@google.com681ccf02013-08-16 14:51:51 +00001054 SkIRect devClipBounds;
Robert Phillips784b7bf2016-12-09 13:35:02 -05001055 args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
1056 args.fRenderTargetContext->height(),
robertphillips976f5f02016-06-03 10:59:20 -07001057 &devClipBounds);
bsalomon8acedde2016-06-24 10:42:16 -07001058 SkPath path;
1059 args.fShape->asPath(&path);
Brian Salomona531f252017-07-07 13:29:28 -04001060 std::unique_ptr<GrDrawOp> op =
Robert Phillips7c525e62018-06-12 10:11:12 -04001061 AAHairlineOp::Make(args.fContext, std::move(args.fPaint), *args.fViewMatrix, path,
Brian Salomona531f252017-07-07 13:29:28 -04001062 args.fShape->style(), devClipBounds, args.fUserStencilSettings);
1063 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
bsalomon@google.comc2099d22012-03-02 21:26:50 +00001064 return true;
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001065}
joshualitt40ded322015-05-02 07:07:17 -07001066
1067///////////////////////////////////////////////////////////////////////////////////////////////////
1068
Hal Canary6f6961e2017-01-31 13:50:44 -05001069#if GR_TEST_UTILS
joshualitt40ded322015-05-02 07:07:17 -07001070
Brian Salomona531f252017-07-07 13:29:28 -04001071GR_DRAW_OP_TEST_DEFINE(AAHairlineOp) {
joshualitt40ded322015-05-02 07:07:17 -07001072 SkMatrix viewMatrix = GrTest::TestMatrix(random);
joshualitt40ded322015-05-02 07:07:17 -07001073 SkPath path = GrTest::TestPath(random);
1074 SkIRect devClipBounds;
1075 devClipBounds.setEmpty();
Robert Phillips7c525e62018-06-12 10:11:12 -04001076 return AAHairlineOp::Make(context, std::move(paint), viewMatrix, path,
1077 GrStyle::SimpleHairline(), devClipBounds,
1078 GrGetRandomStencil(random, context));
joshualitt40ded322015-05-02 07:07:17 -07001079}
1080
1081#endif