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 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 567 | GrGLSLVertToFrag v(kHalf4_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 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 588 | fragBuilder->codeAppendf("half 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 |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 591 | fragBuilder->codeAppendf("half2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 592 | fragBuilder->codeAppendf("half2 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 {"); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 598 | fragBuilder->codeAppendf("half2 gF = half2(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 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 606 | fragBuilder->codeAppendf("%s = half4(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) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame^] | 637 | : INHERITED(kQuadEdgeEffect_ClassID) |
| 638 | , fLocalMatrix(localMatrix) |
| 639 | , fUsesLocalCoords(usesLocalCoords) { |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 640 | fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); |
| 641 | fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); |
| 642 | fInQuadEdge = &this->addVertexAttrib("inQuadEdge", kHalf4_GrVertexAttribType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 643 | } |
| 644 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 645 | const Attribute* fInPosition; |
| 646 | const Attribute* fInQuadEdge; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 647 | const Attribute* fInColor; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 648 | SkMatrix fLocalMatrix; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 649 | bool fUsesLocalCoords; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 650 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 651 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 652 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 653 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 656 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 657 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 658 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 659 | sk_sp<GrGeometryProcessor> QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 660 | // Doesn't work without derivative instructions. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 661 | return d->caps()->shaderCaps()->shaderDerivativeSupport() |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 662 | ? QuadEdgeEffect::Make(GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool()) |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 663 | : nullptr; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 664 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 665 | #endif |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 666 | |
| 667 | /////////////////////////////////////////////////////////////////////////////// |
| 668 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 669 | GrPathRenderer::CanDrawPath |
| 670 | GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
| 671 | if (args.fCaps->shaderCaps()->shaderDerivativeSupport() && |
| 672 | (GrAAType::kCoverage == args.fAAType) && args.fShape->style().isSimpleFill() && |
| 673 | !args.fShape->inverseFilled() && args.fShape->knownToBeConvex()) { |
| 674 | return CanDrawPath::kYes; |
| 675 | } |
| 676 | return CanDrawPath::kNo; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 677 | } |
| 678 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 679 | // extract the result vertices and indices from the GrAAConvexTessellator |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 680 | static void extract_lines_only_verts(const GrAAConvexTessellator& tess, |
| 681 | void* vertices, |
| 682 | size_t vertexStride, |
| 683 | GrColor color, |
| 684 | uint16_t* idxs, |
| 685 | bool tweakAlphaForCoverage) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 686 | intptr_t verts = reinterpret_cast<intptr_t>(vertices); |
| 687 | |
| 688 | for (int i = 0; i < tess.numPts(); ++i) { |
| 689 | *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i); |
| 690 | } |
| 691 | |
| 692 | // Make 'verts' point to the colors |
| 693 | verts += sizeof(SkPoint); |
| 694 | for (int i = 0; i < tess.numPts(); ++i) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 695 | if (tweakAlphaForCoverage) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 696 | SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| 697 | unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 698 | GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 699 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| 700 | } else { |
| 701 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 702 | *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 703 | tess.coverage(i); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | for (int i = 0; i < tess.numIndices(); ++i) { |
| 708 | idxs[i] = tess.index(i); |
| 709 | } |
| 710 | } |
| 711 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 712 | static sk_sp<GrGeometryProcessor> make_lines_only_gp(bool tweakAlphaForCoverage, |
| 713 | const SkMatrix& viewMatrix, |
| 714 | bool usesLocalCoords) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 715 | using namespace GrDefaultGeoProcFactory; |
joshualitt | e494a58 | 2015-08-03 09:32:36 -0700 | [diff] [blame] | 716 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 717 | Coverage::Type coverageType; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 718 | if (tweakAlphaForCoverage) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 719 | coverageType = Coverage::kSolid_Type; |
| 720 | } else { |
| 721 | coverageType = Coverage::kAttribute_Type; |
| 722 | } |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 723 | LocalCoords::Type localCoordsType = |
| 724 | usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 725 | return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType, |
| 726 | viewMatrix); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 729 | namespace { |
| 730 | |
| 731 | class AAConvexPathOp final : public GrMeshDrawOp { |
| 732 | private: |
| 733 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 734 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 735 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 736 | DEFINE_OP_CLASS_ID |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 737 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 738 | static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint, const SkMatrix& viewMatrix, |
| 739 | const SkPath& path, |
| 740 | const GrUserStencilSettings* stencilSettings) { |
| 741 | return Helper::FactoryHelper<AAConvexPathOp>(std::move(paint), viewMatrix, path, |
| 742 | stencilSettings); |
| 743 | } |
| 744 | |
| 745 | AAConvexPathOp(const Helper::MakeArgs& helperArgs, GrColor color, const SkMatrix& viewMatrix, |
| 746 | const SkPath& path, const GrUserStencilSettings* stencilSettings) |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 747 | : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) { |
| 748 | fPaths.emplace_back(PathData{viewMatrix, path, color}); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 749 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); |
| 750 | fLinesOnly = SkPath::kLine_SegmentMask == path.getSegmentMasks(); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 751 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 752 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 753 | const char* name() const override { return "AAConvexPathOp"; } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 754 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 755 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 756 | fHelper.visitProxies(func); |
| 757 | } |
| 758 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 759 | SkString dumpInfo() const override { |
| 760 | SkString string; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 761 | string.appendf("Count: %d\n", fPaths.count()); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 762 | string += fHelper.dumpInfo(); |
| 763 | string += INHERITED::dumpInfo(); |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 764 | return string; |
| 765 | } |
| 766 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 767 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 768 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 769 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 770 | GrPixelConfigIsClamped dstIsClamped) override { |
| 771 | return fHelper.xpRequiresDstTexture(caps, clip, dstIsClamped, |
| 772 | GrProcessorAnalysisCoverage::kSingleChannel, |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 773 | &fPaths.back().fColor); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 774 | } |
| 775 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 776 | private: |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 777 | void prepareLinesOnlyDraws(Target* target) { |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 778 | // Setup GrGeometryProcessor |
| 779 | sk_sp<GrGeometryProcessor> gp(make_lines_only_gp(fHelper.compatibleWithAlphaAsCoverage(), |
| 780 | fPaths.back().fViewMatrix, |
| 781 | fHelper.usesLocalCoords())); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 782 | if (!gp) { |
| 783 | SkDebugf("Could not create GrGeometryProcessor\n"); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 784 | return; |
| 785 | } |
| 786 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 787 | size_t vertexStride = gp->getVertexStride(); |
| 788 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 789 | SkASSERT(fHelper.compatibleWithAlphaAsCoverage() |
| 790 | ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) |
| 791 | : vertexStride == |
| 792 | sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 793 | |
| 794 | GrAAConvexTessellator tess; |
| 795 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 796 | int instanceCount = fPaths.count(); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 797 | const GrPipeline* pipeline = fHelper.makePipeline(target); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 798 | for (int i = 0; i < instanceCount; i++) { |
| 799 | tess.rewind(); |
| 800 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 801 | const PathData& args = fPaths[i]; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 802 | |
| 803 | if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 804 | continue; |
| 805 | } |
| 806 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 807 | const GrBuffer* vertexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 808 | int firstVertex; |
| 809 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 810 | void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), &vertexBuffer, |
| 811 | &firstVertex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 812 | if (!verts) { |
| 813 | SkDebugf("Could not allocate vertices\n"); |
| 814 | return; |
| 815 | } |
| 816 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 817 | const GrBuffer* indexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 818 | int firstIndex; |
| 819 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 820 | uint16_t* idxs = target->makeIndexSpace(tess.numIndices(), &indexBuffer, &firstIndex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 821 | if (!idxs) { |
| 822 | SkDebugf("Could not allocate indices\n"); |
| 823 | return; |
| 824 | } |
| 825 | |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 826 | extract_lines_only_verts(tess, verts, vertexStride, args.fColor, idxs, |
| 827 | fHelper.compatibleWithAlphaAsCoverage()); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 828 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 829 | GrMesh mesh(GrPrimitiveType::kTriangles); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 830 | mesh.setIndexed(indexBuffer, tess.numIndices(), firstIndex, 0, tess.numPts() - 1); |
| 831 | mesh.setVertexData(vertexBuffer, firstVertex); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 832 | target->draw(gp.get(), pipeline, mesh); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 833 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 836 | void onPrepareDraws(Target* target) override { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 837 | #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 838 | if (fLinesOnly) { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 839 | this->prepareLinesOnlyDraws(target); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | #endif |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 843 | const GrPipeline* pipeline = fHelper.makePipeline(target); |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 844 | int instanceCount = fPaths.count(); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 845 | |
| 846 | SkMatrix invert; |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 847 | if (fHelper.usesLocalCoords() && !fPaths.back().fViewMatrix.invert(&invert)) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 848 | SkDebugf("Could not invert viewmatrix\n"); |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | // Setup GrGeometryProcessor |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 853 | sk_sp<GrGeometryProcessor> quadProcessor( |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 854 | QuadEdgeEffect::Make(invert, fHelper.usesLocalCoords())); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 855 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 856 | // TODO generate all segments for all paths and use one vertex buffer |
| 857 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 858 | const PathData& args = fPaths[i]; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 859 | |
| 860 | // We use the fact that SkPath::transform path does subdivision based on |
| 861 | // perspective. Otherwise, we apply the view matrix when copying to the |
| 862 | // segment representation. |
| 863 | const SkMatrix* viewMatrix = &args.fViewMatrix; |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 864 | |
| 865 | // We avoid initializing the path unless we have to |
| 866 | const SkPath* pathPtr = &args.fPath; |
| 867 | SkTLazy<SkPath> tmpPath; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 868 | if (viewMatrix->hasPerspective()) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 869 | SkPath* tmpPathPtr = tmpPath.init(*pathPtr); |
| 870 | tmpPathPtr->setIsVolatile(true); |
| 871 | tmpPathPtr->transform(*viewMatrix); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 872 | viewMatrix = &SkMatrix::I(); |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 873 | pathPtr = tmpPathPtr; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | int vertexCount; |
| 877 | int indexCount; |
| 878 | enum { |
| 879 | kPreallocSegmentCnt = 512 / sizeof(Segment), |
| 880 | kPreallocDrawCnt = 4, |
| 881 | }; |
| 882 | SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
| 883 | SkPoint fanPt; |
| 884 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 885 | if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 886 | &indexCount)) { |
| 887 | continue; |
| 888 | } |
| 889 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 890 | const GrBuffer* vertexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 891 | int firstVertex; |
| 892 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 893 | size_t vertexStride = quadProcessor->getVertexStride(); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 894 | QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace( |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 895 | vertexStride, vertexCount, &vertexBuffer, &firstVertex)); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 896 | |
| 897 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 898 | SkDebugf("Could not allocate vertices\n"); |
| 899 | return; |
| 900 | } |
| 901 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 902 | const GrBuffer* indexBuffer; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 903 | int firstIndex; |
| 904 | |
| 905 | uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex); |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 906 | if (!idxs) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 907 | SkDebugf("Could not allocate indices\n"); |
| 908 | return; |
| 909 | } |
| 910 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 911 | SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 912 | create_vertices(segments, fanPt, args.fColor, &draws, verts, idxs); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 913 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 914 | GrMesh mesh(GrPrimitiveType::kTriangles); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 915 | |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 916 | for (int j = 0; j < draws.count(); ++j) { |
| 917 | const Draw& draw = draws[j]; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 918 | mesh.setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0, draw.fVertexCnt - 1); |
| 919 | mesh.setVertexData(vertexBuffer, firstVertex); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 920 | target->draw(quadProcessor.get(), pipeline, mesh); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 921 | firstIndex += draw.fIndexCnt; |
| 922 | firstVertex += draw.fVertexCnt; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 927 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 928 | AAConvexPathOp* that = t->cast<AAConvexPathOp>(); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 929 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 930 | return false; |
| 931 | } |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 932 | if (fHelper.usesLocalCoords() && |
| 933 | !fPaths[0].fViewMatrix.cheapEqualTo(that->fPaths[0].fViewMatrix)) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 934 | return false; |
| 935 | } |
| 936 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 937 | if (fLinesOnly != that->fLinesOnly) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 938 | return false; |
| 939 | } |
| 940 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 941 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 942 | this->joinBounds(*that); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 943 | return true; |
| 944 | } |
| 945 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 946 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 947 | SkMatrix fViewMatrix; |
| 948 | SkPath fPath; |
Brian Salomon | 60fb0b2 | 2017-06-15 17:09:36 -0400 | [diff] [blame] | 949 | GrColor fColor; |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 950 | }; |
| 951 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 952 | Helper fHelper; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 953 | SkSTArray<1, PathData, true> fPaths; |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 954 | bool fLinesOnly; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 955 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 956 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 957 | }; |
| 958 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 959 | } // anonymous namespace |
| 960 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 961 | bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 962 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 963 | "GrAAConvexPathRenderer::onDrawPath"); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 964 | SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType()); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 965 | SkASSERT(!args.fShape->isEmpty()); |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 966 | |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 967 | SkPath path; |
| 968 | args.fShape->asPath(&path); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 969 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 970 | std::unique_ptr<GrDrawOp> op = AAConvexPathOp::Make(std::move(args.fPaint), *args.fViewMatrix, |
| 971 | path, args.fUserStencilSettings); |
| 972 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 973 | return true; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 974 | } |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 975 | |
| 976 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 977 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 978 | #if GR_TEST_UTILS |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 979 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 980 | GR_DRAW_OP_TEST_DEFINE(AAConvexPathOp) { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 981 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 982 | SkPath path = GrTest::TestPathConvex(random); |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 983 | const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context); |
| 984 | return AAConvexPathOp::Make(std::move(paint), viewMatrix, path, stencilSettings); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | #endif |