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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkPoint3.h" |
| 9 | #include "include/private/SkTemplates.h" |
| 10 | #include "src/core/SkGeometry.h" |
| 11 | #include "src/core/SkMatrixPriv.h" |
| 12 | #include "src/core/SkPointPriv.h" |
| 13 | #include "src/core/SkRectPriv.h" |
| 14 | #include "src/core/SkStroke.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrBuffer.h" |
| 17 | #include "src/gpu/GrCaps.h" |
| 18 | #include "src/gpu/GrClip.h" |
| 19 | #include "src/gpu/GrDefaultGeoProcFactory.h" |
| 20 | #include "src/gpu/GrDrawOpTest.h" |
| 21 | #include "src/gpu/GrOpFlushState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrProcessor.h" |
| 23 | #include "src/gpu/GrResourceProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrStyle.h" |
| 25 | #include "src/gpu/effects/GrBezierEffect.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 26 | #include "src/gpu/geometry/GrPathUtils.h" |
| 27 | #include "src/gpu/geometry/GrShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "src/gpu/ops/GrAAHairLinePathRenderer.h" |
| 29 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 30 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.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]; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 315 | SkPath::Verb verb = iter.next(pathPts); |
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; |
Brian Osman | e3deee1 | 2018-11-20 11:10:15 -0500 | [diff] [blame] | 321 | const SkPoint* quadPts = converter.computeQuads(pathPts, weight, 0.25f); |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 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); |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 501 | if (!SkScalarIsFinite(wInv)) { |
| 502 | // lines are parallel, pick the point in between |
| 503 | *result = (ptA + ptB)*SK_ScalarHalf; |
| 504 | *result += normA; |
| 505 | } else { |
| 506 | result->fX = normA.fY * lineBW - lineAW * normB.fY; |
| 507 | result->fX *= wInv; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 508 | |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 509 | result->fY = lineAW * normB.fX - normA.fX * lineBW; |
| 510 | result->fY *= wInv; |
| 511 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 512 | } |
| 513 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 514 | 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] | 515 | // this should be in the src space, not dev coords, when we have perspective |
| 516 | GrPathUtils::QuadUVMatrix DevToUV(qpts); |
Brian Osman | 568bec7 | 2018-12-26 16:48:25 -0500 | [diff] [blame] | 517 | DevToUV.apply(verts, kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint)); |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 518 | } |
| 519 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 520 | static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, |
| 521 | const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices]) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 522 | SkASSERT(!toDevice == !toSrc); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 523 | // original quad is specified by tri a,b,c |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 524 | SkPoint a = qpts[0]; |
| 525 | SkPoint b = qpts[1]; |
| 526 | SkPoint c = qpts[2]; |
| 527 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 528 | if (toDevice) { |
| 529 | toDevice->mapPoints(&a, 1); |
| 530 | toDevice->mapPoints(&b, 1); |
| 531 | toDevice->mapPoints(&c, 1); |
| 532 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 533 | // make a new poly where we replace a and c by a 1-pixel wide edges orthog |
| 534 | // to edges ab and bc: |
| 535 | // |
| 536 | // before | after |
| 537 | // | b0 |
| 538 | // b | |
| 539 | // | |
| 540 | // | a0 c0 |
| 541 | // a c | a1 c1 |
| 542 | // |
| 543 | // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c, |
| 544 | // respectively. |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 545 | BezierVertex& a0 = verts[0]; |
| 546 | BezierVertex& a1 = verts[1]; |
| 547 | BezierVertex& b0 = verts[2]; |
| 548 | BezierVertex& c0 = verts[3]; |
| 549 | BezierVertex& c1 = verts[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 550 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 551 | SkVector ab = b; |
| 552 | ab -= a; |
| 553 | SkVector ac = c; |
| 554 | ac -= a; |
| 555 | SkVector cb = b; |
| 556 | cb -= c; |
| 557 | |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 558 | // After the transform we might have a line, try to do something reasonable |
| 559 | if (toDevice && SkPointPriv::LengthSqd(ab) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
| 560 | ab = cb; |
| 561 | } |
| 562 | if (toDevice && SkPointPriv::LengthSqd(cb) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
| 563 | cb = ab; |
| 564 | } |
| 565 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 566 | // We should have already handled degenerates |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 567 | SkASSERT(toDevice || (ab.length() > 0 && cb.length() > 0)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 568 | |
| 569 | ab.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 570 | SkVector abN = SkPointPriv::MakeOrthog(ab, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 571 | if (abN.dot(ac) > 0) { |
| 572 | abN.negate(); |
| 573 | } |
| 574 | |
| 575 | cb.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 576 | SkVector cbN = SkPointPriv::MakeOrthog(cb, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 577 | if (cbN.dot(ac) < 0) { |
| 578 | cbN.negate(); |
| 579 | } |
| 580 | |
| 581 | a0.fPos = a; |
| 582 | a0.fPos += abN; |
| 583 | a1.fPos = a; |
| 584 | a1.fPos -= abN; |
| 585 | |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 586 | if (toDevice && SkPointPriv::LengthSqd(ac) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
| 587 | c = b; |
| 588 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 589 | c0.fPos = c; |
| 590 | c0.fPos += cbN; |
| 591 | c1.fPos = c; |
| 592 | c1.fPos -= cbN; |
| 593 | |
| 594 | intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); |
| 595 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 596 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 597 | SkMatrixPriv::MapPointsWithStride(*toSrc, &verts[0].fPos, sizeof(BezierVertex), |
| 598 | kQuadNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 599 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 600 | } |
| 601 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 602 | // Equations based off of Loop-Blinn Quadratic GPU Rendering |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 603 | // Input Parametric: |
| 604 | // 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) |
| 605 | // Output Implicit: |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 606 | // f(x, y, w) = f(P) = K^2 - LM |
| 607 | // 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] | 608 | // k, l, m are calculated in function GrPathUtils::getConicKLM |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 609 | static void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices], |
| 610 | const SkScalar weight) { |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 611 | SkMatrix klm; |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 612 | |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 613 | GrPathUtils::getConicKLM(p, weight, &klm); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 614 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 615 | for (int i = 0; i < kQuadNumVertices; ++i) { |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 616 | const SkPoint3 pt3 = {verts[i].fPos.x(), verts[i].fPos.y(), 1.f}; |
| 617 | klm.mapHomogeneousPoints((SkPoint3* ) verts[i].fConic.fKLM, &pt3, 1); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 621 | static void add_conics(const SkPoint p[3], |
| 622 | const SkScalar weight, |
| 623 | const SkMatrix* toDevice, |
| 624 | const SkMatrix* toSrc, |
| 625 | BezierVertex** vert) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 626 | bloat_quad(p, toDevice, toSrc, *vert); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 627 | set_conic_coeffs(p, *vert, weight); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 628 | *vert += kQuadNumVertices; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 629 | } |
| 630 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 631 | static void add_quads(const SkPoint p[3], |
| 632 | int subdiv, |
| 633 | const SkMatrix* toDevice, |
| 634 | const SkMatrix* toSrc, |
| 635 | BezierVertex** vert) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 636 | SkASSERT(subdiv >= 0); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 637 | if (subdiv) { |
| 638 | SkPoint newP[5]; |
| 639 | SkChopQuadAtHalf(p, newP); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 640 | add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert); |
| 641 | add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 642 | } else { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 643 | bloat_quad(p, toDevice, toSrc, *vert); |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 644 | set_uv_quad(p, *vert); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 645 | *vert += kQuadNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 649 | static void add_line(const SkPoint p[2], |
| 650 | const SkMatrix* toSrc, |
| 651 | uint8_t coverage, |
| 652 | LineVertex** vert) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 653 | const SkPoint& a = p[0]; |
| 654 | const SkPoint& b = p[1]; |
| 655 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 656 | SkVector ortho, vec = b; |
| 657 | vec -= a; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 658 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 659 | SkScalar lengthSqd = SkPointPriv::LengthSqd(vec); |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 660 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 661 | if (vec.setLength(SK_ScalarHalf)) { |
| 662 | // Create a vector orthogonal to 'vec' and of unit length |
| 663 | ortho.fX = 2.0f * vec.fY; |
| 664 | ortho.fY = -2.0f * vec.fX; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 665 | |
egdaniel | e27065a | 2014-11-06 08:00:48 -0800 | [diff] [blame] | 666 | float floatCoverage = GrNormalizeByteToFloat(coverage); |
| 667 | |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 668 | if (lengthSqd >= 1.0f) { |
| 669 | // Relative to points a and b: |
| 670 | // The inner vertices are inset half a pixel along the line a,b |
| 671 | (*vert)[0].fPos = a + vec; |
| 672 | (*vert)[0].fCoverage = floatCoverage; |
| 673 | (*vert)[1].fPos = b - vec; |
| 674 | (*vert)[1].fCoverage = floatCoverage; |
| 675 | } else { |
| 676 | // The inner vertices are inset a distance of length(a,b) from the outer edge of |
| 677 | // geometry. For the "a" inset this is the same as insetting from b by half a pixel. |
| 678 | // The coverage is then modulated by the length. This gives us the correct |
| 679 | // coverage for rects shorter than a pixel as they get translated subpixel amounts |
| 680 | // inside of a pixel. |
| 681 | SkScalar length = SkScalarSqrt(lengthSqd); |
| 682 | (*vert)[0].fPos = b - vec; |
| 683 | (*vert)[0].fCoverage = floatCoverage * length; |
| 684 | (*vert)[1].fPos = a + vec; |
| 685 | (*vert)[1].fCoverage = floatCoverage * length; |
| 686 | } |
| 687 | // Relative to points a and b: |
| 688 | // The outer vertices are outset half a pixel along the line a,b and then a whole pixel |
| 689 | // orthogonally. |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 690 | (*vert)[2].fPos = a - vec + ortho; |
| 691 | (*vert)[2].fCoverage = 0; |
| 692 | (*vert)[3].fPos = b + vec + ortho; |
| 693 | (*vert)[3].fCoverage = 0; |
| 694 | (*vert)[4].fPos = a - vec - ortho; |
| 695 | (*vert)[4].fCoverage = 0; |
| 696 | (*vert)[5].fPos = b + vec - ortho; |
| 697 | (*vert)[5].fCoverage = 0; |
| 698 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 699 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 700 | SkMatrixPriv::MapPointsWithStride(*toSrc, &(*vert)->fPos, sizeof(LineVertex), |
| 701 | kLineSegNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 702 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 703 | } else { |
| 704 | // just make it degenerate and likely offscreen |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 705 | for (int i = 0; i < kLineSegNumVertices; ++i) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 706 | (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 707 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 708 | } |
| 709 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 710 | *vert += kLineSegNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 711 | } |
| 712 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 713 | /////////////////////////////////////////////////////////////////////////////// |
| 714 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 715 | GrPathRenderer::CanDrawPath |
| 716 | GrAAHairLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 717 | if (GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 718 | return CanDrawPath::kNo; |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 719 | } |
| 720 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 721 | if (!IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 722 | return CanDrawPath::kNo; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | // We don't currently handle dashing in this class though perhaps we should. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 726 | if (args.fShape->style().pathEffect()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 727 | return CanDrawPath::kNo; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 728 | } |
| 729 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 730 | if (SkPath::kLine_SegmentMask == args.fShape->segmentMask() || |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 731 | args.fCaps->shaderCaps()->shaderDerivativeSupport()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 732 | return CanDrawPath::kYes; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 733 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 734 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 735 | return CanDrawPath::kNo; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 736 | } |
| 737 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 738 | template <class VertexType> |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 739 | 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] | 740 | { |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 741 | SkRect tolDevBounds = devBounds; |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 742 | // The bounds ought to be tight, but in perspective the below code runs the verts |
| 743 | // 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] | 744 | if (viewMatrix.hasPerspective()) { |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 745 | tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000); |
| 746 | } else { |
| 747 | // Non-persp matrices cause this path renderer to draw in device space. |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 748 | SkASSERT(viewMatrix.isIdentity()); |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 749 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 750 | SkRect actualBounds; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 751 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 752 | VertexType* verts = reinterpret_cast<VertexType*>(vertices); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 753 | bool first = true; |
| 754 | for (int i = 0; i < vCount; ++i) { |
| 755 | SkPoint pos = verts[i].fPos; |
| 756 | // This is a hack to workaround the fact that we move some degenerate segments offscreen. |
| 757 | if (SK_ScalarMax == pos.fX) { |
| 758 | continue; |
| 759 | } |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 760 | viewMatrix.mapPoints(&pos, 1); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 761 | if (first) { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 762 | actualBounds.setLTRB(pos.fX, pos.fY, pos.fX, pos.fY); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 763 | first = false; |
| 764 | } else { |
Mike Reed | 185ffe9 | 2018-01-08 17:09:54 -0500 | [diff] [blame] | 765 | SkRectPriv::GrowToInclude(&actualBounds, pos); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | if (!first) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 769 | return tolDevBounds.contains(actualBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 770 | } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 771 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 772 | return true; |
| 773 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 774 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 775 | namespace { |
| 776 | |
| 777 | class AAHairlineOp final : public GrMeshDrawOp { |
| 778 | private: |
| 779 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 780 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 781 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 782 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 783 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 784 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 785 | GrPaint&& paint, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 786 | const SkMatrix& viewMatrix, |
| 787 | const SkPath& path, |
| 788 | const GrStyle& style, |
| 789 | const SkIRect& devClipBounds, |
| 790 | const GrUserStencilSettings* stencilSettings) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 791 | SkScalar hairlineCoverage; |
| 792 | uint8_t newCoverage = 0xff; |
| 793 | if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) { |
| 794 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 795 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 796 | |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 797 | const SkStrokeRec& stroke = style.strokeRec(); |
| 798 | SkScalar capLength = SkPaint::kButt_Cap != stroke.getCap() ? hairlineCoverage * 0.5f : 0.0f; |
| 799 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 800 | return Helper::FactoryHelper<AAHairlineOp>(context, std::move(paint), newCoverage, |
| 801 | viewMatrix, path, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 802 | devClipBounds, capLength, stencilSettings); |
| 803 | } |
| 804 | |
| 805 | AAHairlineOp(const Helper::MakeArgs& helperArgs, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 806 | const SkPMColor4f& color, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 807 | uint8_t coverage, |
| 808 | const SkMatrix& viewMatrix, |
| 809 | const SkPath& path, |
| 810 | SkIRect devClipBounds, |
| 811 | SkScalar capLength, |
| 812 | const GrUserStencilSettings* stencilSettings) |
| 813 | : INHERITED(ClassID()) |
| 814 | , fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) |
| 815 | , fColor(color) |
| 816 | , fCoverage(coverage) { |
| 817 | fPaths.emplace_back(PathData{viewMatrix, path, devClipBounds, capLength}); |
| 818 | |
| 819 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, |
| 820 | IsZeroArea::kYes); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 821 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 822 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 823 | const char* name() const override { return "AAHairlineOp"; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 824 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 825 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 826 | fHelper.visitProxies(func); |
| 827 | } |
| 828 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 829 | #ifdef SK_DEBUG |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 830 | SkString dumpInfo() const override { |
| 831 | SkString string; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 832 | string.appendf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n", fColor.toBytes_RGBA(), |
Brian Osman | 1be2b7c | 2018-10-29 16:07:15 -0400 | [diff] [blame] | 833 | fCoverage, fPaths.count()); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 834 | string += INHERITED::dumpInfo(); |
| 835 | string += fHelper.dumpInfo(); |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 836 | return string; |
| 837 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 838 | #endif |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 839 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 840 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 841 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 842 | GrProcessorSet::Analysis finalize( |
| 843 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 844 | GrClampType clampType) override { |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 845 | // This Op uses uniform (not vertex) color, so doesn't need to track wide color. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 846 | return fHelper.finalizeProcessors(caps, clip, hasMixedSampledCoverage, clampType, |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 847 | GrProcessorAnalysisCoverage::kSingleChannel, &fColor, |
| 848 | nullptr); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 849 | } |
| 850 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 851 | private: |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 852 | void onPrepareDraws(Target*) override; |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 853 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 854 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 855 | typedef SkTArray<SkPoint, true> PtArray; |
| 856 | typedef SkTArray<int, true> IntArray; |
| 857 | typedef SkTArray<float, true> FloatArray; |
| 858 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 859 | CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 860 | AAHairlineOp* that = t->cast<AAHairlineOp>(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 861 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 862 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 863 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 864 | } |
| 865 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 866 | if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 867 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | // We go to identity if we don't have perspective |
| 871 | if (this->viewMatrix().hasPerspective() && |
| 872 | !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 873 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 876 | // TODO we can actually combine hairlines if they are the same color in a kind of bulk |
| 877 | // method but we haven't implemented this yet |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 878 | // TODO investigate going to vertex color and coverage? |
| 879 | if (this->coverage() != that->coverage()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 880 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | if (this->color() != that->color()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 884 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 885 | } |
| 886 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 887 | if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 888 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 889 | } |
| 890 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 891 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 892 | return CombineResult::kMerged; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 895 | const SkPMColor4f& color() const { return fColor; } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 896 | uint8_t coverage() const { return fCoverage; } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 897 | const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 898 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 899 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 900 | SkMatrix fViewMatrix; |
| 901 | SkPath fPath; |
| 902 | SkIRect fDevClipBounds; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 903 | SkScalar fCapLength; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 904 | }; |
| 905 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 906 | SkSTArray<1, PathData, true> fPaths; |
| 907 | Helper fHelper; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 908 | SkPMColor4f fColor; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 909 | uint8_t fCoverage; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 910 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 911 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 912 | }; |
| 913 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 914 | } // anonymous namespace |
| 915 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 916 | void AAHairlineOp::onPrepareDraws(Target* target) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 917 | // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. |
| 918 | SkMatrix invert; |
| 919 | if (!this->viewMatrix().invert(&invert)) { |
| 920 | return; |
| 921 | } |
| 922 | |
| 923 | // we will transform to identity space if the viewmatrix does not have perspective |
| 924 | bool hasPerspective = this->viewMatrix().hasPerspective(); |
| 925 | const SkMatrix* geometryProcessorViewM = &SkMatrix::I(); |
| 926 | const SkMatrix* geometryProcessorLocalM = &invert; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 927 | const SkMatrix* toDevice = nullptr; |
| 928 | const SkMatrix* toSrc = nullptr; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 929 | if (hasPerspective) { |
| 930 | geometryProcessorViewM = &this->viewMatrix(); |
| 931 | geometryProcessorLocalM = &SkMatrix::I(); |
| 932 | toDevice = &this->viewMatrix(); |
| 933 | toSrc = &invert; |
| 934 | } |
| 935 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 936 | // This is hand inlined for maximum performance. |
| 937 | PREALLOC_PTARRAY(128) lines; |
| 938 | PREALLOC_PTARRAY(128) quads; |
| 939 | PREALLOC_PTARRAY(128) conics; |
| 940 | IntArray qSubdivs; |
| 941 | FloatArray cWeights; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 942 | int quadCount = 0; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 943 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 944 | int instanceCount = fPaths.count(); |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 945 | bool convertConicsToQuads = !target->caps().shaderCaps()->floatIs32Bits(); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 946 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 947 | const PathData& args = fPaths[i]; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 948 | quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds, |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 949 | args.fCapLength, convertConicsToQuads, &lines, &quads, |
| 950 | &conics, &qSubdivs, &cWeights); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 951 | } |
| 952 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 953 | int lineCount = lines.count() / 2; |
| 954 | int conicCount = conics.count() / 3; |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 955 | int quadAndConicCount = conicCount + quadCount; |
| 956 | |
| 957 | static constexpr int kMaxLines = SK_MaxS32 / kLineSegNumVertices; |
| 958 | static constexpr int kMaxQuadsAndConics = SK_MaxS32 / kQuadNumVertices; |
| 959 | if (lineCount > kMaxLines || quadAndConicCount > kMaxQuadsAndConics) { |
| 960 | return; |
| 961 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 962 | |
| 963 | // do lines first |
| 964 | if (lineCount) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 965 | sk_sp<GrGeometryProcessor> lineGP; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 966 | { |
| 967 | using namespace GrDefaultGeoProcFactory; |
| 968 | |
| 969 | Color color(this->color()); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 970 | LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type |
| 971 | : LocalCoords::kUnused_Type); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 972 | localCoords.fMatrix = geometryProcessorLocalM; |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 973 | lineGP = GrDefaultGeoProcFactory::Make(target->caps().shaderCaps(), |
| 974 | color, Coverage::kAttribute_Type, localCoords, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 975 | *geometryProcessorViewM); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 978 | sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider()); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 979 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 980 | sk_sp<const GrBuffer> vertexBuffer; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 981 | int firstVertex; |
| 982 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 983 | SkASSERT(sizeof(LineVertex) == lineGP->vertexStride()); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 984 | int vertexCount = kLineSegNumVertices * lineCount; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 985 | LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace( |
| 986 | sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex)); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 987 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 988 | if (!verts|| !linesIndexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 989 | SkDebugf("Could not allocate vertices\n"); |
| 990 | return; |
| 991 | } |
| 992 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 993 | for (int i = 0; i < lineCount; ++i) { |
| 994 | add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
| 995 | } |
| 996 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 997 | GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 998 | mesh->setIndexedPatterned(std::move(linesIndexBuffer), kIdxsPerLineSeg, kLineSegNumVertices, |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 999 | lineCount, kLineSegsNumInIdxBuffer); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1000 | mesh->setVertexData(std::move(vertexBuffer), firstVertex); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1001 | target->recordDraw(std::move(lineGP), mesh); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | if (quadCount || conicCount) { |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1005 | sk_sp<GrGeometryProcessor> quadGP(GrQuadEffect::Make(this->color(), |
| 1006 | *geometryProcessorViewM, |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1007 | GrClipEdgeType::kHairlineAA, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1008 | target->caps(), |
| 1009 | *geometryProcessorLocalM, |
| 1010 | fHelper.usesLocalCoords(), |
| 1011 | this->coverage())); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1012 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1013 | sk_sp<GrGeometryProcessor> conicGP(GrConicEffect::Make(this->color(), |
| 1014 | *geometryProcessorViewM, |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 1015 | GrClipEdgeType::kHairlineAA, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1016 | target->caps(), |
| 1017 | *geometryProcessorLocalM, |
| 1018 | fHelper.usesLocalCoords(), |
| 1019 | this->coverage())); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1020 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1021 | sk_sp<const GrBuffer> vertexBuffer; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1022 | int firstVertex; |
| 1023 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 1024 | sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider()); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1025 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 1026 | SkASSERT(sizeof(BezierVertex) == quadGP->vertexStride()); |
| 1027 | SkASSERT(sizeof(BezierVertex) == conicGP->vertexStride()); |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 1028 | int vertexCount = kQuadNumVertices * quadAndConicCount; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1029 | void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer, |
| 1030 | &firstVertex); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1031 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1032 | if (!vertices || !quadsIndexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1033 | SkDebugf("Could not allocate vertices\n"); |
| 1034 | return; |
| 1035 | } |
| 1036 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1037 | // Setup vertices |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1038 | BezierVertex* bezVerts = reinterpret_cast<BezierVertex*>(vertices); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1039 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1040 | int unsubdivQuadCnt = quads.count() / 3; |
| 1041 | for (int i = 0; i < unsubdivQuadCnt; ++i) { |
| 1042 | SkASSERT(qSubdivs[i] >= 0); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1043 | add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | // Start Conics |
| 1047 | for (int i = 0; i < conicCount; ++i) { |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1048 | add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | if (quadCount > 0) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1052 | GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1053 | mesh->setIndexedPatterned(quadsIndexBuffer, kIdxsPerQuad, kQuadNumVertices, quadCount, |
| 1054 | kQuadsNumInIdxBuffer); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1055 | mesh->setVertexData(vertexBuffer, firstVertex); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1056 | target->recordDraw(std::move(quadGP), mesh); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1057 | firstVertex += quadCount * kQuadNumVertices; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | if (conicCount > 0) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1061 | GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1062 | mesh->setIndexedPatterned(std::move(quadsIndexBuffer), kIdxsPerQuad, kQuadNumVertices, |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1063 | conicCount, kQuadsNumInIdxBuffer); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1064 | mesh->setVertexData(std::move(vertexBuffer), firstVertex); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1065 | target->recordDraw(std::move(conicGP), mesh); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1070 | void AAHairlineOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
| 1071 | fHelper.executeDrawsAndUploads(this, flushState, chainBounds); |
| 1072 | } |
| 1073 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1074 | bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1075 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1076 | "GrAAHairlinePathRenderer::onDrawPath"); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1077 | SkASSERT(args.fRenderTargetContext->numSamples() <= 1); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 1078 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 1079 | SkIRect devClipBounds; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 1080 | args.fClip->getConservativeBounds(args.fRenderTargetContext->width(), |
| 1081 | args.fRenderTargetContext->height(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1082 | &devClipBounds); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1083 | SkPath path; |
| 1084 | args.fShape->asPath(&path); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1085 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1086 | AAHairlineOp::Make(args.fContext, std::move(args.fPaint), *args.fViewMatrix, path, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1087 | args.fShape->style(), devClipBounds, args.fUserStencilSettings); |
| 1088 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1089 | return true; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1090 | } |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1091 | |
| 1092 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1093 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 1094 | #if GR_TEST_UTILS |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1095 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1096 | GR_DRAW_OP_TEST_DEFINE(AAHairlineOp) { |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1097 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1098 | SkPath path = GrTest::TestPath(random); |
| 1099 | SkIRect devClipBounds; |
| 1100 | devClipBounds.setEmpty(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1101 | return AAHairlineOp::Make(context, std::move(paint), viewMatrix, path, |
| 1102 | GrStyle::SimpleHairline(), devClipBounds, |
| 1103 | GrGetRandomStencil(random, context)); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | #endif |