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 | |
| 8 | #include "GrAAConvexPathRenderer.h" |
| 9 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 10 | #include "GrAAConvexTessellator.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 13 | #include "GrDefaultGeoProcFactory.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 14 | #include "GrDrawOpTest.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 15 | #include "GrGeometryProcessor.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 16 | #include "GrOpFlushState.h" |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 17 | #include "GrPathUtils.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 18 | #include "GrProcessor.h" |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 19 | #include "GrSimpleMeshDrawOpHelper.h" |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 20 | #include "SkGeometry.h" |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 21 | #include "SkPathPriv.h" |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 22 | #include "SkString.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 23 | #include "SkTraceEvent.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 24 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 25 | #include "glsl/GrGLSLGeometryProcessor.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 26 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 27 | #include "glsl/GrGLSLUniformHandler.h" |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 28 | #include "glsl/GrGLSLVarying.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 29 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 30 | #include "ops/GrMeshDrawOp.h" |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 31 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 32 | GrAAConvexPathRenderer::GrAAConvexPathRenderer() { |
| 33 | } |
| 34 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 35 | struct Segment { |
| 36 | enum { |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 37 | // These enum values are assumed in member functions below. |
| 38 | kLine = 0, |
| 39 | kQuad = 1, |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 40 | } fType; |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 42 | // line uses one pt, quad uses 2 pts |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 43 | SkPoint fPts[2]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 44 | // normal to edge ending at each pt |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 45 | SkVector fNorms[2]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 46 | // is the corner where the previous segment meets this segment |
| 47 | // sharp. If so, fMid is a normalized bisector facing outward. |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 48 | SkVector fMid; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 49 | |
| 50 | int countPoints() { |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 51 | GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); |
| 52 | return fType + 1; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 53 | } |
| 54 | const SkPoint& endPt() const { |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 55 | GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); |
| 56 | return fPts[fType]; |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 57 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 58 | const SkPoint& endNorm() const { |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 59 | GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); |
| 60 | return fNorms[fType]; |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 61 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | typedef SkTArray<Segment, true> SegmentArray; |
| 65 | |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 66 | static void center_of_mass(const SegmentArray& segments, SkPoint* c) { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 67 | SkScalar area = 0; |
vandebo@chromium.org | 6390c72 | 2012-03-28 21:03:22 +0000 | [diff] [blame] | 68 | SkPoint center = {0, 0}; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 69 | int count = segments.count(); |
vandebo@chromium.org | 6390c72 | 2012-03-28 21:03:22 +0000 | [diff] [blame] | 70 | SkPoint p0 = {0, 0}; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 71 | if (count > 2) { |
| 72 | // We translate the polygon so that the first point is at the origin. |
| 73 | // This avoids some precision issues with small area polygons far away |
| 74 | // from the origin. |
| 75 | p0 = segments[0].endPt(); |
| 76 | SkPoint pi; |
| 77 | SkPoint pj; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 78 | // the first and last iteration of the below loop would compute |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 79 | // zeros since the starting / ending point is (0,0). So instead we start |
| 80 | // at i=1 and make the last iteration i=count-2. |
| 81 | pj = segments[1].endPt() - p0; |
| 82 | for (int i = 1; i < count - 1; ++i) { |
| 83 | pi = pj; |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 84 | pj = segments[i + 1].endPt() - p0; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 85 | |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 86 | SkScalar t = SkPoint::CrossProduct(pi, pj); |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 87 | area += t; |
| 88 | center.fX += (pi.fX + pj.fX) * t; |
| 89 | center.fY += (pi.fY + pj.fY) * t; |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 90 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 91 | } |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 92 | |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 93 | // If the poly has no area then we instead return the average of |
| 94 | // its points. |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 95 | if (SkScalarNearlyZero(area)) { |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 96 | SkPoint avg; |
| 97 | avg.set(0, 0); |
| 98 | for (int i = 0; i < count; ++i) { |
| 99 | const SkPoint& pt = segments[i].endPt(); |
| 100 | avg.fX += pt.fX; |
| 101 | avg.fY += pt.fY; |
| 102 | } |
| 103 | SkScalar denom = SK_Scalar1 / count; |
| 104 | avg.scale(denom); |
| 105 | *c = avg; |
| 106 | } else { |
| 107 | area *= 3; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 108 | area = SkScalarInvert(area); |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 109 | center.scale(area); |
bsalomon@google.com | 5b56d9e | 2012-02-23 19:18:37 +0000 | [diff] [blame] | 110 | // undo the translate of p0 to the origin. |
| 111 | *c = center + p0; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 112 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 113 | SkASSERT(!SkScalarIsNaN(c->fX) && !SkScalarIsNaN(c->fY)); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 114 | } |
| 115 | |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 116 | static void compute_vectors(SegmentArray* segments, |
| 117 | SkPoint* fanPt, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 118 | SkPathPriv::FirstDirection dir, |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 119 | int* vCount, |
| 120 | int* iCount) { |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 121 | center_of_mass(*segments, fanPt); |
| 122 | int count = segments->count(); |
| 123 | |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 124 | // Make the normals point towards the outside |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 125 | SkPoint::Side normSide; |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 126 | if (dir == SkPathPriv::kCCW_FirstDirection) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 127 | normSide = SkPoint::kRight_Side; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 128 | } else { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 129 | normSide = SkPoint::kLeft_Side; |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 130 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 131 | |
| 132 | *vCount = 0; |
| 133 | *iCount = 0; |
| 134 | // compute normals at all points |
| 135 | for (int a = 0; a < count; ++a) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 136 | Segment& sega = (*segments)[a]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 137 | int b = (a + 1) % count; |
| 138 | Segment& segb = (*segments)[b]; |
| 139 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 140 | const SkPoint* prevPt = &sega.endPt(); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 141 | int n = segb.countPoints(); |
| 142 | for (int p = 0; p < n; ++p) { |
| 143 | segb.fNorms[p] = segb.fPts[p] - *prevPt; |
| 144 | segb.fNorms[p].normalize(); |
| 145 | segb.fNorms[p].setOrthog(segb.fNorms[p], normSide); |
| 146 | prevPt = &segb.fPts[p]; |
| 147 | } |
| 148 | if (Segment::kLine == segb.fType) { |
| 149 | *vCount += 5; |
| 150 | *iCount += 9; |
| 151 | } else { |
| 152 | *vCount += 6; |
| 153 | *iCount += 12; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // compute mid-vectors where segments meet. TODO: Detect shallow corners |
| 158 | // and leave out the wedges and close gaps by stitching segments together. |
| 159 | for (int a = 0; a < count; ++a) { |
| 160 | const Segment& sega = (*segments)[a]; |
| 161 | int b = (a + 1) % count; |
| 162 | Segment& segb = (*segments)[b]; |
| 163 | segb.fMid = segb.fNorms[0] + sega.endNorm(); |
| 164 | segb.fMid.normalize(); |
| 165 | // corner wedges |
| 166 | *vCount += 4; |
| 167 | *iCount += 6; |
| 168 | } |
| 169 | } |
| 170 | |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 171 | struct DegenerateTestData { |
| 172 | DegenerateTestData() { fStage = kInitial; } |
| 173 | bool isDegenerate() const { return kNonDegenerate != fStage; } |
| 174 | enum { |
| 175 | kInitial, |
| 176 | kPoint, |
| 177 | kLine, |
| 178 | kNonDegenerate |
| 179 | } fStage; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 180 | SkPoint fFirstPoint; |
| 181 | SkVector fLineNormal; |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 182 | SkScalar fLineC; |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 185 | static const SkScalar kClose = (SK_Scalar1 / 16); |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 186 | static const SkScalar kCloseSqd = kClose * kClose; |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 187 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 188 | static void update_degenerate_test(DegenerateTestData* data, const SkPoint& pt) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 189 | switch (data->fStage) { |
| 190 | case DegenerateTestData::kInitial: |
| 191 | data->fFirstPoint = pt; |
| 192 | data->fStage = DegenerateTestData::kPoint; |
| 193 | break; |
| 194 | case DegenerateTestData::kPoint: |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 195 | if (pt.distanceToSqd(data->fFirstPoint) > kCloseSqd) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 196 | data->fLineNormal = pt - data->fFirstPoint; |
| 197 | data->fLineNormal.normalize(); |
| 198 | data->fLineNormal.setOrthog(data->fLineNormal); |
| 199 | data->fLineC = -data->fLineNormal.dot(data->fFirstPoint); |
| 200 | data->fStage = DegenerateTestData::kLine; |
| 201 | } |
| 202 | break; |
| 203 | case DegenerateTestData::kLine: |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 204 | if (SkScalarAbs(data->fLineNormal.dot(pt) + data->fLineC) > kClose) { |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 205 | data->fStage = DegenerateTestData::kNonDegenerate; |
| 206 | } |
| 207 | case DegenerateTestData::kNonDegenerate: |
| 208 | break; |
| 209 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 210 | SK_ABORT("Unexpected degenerate test stage."); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 214 | static inline bool get_direction(const SkPath& path, const SkMatrix& m, |
| 215 | SkPathPriv::FirstDirection* dir) { |
| 216 | if (!SkPathPriv::CheapComputeFirstDirection(path, dir)) { |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 217 | return false; |
| 218 | } |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 219 | // check whether m reverses the orientation |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 220 | SkASSERT(!m.hasPerspective()); |
Mike Reed | 8be952a | 2017-02-13 20:44:33 -0500 | [diff] [blame] | 221 | SkScalar det2x2 = m.get(SkMatrix::kMScaleX) * m.get(SkMatrix::kMScaleY) - |
| 222 | m.get(SkMatrix::kMSkewX) * m.get(SkMatrix::kMSkewY); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 223 | if (det2x2 < 0) { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 224 | *dir = SkPathPriv::OppositeFirstDirection(*dir); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 225 | } |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 226 | return true; |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 227 | } |
| 228 | |
commit-bot@chromium.org | 106655e | 2013-09-03 21:28:55 +0000 | [diff] [blame] | 229 | static inline void add_line_to_segment(const SkPoint& pt, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 230 | SegmentArray* segments) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 231 | segments->push_back(); |
| 232 | segments->back().fType = Segment::kLine; |
| 233 | segments->back().fPts[0] = pt; |
| 234 | } |
| 235 | |
commit-bot@chromium.org | 106655e | 2013-09-03 21:28:55 +0000 | [diff] [blame] | 236 | static inline void add_quad_segment(const SkPoint pts[3], |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 237 | SegmentArray* segments) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 238 | if (pts[0].distanceToSqd(pts[1]) < kCloseSqd || pts[1].distanceToSqd(pts[2]) < kCloseSqd) { |
| 239 | if (pts[0] != pts[2]) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 240 | add_line_to_segment(pts[2], segments); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 241 | } |
| 242 | } else { |
| 243 | segments->push_back(); |
| 244 | segments->back().fType = Segment::kQuad; |
| 245 | segments->back().fPts[0] = pts[1]; |
| 246 | segments->back().fPts[1] = pts[2]; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | static inline void add_cubic_segments(const SkPoint pts[4], |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 251 | SkPathPriv::FirstDirection dir, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 252 | SegmentArray* segments) { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 253 | SkSTArray<15, SkPoint, true> quads; |
bsalomon | 18fab30 | 2016-02-16 08:00:05 -0800 | [diff] [blame] | 254 | GrPathUtils::convertCubicToQuadsConstrainToTangents(pts, SK_Scalar1, dir, &quads); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 255 | int count = quads.count(); |
| 256 | for (int q = 0; q < count; q += 3) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 257 | add_quad_segment(&quads[q], segments); |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | static bool get_segments(const SkPath& path, |
| 262 | const SkMatrix& m, |
| 263 | SegmentArray* segments, |
| 264 | SkPoint* fanPt, |
| 265 | int* vCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 266 | int* iCount) { |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 267 | SkPath::Iter iter(path, true); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 268 | // 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] | 269 | // to the path from the sample to compute coverage. Every pixel intersected |
| 270 | // 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] | 271 | // 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] | 272 | // thus should be very light. This is particularly egregious for degenerate |
| 273 | // line paths. We detect paths that are very close to a line (zero area) and |
| 274 | // draw nothing. |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 275 | DegenerateTestData degenerateData; |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 276 | SkPathPriv::FirstDirection dir; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 277 | // get_direction can fail for some degenerate paths. |
| 278 | if (!get_direction(path, m, &dir)) { |
| 279 | return false; |
| 280 | } |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 281 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 282 | for (;;) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 283 | SkPoint pts[4]; |
Brian Salomon | 97042bf | 2017-02-28 11:21:28 -0500 | [diff] [blame] | 284 | SkPath::Verb verb = iter.next(pts, true, true); |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 285 | switch (verb) { |
| 286 | case SkPath::kMove_Verb: |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 287 | m.mapPoints(pts, 1); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 288 | update_degenerate_test(°enerateData, pts[0]); |
| 289 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 290 | case SkPath::kLine_Verb: { |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 291 | m.mapPoints(&pts[1], 1); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 292 | update_degenerate_test(°enerateData, pts[1]); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 293 | add_line_to_segment(pts[1], segments); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 294 | break; |
| 295 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 296 | case SkPath::kQuad_Verb: |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 297 | m.mapPoints(pts, 3); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 298 | update_degenerate_test(°enerateData, pts[1]); |
| 299 | update_degenerate_test(°enerateData, pts[2]); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 300 | add_quad_segment(pts, segments); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 301 | break; |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 302 | case SkPath::kConic_Verb: { |
| 303 | m.mapPoints(pts, 3); |
| 304 | SkScalar weight = iter.conicWeight(); |
| 305 | SkAutoConicToQuads converter; |
| 306 | const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.5f); |
| 307 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 308 | update_degenerate_test(°enerateData, quadPts[2*i + 1]); |
| 309 | update_degenerate_test(°enerateData, quadPts[2*i + 2]); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 310 | add_quad_segment(quadPts + 2*i, segments); |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 311 | } |
| 312 | break; |
| 313 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 314 | case SkPath::kCubic_Verb: { |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 315 | m.mapPoints(pts, 4); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 316 | update_degenerate_test(°enerateData, pts[1]); |
| 317 | update_degenerate_test(°enerateData, pts[2]); |
| 318 | update_degenerate_test(°enerateData, pts[3]); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 319 | add_cubic_segments(pts, dir, segments); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 320 | break; |
| 321 | }; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 322 | case SkPath::kDone_Verb: |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 323 | if (degenerateData.isDegenerate()) { |
| 324 | return false; |
| 325 | } else { |
bsalomon@google.com | 278dc69 | 2012-02-15 16:52:51 +0000 | [diff] [blame] | 326 | compute_vectors(segments, fanPt, dir, vCount, iCount); |
bsalomon@google.com | 9732f62 | 2012-01-31 15:19:21 +0000 | [diff] [blame] | 327 | return true; |
| 328 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | struct QuadVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 336 | SkPoint fPos; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 337 | GrColor fColor; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 338 | SkPoint fUV; |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 339 | SkScalar fD0; |
| 340 | SkScalar fD1; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 341 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 342 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 343 | struct Draw { |
| 344 | Draw() : fVertexCnt(0), fIndexCnt(0) {} |
| 345 | int fVertexCnt; |
| 346 | int fIndexCnt; |
| 347 | }; |
| 348 | |
| 349 | typedef SkTArray<Draw, true> DrawArray; |
| 350 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 351 | static void create_vertices(const SegmentArray& segments, |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 352 | const SkPoint& fanPt, |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 353 | GrColor color, |
| 354 | DrawArray* draws, |
| 355 | QuadVertex* verts, |
| 356 | uint16_t* idxs) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 357 | Draw* draw = &draws->push_back(); |
| 358 | // alias just to make vert/index assignments easier to read. |
| 359 | int* v = &draw->fVertexCnt; |
| 360 | int* i = &draw->fIndexCnt; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 361 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 362 | int count = segments.count(); |
| 363 | for (int a = 0; a < count; ++a) { |
| 364 | const Segment& sega = segments[a]; |
| 365 | int b = (a + 1) % count; |
| 366 | const Segment& segb = segments[b]; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 367 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 368 | // Check whether adding the verts for this segment to the current draw would cause index |
| 369 | // values to overflow. |
| 370 | int vCount = 4; |
| 371 | if (Segment::kLine == segb.fType) { |
| 372 | vCount += 5; |
| 373 | } else { |
| 374 | vCount += 6; |
| 375 | } |
| 376 | if (draw->fVertexCnt + vCount > (1 << 16)) { |
| 377 | verts += *v; |
| 378 | idxs += *i; |
| 379 | draw = &draws->push_back(); |
| 380 | v = &draw->fVertexCnt; |
| 381 | i = &draw->fIndexCnt; |
| 382 | } |
| 383 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 384 | // FIXME: These tris are inset in the 1 unit arc around the corner |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 385 | verts[*v + 0].fPos = sega.endPt(); |
| 386 | verts[*v + 1].fPos = verts[*v + 0].fPos + sega.endNorm(); |
| 387 | verts[*v + 2].fPos = verts[*v + 0].fPos + segb.fMid; |
| 388 | verts[*v + 3].fPos = verts[*v + 0].fPos + segb.fNorms[0]; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 389 | verts[*v + 0].fColor = color; |
| 390 | verts[*v + 1].fColor = color; |
| 391 | verts[*v + 2].fColor = color; |
| 392 | verts[*v + 3].fColor = color; |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 393 | verts[*v + 0].fUV.set(0,0); |
| 394 | verts[*v + 1].fUV.set(0,-SK_Scalar1); |
| 395 | verts[*v + 2].fUV.set(0,-SK_Scalar1); |
| 396 | verts[*v + 3].fUV.set(0,-SK_Scalar1); |
| 397 | verts[*v + 0].fD0 = verts[*v + 0].fD1 = -SK_Scalar1; |
| 398 | verts[*v + 1].fD0 = verts[*v + 1].fD1 = -SK_Scalar1; |
| 399 | verts[*v + 2].fD0 = verts[*v + 2].fD1 = -SK_Scalar1; |
| 400 | verts[*v + 3].fD0 = verts[*v + 3].fD1 = -SK_Scalar1; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 401 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 402 | idxs[*i + 0] = *v + 0; |
| 403 | idxs[*i + 1] = *v + 2; |
| 404 | idxs[*i + 2] = *v + 1; |
| 405 | idxs[*i + 3] = *v + 0; |
| 406 | idxs[*i + 4] = *v + 3; |
| 407 | idxs[*i + 5] = *v + 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 408 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 409 | *v += 4; |
| 410 | *i += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 411 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 412 | if (Segment::kLine == segb.fType) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 413 | verts[*v + 0].fPos = fanPt; |
| 414 | verts[*v + 1].fPos = sega.endPt(); |
| 415 | verts[*v + 2].fPos = segb.fPts[0]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 416 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 417 | verts[*v + 3].fPos = verts[*v + 1].fPos + segb.fNorms[0]; |
| 418 | verts[*v + 4].fPos = verts[*v + 2].fPos + segb.fNorms[0]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 419 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 420 | verts[*v + 0].fColor = color; |
| 421 | verts[*v + 1].fColor = color; |
| 422 | verts[*v + 2].fColor = color; |
| 423 | verts[*v + 3].fColor = color; |
| 424 | verts[*v + 4].fColor = color; |
| 425 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 426 | // we draw the line edge as a degenerate quad (u is 0, v is the |
| 427 | // signed distance to the edge) |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 428 | SkScalar dist = fanPt.distanceToLineBetween(verts[*v + 1].fPos, |
| 429 | verts[*v + 2].fPos); |
| 430 | verts[*v + 0].fUV.set(0, dist); |
| 431 | verts[*v + 1].fUV.set(0, 0); |
| 432 | verts[*v + 2].fUV.set(0, 0); |
| 433 | verts[*v + 3].fUV.set(0, -SK_Scalar1); |
| 434 | verts[*v + 4].fUV.set(0, -SK_Scalar1); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 435 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 436 | verts[*v + 0].fD0 = verts[*v + 0].fD1 = -SK_Scalar1; |
| 437 | verts[*v + 1].fD0 = verts[*v + 1].fD1 = -SK_Scalar1; |
| 438 | verts[*v + 2].fD0 = verts[*v + 2].fD1 = -SK_Scalar1; |
| 439 | verts[*v + 3].fD0 = verts[*v + 3].fD1 = -SK_Scalar1; |
| 440 | verts[*v + 4].fD0 = verts[*v + 4].fD1 = -SK_Scalar1; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 441 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 442 | idxs[*i + 0] = *v + 3; |
| 443 | idxs[*i + 1] = *v + 1; |
| 444 | idxs[*i + 2] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 445 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 446 | idxs[*i + 3] = *v + 4; |
| 447 | idxs[*i + 4] = *v + 3; |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 448 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 449 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 450 | *i += 6; |
| 451 | |
| 452 | // Draw the interior fan if it exists. |
| 453 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 454 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 455 | if (count >= 3) { |
| 456 | idxs[*i + 0] = *v + 0; |
| 457 | idxs[*i + 1] = *v + 2; |
| 458 | idxs[*i + 2] = *v + 1; |
| 459 | |
| 460 | *i += 3; |
| 461 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 462 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 463 | *v += 5; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 464 | } else { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 465 | SkPoint qpts[] = {sega.endPt(), segb.fPts[0], segb.fPts[1]}; |
bsalomon@google.com | 495e210 | 2012-01-21 14:48:36 +0000 | [diff] [blame] | 466 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 467 | SkVector midVec = segb.fNorms[0] + segb.fNorms[1]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 468 | midVec.normalize(); |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 469 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 470 | verts[*v + 0].fPos = fanPt; |
| 471 | verts[*v + 1].fPos = qpts[0]; |
| 472 | verts[*v + 2].fPos = qpts[2]; |
| 473 | verts[*v + 3].fPos = qpts[0] + segb.fNorms[0]; |
| 474 | verts[*v + 4].fPos = qpts[2] + segb.fNorms[1]; |
| 475 | verts[*v + 5].fPos = qpts[1] + midVec; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 476 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 477 | verts[*v + 0].fColor = color; |
| 478 | verts[*v + 1].fColor = color; |
| 479 | verts[*v + 2].fColor = color; |
| 480 | verts[*v + 3].fColor = color; |
| 481 | verts[*v + 4].fColor = color; |
| 482 | verts[*v + 5].fColor = color; |
| 483 | |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 484 | SkScalar c = segb.fNorms[0].dot(qpts[0]); |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 485 | verts[*v + 0].fD0 = -segb.fNorms[0].dot(fanPt) + c; |
| 486 | verts[*v + 1].fD0 = 0.f; |
| 487 | verts[*v + 2].fD0 = -segb.fNorms[0].dot(qpts[2]) + c; |
| 488 | verts[*v + 3].fD0 = -SK_ScalarMax/100; |
| 489 | verts[*v + 4].fD0 = -SK_ScalarMax/100; |
| 490 | verts[*v + 5].fD0 = -SK_ScalarMax/100; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 491 | |
| 492 | c = segb.fNorms[1].dot(qpts[2]); |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 493 | verts[*v + 0].fD1 = -segb.fNorms[1].dot(fanPt) + c; |
| 494 | verts[*v + 1].fD1 = -segb.fNorms[1].dot(qpts[0]) + c; |
| 495 | verts[*v + 2].fD1 = 0.f; |
| 496 | verts[*v + 3].fD1 = -SK_ScalarMax/100; |
| 497 | verts[*v + 4].fD1 = -SK_ScalarMax/100; |
| 498 | verts[*v + 5].fD1 = -SK_ScalarMax/100; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 499 | |
bsalomon@google.com | 1971317 | 2012-03-15 13:51:08 +0000 | [diff] [blame] | 500 | GrPathUtils::QuadUVMatrix toUV(qpts); |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 501 | toUV.apply<6, sizeof(QuadVertex), offsetof(QuadVertex, fUV)>(verts + *v); |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 502 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 503 | idxs[*i + 0] = *v + 3; |
| 504 | idxs[*i + 1] = *v + 1; |
| 505 | idxs[*i + 2] = *v + 2; |
| 506 | idxs[*i + 3] = *v + 4; |
| 507 | idxs[*i + 4] = *v + 3; |
| 508 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 510 | idxs[*i + 6] = *v + 5; |
| 511 | idxs[*i + 7] = *v + 3; |
| 512 | idxs[*i + 8] = *v + 4; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 513 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 514 | *i += 9; |
| 515 | |
| 516 | // Draw the interior fan if it exists. |
| 517 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 518 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 519 | if (count >= 3) { |
| 520 | idxs[*i + 0] = *v + 0; |
| 521 | idxs[*i + 1] = *v + 2; |
| 522 | idxs[*i + 2] = *v + 1; |
| 523 | |
| 524 | *i += 3; |
| 525 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 526 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 527 | *v += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 532 | /////////////////////////////////////////////////////////////////////////////// |
| 533 | |
| 534 | /* |
| 535 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 536 | * two components of the vertex attribute. Coverage is based on signed |
| 537 | * distance with negative being inside, positive outside. The edge is specified in |
| 538 | * window space (y-down). If either the third or fourth component of the interpolated |
| 539 | * 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] | 540 | * attempt to trim to a portion of the infinite quad. |
| 541 | * Requires shader derivative instruction support. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 542 | */ |
| 543 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 544 | class QuadEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 545 | public: |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 546 | static sk_sp<GrGeometryProcessor> Make(const SkMatrix& localMatrix, bool usesLocalCoords) { |
| 547 | return sk_sp<GrGeometryProcessor>(new QuadEdgeEffect(localMatrix, usesLocalCoords)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 550 | ~QuadEdgeEffect() override {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 551 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 552 | const char* name() const override { return "QuadEdge"; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 553 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 554 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 555 | public: |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 556 | GLSLProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 557 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 558 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 559 | const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 560 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 561 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 562 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 563 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 564 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 565 | varyingHandler->emitAttributes(qe); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 566 | |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 567 | GrGLSLVertToFrag v(kVec4f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 568 | varyingHandler->addVarying("QuadEdge", &v); |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 569 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge->fName); |
| 570 | |
| 571 | // Setup pass through color |
| 572 | varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 573 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 574 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 575 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 576 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 577 | this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition->fName); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 578 | |
| 579 | // emit transforms |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 580 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 581 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 582 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 583 | gpArgs->fPositionVar, |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 584 | qe.fInPosition->fName, |
| 585 | qe.fLocalMatrix, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 586 | args.fFPCoordTransformHandler); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 587 | |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 588 | fragBuilder->codeAppendf("float edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 589 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 590 | // keep the derivative instructions outside the conditional |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 591 | fragBuilder->codeAppendf("float2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 592 | fragBuilder->codeAppendf("float2 duvdy = dFdy(%s.xy);", v.fsIn()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 593 | 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] | 594 | // today we know z and w are in device space. We could use derivatives |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 595 | fragBuilder->codeAppendf("edgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);", v.fsIn(), |
| 596 | v.fsIn()); |
| 597 | fragBuilder->codeAppendf ("} else {"); |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 598 | fragBuilder->codeAppendf("float2 gF = float2(2.0*%s.x*duvdx.x - duvdx.y," |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 599 | " 2.0*%s.x*duvdy.x - duvdy.y);", |
| 600 | v.fsIn(), v.fsIn()); |
| 601 | fragBuilder->codeAppendf("edgeAlpha = (%s.x*%s.x - %s.y);", v.fsIn(), v.fsIn(), |
| 602 | v.fsIn()); |
| 603 | fragBuilder->codeAppendf("edgeAlpha = " |
| 604 | "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);}"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 605 | |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 606 | fragBuilder->codeAppendf("%s = float4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 607 | } |
| 608 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 609 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 610 | const GrShaderCaps&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 611 | GrProcessorKeyBuilder* b) { |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 612 | const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 613 | b->add32(SkToBool(qee.fUsesLocalCoords && qee.fLocalMatrix.hasPerspective())); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 614 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 615 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 616 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 617 | const GrPrimitiveProcessor& gp, |
| 618 | FPCoordTransformIter&& transformIter) override { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 619 | const QuadEdgeEffect& qe = gp.cast<QuadEdgeEffect>(); |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 620 | this->setTransformDataHelper(qe.fLocalMatrix, pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 621 | } |
| 622 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 623 | private: |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 624 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 625 | }; |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 626 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 627 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 628 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 631 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 632 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 633 | } |
| 634 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 635 | private: |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 636 | QuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords) |
| 637 | : fLocalMatrix(localMatrix), fUsesLocalCoords(usesLocalCoords) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 638 | this->initClassID<QuadEdgeEffect>(); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 639 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType); |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 640 | fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribType); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 641 | fInQuadEdge = &this->addVertexAttrib("inQuadEdge", kVec4f_GrVertexAttribType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 642 | } |
| 643 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 644 | const Attribute* fInPosition; |
| 645 | const Attribute* fInQuadEdge; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 646 | const Attribute* fInColor; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 647 | SkMatrix fLocalMatrix; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 648 | bool fUsesLocalCoords; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 649 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 650 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 651 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 652 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 653 | }; |
| 654 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 655 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 656 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 657 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 658 | sk_sp<GrGeometryProcessor> QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 659 | // Doesn't work without derivative instructions. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 660 | return d->caps()->shaderCaps()->shaderDerivativeSupport() |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 661 | ? QuadEdgeEffect::Make(GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool()) |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 662 | : nullptr; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 663 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 664 | #endif |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 665 | |
| 666 | /////////////////////////////////////////////////////////////////////////////// |
| 667 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame^] | 668 | GrPathRenderer::CanDrawPath |
| 669 | GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
| 670 | if (args.fCaps->shaderCaps()->shaderDerivativeSupport() && |
| 671 | (GrAAType::kCoverage == args.fAAType) && args.fShape->style().isSimpleFill() && |
| 672 | !args.fShape->inverseFilled() && args.fShape->knownToBeConvex()) { |
| 673 | return CanDrawPath::kYes; |
| 674 | } |
| 675 | return CanDrawPath::kNo; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 676 | } |
| 677 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 678 | // extract the result vertices and indices from the GrAAConvexTessellator |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 679 | static void extract_lines_only_verts(const GrAAConvexTessellator& tess, |
| 680 | void* vertices, |
| 681 | size_t vertexStride, |
| 682 | GrColor color, |
| 683 | uint16_t* idxs, |
| 684 | bool tweakAlphaForCoverage) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 685 | intptr_t verts = reinterpret_cast<intptr_t>(vertices); |
| 686 | |
| 687 | for (int i = 0; i < tess.numPts(); ++i) { |
| 688 | *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i); |
| 689 | } |
| 690 | |
| 691 | // Make 'verts' point to the colors |
| 692 | verts += sizeof(SkPoint); |
| 693 | for (int i = 0; i < tess.numPts(); ++i) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 694 | if (tweakAlphaForCoverage) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 695 | SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| 696 | unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 697 | GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 698 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| 699 | } else { |
| 700 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 701 | *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 702 | tess.coverage(i); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | for (int i = 0; i < tess.numIndices(); ++i) { |
| 707 | idxs[i] = tess.index(i); |
| 708 | } |
| 709 | } |
| 710 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 711 | static sk_sp<GrGeometryProcessor> make_lines_only_gp(bool tweakAlphaForCoverage, |
| 712 | const SkMatrix& viewMatrix, |
| 713 | bool usesLocalCoords) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 714 | using namespace GrDefaultGeoProcFactory; |
joshualitt | e494a58 | 2015-08-03 09:32:36 -0700 | [diff] [blame] | 715 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 716 | Coverage::Type coverageType; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 717 | if (tweakAlphaForCoverage) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 718 | coverageType = Coverage::kSolid_Type; |
| 719 | } else { |
| 720 | coverageType = Coverage::kAttribute_Type; |
| 721 | } |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 722 | LocalCoords::Type localCoordsType = |
| 723 | usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 724 | return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType, |
| 725 | viewMatrix); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 728 | namespace { |
| 729 | |
| 730 | class AAConvexPathOp final : public GrMeshDrawOp { |
| 731 | private: |
| 732 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 733 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 734 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 735 | DEFINE_OP_CLASS_ID |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 736 | static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint, const SkMatrix& viewMatrix, |
| 737 | const SkPath& path, |
| 738 | const GrUserStencilSettings* stencilSettings) { |
| 739 | return Helper::FactoryHelper<AAConvexPathOp>(std::move(paint), viewMatrix, path, |
| 740 | stencilSettings); |
| 741 | } |
| 742 | |
| 743 | AAConvexPathOp(const Helper::MakeArgs& helperArgs, GrColor color, const SkMatrix& viewMatrix, |
| 744 | const SkPath& path, const GrUserStencilSettings* stencilSettings) |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 745 | : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) { |
| 746 | fPaths.emplace_back(PathData{viewMatrix, path, color}); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 747 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); |
| 748 | fLinesOnly = SkPath::kLine_SegmentMask == path.getSegmentMasks(); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 749 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 750 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 751 | const char* name() const override { return "AAConvexPathOp"; } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 752 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 753 | SkString dumpInfo() const override { |
| 754 | SkString string; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 755 | string.appendf("Count: %d\n", fPaths.count()); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 756 | string += fHelper.dumpInfo(); |
| 757 | string += INHERITED::dumpInfo(); |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 758 | return string; |
| 759 | } |
| 760 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 761 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 762 | |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 763 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 764 | return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel, |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 765 | &fPaths.back().fColor); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 766 | } |
| 767 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 768 | private: |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 769 | void prepareLinesOnlyDraws(Target* target) { |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 770 | // Setup GrGeometryProcessor |
| 771 | sk_sp<GrGeometryProcessor> gp(make_lines_only_gp(fHelper.compatibleWithAlphaAsCoverage(), |
| 772 | fPaths.back().fViewMatrix, |
| 773 | fHelper.usesLocalCoords())); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 774 | if (!gp) { |
| 775 | SkDebugf("Could not create GrGeometryProcessor\n"); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 779 | size_t vertexStride = gp->getVertexStride(); |
| 780 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 781 | SkASSERT(fHelper.compatibleWithAlphaAsCoverage() |
| 782 | ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) |
| 783 | : vertexStride == |
| 784 | sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 785 | |
| 786 | GrAAConvexTessellator tess; |
| 787 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 788 | int instanceCount = fPaths.count(); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 789 | const GrPipeline* pipeline = fHelper.makePipeline(target); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 790 | for (int i = 0; i < instanceCount; i++) { |
| 791 | tess.rewind(); |
| 792 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 793 | const PathData& args = fPaths[i]; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 794 | |
| 795 | if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 796 | continue; |
| 797 | } |
| 798 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 799 | const GrBuffer* vertexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 800 | int firstVertex; |
| 801 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 802 | void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), &vertexBuffer, |
| 803 | &firstVertex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 804 | if (!verts) { |
| 805 | SkDebugf("Could not allocate vertices\n"); |
| 806 | return; |
| 807 | } |
| 808 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 809 | const GrBuffer* indexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 810 | int firstIndex; |
| 811 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 812 | uint16_t* idxs = target->makeIndexSpace(tess.numIndices(), &indexBuffer, &firstIndex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 813 | if (!idxs) { |
| 814 | SkDebugf("Could not allocate indices\n"); |
| 815 | return; |
| 816 | } |
| 817 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 818 | extract_lines_only_verts(tess, verts, vertexStride, args.fColor, idxs, |
| 819 | fHelper.compatibleWithAlphaAsCoverage()); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 820 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 821 | GrMesh mesh(GrPrimitiveType::kTriangles); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 822 | mesh.setIndexed(indexBuffer, tess.numIndices(), firstIndex, 0, tess.numPts() - 1); |
| 823 | mesh.setVertexData(vertexBuffer, firstVertex); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 824 | target->draw(gp.get(), pipeline, mesh); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 825 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 826 | } |
| 827 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 828 | void onPrepareDraws(Target* target) override { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 829 | #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 830 | if (fLinesOnly) { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 831 | this->prepareLinesOnlyDraws(target); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 832 | return; |
| 833 | } |
| 834 | #endif |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 835 | const GrPipeline* pipeline = fHelper.makePipeline(target); |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 836 | int instanceCount = fPaths.count(); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 837 | |
| 838 | SkMatrix invert; |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 839 | if (fHelper.usesLocalCoords() && !fPaths.back().fViewMatrix.invert(&invert)) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 840 | SkDebugf("Could not invert viewmatrix\n"); |
| 841 | return; |
| 842 | } |
| 843 | |
| 844 | // Setup GrGeometryProcessor |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 845 | sk_sp<GrGeometryProcessor> quadProcessor( |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 846 | QuadEdgeEffect::Make(invert, fHelper.usesLocalCoords())); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 847 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 848 | // TODO generate all segments for all paths and use one vertex buffer |
| 849 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 850 | const PathData& args = fPaths[i]; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 851 | |
| 852 | // We use the fact that SkPath::transform path does subdivision based on |
| 853 | // perspective. Otherwise, we apply the view matrix when copying to the |
| 854 | // segment representation. |
| 855 | const SkMatrix* viewMatrix = &args.fViewMatrix; |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 856 | |
| 857 | // We avoid initializing the path unless we have to |
| 858 | const SkPath* pathPtr = &args.fPath; |
| 859 | SkTLazy<SkPath> tmpPath; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 860 | if (viewMatrix->hasPerspective()) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 861 | SkPath* tmpPathPtr = tmpPath.init(*pathPtr); |
| 862 | tmpPathPtr->setIsVolatile(true); |
| 863 | tmpPathPtr->transform(*viewMatrix); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 864 | viewMatrix = &SkMatrix::I(); |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 865 | pathPtr = tmpPathPtr; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | int vertexCount; |
| 869 | int indexCount; |
| 870 | enum { |
| 871 | kPreallocSegmentCnt = 512 / sizeof(Segment), |
| 872 | kPreallocDrawCnt = 4, |
| 873 | }; |
| 874 | SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
| 875 | SkPoint fanPt; |
| 876 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 877 | if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 878 | &indexCount)) { |
| 879 | continue; |
| 880 | } |
| 881 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 882 | const GrBuffer* vertexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 883 | int firstVertex; |
| 884 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 885 | size_t vertexStride = quadProcessor->getVertexStride(); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 886 | QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace( |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 887 | vertexStride, vertexCount, &vertexBuffer, &firstVertex)); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 888 | |
| 889 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 890 | SkDebugf("Could not allocate vertices\n"); |
| 891 | return; |
| 892 | } |
| 893 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 894 | const GrBuffer* indexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 895 | int firstIndex; |
| 896 | |
| 897 | uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex); |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 898 | if (!idxs) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 899 | SkDebugf("Could not allocate indices\n"); |
| 900 | return; |
| 901 | } |
| 902 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 903 | SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 904 | create_vertices(segments, fanPt, args.fColor, &draws, verts, idxs); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 905 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 906 | GrMesh mesh(GrPrimitiveType::kTriangles); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 907 | |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 908 | for (int j = 0; j < draws.count(); ++j) { |
| 909 | const Draw& draw = draws[j]; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 910 | mesh.setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0, draw.fVertexCnt - 1); |
| 911 | mesh.setVertexData(vertexBuffer, firstVertex); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 912 | target->draw(quadProcessor.get(), pipeline, mesh); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 913 | firstIndex += draw.fIndexCnt; |
| 914 | firstVertex += draw.fVertexCnt; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 919 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 920 | AAConvexPathOp* that = t->cast<AAConvexPathOp>(); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 921 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 922 | return false; |
| 923 | } |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 924 | if (fHelper.usesLocalCoords() && |
| 925 | !fPaths[0].fViewMatrix.cheapEqualTo(that->fPaths[0].fViewMatrix)) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 926 | return false; |
| 927 | } |
| 928 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 929 | if (fLinesOnly != that->fLinesOnly) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 930 | return false; |
| 931 | } |
| 932 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 933 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 934 | this->joinBounds(*that); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 935 | return true; |
| 936 | } |
| 937 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 938 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 939 | SkMatrix fViewMatrix; |
| 940 | SkPath fPath; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 941 | GrColor fColor; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 942 | }; |
| 943 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 944 | Helper fHelper; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 945 | SkSTArray<1, PathData, true> fPaths; |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 946 | bool fLinesOnly; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 947 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 948 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 949 | }; |
| 950 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 951 | } // anonymous namespace |
| 952 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 953 | bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 954 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 955 | "GrAAConvexPathRenderer::onDrawPath"); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 956 | SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType()); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 957 | SkASSERT(!args.fShape->isEmpty()); |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 958 | |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 959 | SkPath path; |
| 960 | args.fShape->asPath(&path); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 961 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 962 | std::unique_ptr<GrDrawOp> op = AAConvexPathOp::Make(std::move(args.fPaint), *args.fViewMatrix, |
| 963 | path, args.fUserStencilSettings); |
| 964 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 965 | return true; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 966 | } |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 967 | |
| 968 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 969 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 970 | #if GR_TEST_UTILS |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 971 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 972 | GR_DRAW_OP_TEST_DEFINE(AAConvexPathOp) { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 973 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 974 | SkPath path = GrTest::TestPathConvex(random); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 975 | const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context); |
| 976 | return AAConvexPathOp::Make(std::move(paint), viewMatrix, path, stencilSettings); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | #endif |