bsalomon@google.com | f75b84e | 2011-09-29 14:58:28 +0000 | [diff] [blame] | 1 | /* |
| 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 8 | #include "GrAAHairLinePathRenderer.h" |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 9 | #include "GrBuffer.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 11 | #include "GrClip.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 13 | #include "GrDefaultGeoProcFactory.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 14 | #include "GrDrawOpTest.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 15 | #include "GrOpFlushState.h" |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 16 | #include "GrPathUtils.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 17 | #include "GrProcessor.h" |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 18 | #include "GrResourceProvider.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 19 | #include "GrShape.h" |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 20 | #include "GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 21 | #include "GrStyle.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 22 | #include "SkGeometry.h" |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 23 | #include "SkMatrixPriv.h" |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 24 | #include "SkPoint3.h" |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 25 | #include "SkPointPriv.h" |
Mike Reed | 185ffe9 | 2018-01-08 17:09:54 -0500 | [diff] [blame] | 26 | #include "SkRectPriv.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 27 | #include "SkStroke.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 28 | #include "SkTemplates.h" |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 29 | #include "effects/GrBezierEffect.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 30 | #include "ops/GrMeshDrawOp.h" |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 31 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 32 | #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true> |
| 33 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 34 | // 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.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 36 | // bloat_quad. Quadratics and conics share an index buffer |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 37 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 38 | // lines are rendered as: |
| 39 | // *______________* |
| 40 | // |\ -_______ /| |
| 41 | // | \ \ / | |
| 42 | // | *--------* | |
| 43 | // | / ______/ \ | |
| 44 | // */_-__________\* |
| 45 | // For: 6 vertices and 18 indices (for 6 triangles) |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 46 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 47 | // 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 |
egdaniel | 14afb43 | 2014-12-22 10:57:08 -0800 | [diff] [blame] | 58 | // Each is drawn as three triangles ((a0,a1,b0), (b0,c1,c0), (a1,c1,b0)) |
| 59 | // specified by these 9 indices: |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 60 | static const uint16_t kQuadIdxBufPattern[] = { |
| 61 | 0, 1, 2, |
| 62 | 2, 4, 3, |
| 63 | 1, 4, 2 |
| 64 | }; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 65 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 66 | static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern); |
| 67 | static const int kQuadNumVertices = 5; |
| 68 | static const int kQuadsNumInIdxBuffer = 256; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 69 | GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); |
| 70 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 71 | static sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 72 | GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 73 | return resourceProvider->findOrCreatePatternedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 74 | kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices, |
| 75 | gQuadsIndexBufferKey); |
| 76 | } |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 77 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 78 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 79 | // 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.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 89 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 90 | static 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.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 98 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 99 | static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern); |
| 100 | static const int kLineSegNumVertices = 6; |
| 101 | static const int kLineSegsNumInIdxBuffer = 256; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 102 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 103 | GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); |
| 104 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 105 | static sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 106 | GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 107 | return resourceProvider->findOrCreatePatternedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 108 | kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices, |
| 109 | gLinesIndexBufferKey); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 112 | // Takes 178th time of logf on Z600 / VC2010 |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 113 | static int get_float_exp(float x) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 114 | GR_STATIC_ASSERT(sizeof(int) == sizeof(float)); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 115 | #ifdef SK_DEBUG |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 116 | static bool tested; |
| 117 | if (!tested) { |
| 118 | tested = true; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 119 | 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 130 | } |
| 131 | #endif |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 132 | const int* iptr = (const int*)&x; |
| 133 | return (((*iptr) & 0x7f800000) >> 23) - 127; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 136 | // 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.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 139 | // dst[0] is the original conic. If it returns 2 the dst[0] |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 140 | // and dst[1] are the two new conics. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 141 | static int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 142 | SkScalar t = SkFindQuadMaxCurvature(src); |
Chris Dalton | 1d474dd | 2018-07-24 01:08:31 -0600 | [diff] [blame] | 143 | if (t == 0 || t == 1) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 144 | 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); |
caryclark | 414c429 | 2016-09-26 11:03:54 -0700 | [diff] [blame] | 152 | if (!conic.chopAt(t, dst)) { |
| 153 | dst[0].set(src, weight); |
| 154 | return 1; |
| 155 | } |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 156 | } |
| 157 | return 2; |
| 158 | } |
| 159 | } |
| 160 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 161 | // 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). |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 164 | static int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 165 | 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.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 176 | // returns 0 if quad/conic is degen or close to it |
| 177 | // in this case approx the path with lines |
| 178 | // otherwise returns 1 |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 179 | static int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) { |
jvanverth | cfeb85f | 2016-04-29 07:38:10 -0700 | [diff] [blame] | 180 | static const SkScalar gDegenerateToLineTol = GrPathUtils::kDefaultTolerance; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 181 | static const SkScalar gDegenerateToLineTolSqd = |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 182 | gDegenerateToLineTol * gDegenerateToLineTol; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 183 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 184 | if (SkPointPriv::DistanceToSqd(p[0], p[1]) < gDegenerateToLineTolSqd || |
| 185 | SkPointPriv::DistanceToSqd(p[1], p[2]) < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 186 | return 1; |
| 187 | } |
| 188 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 189 | *dsqd = SkPointPriv::DistanceToLineBetweenSqd(p[1], p[0], p[2]); |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 190 | if (*dsqd < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 191 | return 1; |
| 192 | } |
| 193 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 194 | if (SkPointPriv::DistanceToLineBetweenSqd(p[2], p[1], p[0]) < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 195 | return 1; |
| 196 | } |
| 197 | return 0; |
| 198 | } |
| 199 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 200 | static int is_degen_quad_or_conic(const SkPoint p[3]) { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 201 | SkScalar dsqd; |
| 202 | return is_degen_quad_or_conic(p, &dsqd); |
| 203 | } |
| 204 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 205 | // we subdivide the quads to avoid huge overfill |
| 206 | // if it returns -1 then should be drawn as lines |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 207 | static int num_quad_subdivs(const SkPoint p[3]) { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 208 | SkScalar dsqd; |
| 209 | if (is_degen_quad_or_conic(p, &dsqd)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 210 | return -1; |
| 211 | } |
| 212 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 213 | // 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 Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 219 | if (dsqd <= gSubdivTol * gSubdivTol) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 220 | return 0; |
| 221 | } else { |
robertphillips@google.com | 87379e1 | 2013-03-29 12:11:10 +0000 | [diff] [blame] | 222 | static const int kMaxSub = 4; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 223 | // 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 227 | // +1 since we're ignoring the mantissa contribution. |
| 228 | int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 229 | log = SkTMin(SkTMax(0, log), kMaxSub); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 230 | return log; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 234 | /** |
| 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 | */ |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 243 | static int gather_lines_and_quads(const SkPath& path, |
| 244 | const SkMatrix& m, |
| 245 | const SkIRect& devClipBounds, |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 246 | SkScalar capLength, |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 247 | bool convertConicsToQuads, |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 248 | GrAAHairLinePathRenderer::PtArray* lines, |
| 249 | GrAAHairLinePathRenderer::PtArray* quads, |
| 250 | GrAAHairLinePathRenderer::PtArray* conics, |
| 251 | GrAAHairLinePathRenderer::IntArray* quadSubdivCnts, |
| 252 | GrAAHairLinePathRenderer::FloatArray* conicWeights) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 253 | SkPath::Iter iter(path, false); |
| 254 | |
| 255 | int totalQuadCount = 0; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 256 | SkRect bounds; |
| 257 | SkIRect ibounds; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 258 | |
| 259 | bool persp = m.hasPerspective(); |
| 260 | |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 261 | // 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 Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 268 | // 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 313 | for (;;) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 314 | SkPoint pathPts[4]; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 315 | SkPath::Verb verb = iter.next(pathPts, false); |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 316 | switch (verb) { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 317 | 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 Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 358 | } |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 362 | verbsInContour++; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 363 | break; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 364 | case SkPath::kMove_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 365 | // 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 374 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 375 | case SkPath::kLine_Verb: { |
| 376 | SkPoint devPts[2]; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 377 | m.mapPoints(devPts, pathPts, 2); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 378 | bounds.setBounds(devPts, 2); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 379 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 380 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 381 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 382 | SkPoint* pts = lines->push_back_n(2); |
| 383 | pts[0] = devPts[0]; |
| 384 | pts[1] = devPts[1]; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 385 | if (verbsInContour == 0 && pts[0] == pts[1]) { |
| 386 | seenZeroLengthVerb = true; |
| 387 | zeroVerbPt = pts[0]; |
| 388 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 389 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 390 | verbsInContour++; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 391 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 392 | } |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 393 | 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 Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 402 | addSrcChoppedQuad(choppedPts + i * 2, !verbsInContour && 0 == i); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 403 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 404 | verbsInContour++; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 405 | break; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 406 | } |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 407 | case SkPath::kCubic_Verb: { |
| 408 | SkPoint devPts[4]; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 409 | m.mapPoints(devPts, pathPts, 4); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 410 | bounds.setBounds(devPts, 4); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 411 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 412 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 413 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 414 | PREALLOC_PTARRAY(32) q; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 415 | // We convert cubics to quadratics (for now). |
| 416 | // In perspective have to do conversion in src space. |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 417 | if (persp) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 418 | SkScalar tolScale = |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 419 | GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, path.getBounds()); |
| 420 | GrPathUtils::convertCubicToQuads(pathPts, tolScale, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 421 | } else { |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 422 | GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 423 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 424 | for (int i = 0; i < q.count(); i += 3) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 425 | if (persp) { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 426 | addSrcChoppedQuad(&q[i], !verbsInContour && 0 == i); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 427 | } else { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 428 | addChoppedQuad(nullptr, &q[i], !verbsInContour && 0 == i); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 432 | verbsInContour++; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 433 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 434 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 435 | case SkPath::kClose_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 436 | // 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 Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 445 | SkPoint devPts[2]; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 446 | 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 458 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 459 | case SkPath::kDone_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 460 | 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 467 | return totalQuadCount; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 472 | struct LineVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 473 | SkPoint fPos; |
egdaniel | e27065a | 2014-11-06 08:00:48 -0800 | [diff] [blame] | 474 | float fCoverage; |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 475 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 476 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 477 | struct BezierVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 478 | SkPoint fPos; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 479 | union { |
| 480 | struct { |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 481 | SkScalar fKLM[3]; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 482 | } fConic; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 483 | SkVector fQuadCoord; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 484 | struct { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 485 | SkScalar fBogus[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 486 | }; |
| 487 | }; |
| 488 | }; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 489 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 490 | GR_STATIC_ASSERT(sizeof(BezierVertex) == 3 * sizeof(SkPoint)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 491 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 492 | static void intersect_lines(const SkPoint& ptA, const SkVector& normA, |
| 493 | const SkPoint& ptB, const SkVector& normB, |
| 494 | SkPoint* result) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 495 | |
| 496 | SkScalar lineAW = -normA.dot(ptA); |
| 497 | SkScalar lineBW = -normB.dot(ptB); |
| 498 | |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 499 | SkScalar wInv = normA.fX * normB.fY - normA.fY * normB.fX; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 500 | wInv = SkScalarInvert(wInv); |
| 501 | |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 502 | result->fX = normA.fY * lineBW - lineAW * normB.fY; |
| 503 | result->fX *= wInv; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 504 | |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 505 | result->fY = lineAW * normB.fX - normA.fX * lineBW; |
| 506 | result->fY *= wInv; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 507 | } |
| 508 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 509 | static void set_uv_quad(const SkPoint qpts[3], BezierVertex verts[kQuadNumVertices]) { |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 510 | // this should be in the src space, not dev coords, when we have perspective |
| 511 | GrPathUtils::QuadUVMatrix DevToUV(qpts); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 512 | DevToUV.apply<kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint)>(verts); |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 513 | } |
| 514 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 515 | static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, |
| 516 | const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices]) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 517 | SkASSERT(!toDevice == !toSrc); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 518 | // original quad is specified by tri a,b,c |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 519 | SkPoint a = qpts[0]; |
| 520 | SkPoint b = qpts[1]; |
| 521 | SkPoint c = qpts[2]; |
| 522 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 523 | if (toDevice) { |
| 524 | toDevice->mapPoints(&a, 1); |
| 525 | toDevice->mapPoints(&b, 1); |
| 526 | toDevice->mapPoints(&c, 1); |
| 527 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 528 | // 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.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 540 | 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 545 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 546 | 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.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 554 | SkASSERT(ab.length() > 0 && cb.length() > 0); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 555 | |
| 556 | ab.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 557 | SkVector abN = SkPointPriv::MakeOrthog(ab, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 558 | if (abN.dot(ac) > 0) { |
| 559 | abN.negate(); |
| 560 | } |
| 561 | |
| 562 | cb.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 563 | SkVector cbN = SkPointPriv::MakeOrthog(cb, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 564 | 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.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 580 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 581 | SkMatrixPriv::MapPointsWithStride(*toSrc, &verts[0].fPos, sizeof(BezierVertex), |
| 582 | kQuadNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 583 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 584 | } |
| 585 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 586 | // Equations based off of Loop-Blinn Quadratic GPU Rendering |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 587 | // 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.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 590 | // 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.org | 1394840 | 2013-08-20 17:55:43 +0000 | [diff] [blame] | 592 | // k, l, m are calculated in function GrPathUtils::getConicKLM |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 593 | static void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices], |
| 594 | const SkScalar weight) { |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 595 | SkMatrix klm; |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 596 | |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 597 | GrPathUtils::getConicKLM(p, weight, &klm); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 598 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 599 | for (int i = 0; i < kQuadNumVertices; ++i) { |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 600 | 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.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 605 | static void add_conics(const SkPoint p[3], |
| 606 | const SkScalar weight, |
| 607 | const SkMatrix* toDevice, |
| 608 | const SkMatrix* toSrc, |
| 609 | BezierVertex** vert) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 610 | bloat_quad(p, toDevice, toSrc, *vert); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 611 | set_conic_coeffs(p, *vert, weight); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 612 | *vert += kQuadNumVertices; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 613 | } |
| 614 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 615 | static void add_quads(const SkPoint p[3], |
| 616 | int subdiv, |
| 617 | const SkMatrix* toDevice, |
| 618 | const SkMatrix* toSrc, |
| 619 | BezierVertex** vert) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 620 | SkASSERT(subdiv >= 0); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 621 | if (subdiv) { |
| 622 | SkPoint newP[5]; |
| 623 | SkChopQuadAtHalf(p, newP); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 624 | add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert); |
| 625 | add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 626 | } else { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 627 | bloat_quad(p, toDevice, toSrc, *vert); |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 628 | set_uv_quad(p, *vert); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 629 | *vert += kQuadNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 633 | static void add_line(const SkPoint p[2], |
| 634 | const SkMatrix* toSrc, |
| 635 | uint8_t coverage, |
| 636 | LineVertex** vert) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 637 | const SkPoint& a = p[0]; |
| 638 | const SkPoint& b = p[1]; |
| 639 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 640 | SkVector ortho, vec = b; |
| 641 | vec -= a; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 642 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 643 | SkScalar lengthSqd = SkPointPriv::LengthSqd(vec); |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 644 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 645 | 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 649 | |
egdaniel | e27065a | 2014-11-06 08:00:48 -0800 | [diff] [blame] | 650 | float floatCoverage = GrNormalizeByteToFloat(coverage); |
| 651 | |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 652 | 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.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 674 | (*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 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 683 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 684 | SkMatrixPriv::MapPointsWithStride(*toSrc, &(*vert)->fPos, sizeof(LineVertex), |
| 685 | kLineSegNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 686 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 687 | } else { |
| 688 | // just make it degenerate and likely offscreen |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 689 | for (int i = 0; i < kLineSegNumVertices; ++i) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 690 | (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 691 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 692 | } |
| 693 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 694 | *vert += kLineSegNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 695 | } |
| 696 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 697 | /////////////////////////////////////////////////////////////////////////////// |
| 698 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 699 | GrPathRenderer::CanDrawPath |
| 700 | GrAAHairLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 701 | if (GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 702 | return CanDrawPath::kNo; |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 703 | } |
| 704 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 705 | if (!IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 706 | return CanDrawPath::kNo; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | // We don't currently handle dashing in this class though perhaps we should. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 710 | if (args.fShape->style().pathEffect()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 711 | return CanDrawPath::kNo; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 712 | } |
| 713 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 714 | if (SkPath::kLine_SegmentMask == args.fShape->segmentMask() || |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 715 | args.fCaps->shaderCaps()->shaderDerivativeSupport()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 716 | return CanDrawPath::kYes; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 717 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 718 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 719 | return CanDrawPath::kNo; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 720 | } |
| 721 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 722 | template <class VertexType> |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 723 | bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* vertices, int vCount) |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 724 | { |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 725 | SkRect tolDevBounds = devBounds; |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 726 | // 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. |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 728 | if (viewMatrix.hasPerspective()) { |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 729 | tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000); |
| 730 | } else { |
| 731 | // Non-persp matrices cause this path renderer to draw in device space. |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 732 | SkASSERT(viewMatrix.isIdentity()); |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 733 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 734 | SkRect actualBounds; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 735 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 736 | VertexType* verts = reinterpret_cast<VertexType*>(vertices); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 737 | 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 | } |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 744 | viewMatrix.mapPoints(&pos, 1); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 745 | if (first) { |
| 746 | actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY); |
| 747 | first = false; |
| 748 | } else { |
Mike Reed | 185ffe9 | 2018-01-08 17:09:54 -0500 | [diff] [blame] | 749 | SkRectPriv::GrowToInclude(&actualBounds, pos); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | if (!first) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 753 | return tolDevBounds.contains(actualBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 754 | } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 755 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 756 | return true; |
| 757 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 758 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 759 | namespace { |
| 760 | |
| 761 | class AAHairlineOp final : public GrMeshDrawOp { |
| 762 | private: |
| 763 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 764 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 765 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 766 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 767 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 768 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 769 | GrPaint&& paint, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 770 | const SkMatrix& viewMatrix, |
| 771 | const SkPath& path, |
| 772 | const GrStyle& style, |
| 773 | const SkIRect& devClipBounds, |
| 774 | const GrUserStencilSettings* stencilSettings) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 775 | SkScalar hairlineCoverage; |
| 776 | uint8_t newCoverage = 0xff; |
| 777 | if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) { |
| 778 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 779 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 780 | |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 781 | const SkStrokeRec& stroke = style.strokeRec(); |
| 782 | SkScalar capLength = SkPaint::kButt_Cap != stroke.getCap() ? hairlineCoverage * 0.5f : 0.0f; |
| 783 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 784 | return Helper::FactoryHelper<AAHairlineOp>(context, std::move(paint), newCoverage, |
| 785 | viewMatrix, path, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 786 | 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); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 805 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 806 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 807 | const char* name() const override { return "AAHairlineOp"; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 808 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 809 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 810 | fHelper.visitProxies(func); |
| 811 | } |
| 812 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 813 | SkString dumpInfo() const override { |
| 814 | SkString string; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 815 | string.appendf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n", fColor, fCoverage, |
| 816 | fPaths.count()); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 817 | string += INHERITED::dumpInfo(); |
| 818 | string += fHelper.dumpInfo(); |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 819 | return string; |
| 820 | } |
| 821 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 822 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 823 | |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 824 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { |
| 825 | return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel, |
| 826 | &fColor); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 827 | } |
| 828 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 829 | private: |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 830 | void onPrepareDraws(Target*) override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 831 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 832 | typedef SkTArray<SkPoint, true> PtArray; |
| 833 | typedef SkTArray<int, true> IntArray; |
| 834 | typedef SkTArray<float, true> FloatArray; |
| 835 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 836 | CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 837 | AAHairlineOp* that = t->cast<AAHairlineOp>(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 838 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 839 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 840 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 841 | } |
| 842 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 843 | if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 844 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | // We go to identity if we don't have perspective |
| 848 | if (this->viewMatrix().hasPerspective() && |
| 849 | !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 850 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 853 | // 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 |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 855 | // TODO investigate going to vertex color and coverage? |
| 856 | if (this->coverage() != that->coverage()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 857 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | if (this->color() != that->color()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 861 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 862 | } |
| 863 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 864 | if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 865 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 868 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 869 | this->joinBounds(*that); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 870 | return CombineResult::kMerged; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 871 | } |
| 872 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 873 | GrColor color() const { return fColor; } |
| 874 | uint8_t coverage() const { return fCoverage; } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 875 | const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 876 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 877 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 878 | SkMatrix fViewMatrix; |
| 879 | SkPath fPath; |
| 880 | SkIRect fDevClipBounds; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 881 | SkScalar fCapLength; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 882 | }; |
| 883 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 884 | SkSTArray<1, PathData, true> fPaths; |
| 885 | Helper fHelper; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 886 | GrColor fColor; |
| 887 | uint8_t fCoverage; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 888 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 889 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 890 | }; |
| 891 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 892 | } // anonymous namespace |
| 893 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 894 | void AAHairlineOp::onPrepareDraws(Target* target) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 895 | // 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; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 905 | const SkMatrix* toDevice = nullptr; |
| 906 | const SkMatrix* toSrc = nullptr; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 907 | if (hasPerspective) { |
| 908 | geometryProcessorViewM = &this->viewMatrix(); |
| 909 | geometryProcessorLocalM = &SkMatrix::I(); |
| 910 | toDevice = &this->viewMatrix(); |
| 911 | toSrc = &invert; |
| 912 | } |
| 913 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 914 | // 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; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 920 | int quadCount = 0; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 921 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 922 | int instanceCount = fPaths.count(); |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 923 | bool convertConicsToQuads = !target->caps().shaderCaps()->floatIs32Bits(); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 924 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 925 | const PathData& args = fPaths[i]; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 926 | quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds, |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 927 | args.fCapLength, convertConicsToQuads, &lines, &quads, |
| 928 | &conics, &qSubdivs, &cWeights); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 929 | } |
| 930 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 931 | int lineCount = lines.count() / 2; |
| 932 | int conicCount = conics.count() / 3; |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 933 | 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 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 940 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 941 | auto pipe = fHelper.makePipeline(target); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 942 | // do lines first |
| 943 | if (lineCount) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 944 | sk_sp<GrGeometryProcessor> lineGP; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 945 | { |
| 946 | using namespace GrDefaultGeoProcFactory; |
| 947 | |
| 948 | Color color(this->color()); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 949 | LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type |
| 950 | : LocalCoords::kUnused_Type); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 951 | localCoords.fMatrix = geometryProcessorLocalM; |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 952 | lineGP = GrDefaultGeoProcFactory::Make(target->caps().shaderCaps(), |
| 953 | color, Coverage::kAttribute_Type, localCoords, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 954 | *geometryProcessorViewM); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 957 | sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider()); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 958 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 959 | const GrBuffer* vertexBuffer; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 960 | int firstVertex; |
| 961 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 962 | SkASSERT(sizeof(LineVertex) == lineGP->debugOnly_vertexStride()); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 963 | int vertexCount = kLineSegNumVertices * lineCount; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 964 | LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace( |
| 965 | sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex)); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 966 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 967 | if (!verts|| !linesIndexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 968 | SkDebugf("Could not allocate vertices\n"); |
| 969 | return; |
| 970 | } |
| 971 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 972 | for (int i = 0; i < lineCount; ++i) { |
| 973 | add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
| 974 | } |
| 975 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 976 | 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); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | if (quadCount || conicCount) { |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 984 | sk_sp<GrGeometryProcessor> quadGP(GrQuadEffect::Make(this->color(), |
| 985 | *geometryProcessorViewM, |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 986 | GrClipEdgeType::kHairlineAA, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 987 | target->caps(), |
| 988 | *geometryProcessorLocalM, |
| 989 | fHelper.usesLocalCoords(), |
| 990 | this->coverage())); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 991 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 992 | sk_sp<GrGeometryProcessor> conicGP(GrConicEffect::Make(this->color(), |
| 993 | *geometryProcessorViewM, |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 994 | GrClipEdgeType::kHairlineAA, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 995 | target->caps(), |
| 996 | *geometryProcessorLocalM, |
| 997 | fHelper.usesLocalCoords(), |
| 998 | this->coverage())); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 999 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 1000 | const GrBuffer* vertexBuffer; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1001 | int firstVertex; |
| 1002 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 1003 | sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider()); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1004 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1005 | SkASSERT(sizeof(BezierVertex) == quadGP->debugOnly_vertexStride()); |
| 1006 | SkASSERT(sizeof(BezierVertex) == conicGP->debugOnly_vertexStride()); |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 1007 | int vertexCount = kQuadNumVertices * quadAndConicCount; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1008 | void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer, |
| 1009 | &firstVertex); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1010 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1011 | if (!vertices || !quadsIndexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1012 | SkDebugf("Could not allocate vertices\n"); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1016 | // Setup vertices |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1017 | BezierVertex* bezVerts = reinterpret_cast<BezierVertex*>(vertices); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1018 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1019 | int unsubdivQuadCnt = quads.count() / 3; |
| 1020 | for (int i = 0; i < unsubdivQuadCnt; ++i) { |
| 1021 | SkASSERT(qSubdivs[i] >= 0); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1022 | add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | // Start Conics |
| 1026 | for (int i = 0; i < conicCount; ++i) { |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1027 | add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | if (quadCount > 0) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1031 | 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); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1036 | firstVertex += quadCount * kQuadNumVertices; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | if (conicCount > 0) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1040 | 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); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1049 | bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1050 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1051 | "GrAAHairlinePathRenderer::onDrawPath"); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1052 | SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType()); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 1053 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 1054 | SkIRect devClipBounds; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 1055 | args.fClip->getConservativeBounds(args.fRenderTargetContext->width(), |
| 1056 | args.fRenderTargetContext->height(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1057 | &devClipBounds); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1058 | SkPath path; |
| 1059 | args.fShape->asPath(&path); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1060 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1061 | AAHairlineOp::Make(args.fContext, std::move(args.fPaint), *args.fViewMatrix, path, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1062 | args.fShape->style(), devClipBounds, args.fUserStencilSettings); |
| 1063 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1064 | return true; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1065 | } |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1066 | |
| 1067 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1068 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 1069 | #if GR_TEST_UTILS |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1070 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1071 | GR_DRAW_OP_TEST_DEFINE(AAHairlineOp) { |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1072 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1073 | SkPath path = GrTest::TestPath(random); |
| 1074 | SkIRect devClipBounds; |
| 1075 | devClipBounds.setEmpty(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1076 | return AAHairlineOp::Make(context, std::move(paint), viewMatrix, path, |
| 1077 | GrStyle::SimpleHairline(), devClipBounds, |
| 1078 | GrGetRandomStencil(random, context)); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | #endif |