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