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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrDefaultGeoProcFactory.h" |
| 19 | #include "src/gpu/GrDrawOpTest.h" |
| 20 | #include "src/gpu/GrOpFlushState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrProcessor.h" |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrResourceProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrStyle.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrSurfaceDrawContext.h" |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 26 | #include "src/gpu/GrUtil.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/effects/GrBezierEffect.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 28 | #include "src/gpu/geometry/GrPathUtils.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 29 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/ops/GrAAHairLinePathRenderer.h" |
| 31 | #include "src/gpu/ops/GrMeshDrawOp.h" |
Robert Phillips | 55f681f | 2020-02-28 08:58:15 -0500 | [diff] [blame] | 32 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h" |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 33 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 34 | #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true> |
| 35 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 36 | // quadratics are rendered as 5-sided polys in order to bound the |
| 37 | // 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] | 38 | // bloat_quad. Quadratics and conics share an index buffer |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 39 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 40 | // lines are rendered as: |
| 41 | // *______________* |
| 42 | // |\ -_______ /| |
| 43 | // | \ \ / | |
| 44 | // | *--------* | |
| 45 | // | / ______/ \ | |
| 46 | // */_-__________\* |
| 47 | // For: 6 vertices and 18 indices (for 6 triangles) |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 48 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 49 | // Each quadratic is rendered as a five sided polygon. This poly bounds |
| 50 | // the quadratic's bounding triangle but has been expanded so that the |
| 51 | // 1-pixel wide area around the curve is inside the poly. |
| 52 | // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1 |
| 53 | // that is rendered would look like this: |
| 54 | // b0 |
| 55 | // b |
| 56 | // |
| 57 | // a0 c0 |
| 58 | // a c |
| 59 | // a1 c1 |
egdaniel | 14afb43 | 2014-12-22 10:57:08 -0800 | [diff] [blame] | 60 | // Each is drawn as three triangles ((a0,a1,b0), (b0,c1,c0), (a1,c1,b0)) |
| 61 | // specified by these 9 indices: |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 62 | static const uint16_t kQuadIdxBufPattern[] = { |
| 63 | 0, 1, 2, |
| 64 | 2, 4, 3, |
| 65 | 1, 4, 2 |
| 66 | }; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 67 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 68 | static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern); |
| 69 | static const int kQuadNumVertices = 5; |
| 70 | static const int kQuadsNumInIdxBuffer = 256; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 71 | GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); |
| 72 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 73 | static sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 74 | GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 75 | return resourceProvider->findOrCreatePatternedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 76 | kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices, |
| 77 | gQuadsIndexBufferKey); |
| 78 | } |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 79 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 80 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 81 | // Each line segment is rendered as two quads and two triangles. |
| 82 | // p0 and p1 have alpha = 1 while all other points have alpha = 0. |
| 83 | // The four external points are offset 1 pixel perpendicular to the |
| 84 | // line and half a pixel parallel to the line. |
| 85 | // |
| 86 | // p4 p5 |
| 87 | // p0 p1 |
| 88 | // p2 p3 |
| 89 | // |
| 90 | // Each is drawn as six triangles specified by these 18 indices: |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 91 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 92 | static const uint16_t kLineSegIdxBufPattern[] = { |
| 93 | 0, 1, 3, |
| 94 | 0, 3, 2, |
| 95 | 0, 4, 5, |
| 96 | 0, 5, 1, |
| 97 | 0, 2, 4, |
| 98 | 1, 5, 3 |
| 99 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 100 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 101 | static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern); |
| 102 | static const int kLineSegNumVertices = 6; |
| 103 | static const int kLineSegsNumInIdxBuffer = 256; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 104 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 105 | GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); |
| 106 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 107 | static sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 108 | GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 109 | return resourceProvider->findOrCreatePatternedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 110 | kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices, |
| 111 | gLinesIndexBufferKey); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 112 | } |
| 113 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 114 | // Takes 178th time of logf on Z600 / VC2010 |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 115 | static int get_float_exp(float x) { |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 116 | static_assert(sizeof(int) == sizeof(float)); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 117 | #ifdef SK_DEBUG |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 118 | static bool tested; |
| 119 | if (!tested) { |
| 120 | tested = true; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 121 | SkASSERT(get_float_exp(0.25f) == -2); |
| 122 | SkASSERT(get_float_exp(0.3f) == -2); |
| 123 | SkASSERT(get_float_exp(0.5f) == -1); |
| 124 | SkASSERT(get_float_exp(1.f) == 0); |
| 125 | SkASSERT(get_float_exp(2.f) == 1); |
| 126 | SkASSERT(get_float_exp(2.5f) == 1); |
| 127 | SkASSERT(get_float_exp(8.f) == 3); |
| 128 | SkASSERT(get_float_exp(100.f) == 6); |
| 129 | SkASSERT(get_float_exp(1000.f) == 9); |
| 130 | SkASSERT(get_float_exp(1024.f) == 10); |
| 131 | SkASSERT(get_float_exp(3000000.f) == 21); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 132 | } |
| 133 | #endif |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 134 | const int* iptr = (const int*)&x; |
| 135 | return (((*iptr) & 0x7f800000) >> 23) - 127; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 136 | } |
| 137 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 138 | // Uses the max curvature function for quads to estimate |
| 139 | // where to chop the conic. If the max curvature is not |
| 140 | // found along the curve segment it will return 1 and |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 141 | // 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] | 142 | // and dst[1] are the two new conics. |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 143 | 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] | 144 | SkScalar t = SkFindQuadMaxCurvature(src); |
Chris Dalton | 1d474dd | 2018-07-24 01:08:31 -0600 | [diff] [blame] | 145 | if (t == 0 || t == 1) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 146 | if (dst) { |
| 147 | dst[0].set(src, weight); |
| 148 | } |
| 149 | return 1; |
| 150 | } else { |
| 151 | if (dst) { |
| 152 | SkConic conic; |
| 153 | conic.set(src, weight); |
caryclark | 414c429 | 2016-09-26 11:03:54 -0700 | [diff] [blame] | 154 | if (!conic.chopAt(t, dst)) { |
| 155 | dst[0].set(src, weight); |
| 156 | return 1; |
| 157 | } |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 158 | } |
| 159 | return 2; |
| 160 | } |
| 161 | } |
| 162 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 163 | // Calls split_conic on the entire conic and then once more on each subsection. |
| 164 | // Most cases will result in either 1 conic (chop point is not within t range) |
| 165 | // or 3 points (split once and then one subsection is split again). |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 166 | 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] | 167 | SkConic dstTemp[2]; |
| 168 | int conicCnt = split_conic(src, dstTemp, weight); |
| 169 | if (2 == conicCnt) { |
| 170 | int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW); |
| 171 | conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW); |
| 172 | } else { |
| 173 | dst[0] = dstTemp[0]; |
| 174 | } |
| 175 | return conicCnt; |
| 176 | } |
| 177 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 178 | // returns 0 if quad/conic is degen or close to it |
| 179 | // in this case approx the path with lines |
| 180 | // otherwise returns 1 |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 181 | static int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) { |
jvanverth | cfeb85f | 2016-04-29 07:38:10 -0700 | [diff] [blame] | 182 | static const SkScalar gDegenerateToLineTol = GrPathUtils::kDefaultTolerance; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 183 | static const SkScalar gDegenerateToLineTolSqd = |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 184 | gDegenerateToLineTol * gDegenerateToLineTol; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 185 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 186 | if (SkPointPriv::DistanceToSqd(p[0], p[1]) < gDegenerateToLineTolSqd || |
| 187 | SkPointPriv::DistanceToSqd(p[1], p[2]) < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 188 | return 1; |
| 189 | } |
| 190 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 191 | *dsqd = SkPointPriv::DistanceToLineBetweenSqd(p[1], p[0], p[2]); |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 192 | if (*dsqd < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 193 | return 1; |
| 194 | } |
| 195 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 196 | if (SkPointPriv::DistanceToLineBetweenSqd(p[2], p[1], p[0]) < gDegenerateToLineTolSqd) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 197 | return 1; |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 202 | static int is_degen_quad_or_conic(const SkPoint p[3]) { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 203 | SkScalar dsqd; |
| 204 | return is_degen_quad_or_conic(p, &dsqd); |
| 205 | } |
| 206 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 207 | // we subdivide the quads to avoid huge overfill |
| 208 | // if it returns -1 then should be drawn as lines |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 209 | static int num_quad_subdivs(const SkPoint p[3]) { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 210 | SkScalar dsqd; |
| 211 | if (is_degen_quad_or_conic(p, &dsqd)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 212 | return -1; |
| 213 | } |
| 214 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 215 | // tolerance of triangle height in pixels |
| 216 | // tuned on windows Quadro FX 380 / Z600 |
| 217 | // trade off of fill vs cpu time on verts |
| 218 | // maybe different when do this using gpu (geo or tess shaders) |
| 219 | static const SkScalar gSubdivTol = 175 * SK_Scalar1; |
| 220 | |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 221 | if (dsqd <= gSubdivTol * gSubdivTol) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 222 | return 0; |
| 223 | } else { |
robertphillips@google.com | 87379e1 | 2013-03-29 12:11:10 +0000 | [diff] [blame] | 224 | static const int kMaxSub = 4; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 225 | // subdividing the quad reduces d by 4. so we want x = log4(d/tol) |
| 226 | // = log4(d*d/tol*tol)/2 |
| 227 | // = log2(d*d/tol*tol) |
| 228 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 229 | // +1 since we're ignoring the mantissa contribution. |
| 230 | int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 231 | log = std::min(std::max(0, log), kMaxSub); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 232 | return log; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 236 | /** |
| 237 | * Generates the lines and quads to be rendered. Lines are always recorded in |
| 238 | * device space. We will do a device space bloat to account for the 1pixel |
| 239 | * thickness. |
| 240 | * Quads are recorded in device space unless m contains |
| 241 | * perspective, then in they are in src space. We do this because we will |
| 242 | * subdivide large quads to reduce over-fill. This subdivision has to be |
| 243 | * performed before applying the perspective matrix. |
| 244 | */ |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 245 | static int gather_lines_and_quads(const SkPath& path, |
| 246 | const SkMatrix& m, |
| 247 | const SkIRect& devClipBounds, |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 248 | SkScalar capLength, |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 249 | bool convertConicsToQuads, |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 250 | GrAAHairLinePathRenderer::PtArray* lines, |
| 251 | GrAAHairLinePathRenderer::PtArray* quads, |
| 252 | GrAAHairLinePathRenderer::PtArray* conics, |
| 253 | GrAAHairLinePathRenderer::IntArray* quadSubdivCnts, |
| 254 | GrAAHairLinePathRenderer::FloatArray* conicWeights) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 255 | SkPath::Iter iter(path, false); |
| 256 | |
| 257 | int totalQuadCount = 0; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 258 | SkRect bounds; |
| 259 | SkIRect ibounds; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 260 | |
| 261 | bool persp = m.hasPerspective(); |
| 262 | |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 263 | // Whenever a degenerate, zero-length contour is encountered, this code will insert a |
| 264 | // 'capLength' x-aligned line segment. Since this is rendering hairlines it is hoped this will |
| 265 | // suffice for AA square & circle capping. |
| 266 | int verbsInContour = 0; // Does not count moves |
| 267 | bool seenZeroLengthVerb = false; |
| 268 | SkPoint zeroVerbPt; |
| 269 | |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 270 | // Adds a quad that has already been chopped to the list and checks for quads that are close to |
| 271 | // lines. Also does a bounding box check. It takes points that are in src space and device |
| 272 | // space. The src points are only required if the view matrix has perspective. |
| 273 | auto addChoppedQuad = [&](const SkPoint srcPts[3], const SkPoint devPts[4], |
| 274 | bool isContourStart) { |
| 275 | SkRect bounds; |
| 276 | SkIRect ibounds; |
| 277 | bounds.setBounds(devPts, 3); |
| 278 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 279 | bounds.roundOut(&ibounds); |
| 280 | // We only need the src space space pts when not in perspective. |
| 281 | SkASSERT(srcPts || !persp); |
| 282 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
| 283 | int subdiv = num_quad_subdivs(devPts); |
| 284 | SkASSERT(subdiv >= -1); |
| 285 | if (-1 == subdiv) { |
| 286 | SkPoint* pts = lines->push_back_n(4); |
| 287 | pts[0] = devPts[0]; |
| 288 | pts[1] = devPts[1]; |
| 289 | pts[2] = devPts[1]; |
| 290 | pts[3] = devPts[2]; |
| 291 | if (isContourStart && pts[0] == pts[1] && pts[2] == pts[3]) { |
| 292 | seenZeroLengthVerb = true; |
| 293 | zeroVerbPt = pts[0]; |
| 294 | } |
| 295 | } else { |
| 296 | // when in perspective keep quads in src space |
| 297 | const SkPoint* qPts = persp ? srcPts : devPts; |
| 298 | SkPoint* pts = quads->push_back_n(3); |
| 299 | pts[0] = qPts[0]; |
| 300 | pts[1] = qPts[1]; |
| 301 | pts[2] = qPts[2]; |
| 302 | quadSubdivCnts->push_back() = subdiv; |
| 303 | totalQuadCount += 1 << subdiv; |
| 304 | } |
| 305 | } |
| 306 | }; |
| 307 | |
| 308 | // Applies the view matrix to quad src points and calls the above helper. |
| 309 | auto addSrcChoppedQuad = [&](const SkPoint srcSpaceQuadPts[3], bool isContourStart) { |
| 310 | SkPoint devPts[3]; |
| 311 | m.mapPoints(devPts, srcSpaceQuadPts, 3); |
| 312 | addChoppedQuad(srcSpaceQuadPts, devPts, isContourStart); |
| 313 | }; |
| 314 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 315 | for (;;) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 316 | SkPoint pathPts[4]; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 317 | SkPath::Verb verb = iter.next(pathPts); |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 318 | switch (verb) { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 319 | case SkPath::kConic_Verb: |
| 320 | if (convertConicsToQuads) { |
| 321 | SkScalar weight = iter.conicWeight(); |
| 322 | SkAutoConicToQuads converter; |
Brian Osman | e3deee1 | 2018-11-20 11:10:15 -0500 | [diff] [blame] | 323 | const SkPoint* quadPts = converter.computeQuads(pathPts, weight, 0.25f); |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 324 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 325 | addSrcChoppedQuad(quadPts + 2 * i, !verbsInContour && 0 == i); |
| 326 | } |
| 327 | } else { |
| 328 | SkConic dst[4]; |
| 329 | // We chop the conics to create tighter clipping to hide error |
| 330 | // that appears near max curvature of very thin conics. Thin |
| 331 | // hyperbolas with high weight still show error. |
| 332 | int conicCnt = chop_conic(pathPts, dst, iter.conicWeight()); |
| 333 | for (int i = 0; i < conicCnt; ++i) { |
| 334 | SkPoint devPts[4]; |
| 335 | SkPoint* chopPnts = dst[i].fPts; |
| 336 | m.mapPoints(devPts, chopPnts, 3); |
| 337 | bounds.setBounds(devPts, 3); |
| 338 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 339 | bounds.roundOut(&ibounds); |
| 340 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
| 341 | if (is_degen_quad_or_conic(devPts)) { |
| 342 | SkPoint* pts = lines->push_back_n(4); |
| 343 | pts[0] = devPts[0]; |
| 344 | pts[1] = devPts[1]; |
| 345 | pts[2] = devPts[1]; |
| 346 | pts[3] = devPts[2]; |
| 347 | if (verbsInContour == 0 && i == 0 && pts[0] == pts[1] && |
| 348 | pts[2] == pts[3]) { |
| 349 | seenZeroLengthVerb = true; |
| 350 | zeroVerbPt = pts[0]; |
| 351 | } |
| 352 | } else { |
| 353 | // when in perspective keep conics in src space |
| 354 | SkPoint* cPts = persp ? chopPnts : devPts; |
| 355 | SkPoint* pts = conics->push_back_n(3); |
| 356 | pts[0] = cPts[0]; |
| 357 | pts[1] = cPts[1]; |
| 358 | pts[2] = cPts[2]; |
| 359 | conicWeights->push_back() = dst[i].fW; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 360 | } |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 364 | verbsInContour++; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 365 | break; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 366 | case SkPath::kMove_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 367 | // New contour (and last one was unclosed). If it was just a zero length drawing |
| 368 | // operation, and we're supposed to draw caps, then add a tiny line. |
| 369 | if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) { |
| 370 | SkPoint* pts = lines->push_back_n(2); |
| 371 | pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY); |
| 372 | pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY); |
| 373 | } |
| 374 | verbsInContour = 0; |
| 375 | seenZeroLengthVerb = false; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 376 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 377 | case SkPath::kLine_Verb: { |
| 378 | SkPoint devPts[2]; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 379 | m.mapPoints(devPts, pathPts, 2); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 380 | bounds.setBounds(devPts, 2); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 381 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 382 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 383 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 384 | SkPoint* pts = lines->push_back_n(2); |
| 385 | pts[0] = devPts[0]; |
| 386 | pts[1] = devPts[1]; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 387 | if (verbsInContour == 0 && pts[0] == pts[1]) { |
| 388 | seenZeroLengthVerb = true; |
| 389 | zeroVerbPt = pts[0]; |
| 390 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 391 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 392 | verbsInContour++; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 393 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 394 | } |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 395 | case SkPath::kQuad_Verb: { |
| 396 | SkPoint choppedPts[5]; |
| 397 | // Chopping the quad helps when the quad is either degenerate or nearly degenerate. |
| 398 | // When it is degenerate it allows the approximation with lines to work since the |
| 399 | // chop point (if there is one) will be at the parabola's vertex. In the nearly |
| 400 | // degenerate the QuadUVMatrix computed for the points is almost singular which |
| 401 | // can cause rendering artifacts. |
| 402 | int n = SkChopQuadAtMaxCurvature(pathPts, choppedPts); |
| 403 | for (int i = 0; i < n; ++i) { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 404 | addSrcChoppedQuad(choppedPts + i * 2, !verbsInContour && 0 == i); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 405 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 406 | verbsInContour++; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 407 | break; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 408 | } |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 409 | case SkPath::kCubic_Verb: { |
| 410 | SkPoint devPts[4]; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 411 | m.mapPoints(devPts, pathPts, 4); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 412 | bounds.setBounds(devPts, 4); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 413 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 414 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 415 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 416 | PREALLOC_PTARRAY(32) q; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 417 | // We convert cubics to quadratics (for now). |
| 418 | // In perspective have to do conversion in src space. |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 419 | if (persp) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 420 | SkScalar tolScale = |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 421 | GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, path.getBounds()); |
| 422 | GrPathUtils::convertCubicToQuads(pathPts, tolScale, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 423 | } else { |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 424 | GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 425 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 426 | for (int i = 0; i < q.count(); i += 3) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 427 | if (persp) { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 428 | addSrcChoppedQuad(&q[i], !verbsInContour && 0 == i); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 429 | } else { |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 430 | addChoppedQuad(nullptr, &q[i], !verbsInContour && 0 == i); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | } |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 434 | verbsInContour++; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 435 | break; |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 436 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 437 | case SkPath::kClose_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 438 | // Contour is closed, so we don't need to grow the starting line, unless it's |
| 439 | // *just* a zero length subpath. (SVG Spec 11.4, 'stroke'). |
| 440 | if (capLength > 0) { |
| 441 | if (seenZeroLengthVerb && verbsInContour == 1) { |
| 442 | SkPoint* pts = lines->push_back_n(2); |
| 443 | pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY); |
| 444 | pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY); |
| 445 | } else if (verbsInContour == 0) { |
| 446 | // Contour was (moveTo, close). Add a line. |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 447 | SkPoint devPts[2]; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 448 | m.mapPoints(devPts, pathPts, 1); |
| 449 | devPts[1] = devPts[0]; |
| 450 | bounds.setBounds(devPts, 2); |
| 451 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 452 | bounds.roundOut(&ibounds); |
| 453 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
| 454 | SkPoint* pts = lines->push_back_n(2); |
| 455 | pts[0] = SkPoint::Make(devPts[0].fX - capLength, devPts[0].fY); |
| 456 | pts[1] = SkPoint::Make(devPts[1].fX + capLength, devPts[1].fY); |
| 457 | } |
| 458 | } |
| 459 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 460 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 461 | case SkPath::kDone_Verb: |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 462 | if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) { |
| 463 | // Path ended with a dangling (moveTo, line|quad|etc). If the final verb is |
| 464 | // degenerate, we need to draw a line. |
| 465 | SkPoint* pts = lines->push_back_n(2); |
| 466 | pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY); |
| 467 | pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY); |
| 468 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 469 | return totalQuadCount; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 474 | struct LineVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 475 | SkPoint fPos; |
egdaniel | e27065a | 2014-11-06 08:00:48 -0800 | [diff] [blame] | 476 | float fCoverage; |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 477 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 478 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 479 | struct BezierVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 480 | SkPoint fPos; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 481 | union { |
| 482 | struct { |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 483 | SkScalar fKLM[3]; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 484 | } fConic; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 485 | SkVector fQuadCoord; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 486 | struct { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 487 | SkScalar fBogus[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 488 | }; |
| 489 | }; |
| 490 | }; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 491 | |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 492 | static_assert(sizeof(BezierVertex) == 3 * sizeof(SkPoint)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 493 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 494 | static void intersect_lines(const SkPoint& ptA, const SkVector& normA, |
| 495 | const SkPoint& ptB, const SkVector& normB, |
| 496 | SkPoint* result) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 497 | |
| 498 | SkScalar lineAW = -normA.dot(ptA); |
| 499 | SkScalar lineBW = -normB.dot(ptB); |
| 500 | |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 501 | SkScalar wInv = normA.fX * normB.fY - normA.fY * normB.fX; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 502 | wInv = SkScalarInvert(wInv); |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 503 | if (!SkScalarIsFinite(wInv)) { |
| 504 | // lines are parallel, pick the point in between |
| 505 | *result = (ptA + ptB)*SK_ScalarHalf; |
| 506 | *result += normA; |
| 507 | } else { |
| 508 | result->fX = normA.fY * lineBW - lineAW * normB.fY; |
| 509 | result->fX *= wInv; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 510 | |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 511 | result->fY = lineAW * normB.fX - normA.fX * lineBW; |
| 512 | result->fY *= wInv; |
| 513 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 514 | } |
| 515 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 516 | 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] | 517 | // this should be in the src space, not dev coords, when we have perspective |
| 518 | GrPathUtils::QuadUVMatrix DevToUV(qpts); |
Brian Osman | 568bec7 | 2018-12-26 16:48:25 -0500 | [diff] [blame] | 519 | DevToUV.apply(verts, kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint)); |
egdaniel@google.com | 34b05ca | 2013-08-05 20:43:12 +0000 | [diff] [blame] | 520 | } |
| 521 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 522 | static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, |
| 523 | const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices]) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 524 | SkASSERT(!toDevice == !toSrc); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 525 | // original quad is specified by tri a,b,c |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 526 | SkPoint a = qpts[0]; |
| 527 | SkPoint b = qpts[1]; |
| 528 | SkPoint c = qpts[2]; |
| 529 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 530 | if (toDevice) { |
| 531 | toDevice->mapPoints(&a, 1); |
| 532 | toDevice->mapPoints(&b, 1); |
| 533 | toDevice->mapPoints(&c, 1); |
| 534 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 535 | // make a new poly where we replace a and c by a 1-pixel wide edges orthog |
| 536 | // to edges ab and bc: |
| 537 | // |
| 538 | // before | after |
| 539 | // | b0 |
| 540 | // b | |
| 541 | // | |
| 542 | // | a0 c0 |
| 543 | // a c | a1 c1 |
| 544 | // |
| 545 | // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c, |
| 546 | // respectively. |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 547 | BezierVertex& a0 = verts[0]; |
| 548 | BezierVertex& a1 = verts[1]; |
| 549 | BezierVertex& b0 = verts[2]; |
| 550 | BezierVertex& c0 = verts[3]; |
| 551 | BezierVertex& c1 = verts[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 552 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 553 | SkVector ab = b; |
| 554 | ab -= a; |
| 555 | SkVector ac = c; |
| 556 | ac -= a; |
| 557 | SkVector cb = b; |
| 558 | cb -= c; |
| 559 | |
Robert Phillips | 2c2303e | 2021-02-04 11:04:01 -0500 | [diff] [blame] | 560 | // After the transform (or due to floating point math) we might have a line, |
| 561 | // try to do something reasonable |
| 562 | if (SkPointPriv::LengthSqd(ab) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 563 | ab = cb; |
| 564 | } |
Robert Phillips | 2c2303e | 2021-02-04 11:04:01 -0500 | [diff] [blame] | 565 | if (SkPointPriv::LengthSqd(cb) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 566 | cb = ab; |
| 567 | } |
| 568 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 569 | // We should have already handled degenerates |
Robert Phillips | 2c2303e | 2021-02-04 11:04:01 -0500 | [diff] [blame] | 570 | SkASSERT(ab.length() > 0 && cb.length() > 0); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 571 | |
| 572 | ab.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 573 | SkVector abN = SkPointPriv::MakeOrthog(ab, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 574 | if (abN.dot(ac) > 0) { |
| 575 | abN.negate(); |
| 576 | } |
| 577 | |
| 578 | cb.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 579 | SkVector cbN = SkPointPriv::MakeOrthog(cb, SkPointPriv::kLeft_Side); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 580 | if (cbN.dot(ac) < 0) { |
| 581 | cbN.negate(); |
| 582 | } |
| 583 | |
| 584 | a0.fPos = a; |
| 585 | a0.fPos += abN; |
| 586 | a1.fPos = a; |
| 587 | a1.fPos -= abN; |
| 588 | |
Jim Van Verth | 1499d9e | 2018-10-09 16:30:52 -0400 | [diff] [blame] | 589 | if (toDevice && SkPointPriv::LengthSqd(ac) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) { |
| 590 | c = b; |
| 591 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 592 | c0.fPos = c; |
| 593 | c0.fPos += cbN; |
| 594 | c1.fPos = c; |
| 595 | c1.fPos -= cbN; |
| 596 | |
| 597 | intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); |
| 598 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 599 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 600 | SkMatrixPriv::MapPointsWithStride(*toSrc, &verts[0].fPos, sizeof(BezierVertex), |
| 601 | kQuadNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 602 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 603 | } |
| 604 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 605 | // Equations based off of Loop-Blinn Quadratic GPU Rendering |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 606 | // Input Parametric: |
| 607 | // 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) |
| 608 | // Output Implicit: |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 609 | // f(x, y, w) = f(P) = K^2 - LM |
| 610 | // 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] | 611 | // k, l, m are calculated in function GrPathUtils::getConicKLM |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 612 | static void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices], |
| 613 | const SkScalar weight) { |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 614 | SkMatrix klm; |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame] | 615 | |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 616 | GrPathUtils::getConicKLM(p, weight, &klm); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 617 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 618 | for (int i = 0; i < kQuadNumVertices; ++i) { |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 619 | const SkPoint3 pt3 = {verts[i].fPos.x(), verts[i].fPos.y(), 1.f}; |
| 620 | klm.mapHomogeneousPoints((SkPoint3* ) verts[i].fConic.fKLM, &pt3, 1); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 624 | static void add_conics(const SkPoint p[3], |
| 625 | const SkScalar weight, |
| 626 | const SkMatrix* toDevice, |
| 627 | const SkMatrix* toSrc, |
| 628 | BezierVertex** vert) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 629 | bloat_quad(p, toDevice, toSrc, *vert); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 630 | set_conic_coeffs(p, *vert, weight); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 631 | *vert += kQuadNumVertices; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 632 | } |
| 633 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 634 | static void add_quads(const SkPoint p[3], |
| 635 | int subdiv, |
| 636 | const SkMatrix* toDevice, |
| 637 | const SkMatrix* toSrc, |
| 638 | BezierVertex** vert) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 639 | SkASSERT(subdiv >= 0); |
Jim Van Verth | 14982c8 | 2020-07-15 15:42:19 -0400 | [diff] [blame] | 640 | // temporary vertex storage to avoid reading the vertex buffer |
Jim Van Verth | 3557ab4 | 2020-07-28 09:46:03 -0400 | [diff] [blame] | 641 | BezierVertex outVerts[kQuadNumVertices] = {}; |
Jim Van Verth | 14982c8 | 2020-07-15 15:42:19 -0400 | [diff] [blame] | 642 | |
| 643 | // storage for the chopped quad |
| 644 | // pts 0,1,2 are the first quad, and 2,3,4 the second quad |
| 645 | SkPoint choppedQuadPts[5]; |
| 646 | // start off with our original curve in the second quad slot |
| 647 | memcpy(&choppedQuadPts[2], p, 3*sizeof(SkPoint)); |
| 648 | |
| 649 | int stepCount = 1 << subdiv; |
| 650 | while (stepCount > 1) { |
| 651 | // The general idea is: |
| 652 | // * chop the quad using pts 2,3,4 as the input |
| 653 | // * write out verts using pts 0,1,2 |
| 654 | // * now 2,3,4 is the remainder of the curve, chop again until all subdivisions are done |
| 655 | SkScalar h = 1.f / stepCount; |
| 656 | SkChopQuadAt(&choppedQuadPts[2], choppedQuadPts, h); |
| 657 | |
| 658 | bloat_quad(choppedQuadPts, toDevice, toSrc, outVerts); |
| 659 | set_uv_quad(choppedQuadPts, outVerts); |
| 660 | memcpy(*vert, outVerts, kQuadNumVertices*sizeof(BezierVertex)); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 661 | *vert += kQuadNumVertices; |
Jim Van Verth | 14982c8 | 2020-07-15 15:42:19 -0400 | [diff] [blame] | 662 | --stepCount; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 663 | } |
Jim Van Verth | 14982c8 | 2020-07-15 15:42:19 -0400 | [diff] [blame] | 664 | |
| 665 | // finish up, write out the final quad |
| 666 | bloat_quad(&choppedQuadPts[2], toDevice, toSrc, outVerts); |
| 667 | set_uv_quad(&choppedQuadPts[2], outVerts); |
| 668 | memcpy(*vert, outVerts, kQuadNumVertices * sizeof(BezierVertex)); |
| 669 | *vert += kQuadNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 670 | } |
| 671 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 672 | static void add_line(const SkPoint p[2], |
| 673 | const SkMatrix* toSrc, |
| 674 | uint8_t coverage, |
| 675 | LineVertex** vert) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 676 | const SkPoint& a = p[0]; |
| 677 | const SkPoint& b = p[1]; |
| 678 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 679 | SkVector ortho, vec = b; |
| 680 | vec -= a; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 681 | |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 682 | SkScalar lengthSqd = SkPointPriv::LengthSqd(vec); |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 683 | |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 684 | if (vec.setLength(SK_ScalarHalf)) { |
| 685 | // Create a vector orthogonal to 'vec' and of unit length |
| 686 | ortho.fX = 2.0f * vec.fY; |
| 687 | ortho.fY = -2.0f * vec.fX; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 688 | |
egdaniel | e27065a | 2014-11-06 08:00:48 -0800 | [diff] [blame] | 689 | float floatCoverage = GrNormalizeByteToFloat(coverage); |
| 690 | |
Greg Daniel | 2e67dea | 2017-10-12 15:14:41 -0400 | [diff] [blame] | 691 | if (lengthSqd >= 1.0f) { |
| 692 | // Relative to points a and b: |
| 693 | // The inner vertices are inset half a pixel along the line a,b |
| 694 | (*vert)[0].fPos = a + vec; |
| 695 | (*vert)[0].fCoverage = floatCoverage; |
| 696 | (*vert)[1].fPos = b - vec; |
| 697 | (*vert)[1].fCoverage = floatCoverage; |
| 698 | } else { |
| 699 | // The inner vertices are inset a distance of length(a,b) from the outer edge of |
| 700 | // geometry. For the "a" inset this is the same as insetting from b by half a pixel. |
| 701 | // The coverage is then modulated by the length. This gives us the correct |
| 702 | // coverage for rects shorter than a pixel as they get translated subpixel amounts |
| 703 | // inside of a pixel. |
| 704 | SkScalar length = SkScalarSqrt(lengthSqd); |
| 705 | (*vert)[0].fPos = b - vec; |
| 706 | (*vert)[0].fCoverage = floatCoverage * length; |
| 707 | (*vert)[1].fPos = a + vec; |
| 708 | (*vert)[1].fCoverage = floatCoverage * length; |
| 709 | } |
| 710 | // Relative to points a and b: |
| 711 | // The outer vertices are outset half a pixel along the line a,b and then a whole pixel |
| 712 | // orthogonally. |
robertphillips@google.com | ada90da | 2013-09-18 22:14:49 +0000 | [diff] [blame] | 713 | (*vert)[2].fPos = a - vec + ortho; |
| 714 | (*vert)[2].fCoverage = 0; |
| 715 | (*vert)[3].fPos = b + vec + ortho; |
| 716 | (*vert)[3].fCoverage = 0; |
| 717 | (*vert)[4].fPos = a - vec - ortho; |
| 718 | (*vert)[4].fCoverage = 0; |
| 719 | (*vert)[5].fPos = b + vec - ortho; |
| 720 | (*vert)[5].fCoverage = 0; |
| 721 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 722 | if (toSrc) { |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 723 | SkMatrixPriv::MapPointsWithStride(*toSrc, &(*vert)->fPos, sizeof(LineVertex), |
| 724 | kLineSegNumVertices); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 725 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 726 | } else { |
| 727 | // just make it degenerate and likely offscreen |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 728 | for (int i = 0; i < kLineSegNumVertices; ++i) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 729 | (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 730 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 731 | } |
| 732 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 733 | *vert += kLineSegNumVertices; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 734 | } |
| 735 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 736 | /////////////////////////////////////////////////////////////////////////////// |
| 737 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 738 | GrPathRenderer::CanDrawPath |
| 739 | GrAAHairLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 740 | if (GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 741 | return CanDrawPath::kNo; |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 744 | if (!GrIsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 745 | return CanDrawPath::kNo; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // We don't currently handle dashing in this class though perhaps we should. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 749 | if (args.fShape->style().pathEffect()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 750 | return CanDrawPath::kNo; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 751 | } |
| 752 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 753 | if (SkPath::kLine_SegmentMask == args.fShape->segmentMask() || |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 754 | args.fCaps->shaderCaps()->shaderDerivativeSupport()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 755 | return CanDrawPath::kYes; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 756 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 757 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 758 | return CanDrawPath::kNo; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 759 | } |
| 760 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 761 | template <class VertexType> |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 762 | 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] | 763 | { |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 764 | SkRect tolDevBounds = devBounds; |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 765 | // The bounds ought to be tight, but in perspective the below code runs the verts |
| 766 | // 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] | 767 | if (viewMatrix.hasPerspective()) { |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 768 | tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000); |
| 769 | } else { |
| 770 | // Non-persp matrices cause this path renderer to draw in device space. |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 771 | SkASSERT(viewMatrix.isIdentity()); |
commit-bot@chromium.org | b8bd6cb | 2013-09-03 14:56:17 +0000 | [diff] [blame] | 772 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 773 | SkRect actualBounds; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 774 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 775 | VertexType* verts = reinterpret_cast<VertexType*>(vertices); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 776 | bool first = true; |
| 777 | for (int i = 0; i < vCount; ++i) { |
| 778 | SkPoint pos = verts[i].fPos; |
| 779 | // This is a hack to workaround the fact that we move some degenerate segments offscreen. |
| 780 | if (SK_ScalarMax == pos.fX) { |
| 781 | continue; |
| 782 | } |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 783 | viewMatrix.mapPoints(&pos, 1); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 784 | if (first) { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 785 | actualBounds.setLTRB(pos.fX, pos.fY, pos.fX, pos.fY); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 786 | first = false; |
| 787 | } else { |
Mike Reed | 185ffe9 | 2018-01-08 17:09:54 -0500 | [diff] [blame] | 788 | SkRectPriv::GrowToInclude(&actualBounds, pos); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | if (!first) { |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 792 | return tolDevBounds.contains(actualBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 793 | } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 794 | |
jvanverth@google.com | 681ccf0 | 2013-08-16 14:51:51 +0000 | [diff] [blame] | 795 | return true; |
| 796 | } |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 797 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 798 | class AAHairlineOp final : public GrMeshDrawOp { |
| 799 | private: |
| 800 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 801 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 802 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 803 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 804 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 805 | static GrOp::Owner Make(GrRecordingContext* context, |
| 806 | GrPaint&& paint, |
| 807 | const SkMatrix& viewMatrix, |
| 808 | const SkPath& path, |
| 809 | const GrStyle& style, |
| 810 | const SkIRect& devClipBounds, |
| 811 | const GrUserStencilSettings* stencilSettings) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 812 | SkScalar hairlineCoverage; |
| 813 | uint8_t newCoverage = 0xff; |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 814 | if (GrIsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 815 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 816 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 817 | |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 818 | const SkStrokeRec& stroke = style.strokeRec(); |
| 819 | SkScalar capLength = SkPaint::kButt_Cap != stroke.getCap() ? hairlineCoverage * 0.5f : 0.0f; |
| 820 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 821 | return Helper::FactoryHelper<AAHairlineOp>(context, std::move(paint), newCoverage, |
| 822 | viewMatrix, path, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 823 | devClipBounds, capLength, stencilSettings); |
| 824 | } |
| 825 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 826 | AAHairlineOp(GrProcessorSet* processorSet, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 827 | const SkPMColor4f& color, |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 828 | uint8_t coverage, |
| 829 | const SkMatrix& viewMatrix, |
| 830 | const SkPath& path, |
| 831 | SkIRect devClipBounds, |
| 832 | SkScalar capLength, |
| 833 | const GrUserStencilSettings* stencilSettings) |
| 834 | : INHERITED(ClassID()) |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 835 | , fHelper(processorSet, GrAAType::kCoverage, stencilSettings) |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 836 | , fColor(color) |
| 837 | , fCoverage(coverage) { |
| 838 | fPaths.emplace_back(PathData{viewMatrix, path, devClipBounds, capLength}); |
| 839 | |
| 840 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 841 | IsHairline::kYes); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 842 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 843 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 844 | const char* name() const override { return "AAHairlineOp"; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 845 | |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 846 | void visitProxies(const GrVisitProxyFunc& func) const override { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 847 | |
| 848 | bool visited = false; |
| 849 | for (int i = 0; i < 3; ++i) { |
| 850 | if (fProgramInfos[i]) { |
| 851 | fProgramInfos[i]->visitFPProxies(func); |
| 852 | visited = true; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | if (!visited) { |
| 857 | fHelper.visitProxies(func); |
| 858 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 859 | } |
| 860 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 861 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 862 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 863 | GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 864 | GrClampType clampType) override { |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 865 | // This Op uses uniform (not vertex) color, so doesn't need to track wide color. |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 866 | return fHelper.finalizeProcessors(caps, clip, clampType, |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 867 | GrProcessorAnalysisCoverage::kSingleChannel, &fColor, |
| 868 | nullptr); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 869 | } |
| 870 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 871 | enum Program : uint8_t { |
| 872 | kNone_Program = 0x0, |
| 873 | kLine_Program = 0x1, |
| 874 | kQuad_Program = 0x2, |
| 875 | kConic_Program = 0x4, |
| 876 | }; |
| 877 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 878 | private: |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 879 | void makeLineProgramInfo(const GrCaps&, SkArenaAlloc*, const GrPipeline*, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 880 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 881 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 882 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 883 | GrXferBarrierFlags renderPassXferBarriers, |
| 884 | GrLoadOp colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 885 | void makeQuadProgramInfo(const GrCaps&, SkArenaAlloc*, const GrPipeline*, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 886 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 887 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 888 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 889 | GrXferBarrierFlags renderPassXferBarriers, |
| 890 | GrLoadOp colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 891 | void makeConicProgramInfo(const GrCaps&, SkArenaAlloc*, const GrPipeline*, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 892 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 893 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 894 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 895 | GrXferBarrierFlags renderPassXferBarriers, |
| 896 | GrLoadOp colorLoadOp); |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 897 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 898 | GrProgramInfo* programInfo() override { |
| 899 | // This Op has 3 programInfos and implements its own onPrePrepareDraws so this entry point |
| 900 | // should really never be called. |
| 901 | SkASSERT(0); |
| 902 | return nullptr; |
| 903 | } |
| 904 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 905 | Program predictPrograms(const GrCaps*) const; |
| 906 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 907 | void onCreateProgramInfo(const GrCaps*, |
| 908 | SkArenaAlloc*, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 909 | const GrSurfaceProxyView& writeView, |
Chris Dalton | 6aaf00f | 2021-07-13 13:26:39 -0600 | [diff] [blame^] | 910 | bool usesMSAASurface, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 911 | GrAppliedClip&&, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 912 | const GrDstProxyView&, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 913 | GrXferBarrierFlags renderPassXferBarriers, |
| 914 | GrLoadOp colorLoadOp) override; |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 915 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 916 | void onPrePrepareDraws(GrRecordingContext*, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 917 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 918 | GrAppliedClip*, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 919 | const GrDstProxyView&, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 920 | GrXferBarrierFlags renderPassXferBarriers, |
| 921 | GrLoadOp colorLoadOp) override; |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 922 | |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 923 | void onPrepareDraws(GrMeshDrawTarget*) override; |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 924 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 925 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 926 | typedef SkTArray<SkPoint, true> PtArray; |
| 927 | typedef SkTArray<int, true> IntArray; |
| 928 | typedef SkTArray<float, true> FloatArray; |
| 929 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 930 | CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 931 | AAHairlineOp* that = t->cast<AAHairlineOp>(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 932 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 933 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 934 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 935 | } |
| 936 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 937 | if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 938 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | // We go to identity if we don't have perspective |
| 942 | if (this->viewMatrix().hasPerspective() && |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 943 | !SkMatrixPriv::CheapEqual(this->viewMatrix(), that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 944 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 947 | // TODO we can actually combine hairlines if they are the same color in a kind of bulk |
| 948 | // method but we haven't implemented this yet |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 949 | // TODO investigate going to vertex color and coverage? |
| 950 | if (this->coverage() != that->coverage()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 951 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | if (this->color() != that->color()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 955 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 958 | if (fHelper.usesLocalCoords() && !SkMatrixPriv::CheapEqual(this->viewMatrix(), |
| 959 | that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 960 | return CombineResult::kCannotCombine; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 963 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 964 | return CombineResult::kMerged; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 965 | } |
| 966 | |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 967 | #if GR_TEST_UTILS |
| 968 | SkString onDumpInfo() const override { |
| 969 | return SkStringPrintf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n%s", |
| 970 | fColor.toBytes_RGBA(), fCoverage, fPaths.count(), |
| 971 | fHelper.dumpInfo().c_str()); |
| 972 | } |
| 973 | #endif |
| 974 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 975 | const SkPMColor4f& color() const { return fColor; } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 976 | uint8_t coverage() const { return fCoverage; } |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 977 | const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 978 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 979 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 980 | SkMatrix fViewMatrix; |
| 981 | SkPath fPath; |
| 982 | SkIRect fDevClipBounds; |
Brian Osman | cf3dc29 | 2017-06-28 16:45:32 -0400 | [diff] [blame] | 983 | SkScalar fCapLength; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 984 | }; |
| 985 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 986 | SkSTArray<1, PathData, true> fPaths; |
| 987 | Helper fHelper; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 988 | SkPMColor4f fColor; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 989 | uint8_t fCoverage; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 990 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 991 | Program fCharacterization = kNone_Program; // holds a mask of required programs |
| 992 | GrSimpleMesh* fMeshes[3] = { nullptr }; |
| 993 | GrProgramInfo* fProgramInfos[3] = { nullptr }; |
| 994 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 995 | using INHERITED = GrMeshDrawOp; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 996 | }; |
| 997 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 998 | GR_MAKE_BITFIELD_OPS(AAHairlineOp::Program) |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 999 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1000 | void AAHairlineOp::makeLineProgramInfo(const GrCaps& caps, SkArenaAlloc* arena, |
| 1001 | const GrPipeline* pipeline, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1002 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1003 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1004 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1005 | GrXferBarrierFlags renderPassXferBarriers, |
| 1006 | GrLoadOp colorLoadOp) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1007 | if (fProgramInfos[0]) { |
| 1008 | return; |
| 1009 | } |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1010 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1011 | GrGeometryProcessor* lineGP; |
| 1012 | { |
| 1013 | using namespace GrDefaultGeoProcFactory; |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1014 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1015 | Color color(this->color()); |
| 1016 | LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type |
| 1017 | : LocalCoords::kUnused_Type); |
| 1018 | localCoords.fMatrix = geometryProcessorLocalM; |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1019 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1020 | lineGP = GrDefaultGeoProcFactory::Make(arena, |
| 1021 | color, |
| 1022 | Coverage::kAttribute_Type, |
| 1023 | localCoords, |
| 1024 | *geometryProcessorViewM); |
| 1025 | SkASSERT(sizeof(LineVertex) == lineGP->vertexStride()); |
| 1026 | } |
| 1027 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1028 | fProgramInfos[0] = GrSimpleMeshDrawOpHelper::CreateProgramInfo( |
| 1029 | arena, pipeline, writeView, lineGP, GrPrimitiveType::kTriangles, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1030 | renderPassXferBarriers, colorLoadOp, fHelper.stencilSettings()); |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1031 | } |
| 1032 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1033 | void AAHairlineOp::makeQuadProgramInfo(const GrCaps& caps, SkArenaAlloc* arena, |
| 1034 | const GrPipeline* pipeline, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1035 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1036 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1037 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1038 | GrXferBarrierFlags renderPassXferBarriers, |
| 1039 | GrLoadOp colorLoadOp) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1040 | if (fProgramInfos[1]) { |
| 1041 | return; |
| 1042 | } |
| 1043 | |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1044 | GrGeometryProcessor* quadGP = GrQuadEffect::Make(arena, |
| 1045 | this->color(), |
| 1046 | *geometryProcessorViewM, |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1047 | caps, |
| 1048 | *geometryProcessorLocalM, |
| 1049 | fHelper.usesLocalCoords(), |
| 1050 | this->coverage()); |
| 1051 | SkASSERT(sizeof(BezierVertex) == quadGP->vertexStride()); |
| 1052 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1053 | fProgramInfos[1] = GrSimpleMeshDrawOpHelper::CreateProgramInfo( |
| 1054 | arena, pipeline, writeView, quadGP, GrPrimitiveType::kTriangles, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1055 | renderPassXferBarriers, colorLoadOp, fHelper.stencilSettings()); |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1056 | } |
| 1057 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1058 | void AAHairlineOp::makeConicProgramInfo(const GrCaps& caps, SkArenaAlloc* arena, |
| 1059 | const GrPipeline* pipeline, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1060 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1061 | const SkMatrix* geometryProcessorViewM, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1062 | const SkMatrix* geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1063 | GrXferBarrierFlags renderPassXferBarriers, |
| 1064 | GrLoadOp colorLoadOp) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1065 | if (fProgramInfos[2]) { |
| 1066 | return; |
| 1067 | } |
| 1068 | |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1069 | GrGeometryProcessor* conicGP = GrConicEffect::Make(arena, |
| 1070 | this->color(), |
| 1071 | *geometryProcessorViewM, |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1072 | caps, |
| 1073 | *geometryProcessorLocalM, |
| 1074 | fHelper.usesLocalCoords(), |
| 1075 | this->coverage()); |
| 1076 | SkASSERT(sizeof(BezierVertex) == conicGP->vertexStride()); |
| 1077 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1078 | fProgramInfos[2] = GrSimpleMeshDrawOpHelper::CreateProgramInfo( |
| 1079 | arena, pipeline, writeView, conicGP, GrPrimitiveType::kTriangles, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1080 | renderPassXferBarriers, colorLoadOp, fHelper.stencilSettings()); |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1081 | } |
| 1082 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1083 | AAHairlineOp::Program AAHairlineOp::predictPrograms(const GrCaps* caps) const { |
| 1084 | bool convertConicsToQuads = !caps->shaderCaps()->floatIs32Bits(); |
| 1085 | |
| 1086 | // When predicting the programs we always include the lineProgram bc it is used as a fallback |
| 1087 | // for quads and conics. In non-DDL mode there are cases where it sometimes isn't needed for a |
| 1088 | // given path. |
| 1089 | Program neededPrograms = kLine_Program; |
| 1090 | |
| 1091 | for (int i = 0; i < fPaths.count(); i++) { |
| 1092 | uint32_t mask = fPaths[i].fPath.getSegmentMasks(); |
| 1093 | |
| 1094 | if (mask & (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)) { |
| 1095 | neededPrograms |= kQuad_Program; |
| 1096 | } |
| 1097 | if (mask & SkPath::kConic_SegmentMask) { |
| 1098 | if (convertConicsToQuads) { |
| 1099 | neededPrograms |= kQuad_Program; |
| 1100 | } else { |
| 1101 | neededPrograms |= kConic_Program; |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | return neededPrograms; |
| 1107 | } |
| 1108 | |
| 1109 | void AAHairlineOp::onCreateProgramInfo(const GrCaps* caps, |
| 1110 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1111 | const GrSurfaceProxyView& writeView, |
Chris Dalton | 6aaf00f | 2021-07-13 13:26:39 -0600 | [diff] [blame^] | 1112 | bool usesMSAASurface, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1113 | GrAppliedClip&& appliedClip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 1114 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1115 | GrXferBarrierFlags renderPassXferBarriers, |
| 1116 | GrLoadOp colorLoadOp) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1117 | // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. |
| 1118 | SkMatrix invert; |
| 1119 | if (!this->viewMatrix().invert(&invert)) { |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | // we will transform to identity space if the viewmatrix does not have perspective |
| 1124 | bool hasPerspective = this->viewMatrix().hasPerspective(); |
| 1125 | const SkMatrix* geometryProcessorViewM = &SkMatrix::I(); |
| 1126 | const SkMatrix* geometryProcessorLocalM = &invert; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1127 | if (hasPerspective) { |
| 1128 | geometryProcessorViewM = &this->viewMatrix(); |
| 1129 | geometryProcessorLocalM = &SkMatrix::I(); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1132 | auto pipeline = fHelper.createPipeline(caps, arena, writeView.swizzle(), |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 1133 | std::move(appliedClip), dstProxyView); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1134 | |
| 1135 | if (fCharacterization & kLine_Program) { |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 1136 | this->makeLineProgramInfo(*caps, arena, pipeline, writeView, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1137 | geometryProcessorViewM, geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1138 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1139 | } |
| 1140 | if (fCharacterization & kQuad_Program) { |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 1141 | this->makeQuadProgramInfo(*caps, arena, pipeline, writeView, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1142 | geometryProcessorViewM, geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1143 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1144 | } |
| 1145 | if (fCharacterization & kConic_Program) { |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 1146 | this->makeConicProgramInfo(*caps, arena, pipeline, writeView, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 1147 | geometryProcessorViewM, geometryProcessorLocalM, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1148 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1149 | |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | void AAHairlineOp::onPrePrepareDraws(GrRecordingContext* context, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 1154 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1155 | GrAppliedClip* clip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 1156 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 1157 | GrXferBarrierFlags renderPassXferBarriers, |
| 1158 | GrLoadOp colorLoadOp) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1159 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
| 1160 | const GrCaps* caps = context->priv().caps(); |
| 1161 | |
Chris Dalton | 6aaf00f | 2021-07-13 13:26:39 -0600 | [diff] [blame^] | 1162 | // http://skbug.com/12201 -- DDL does not yet support DMSAA. |
| 1163 | bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1; |
| 1164 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1165 | // This is equivalent to a GrOpFlushState::detachAppliedClip |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 1166 | GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled(); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1167 | |
| 1168 | // Conservatively predict which programs will be required |
| 1169 | fCharacterization = this->predictPrograms(caps); |
| 1170 | |
Chris Dalton | 6aaf00f | 2021-07-13 13:26:39 -0600 | [diff] [blame^] | 1171 | this->createProgramInfo(caps, arena, writeView, usesMSAASurface, std::move(appliedClip), |
| 1172 | dstProxyView, renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1173 | |
| 1174 | context->priv().recordProgramInfo(fProgramInfos[0]); |
| 1175 | context->priv().recordProgramInfo(fProgramInfos[1]); |
| 1176 | context->priv().recordProgramInfo(fProgramInfos[2]); |
| 1177 | } |
| 1178 | |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 1179 | void AAHairlineOp::onPrepareDraws(GrMeshDrawTarget* target) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1180 | // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. |
| 1181 | SkMatrix invert; |
| 1182 | if (!this->viewMatrix().invert(&invert)) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | // we will transform to identity space if the viewmatrix does not have perspective |
| 1187 | const SkMatrix* toDevice = nullptr; |
| 1188 | const SkMatrix* toSrc = nullptr; |
| 1189 | if (this->viewMatrix().hasPerspective()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1190 | toDevice = &this->viewMatrix(); |
| 1191 | toSrc = &invert; |
| 1192 | } |
| 1193 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1194 | SkDEBUGCODE(Program predictedPrograms = this->predictPrograms(&target->caps())); |
| 1195 | Program actualPrograms = kNone_Program; |
| 1196 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1197 | // This is hand inlined for maximum performance. |
| 1198 | PREALLOC_PTARRAY(128) lines; |
| 1199 | PREALLOC_PTARRAY(128) quads; |
| 1200 | PREALLOC_PTARRAY(128) conics; |
| 1201 | IntArray qSubdivs; |
| 1202 | FloatArray cWeights; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 1203 | int quadCount = 0; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1204 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 1205 | int instanceCount = fPaths.count(); |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 1206 | bool convertConicsToQuads = !target->caps().shaderCaps()->floatIs32Bits(); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1207 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 1208 | const PathData& args = fPaths[i]; |
joshualitt | 351ba1b | 2015-02-16 08:33:19 -0800 | [diff] [blame] | 1209 | quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds, |
Brian Salomon | 969a738 | 2018-05-09 13:28:44 -0400 | [diff] [blame] | 1210 | args.fCapLength, convertConicsToQuads, &lines, &quads, |
| 1211 | &conics, &qSubdivs, &cWeights); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1214 | int lineCount = lines.count() / 2; |
| 1215 | int conicCount = conics.count() / 3; |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 1216 | int quadAndConicCount = conicCount + quadCount; |
| 1217 | |
| 1218 | static constexpr int kMaxLines = SK_MaxS32 / kLineSegNumVertices; |
| 1219 | static constexpr int kMaxQuadsAndConics = SK_MaxS32 / kQuadNumVertices; |
| 1220 | if (lineCount > kMaxLines || quadAndConicCount > kMaxQuadsAndConics) { |
| 1221 | return; |
| 1222 | } |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1223 | |
| 1224 | // do lines first |
| 1225 | if (lineCount) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1226 | SkASSERT(predictedPrograms & kLine_Program); |
| 1227 | actualPrograms |= kLine_Program; |
| 1228 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 1229 | sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider()); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1230 | |
Robert Phillips | e94cdd2 | 2019-11-04 14:15:58 -0500 | [diff] [blame] | 1231 | GrMeshDrawOp::PatternHelper helper(target, GrPrimitiveType::kTriangles, sizeof(LineVertex), |
| 1232 | std::move(linesIndexBuffer), kLineSegNumVertices, |
| 1233 | kIdxsPerLineSeg, lineCount, kLineSegsNumInIdxBuffer); |
| 1234 | |
| 1235 | LineVertex* verts = reinterpret_cast<LineVertex*>(helper.vertices()); |
| 1236 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1237 | SkDebugf("Could not allocate vertices\n"); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1241 | for (int i = 0; i < lineCount; ++i) { |
| 1242 | add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
| 1243 | } |
| 1244 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1245 | fMeshes[0] = helper.mesh(); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | if (quadCount || conicCount) { |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1249 | sk_sp<const GrBuffer> vertexBuffer; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1250 | int firstVertex; |
| 1251 | |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 1252 | sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider()); |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1253 | |
Brian Salomon | 296de50 | 2018-03-13 12:26:55 -0400 | [diff] [blame] | 1254 | int vertexCount = kQuadNumVertices * quadAndConicCount; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1255 | void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer, |
| 1256 | &firstVertex); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1257 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1258 | if (!vertices || !quadsIndexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1259 | SkDebugf("Could not allocate vertices\n"); |
| 1260 | return; |
| 1261 | } |
| 1262 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1263 | // Setup vertices |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1264 | BezierVertex* bezVerts = reinterpret_cast<BezierVertex*>(vertices); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1265 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1266 | int unsubdivQuadCnt = quads.count() / 3; |
| 1267 | for (int i = 0; i < unsubdivQuadCnt; ++i) { |
| 1268 | SkASSERT(qSubdivs[i] >= 0); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1269 | add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | // Start Conics |
| 1273 | for (int i = 0; i < conicCount; ++i) { |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 1274 | add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | if (quadCount > 0) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1278 | SkASSERT(predictedPrograms & kQuad_Program); |
| 1279 | actualPrograms |= kQuad_Program; |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1280 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1281 | fMeshes[1] = target->allocMesh(); |
| 1282 | fMeshes[1]->setIndexedPatterned(quadsIndexBuffer, kIdxsPerQuad, quadCount, |
| 1283 | kQuadsNumInIdxBuffer, vertexBuffer, kQuadNumVertices, |
| 1284 | firstVertex); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1285 | firstVertex += quadCount * kQuadNumVertices; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | if (conicCount > 0) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1289 | SkASSERT(predictedPrograms & kConic_Program); |
| 1290 | actualPrograms |= kConic_Program; |
Robert Phillips | 1b3c267 | 2019-12-04 14:34:48 -0500 | [diff] [blame] | 1291 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1292 | fMeshes[2] = target->allocMesh(); |
| 1293 | fMeshes[2]->setIndexedPatterned(std::move(quadsIndexBuffer), kIdxsPerQuad, conicCount, |
| 1294 | kQuadsNumInIdxBuffer, std::move(vertexBuffer), |
| 1295 | kQuadNumVertices, firstVertex); |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1296 | } |
| 1297 | } |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1298 | |
| 1299 | // In DDL mode this will replace the predicted program requirements with the actual ones. |
| 1300 | // However, we will already have surfaced the predicted programs to the DDL. |
| 1301 | fCharacterization = actualPrograms; |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1304 | void AAHairlineOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1305 | this->createProgramInfo(flushState); |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 1306 | |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1307 | for (int i = 0; i < 3; ++i) { |
| 1308 | if (fProgramInfos[i] && fMeshes[i]) { |
| 1309 | flushState->bindPipelineAndScissorClip(*fProgramInfos[i], chainBounds); |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 1310 | flushState->bindTextures(fProgramInfos[i]->geomProc(), nullptr, |
Robert Phillips | 4f93c57 | 2020-03-18 08:13:53 -0400 | [diff] [blame] | 1311 | fProgramInfos[i]->pipeline()); |
| 1312 | flushState->drawMesh(*fMeshes[i]); |
| 1313 | } |
| 1314 | } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 1317 | bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 1318 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 1319 | "GrAAHairlinePathRenderer::onDrawPath"); |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 1320 | SkASSERT(args.fSurfaceDrawContext->numSamples() <= 1); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 1321 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 1322 | SkPath path; |
| 1323 | args.fShape->asPath(&path); |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 1324 | GrOp::Owner op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1325 | AAHairlineOp::Make(args.fContext, std::move(args.fPaint), *args.fViewMatrix, path, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 1326 | args.fShape->style(), *args.fClipConservativeBounds, |
| 1327 | args.fUserStencilSettings); |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 1328 | args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1329 | return true; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1330 | } |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1331 | |
| 1332 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1333 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 1334 | #if GR_TEST_UTILS |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1335 | |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 1336 | GR_DRAW_OP_TEST_DEFINE(AAHairlineOp) { |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1337 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 1338 | const SkPath& path = GrTest::TestPath(random); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1339 | SkIRect devClipBounds; |
| 1340 | devClipBounds.setEmpty(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 1341 | return AAHairlineOp::Make(context, std::move(paint), viewMatrix, path, |
| 1342 | GrStyle::SimpleHairline(), devClipBounds, |
| 1343 | GrGetRandomStencil(random, context)); |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | #endif |