bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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/SkString.h" |
| 9 | #include "include/core/SkTypes.h" |
| 10 | #include "src/core/SkGeometry.h" |
Michael Ludwig | fbe2859 | 2020-06-26 16:02:15 -0400 | [diff] [blame] | 11 | #include "src/core/SkMatrixPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/core/SkPathPriv.h" |
| 13 | #include "src/core/SkPointPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrCaps.h" |
| 16 | #include "src/gpu/GrDrawOpTest.h" |
| 17 | #include "src/gpu/GrGeometryProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrProcessor.h" |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrProgramInfo.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrSurfaceDrawContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrVertexWriter.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 22 | #include "src/gpu/geometry/GrPathUtils.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 23 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 25 | #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" |
| 26 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 27 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 28 | #include "src/gpu/glsl/GrGLSLVarying.h" |
| 29 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
| 30 | #include "src/gpu/ops/GrAAConvexPathRenderer.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" |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 33 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 34 | GrAAConvexPathRenderer::GrAAConvexPathRenderer() { |
| 35 | } |
| 36 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 37 | struct Segment { |
| 38 | enum { |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 39 | // These enum values are assumed in member functions below. |
| 40 | kLine = 0, |
| 41 | kQuad = 1, |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 42 | } fType; |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 44 | // line uses one pt, quad uses 2 pts |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 45 | SkPoint fPts[2]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 46 | // normal to edge ending at each pt |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 47 | SkVector fNorms[2]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 48 | // is the corner where the previous segment meets this segment |
| 49 | // sharp. If so, fMid is a normalized bisector facing outward. |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 50 | SkVector fMid; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 51 | |
| 52 | int countPoints() { |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 53 | static_assert(0 == kLine && 1 == kQuad); |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 54 | return fType + 1; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 55 | } |
| 56 | const SkPoint& endPt() const { |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 57 | static_assert(0 == kLine && 1 == kQuad); |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 58 | return fPts[fType]; |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 59 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 60 | const SkPoint& endNorm() const { |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 61 | static_assert(0 == kLine && 1 == kQuad); |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 62 | return fNorms[fType]; |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 63 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | typedef SkTArray<Segment, true> SegmentArray; |
| 67 | |
Greg Daniel | 8b09b96 | 2018-04-03 14:53:45 -0400 | [diff] [blame] | 68 | static bool center_of_mass(const SegmentArray& segments, SkPoint* c) { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 69 | SkScalar area = 0; |
vandebo@chromium.org | 6390c72 | 2012-03-28 21:03:22 +0000 | [diff] [blame] | 70 | SkPoint center = {0, 0}; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 71 | int count = segments.count(); |
vandebo@chromium.org | 6390c72 | 2012-03-28 21:03:22 +0000 | [diff] [blame] | 72 | SkPoint p0 = {0, 0}; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 73 | if (count > 2) { |
| 74 | // We translate the polygon so that the first point is at the origin. |
| 75 | // This avoids some precision issues with small area polygons far away |
| 76 | // from the origin. |
| 77 | p0 = segments[0].endPt(); |
| 78 | SkPoint pi; |
| 79 | SkPoint pj; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 80 | // the first and last iteration of the below loop would compute |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 81 | // zeros since the starting / ending point is (0,0). So instead we start |
| 82 | // at i=1 and make the last iteration i=count-2. |
| 83 | pj = segments[1].endPt() - p0; |
| 84 | for (int i = 1; i < count - 1; ++i) { |
| 85 | pi = pj; |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 86 | pj = segments[i + 1].endPt() - p0; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 87 | |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 88 | SkScalar t = SkPoint::CrossProduct(pi, pj); |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 89 | area += t; |
| 90 | center.fX += (pi.fX + pj.fX) * t; |
| 91 | center.fY += (pi.fY + pj.fY) * t; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 92 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 93 | } |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 94 | |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 95 | // If the poly has no area then we instead return the average of |
| 96 | // its points. |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 97 | if (SkScalarNearlyZero(area)) { |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 98 | SkPoint avg; |
| 99 | avg.set(0, 0); |
| 100 | for (int i = 0; i < count; ++i) { |
| 101 | const SkPoint& pt = segments[i].endPt(); |
| 102 | avg.fX += pt.fX; |
| 103 | avg.fY += pt.fY; |
| 104 | } |
| 105 | SkScalar denom = SK_Scalar1 / count; |
| 106 | avg.scale(denom); |
| 107 | *c = avg; |
| 108 | } else { |
| 109 | area *= 3; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 110 | area = SkScalarInvert(area); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 111 | center.scale(area); |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 112 | // undo the translate of p0 to the origin. |
| 113 | *c = center + p0; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 114 | } |
Greg Daniel | 62473ad | 2018-04-03 15:44:18 -0400 | [diff] [blame] | 115 | return !SkScalarIsNaN(c->fX) && !SkScalarIsNaN(c->fY) && c->isFinite(); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Greg Daniel | 8b09b96 | 2018-04-03 14:53:45 -0400 | [diff] [blame] | 118 | static bool compute_vectors(SegmentArray* segments, |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 119 | SkPoint* fanPt, |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 120 | SkPathFirstDirection dir, |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 121 | int* vCount, |
| 122 | int* iCount) { |
Greg Daniel | 8b09b96 | 2018-04-03 14:53:45 -0400 | [diff] [blame] | 123 | if (!center_of_mass(*segments, fanPt)) { |
| 124 | return false; |
| 125 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 126 | int count = segments->count(); |
| 127 | |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 128 | // Make the normals point towards the outside |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 129 | SkPointPriv::Side normSide; |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 130 | if (dir == SkPathFirstDirection::kCCW) { |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 131 | normSide = SkPointPriv::kRight_Side; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 132 | } else { |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 133 | normSide = SkPointPriv::kLeft_Side; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 134 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 135 | |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 136 | int64_t vCount64 = 0; |
| 137 | int64_t iCount64 = 0; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 138 | // compute normals at all points |
| 139 | for (int a = 0; a < count; ++a) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 140 | Segment& sega = (*segments)[a]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 141 | int b = (a + 1) % count; |
| 142 | Segment& segb = (*segments)[b]; |
| 143 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 144 | const SkPoint* prevPt = &sega.endPt(); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 145 | int n = segb.countPoints(); |
| 146 | for (int p = 0; p < n; ++p) { |
| 147 | segb.fNorms[p] = segb.fPts[p] - *prevPt; |
| 148 | segb.fNorms[p].normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 149 | segb.fNorms[p] = SkPointPriv::MakeOrthog(segb.fNorms[p], normSide); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 150 | prevPt = &segb.fPts[p]; |
| 151 | } |
| 152 | if (Segment::kLine == segb.fType) { |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 153 | vCount64 += 5; |
| 154 | iCount64 += 9; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 155 | } else { |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 156 | vCount64 += 6; |
| 157 | iCount64 += 12; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | // compute mid-vectors where segments meet. TODO: Detect shallow corners |
| 162 | // and leave out the wedges and close gaps by stitching segments together. |
| 163 | for (int a = 0; a < count; ++a) { |
| 164 | const Segment& sega = (*segments)[a]; |
| 165 | int b = (a + 1) % count; |
| 166 | Segment& segb = (*segments)[b]; |
| 167 | segb.fMid = segb.fNorms[0] + sega.endNorm(); |
| 168 | segb.fMid.normalize(); |
| 169 | // corner wedges |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 170 | vCount64 += 4; |
| 171 | iCount64 += 6; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 172 | } |
Greg Daniel | d5b4593 | 2018-06-07 13:15:10 -0400 | [diff] [blame] | 173 | if (vCount64 > SK_MaxS32 || iCount64 > SK_MaxS32) { |
| 174 | return false; |
| 175 | } |
| 176 | *vCount = vCount64; |
| 177 | *iCount = iCount64; |
Greg Daniel | 8b09b96 | 2018-04-03 14:53:45 -0400 | [diff] [blame] | 178 | return true; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 179 | } |
| 180 | |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 181 | struct DegenerateTestData { |
| 182 | DegenerateTestData() { fStage = kInitial; } |
| 183 | bool isDegenerate() const { return kNonDegenerate != fStage; } |
| 184 | enum { |
| 185 | kInitial, |
| 186 | kPoint, |
| 187 | kLine, |
| 188 | kNonDegenerate |
| 189 | } fStage; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 190 | SkPoint fFirstPoint; |
| 191 | SkVector fLineNormal; |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 192 | SkScalar fLineC; |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 195 | static const SkScalar kClose = (SK_Scalar1 / 16); |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 196 | static const SkScalar kCloseSqd = kClose * kClose; |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 197 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 198 | static void update_degenerate_test(DegenerateTestData* data, const SkPoint& pt) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 199 | switch (data->fStage) { |
| 200 | case DegenerateTestData::kInitial: |
| 201 | data->fFirstPoint = pt; |
| 202 | data->fStage = DegenerateTestData::kPoint; |
| 203 | break; |
| 204 | case DegenerateTestData::kPoint: |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 205 | if (SkPointPriv::DistanceToSqd(pt, data->fFirstPoint) > kCloseSqd) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 206 | data->fLineNormal = pt - data->fFirstPoint; |
| 207 | data->fLineNormal.normalize(); |
Brian Salomon | 0235c64 | 2018-08-31 12:04:18 -0400 | [diff] [blame] | 208 | data->fLineNormal = SkPointPriv::MakeOrthog(data->fLineNormal); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 209 | data->fLineC = -data->fLineNormal.dot(data->fFirstPoint); |
| 210 | data->fStage = DegenerateTestData::kLine; |
| 211 | } |
| 212 | break; |
| 213 | case DegenerateTestData::kLine: |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 214 | if (SkScalarAbs(data->fLineNormal.dot(pt) + data->fLineC) > kClose) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 215 | data->fStage = DegenerateTestData::kNonDegenerate; |
| 216 | } |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 217 | break; |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 218 | case DegenerateTestData::kNonDegenerate: |
| 219 | break; |
| 220 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 221 | SK_ABORT("Unexpected degenerate test stage."); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 225 | static inline bool get_direction(const SkPath& path, const SkMatrix& m, |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 226 | SkPathFirstDirection* dir) { |
Michael Ludwig | 0a1e9ef | 2019-08-30 10:03:15 -0400 | [diff] [blame] | 227 | // At this point, we've already returned true from canDraw(), which checked that the path's |
| 228 | // direction could be determined, so this should just be fetching the cached direction. |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 229 | // However, if perspective is involved, we're operating on a transformed path, which may no |
| 230 | // longer have a computable direction. |
Mike Reed | 85f51b2 | 2020-08-30 10:32:06 -0400 | [diff] [blame] | 231 | *dir = SkPathPriv::ComputeFirstDirection(path); |
| 232 | if (*dir == SkPathFirstDirection::kUnknown) { |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 233 | return false; |
| 234 | } |
Michael Ludwig | 0a1e9ef | 2019-08-30 10:03:15 -0400 | [diff] [blame] | 235 | |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 236 | // check whether m reverses the orientation |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 237 | SkASSERT(!m.hasPerspective()); |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 238 | SkScalar det2x2 = m.get(SkMatrix::kMScaleX) * m.get(SkMatrix::kMScaleY) - |
| 239 | m.get(SkMatrix::kMSkewX) * m.get(SkMatrix::kMSkewY); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 240 | if (det2x2 < 0) { |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 241 | *dir = SkPathPriv::OppositeFirstDirection(*dir); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 242 | } |
Michael Ludwig | 0a1e9ef | 2019-08-30 10:03:15 -0400 | [diff] [blame] | 243 | |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 244 | return true; |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 245 | } |
| 246 | |
commit-bot@chromium.org | 106655e | 2013-09-03 21:28:55 +0000 | [diff] [blame] | 247 | static inline void add_line_to_segment(const SkPoint& pt, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 248 | SegmentArray* segments) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 249 | segments->push_back(); |
| 250 | segments->back().fType = Segment::kLine; |
| 251 | segments->back().fPts[0] = pt; |
| 252 | } |
| 253 | |
commit-bot@chromium.org | 106655e | 2013-09-03 21:28:55 +0000 | [diff] [blame] | 254 | static inline void add_quad_segment(const SkPoint pts[3], |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 255 | SegmentArray* segments) { |
Brian Salomon | 5f8a62b | 2019-03-29 13:55:32 -0400 | [diff] [blame] | 256 | if (SkPointPriv::DistanceToLineSegmentBetweenSqd(pts[1], pts[0], pts[2]) < kCloseSqd) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 257 | if (pts[0] != pts[2]) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 258 | add_line_to_segment(pts[2], segments); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 259 | } |
| 260 | } else { |
| 261 | segments->push_back(); |
| 262 | segments->back().fType = Segment::kQuad; |
| 263 | segments->back().fPts[0] = pts[1]; |
| 264 | segments->back().fPts[1] = pts[2]; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static inline void add_cubic_segments(const SkPoint pts[4], |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 269 | SkPathFirstDirection dir, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 270 | SegmentArray* segments) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 271 | SkSTArray<15, SkPoint, true> quads; |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 272 | GrPathUtils::convertCubicToQuadsConstrainToTangents(pts, SK_Scalar1, dir, &quads); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 273 | int count = quads.count(); |
| 274 | for (int q = 0; q < count; q += 3) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 275 | add_quad_segment(&quads[q], segments); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | static bool get_segments(const SkPath& path, |
| 280 | const SkMatrix& m, |
| 281 | SegmentArray* segments, |
| 282 | SkPoint* fanPt, |
| 283 | int* vCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 284 | int* iCount) { |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 285 | SkPath::Iter iter(path, true); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 286 | // This renderer over-emphasizes very thin path regions. We use the distance |
bsalomon@google.com | 5cc90d1 | 2012-01-17 16:28:34 +0000 | [diff] [blame] | 287 | // to the path from the sample to compute coverage. Every pixel intersected |
| 288 | // by the path will be hit and the maximum distance is sqrt(2)/2. We don't |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 289 | // notice that the sample may be close to a very thin area of the path and |
bsalomon@google.com | 5cc90d1 | 2012-01-17 16:28:34 +0000 | [diff] [blame] | 290 | // thus should be very light. This is particularly egregious for degenerate |
| 291 | // line paths. We detect paths that are very close to a line (zero area) and |
| 292 | // draw nothing. |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 293 | DegenerateTestData degenerateData; |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 294 | SkPathFirstDirection dir; |
Brian Osman | 2caecd2 | 2019-09-25 14:02:26 -0400 | [diff] [blame] | 295 | if (!get_direction(path, m, &dir)) { |
| 296 | return false; |
| 297 | } |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 298 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 299 | for (;;) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 300 | SkPoint pts[4]; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 301 | SkPath::Verb verb = iter.next(pts); |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 302 | switch (verb) { |
| 303 | case SkPath::kMove_Verb: |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 304 | m.mapPoints(pts, 1); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 305 | update_degenerate_test(°enerateData, pts[0]); |
| 306 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 307 | case SkPath::kLine_Verb: { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 308 | if (!SkPathPriv::AllPointsEq(pts, 2)) { |
| 309 | m.mapPoints(&pts[1], 1); |
| 310 | update_degenerate_test(°enerateData, pts[1]); |
| 311 | add_line_to_segment(pts[1], segments); |
| 312 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 313 | break; |
| 314 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 315 | case SkPath::kQuad_Verb: |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 316 | if (!SkPathPriv::AllPointsEq(pts, 3)) { |
| 317 | m.mapPoints(pts, 3); |
| 318 | update_degenerate_test(°enerateData, pts[1]); |
| 319 | update_degenerate_test(°enerateData, pts[2]); |
| 320 | add_quad_segment(pts, segments); |
| 321 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 322 | break; |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 323 | case SkPath::kConic_Verb: { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 324 | if (!SkPathPriv::AllPointsEq(pts, 3)) { |
| 325 | m.mapPoints(pts, 3); |
| 326 | SkScalar weight = iter.conicWeight(); |
| 327 | SkAutoConicToQuads converter; |
| 328 | const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f); |
| 329 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 330 | update_degenerate_test(°enerateData, quadPts[2*i + 1]); |
| 331 | update_degenerate_test(°enerateData, quadPts[2*i + 2]); |
| 332 | add_quad_segment(quadPts + 2*i, segments); |
| 333 | } |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 334 | } |
| 335 | break; |
| 336 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 337 | case SkPath::kCubic_Verb: { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 338 | if (!SkPathPriv::AllPointsEq(pts, 4)) { |
| 339 | m.mapPoints(pts, 4); |
| 340 | update_degenerate_test(°enerateData, pts[1]); |
| 341 | update_degenerate_test(°enerateData, pts[2]); |
| 342 | update_degenerate_test(°enerateData, pts[3]); |
| 343 | add_cubic_segments(pts, dir, segments); |
| 344 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 345 | break; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 346 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 347 | case SkPath::kDone_Verb: |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 348 | if (degenerateData.isDegenerate()) { |
| 349 | return false; |
| 350 | } else { |
Greg Daniel | 8b09b96 | 2018-04-03 14:53:45 -0400 | [diff] [blame] | 351 | return compute_vectors(segments, fanPt, dir, vCount, iCount); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 352 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 359 | struct Draw { |
| 360 | Draw() : fVertexCnt(0), fIndexCnt(0) {} |
| 361 | int fVertexCnt; |
| 362 | int fIndexCnt; |
| 363 | }; |
| 364 | |
| 365 | typedef SkTArray<Draw, true> DrawArray; |
| 366 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 367 | static void create_vertices(const SegmentArray& segments, |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 368 | const SkPoint& fanPt, |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 369 | const GrVertexColor& color, |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 370 | DrawArray* draws, |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 371 | GrVertexWriter& verts, |
| 372 | uint16_t* idxs, |
| 373 | size_t vertexStride) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 374 | Draw* draw = &draws->push_back(); |
| 375 | // alias just to make vert/index assignments easier to read. |
| 376 | int* v = &draw->fVertexCnt; |
| 377 | int* i = &draw->fIndexCnt; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 378 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 379 | int count = segments.count(); |
| 380 | for (int a = 0; a < count; ++a) { |
| 381 | const Segment& sega = segments[a]; |
| 382 | int b = (a + 1) % count; |
| 383 | const Segment& segb = segments[b]; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 384 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 385 | // Check whether adding the verts for this segment to the current draw would cause index |
| 386 | // values to overflow. |
| 387 | int vCount = 4; |
| 388 | if (Segment::kLine == segb.fType) { |
| 389 | vCount += 5; |
| 390 | } else { |
| 391 | vCount += 6; |
| 392 | } |
| 393 | if (draw->fVertexCnt + vCount > (1 << 16)) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 394 | idxs += *i; |
| 395 | draw = &draws->push_back(); |
| 396 | v = &draw->fVertexCnt; |
| 397 | i = &draw->fIndexCnt; |
| 398 | } |
| 399 | |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 400 | const SkScalar negOneDists[2] = { -SK_Scalar1, -SK_Scalar1 }; |
| 401 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 402 | // FIXME: These tris are inset in the 1 unit arc around the corner |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 403 | SkPoint p0 = sega.endPt(); |
| 404 | // Position, Color, UV, D0, D1 |
| 405 | verts.write(p0, color, SkPoint{0, 0}, negOneDists); |
| 406 | verts.write(p0 + sega.endNorm(), color, SkPoint{0, -SK_Scalar1}, negOneDists); |
| 407 | verts.write(p0 + segb.fMid, color, SkPoint{0, -SK_Scalar1}, negOneDists); |
| 408 | verts.write(p0 + segb.fNorms[0], color, SkPoint{0, -SK_Scalar1}, negOneDists); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 409 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 410 | idxs[*i + 0] = *v + 0; |
| 411 | idxs[*i + 1] = *v + 2; |
| 412 | idxs[*i + 2] = *v + 1; |
| 413 | idxs[*i + 3] = *v + 0; |
| 414 | idxs[*i + 4] = *v + 3; |
| 415 | idxs[*i + 5] = *v + 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 416 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 417 | *v += 4; |
| 418 | *i += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 419 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 420 | if (Segment::kLine == segb.fType) { |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 421 | // we draw the line edge as a degenerate quad (u is 0, v is the |
| 422 | // signed distance to the edge) |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 423 | SkPoint v1Pos = sega.endPt(); |
| 424 | SkPoint v2Pos = segb.fPts[0]; |
| 425 | SkScalar dist = SkPointPriv::DistanceToLineBetween(fanPt, v1Pos, v2Pos); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 426 | |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 427 | verts.write(fanPt, color, SkPoint{0, dist}, negOneDists); |
| 428 | verts.write(v1Pos, color, SkPoint{0, 0}, negOneDists); |
| 429 | verts.write(v2Pos, color, SkPoint{0, 0}, negOneDists); |
| 430 | verts.write(v1Pos + segb.fNorms[0], color, SkPoint{0, -SK_Scalar1}, negOneDists); |
| 431 | verts.write(v2Pos + segb.fNorms[0], color, SkPoint{0, -SK_Scalar1}, negOneDists); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 432 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 433 | idxs[*i + 0] = *v + 3; |
| 434 | idxs[*i + 1] = *v + 1; |
| 435 | idxs[*i + 2] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 436 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 437 | idxs[*i + 3] = *v + 4; |
| 438 | idxs[*i + 4] = *v + 3; |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 439 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 440 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 441 | *i += 6; |
| 442 | |
| 443 | // Draw the interior fan if it exists. |
| 444 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 445 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 446 | if (count >= 3) { |
| 447 | idxs[*i + 0] = *v + 0; |
| 448 | idxs[*i + 1] = *v + 2; |
| 449 | idxs[*i + 2] = *v + 1; |
| 450 | |
| 451 | *i += 3; |
| 452 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 453 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 454 | *v += 5; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 455 | } else { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 456 | SkPoint qpts[] = {sega.endPt(), segb.fPts[0], segb.fPts[1]}; |
bsalomon@google.com | 495e210 | 2012-01-21 14:48:36 +0000 | [diff] [blame] | 457 | |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 458 | SkScalar c0 = segb.fNorms[0].dot(qpts[0]); |
| 459 | SkScalar c1 = segb.fNorms[1].dot(qpts[2]); |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 460 | |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 461 | // We must transform the positions into UV in cpu memory and then copy them to the gpu |
| 462 | // buffer. If we write the position first into the gpu buffer then calculate the UVs, it |
| 463 | // will cause us to read from the GPU buffer which can be very slow. |
| 464 | struct PosAndUV { |
| 465 | SkPoint fPos; |
| 466 | SkPoint fUV; |
| 467 | }; |
| 468 | PosAndUV posAndUVPoints[6]; |
| 469 | posAndUVPoints[0].fPos = fanPt; |
| 470 | posAndUVPoints[1].fPos = qpts[0]; |
| 471 | posAndUVPoints[2].fPos = qpts[2]; |
| 472 | posAndUVPoints[3].fPos = qpts[0] + segb.fNorms[0]; |
| 473 | posAndUVPoints[4].fPos = qpts[2] + segb.fNorms[1]; |
| 474 | SkVector midVec = segb.fNorms[0] + segb.fNorms[1]; |
| 475 | midVec.normalize(); |
| 476 | posAndUVPoints[5].fPos = qpts[1] + midVec; |
| 477 | |
| 478 | GrPathUtils::QuadUVMatrix toUV(qpts); |
| 479 | toUV.apply(posAndUVPoints, 6, sizeof(PosAndUV), sizeof(SkPoint)); |
| 480 | |
| 481 | verts.write(posAndUVPoints[0].fPos, color, posAndUVPoints[0].fUV, |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 482 | -segb.fNorms[0].dot(fanPt) + c0, |
| 483 | -segb.fNorms[1].dot(fanPt) + c1); |
| 484 | |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 485 | verts.write(posAndUVPoints[1].fPos, color, posAndUVPoints[1].fUV, |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 486 | 0.0f, |
| 487 | -segb.fNorms[1].dot(qpts[0]) + c1); |
| 488 | |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 489 | verts.write(posAndUVPoints[2].fPos, color, posAndUVPoints[2].fUV, |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 490 | -segb.fNorms[0].dot(qpts[2]) + c0, |
| 491 | 0.0f); |
Greg Daniel | 1204c4b | 2020-04-22 14:10:12 -0400 | [diff] [blame] | 492 | // We need a negative value that is very large that it won't effect results if it is |
| 493 | // interpolated with. However, the value can't be too large of a negative that it |
| 494 | // effects numerical precision on less powerful GPUs. |
| 495 | static const SkScalar kStableLargeNegativeValue = -SK_ScalarMax/1000000; |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 496 | verts.write(posAndUVPoints[3].fPos, color, posAndUVPoints[3].fUV, |
Greg Daniel | 1204c4b | 2020-04-22 14:10:12 -0400 | [diff] [blame] | 497 | kStableLargeNegativeValue, |
| 498 | kStableLargeNegativeValue); |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 499 | |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 500 | verts.write(posAndUVPoints[4].fPos, color, posAndUVPoints[4].fUV, |
Greg Daniel | 1204c4b | 2020-04-22 14:10:12 -0400 | [diff] [blame] | 501 | kStableLargeNegativeValue, |
| 502 | kStableLargeNegativeValue); |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 503 | |
Greg Daniel | 0a0ad5b | 2021-01-29 22:49:30 -0500 | [diff] [blame] | 504 | verts.write(posAndUVPoints[5].fPos, color, posAndUVPoints[5].fUV, |
Greg Daniel | 1204c4b | 2020-04-22 14:10:12 -0400 | [diff] [blame] | 505 | kStableLargeNegativeValue, |
| 506 | kStableLargeNegativeValue); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 507 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 508 | idxs[*i + 0] = *v + 3; |
| 509 | idxs[*i + 1] = *v + 1; |
| 510 | idxs[*i + 2] = *v + 2; |
| 511 | idxs[*i + 3] = *v + 4; |
| 512 | idxs[*i + 4] = *v + 3; |
| 513 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 514 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 515 | idxs[*i + 6] = *v + 5; |
| 516 | idxs[*i + 7] = *v + 3; |
| 517 | idxs[*i + 8] = *v + 4; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 518 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 519 | *i += 9; |
| 520 | |
| 521 | // Draw the interior fan if it exists. |
| 522 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 523 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 524 | if (count >= 3) { |
| 525 | idxs[*i + 0] = *v + 0; |
| 526 | idxs[*i + 1] = *v + 2; |
| 527 | idxs[*i + 2] = *v + 1; |
| 528 | |
| 529 | *i += 3; |
| 530 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 531 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 532 | *v += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 537 | /////////////////////////////////////////////////////////////////////////////// |
| 538 | |
| 539 | /* |
| 540 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 541 | * two components of the vertex attribute. Coverage is based on signed |
| 542 | * distance with negative being inside, positive outside. The edge is specified in |
| 543 | * window space (y-down). If either the third or fourth component of the interpolated |
| 544 | * vertex coord is > 0 then the pixel is considered outside the edge. This is used to |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 545 | * attempt to trim to a portion of the infinite quad. |
| 546 | * Requires shader derivative instruction support. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 547 | */ |
| 548 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 549 | class QuadEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 550 | public: |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 551 | static GrGeometryProcessor* Make(SkArenaAlloc* arena, |
| 552 | const SkMatrix& localMatrix, |
| 553 | bool usesLocalCoords, |
| 554 | bool wideColor) { |
Mike Klein | f124108 | 2020-12-14 15:59:09 -0600 | [diff] [blame] | 555 | return arena->make([&](void* ptr) { |
| 556 | return new (ptr) QuadEdgeEffect(localMatrix, usesLocalCoords, wideColor); |
| 557 | }); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 560 | ~QuadEdgeEffect() override {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 561 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 562 | const char* name() const override { return "QuadEdge"; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 563 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 564 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 565 | public: |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 566 | GLSLProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 567 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 568 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 569 | const QuadEdgeEffect& qe = args.fGeomProc.cast<QuadEdgeEffect>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 570 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 571 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 572 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 573 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 574 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 575 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 576 | varyingHandler->emitAttributes(qe); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 577 | |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 578 | // GL on iOS 14 needs more precision for the quadedge attributes |
Jim Van Verth | 4b6f54a | 2020-12-11 11:01:10 -0500 | [diff] [blame] | 579 | // We might as well enable it everywhere |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 580 | GrGLSLVarying v(kFloat4_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 581 | varyingHandler->addVarying("QuadEdge", &v); |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 582 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge.name()); |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 583 | |
| 584 | // Setup pass through color |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 585 | fragBuilder->codeAppendf("half4 %s;", args.fOutputColor); |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 586 | varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 587 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 588 | // Setup position |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 589 | WriteOutputPosition(vertBuilder, gpArgs, qe.fInPosition.name()); |
Michael Ludwig | 553db62 | 2020-06-19 10:47:30 -0400 | [diff] [blame] | 590 | if (qe.fUsesLocalCoords) { |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 591 | WriteLocalCoord(vertBuilder, |
| 592 | uniformHandler, |
| 593 | *args.fShaderCaps, |
| 594 | gpArgs, |
| 595 | qe.fInPosition.asShaderVar(), |
| 596 | qe.fLocalMatrix, |
| 597 | &fLocalMatrixUniform); |
Michael Ludwig | 553db62 | 2020-06-19 10:47:30 -0400 | [diff] [blame] | 598 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 599 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 600 | fragBuilder->codeAppendf("half edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 601 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 602 | // keep the derivative instructions outside the conditional |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 603 | fragBuilder->codeAppendf("half2 duvdx = half2(dFdx(%s.xy));", v.fsIn()); |
| 604 | fragBuilder->codeAppendf("half2 duvdy = half2(dFdy(%s.xy));", v.fsIn()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 605 | fragBuilder->codeAppendf("if (%s.z > 0.0 && %s.w > 0.0) {", v.fsIn(), v.fsIn()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 606 | // today we know z and w are in device space. We could use derivatives |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 607 | fragBuilder->codeAppendf("edgeAlpha = half(min(min(%s.z, %s.w) + 0.5, 1.0));", v.fsIn(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 608 | v.fsIn()); |
| 609 | fragBuilder->codeAppendf ("} else {"); |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 610 | fragBuilder->codeAppendf("half2 gF = half2(half(2.0*%s.x*duvdx.x - duvdx.y)," |
| 611 | " half(2.0*%s.x*duvdy.x - duvdy.y));", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 612 | v.fsIn(), v.fsIn()); |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 613 | fragBuilder->codeAppendf("edgeAlpha = half(%s.x*%s.x - %s.y);", v.fsIn(), v.fsIn(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 614 | v.fsIn()); |
| 615 | fragBuilder->codeAppendf("edgeAlpha = " |
Ethan Nicholas | 12fb9cf | 2018-08-03 16:16:57 -0400 | [diff] [blame] | 616 | "saturate(0.5 - edgeAlpha / length(gF));}"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 617 | |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 618 | fragBuilder->codeAppendf("half4 %s = half4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 619 | } |
| 620 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 621 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 622 | const GrShaderCaps& shaderCaps, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 623 | GrProcessorKeyBuilder* b) { |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 624 | const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); |
Brian Osman | 48d7f7c | 2021-03-03 13:38:08 -0500 | [diff] [blame] | 625 | b->addBool(qee.fUsesLocalCoords, "usesLocalCoords"); |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 626 | b->addBits(kMatrixKeyBits, |
| 627 | ComputeMatrixKey(shaderCaps, qee.fLocalMatrix), |
| 628 | "localMatrixType"); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 629 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 630 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 631 | void setData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 632 | const GrShaderCaps& shaderCaps, |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 633 | const GrGeometryProcessor& geomProc) override { |
| 634 | const QuadEdgeEffect& qe = geomProc.cast<QuadEdgeEffect>(); |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 635 | SetTransform(pdman, shaderCaps, fLocalMatrixUniform, qe.fLocalMatrix, &fLocalMatrix); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 636 | } |
| 637 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 638 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 639 | using INHERITED = GrGLSLGeometryProcessor; |
Michael Ludwig | 553db62 | 2020-06-19 10:47:30 -0400 | [diff] [blame] | 640 | |
| 641 | SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix(); |
| 642 | UniformHandle fLocalMatrixUniform; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 643 | }; |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 644 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 645 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 646 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Robert Phillips | f10535f | 2021-03-23 09:30:45 -0400 | [diff] [blame] | 649 | GrGLSLGeometryProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 650 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 651 | } |
| 652 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 653 | private: |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 654 | QuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords, bool wideColor) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 655 | : INHERITED(kQuadEdgeEffect_ClassID) |
| 656 | , fLocalMatrix(localMatrix) |
| 657 | , fUsesLocalCoords(usesLocalCoords) { |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 658 | fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 659 | fInColor = MakeColorAttribute("inColor", wideColor); |
Jim Van Verth | 201bcee | 2020-12-09 13:32:38 -0500 | [diff] [blame] | 660 | // GL on iOS 14 needs more precision for the quadedge attributes |
| 661 | fInQuadEdge = {"inQuadEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType}; |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 662 | this->setVertexAttributes(&fInPosition, 3); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 665 | Attribute fInPosition; |
| 666 | Attribute fInColor; |
| 667 | Attribute fInQuadEdge; |
| 668 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 669 | SkMatrix fLocalMatrix; |
| 670 | bool fUsesLocalCoords; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 671 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 672 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 673 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 674 | using INHERITED = GrGeometryProcessor; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 675 | }; |
| 676 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 677 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 678 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 679 | #if GR_TEST_UTILS |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 680 | GrGeometryProcessor* QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { |
John Stiles | 391a9f6 | 2021-04-29 23:17:41 -0400 | [diff] [blame^] | 681 | SkMatrix localMatrix = GrTest::TestMatrix(d->fRandom); |
| 682 | bool usesLocalCoords = d->fRandom->nextBool(); |
| 683 | bool wideColor = d->fRandom->nextBool(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 684 | // Doesn't work without derivative instructions. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 685 | return d->caps()->shaderCaps()->shaderDerivativeSupport() |
John Stiles | 391a9f6 | 2021-04-29 23:17:41 -0400 | [diff] [blame^] | 686 | ? QuadEdgeEffect::Make(d->allocator(), localMatrix, usesLocalCoords, wideColor) |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 687 | : nullptr; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 688 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 689 | #endif |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 690 | |
| 691 | /////////////////////////////////////////////////////////////////////////////// |
| 692 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 693 | GrPathRenderer::CanDrawPath |
| 694 | GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Michael Ludwig | 0a1e9ef | 2019-08-30 10:03:15 -0400 | [diff] [blame] | 695 | // This check requires convexity and known direction, since the direction is used to build |
| 696 | // the geometry segments. Degenerate convex paths will fall through to some other path renderer. |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 697 | if (args.fCaps->shaderCaps()->shaderDerivativeSupport() && |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 698 | (GrAAType::kCoverage == args.fAAType) && args.fShape->style().isSimpleFill() && |
Michael Ludwig | 0a1e9ef | 2019-08-30 10:03:15 -0400 | [diff] [blame] | 699 | !args.fShape->inverseFilled() && args.fShape->knownToBeConvex() && |
| 700 | args.fShape->knownDirection()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 701 | return CanDrawPath::kYes; |
| 702 | } |
| 703 | return CanDrawPath::kNo; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 706 | namespace { |
| 707 | |
| 708 | class AAConvexPathOp final : public GrMeshDrawOp { |
| 709 | private: |
| 710 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 711 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 712 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 713 | DEFINE_OP_CLASS_ID |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 714 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 715 | static GrOp::Owner Make(GrRecordingContext* context, |
| 716 | GrPaint&& paint, |
| 717 | const SkMatrix& viewMatrix, |
| 718 | const SkPath& path, |
| 719 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 720 | return Helper::FactoryHelper<AAConvexPathOp>(context, std::move(paint), viewMatrix, path, |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 721 | stencilSettings); |
| 722 | } |
| 723 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 724 | AAConvexPathOp(GrProcessorSet* processorSet, const SkPMColor4f& color, |
Brian Osman | 936fe7d | 2018-10-30 15:30:35 -0400 | [diff] [blame] | 725 | const SkMatrix& viewMatrix, const SkPath& path, |
| 726 | const GrUserStencilSettings* stencilSettings) |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 727 | : INHERITED(ClassID()), fHelper(processorSet, GrAAType::kCoverage, stencilSettings) { |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 728 | fPaths.emplace_back(PathData{viewMatrix, path, color}); |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 729 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, |
| 730 | IsHairline::kNo); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 731 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 732 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 733 | const char* name() const override { return "AAConvexPathOp"; } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 734 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 735 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 736 | if (fProgramInfo) { |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 737 | fProgramInfo->visitFPProxies(func); |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 738 | } else { |
| 739 | fHelper.visitProxies(func); |
| 740 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 741 | } |
| 742 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 743 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 744 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 745 | GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 746 | GrClampType clampType) override { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 747 | return fHelper.finalizeProcessors( |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 748 | caps, clip, clampType, GrProcessorAnalysisCoverage::kSingleChannel, |
| 749 | &fPaths.back().fColor, &fWideColor); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 750 | } |
| 751 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 752 | private: |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 753 | GrProgramInfo* programInfo() override { return fProgramInfo; } |
| 754 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 755 | void onCreateProgramInfo(const GrCaps* caps, |
| 756 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 757 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 758 | GrAppliedClip&& appliedClip, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 759 | const GrXferProcessor::DstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 760 | GrXferBarrierFlags renderPassXferBarriers, |
| 761 | GrLoadOp colorLoadOp) override { |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 762 | SkMatrix invert; |
| 763 | if (fHelper.usesLocalCoords() && !fPaths.back().fViewMatrix.invert(&invert)) { |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 764 | return; |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | GrGeometryProcessor* quadProcessor = QuadEdgeEffect::Make(arena, invert, |
| 768 | fHelper.usesLocalCoords(), |
| 769 | fWideColor); |
| 770 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 771 | fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 772 | std::move(appliedClip), |
| 773 | dstProxyView, quadProcessor, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 774 | GrPrimitiveType::kTriangles, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 775 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 778 | void onPrepareDraws(Target* target) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 779 | int instanceCount = fPaths.count(); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 780 | |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 781 | if (!fProgramInfo) { |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 782 | this->createProgramInfo(target); |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 783 | if (!fProgramInfo) { |
| 784 | return; |
| 785 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 786 | } |
| 787 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 788 | const size_t kVertexStride = fProgramInfo->geomProc().vertexStride(); |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 789 | |
| 790 | fDraws.reserve(instanceCount); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 791 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 792 | // TODO generate all segments for all paths and use one vertex buffer |
| 793 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 794 | const PathData& args = fPaths[i]; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 795 | |
| 796 | // We use the fact that SkPath::transform path does subdivision based on |
| 797 | // perspective. Otherwise, we apply the view matrix when copying to the |
| 798 | // segment representation. |
| 799 | const SkMatrix* viewMatrix = &args.fViewMatrix; |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 800 | |
| 801 | // We avoid initializing the path unless we have to |
| 802 | const SkPath* pathPtr = &args.fPath; |
| 803 | SkTLazy<SkPath> tmpPath; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 804 | if (viewMatrix->hasPerspective()) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 805 | SkPath* tmpPathPtr = tmpPath.init(*pathPtr); |
| 806 | tmpPathPtr->setIsVolatile(true); |
| 807 | tmpPathPtr->transform(*viewMatrix); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 808 | viewMatrix = &SkMatrix::I(); |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 809 | pathPtr = tmpPathPtr; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | int vertexCount; |
| 813 | int indexCount; |
| 814 | enum { |
| 815 | kPreallocSegmentCnt = 512 / sizeof(Segment), |
| 816 | kPreallocDrawCnt = 4, |
| 817 | }; |
| 818 | SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
| 819 | SkPoint fanPt; |
| 820 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 821 | if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 822 | &indexCount)) { |
| 823 | continue; |
| 824 | } |
| 825 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 826 | sk_sp<const GrBuffer> vertexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 827 | int firstVertex; |
| 828 | |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 829 | GrVertexWriter verts{target->makeVertexSpace(kVertexStride, vertexCount, |
| 830 | &vertexBuffer, &firstVertex)}; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 831 | |
Brian Osman | d2fa2eb | 2018-12-26 16:48:40 -0500 | [diff] [blame] | 832 | if (!verts.fPtr) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 833 | SkDebugf("Could not allocate vertices\n"); |
| 834 | return; |
| 835 | } |
| 836 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 837 | sk_sp<const GrBuffer> indexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 838 | int firstIndex; |
| 839 | |
| 840 | uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex); |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 841 | if (!idxs) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 842 | SkDebugf("Could not allocate indices\n"); |
| 843 | return; |
| 844 | } |
| 845 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 846 | SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 847 | GrVertexColor color(args.fColor, fWideColor); |
| 848 | create_vertices(segments, fanPt, color, &draws, verts, idxs, kVertexStride); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 849 | |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 850 | GrSimpleMesh* meshes = target->allocMeshes(draws.count()); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 851 | for (int j = 0; j < draws.count(); ++j) { |
| 852 | const Draw& draw = draws[j]; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 853 | meshes[j].setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0, |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 854 | draw.fVertexCnt - 1, GrPrimitiveRestart::kNo, vertexBuffer, |
| 855 | firstVertex); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 856 | firstIndex += draw.fIndexCnt; |
| 857 | firstVertex += draw.fVertexCnt; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 858 | } |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 859 | |
| 860 | fDraws.push_back({ meshes, draws.count() }); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 864 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 865 | if (!fProgramInfo || fDraws.isEmpty()) { |
| 866 | return; |
| 867 | } |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 868 | |
Chris Dalton | 765ed36 | 2020-03-16 17:34:44 -0600 | [diff] [blame] | 869 | flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds); |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 870 | flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline()); |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 871 | for (int i = 0; i < fDraws.count(); ++i) { |
Chris Dalton | 765ed36 | 2020-03-16 17:34:44 -0600 | [diff] [blame] | 872 | for (int j = 0; j < fDraws[i].fMeshCount; ++j) { |
| 873 | flushState->drawMesh(fDraws[i].fMeshes[j]); |
| 874 | } |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 875 | } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 878 | CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 879 | AAConvexPathOp* that = t->cast<AAConvexPathOp>(); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 880 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 881 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 882 | } |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 883 | if (fHelper.usesLocalCoords() && |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 884 | !SkMatrixPriv::CheapEqual(fPaths[0].fViewMatrix, that->fPaths[0].fViewMatrix)) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 885 | return CombineResult::kCannotCombine; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 888 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 889 | fWideColor |= that->fWideColor; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 890 | return CombineResult::kMerged; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 891 | } |
| 892 | |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 893 | #if GR_TEST_UTILS |
| 894 | SkString onDumpInfo() const override { |
| 895 | return SkStringPrintf("Count: %d\n%s", fPaths.count(), fHelper.dumpInfo().c_str()); |
| 896 | } |
| 897 | #endif |
| 898 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 899 | struct PathData { |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 900 | SkMatrix fViewMatrix; |
| 901 | SkPath fPath; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 902 | SkPMColor4f fColor; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 903 | }; |
| 904 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 905 | Helper fHelper; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 906 | SkSTArray<1, PathData, true> fPaths; |
Brian Osman | 7f4735b | 2019-01-02 13:55:10 +0000 | [diff] [blame] | 907 | bool fWideColor; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 908 | |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 909 | struct MeshDraw { |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 910 | GrSimpleMesh* fMeshes; |
| 911 | int fMeshCount; |
Robert Phillips | 3eabf4a | 2020-03-10 14:49:20 -0400 | [diff] [blame] | 912 | }; |
| 913 | |
| 914 | SkTDArray<MeshDraw> fDraws; |
| 915 | GrProgramInfo* fProgramInfo = nullptr; |
| 916 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 917 | using INHERITED = GrMeshDrawOp; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 918 | }; |
| 919 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 920 | } // anonymous namespace |
| 921 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 922 | bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 923 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 924 | "GrAAConvexPathRenderer::onDrawPath"); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 925 | SkASSERT(args.fRenderTargetContext->numSamples() <= 1); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 926 | SkASSERT(!args.fShape->isEmpty()); |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 927 | |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 928 | SkPath path; |
| 929 | args.fShape->asPath(&path); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 930 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 931 | GrOp::Owner op = AAConvexPathOp::Make(args.fContext, std::move(args.fPaint), |
| 932 | *args.fViewMatrix, |
| 933 | path, args.fUserStencilSettings); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 934 | args.fRenderTargetContext->addDrawOp(args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 935 | return true; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 936 | } |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 937 | |
| 938 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 939 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 940 | #if GR_TEST_UTILS |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 941 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 942 | GR_DRAW_OP_TEST_DEFINE(AAConvexPathOp) { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 943 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 944 | const SkPath& path = GrTest::TestPathConvex(random); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 945 | const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 946 | return AAConvexPathOp::Make(context, std::move(paint), viewMatrix, path, stencilSettings); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | #endif |