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" |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 18 | #include "GrPipelineBuilder.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 19 | #include "GrProcessor.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: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 210 | SkFAIL("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; |
| 337 | SkPoint fUV; |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 338 | SkScalar fD0; |
| 339 | SkScalar fD1; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 340 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 341 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 342 | struct Draw { |
| 343 | Draw() : fVertexCnt(0), fIndexCnt(0) {} |
| 344 | int fVertexCnt; |
| 345 | int fIndexCnt; |
| 346 | }; |
| 347 | |
| 348 | typedef SkTArray<Draw, true> DrawArray; |
| 349 | |
commit-bot@chromium.org | fdfbb9d | 2013-08-15 18:16:27 +0000 | [diff] [blame] | 350 | static void create_vertices(const SegmentArray& segments, |
| 351 | const SkPoint& fanPt, |
| 352 | DrawArray* draws, |
| 353 | QuadVertex* verts, |
| 354 | uint16_t* idxs) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 355 | Draw* draw = &draws->push_back(); |
| 356 | // alias just to make vert/index assignments easier to read. |
| 357 | int* v = &draw->fVertexCnt; |
| 358 | int* i = &draw->fIndexCnt; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 359 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 360 | int count = segments.count(); |
| 361 | for (int a = 0; a < count; ++a) { |
| 362 | const Segment& sega = segments[a]; |
| 363 | int b = (a + 1) % count; |
| 364 | const Segment& segb = segments[b]; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 365 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 366 | // Check whether adding the verts for this segment to the current draw would cause index |
| 367 | // values to overflow. |
| 368 | int vCount = 4; |
| 369 | if (Segment::kLine == segb.fType) { |
| 370 | vCount += 5; |
| 371 | } else { |
| 372 | vCount += 6; |
| 373 | } |
| 374 | if (draw->fVertexCnt + vCount > (1 << 16)) { |
| 375 | verts += *v; |
| 376 | idxs += *i; |
| 377 | draw = &draws->push_back(); |
| 378 | v = &draw->fVertexCnt; |
| 379 | i = &draw->fIndexCnt; |
| 380 | } |
| 381 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 382 | // 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] | 383 | verts[*v + 0].fPos = sega.endPt(); |
| 384 | verts[*v + 1].fPos = verts[*v + 0].fPos + sega.endNorm(); |
| 385 | verts[*v + 2].fPos = verts[*v + 0].fPos + segb.fMid; |
| 386 | verts[*v + 3].fPos = verts[*v + 0].fPos + segb.fNorms[0]; |
| 387 | verts[*v + 0].fUV.set(0,0); |
| 388 | verts[*v + 1].fUV.set(0,-SK_Scalar1); |
| 389 | verts[*v + 2].fUV.set(0,-SK_Scalar1); |
| 390 | verts[*v + 3].fUV.set(0,-SK_Scalar1); |
| 391 | verts[*v + 0].fD0 = verts[*v + 0].fD1 = -SK_Scalar1; |
| 392 | verts[*v + 1].fD0 = verts[*v + 1].fD1 = -SK_Scalar1; |
| 393 | verts[*v + 2].fD0 = verts[*v + 2].fD1 = -SK_Scalar1; |
| 394 | verts[*v + 3].fD0 = verts[*v + 3].fD1 = -SK_Scalar1; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 395 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 396 | idxs[*i + 0] = *v + 0; |
| 397 | idxs[*i + 1] = *v + 2; |
| 398 | idxs[*i + 2] = *v + 1; |
| 399 | idxs[*i + 3] = *v + 0; |
| 400 | idxs[*i + 4] = *v + 3; |
| 401 | idxs[*i + 5] = *v + 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 402 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 403 | *v += 4; |
| 404 | *i += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 405 | |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 406 | if (Segment::kLine == segb.fType) { |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 407 | verts[*v + 0].fPos = fanPt; |
| 408 | verts[*v + 1].fPos = sega.endPt(); |
| 409 | verts[*v + 2].fPos = segb.fPts[0]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 410 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 411 | verts[*v + 3].fPos = verts[*v + 1].fPos + segb.fNorms[0]; |
| 412 | verts[*v + 4].fPos = verts[*v + 2].fPos + segb.fNorms[0]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 413 | |
| 414 | // we draw the line edge as a degenerate quad (u is 0, v is the |
| 415 | // signed distance to the edge) |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 416 | SkScalar dist = fanPt.distanceToLineBetween(verts[*v + 1].fPos, |
| 417 | verts[*v + 2].fPos); |
| 418 | verts[*v + 0].fUV.set(0, dist); |
| 419 | verts[*v + 1].fUV.set(0, 0); |
| 420 | verts[*v + 2].fUV.set(0, 0); |
| 421 | verts[*v + 3].fUV.set(0, -SK_Scalar1); |
| 422 | verts[*v + 4].fUV.set(0, -SK_Scalar1); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 423 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 424 | verts[*v + 0].fD0 = verts[*v + 0].fD1 = -SK_Scalar1; |
| 425 | verts[*v + 1].fD0 = verts[*v + 1].fD1 = -SK_Scalar1; |
| 426 | verts[*v + 2].fD0 = verts[*v + 2].fD1 = -SK_Scalar1; |
| 427 | verts[*v + 3].fD0 = verts[*v + 3].fD1 = -SK_Scalar1; |
| 428 | verts[*v + 4].fD0 = verts[*v + 4].fD1 = -SK_Scalar1; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 429 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 430 | idxs[*i + 0] = *v + 3; |
| 431 | idxs[*i + 1] = *v + 1; |
| 432 | idxs[*i + 2] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 433 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 434 | idxs[*i + 3] = *v + 4; |
| 435 | idxs[*i + 4] = *v + 3; |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 436 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 437 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 438 | *i += 6; |
| 439 | |
| 440 | // Draw the interior fan if it exists. |
| 441 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 442 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 443 | if (count >= 3) { |
| 444 | idxs[*i + 0] = *v + 0; |
| 445 | idxs[*i + 1] = *v + 2; |
| 446 | idxs[*i + 2] = *v + 1; |
| 447 | |
| 448 | *i += 3; |
| 449 | } |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 450 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 451 | *v += 5; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 452 | } else { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 453 | SkPoint qpts[] = {sega.endPt(), segb.fPts[0], segb.fPts[1]}; |
bsalomon@google.com | 495e210 | 2012-01-21 14:48:36 +0000 | [diff] [blame] | 454 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 455 | SkVector midVec = segb.fNorms[0] + segb.fNorms[1]; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 456 | midVec.normalize(); |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 457 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 458 | verts[*v + 0].fPos = fanPt; |
| 459 | verts[*v + 1].fPos = qpts[0]; |
| 460 | verts[*v + 2].fPos = qpts[2]; |
| 461 | verts[*v + 3].fPos = qpts[0] + segb.fNorms[0]; |
| 462 | verts[*v + 4].fPos = qpts[2] + segb.fNorms[1]; |
| 463 | verts[*v + 5].fPos = qpts[1] + midVec; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 464 | |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 465 | SkScalar c = segb.fNorms[0].dot(qpts[0]); |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 466 | verts[*v + 0].fD0 = -segb.fNorms[0].dot(fanPt) + c; |
| 467 | verts[*v + 1].fD0 = 0.f; |
| 468 | verts[*v + 2].fD0 = -segb.fNorms[0].dot(qpts[2]) + c; |
| 469 | verts[*v + 3].fD0 = -SK_ScalarMax/100; |
| 470 | verts[*v + 4].fD0 = -SK_ScalarMax/100; |
| 471 | verts[*v + 5].fD0 = -SK_ScalarMax/100; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 472 | |
| 473 | c = segb.fNorms[1].dot(qpts[2]); |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 474 | verts[*v + 0].fD1 = -segb.fNorms[1].dot(fanPt) + c; |
| 475 | verts[*v + 1].fD1 = -segb.fNorms[1].dot(qpts[0]) + c; |
| 476 | verts[*v + 2].fD1 = 0.f; |
| 477 | verts[*v + 3].fD1 = -SK_ScalarMax/100; |
| 478 | verts[*v + 4].fD1 = -SK_ScalarMax/100; |
| 479 | verts[*v + 5].fD1 = -SK_ScalarMax/100; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 480 | |
bsalomon@google.com | 1971317 | 2012-03-15 13:51:08 +0000 | [diff] [blame] | 481 | GrPathUtils::QuadUVMatrix toUV(qpts); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 482 | toUV.apply<6, sizeof(QuadVertex), sizeof(SkPoint)>(verts + *v); |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 483 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 484 | idxs[*i + 0] = *v + 3; |
| 485 | idxs[*i + 1] = *v + 1; |
| 486 | idxs[*i + 2] = *v + 2; |
| 487 | idxs[*i + 3] = *v + 4; |
| 488 | idxs[*i + 4] = *v + 3; |
| 489 | idxs[*i + 5] = *v + 2; |
bsalomon@google.com | 0680961 | 2012-01-21 15:03:39 +0000 | [diff] [blame] | 490 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 491 | idxs[*i + 6] = *v + 5; |
| 492 | idxs[*i + 7] = *v + 3; |
| 493 | idxs[*i + 8] = *v + 4; |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 494 | |
cdalton | 3596482 | 2015-04-29 10:14:03 -0700 | [diff] [blame] | 495 | *i += 9; |
| 496 | |
| 497 | // Draw the interior fan if it exists. |
| 498 | // TODO: Detect and combine colinear segments. This will ensure we catch every case |
| 499 | // with no interior, and that the resulting shared edge uses the same endpoints. |
| 500 | if (count >= 3) { |
| 501 | idxs[*i + 0] = *v + 0; |
| 502 | idxs[*i + 1] = *v + 2; |
| 503 | idxs[*i + 2] = *v + 1; |
| 504 | |
| 505 | *i += 3; |
| 506 | } |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 507 | |
bsalomon@google.com | 7d9ffc8 | 2013-05-14 14:20:28 +0000 | [diff] [blame] | 508 | *v += 6; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 513 | /////////////////////////////////////////////////////////////////////////////// |
| 514 | |
| 515 | /* |
| 516 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 517 | * two components of the vertex attribute. Coverage is based on signed |
| 518 | * distance with negative being inside, positive outside. The edge is specified in |
| 519 | * window space (y-down). If either the third or fourth component of the interpolated |
| 520 | * 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] | 521 | * attempt to trim to a portion of the infinite quad. |
| 522 | * Requires shader derivative instruction support. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 523 | */ |
| 524 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 525 | class QuadEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 526 | public: |
| 527 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 528 | static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& localMatrix, |
| 529 | bool usesLocalCoords) { |
| 530 | return sk_sp<GrGeometryProcessor>(new QuadEdgeEffect(color, localMatrix, usesLocalCoords)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 533 | ~QuadEdgeEffect() override {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 534 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 535 | const char* name() const override { return "QuadEdge"; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 536 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 537 | const Attribute* inPosition() const { return fInPosition; } |
| 538 | const Attribute* inQuadEdge() const { return fInQuadEdge; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 539 | GrColor color() const { return fColor; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 540 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 541 | bool usesLocalCoords() const { return fUsesLocalCoords; } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 542 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 543 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 544 | public: |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 545 | GLSLProcessor() : fColor(GrColor_ILLEGAL) {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 546 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 547 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 548 | const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 549 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 550 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 551 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 552 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 553 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 554 | varyingHandler->emitAttributes(qe); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 555 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 556 | GrGLSLVertToFrag v(kVec4f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 557 | varyingHandler->addVarying("QuadEdge", &v); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 558 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fName); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 559 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 560 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 561 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 562 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, |
| 563 | &fColorUniform); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 564 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 565 | // Setup position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 566 | this->setupPosition(vertBuilder, gpArgs, qe.inPosition()->fName); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 567 | |
| 568 | // emit transforms |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 569 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 570 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 571 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 572 | gpArgs->fPositionVar, |
| 573 | qe.inPosition()->fName, |
| 574 | qe.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 575 | args.fFPCoordTransformHandler); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 576 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 577 | fragBuilder->codeAppendf("float edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 578 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 579 | // keep the derivative instructions outside the conditional |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 580 | fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 581 | fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
| 582 | 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] | 583 | // 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] | 584 | fragBuilder->codeAppendf("edgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);", v.fsIn(), |
| 585 | v.fsIn()); |
| 586 | fragBuilder->codeAppendf ("} else {"); |
| 587 | fragBuilder->codeAppendf("vec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y," |
| 588 | " 2.0*%s.x*duvdy.x - duvdy.y);", |
| 589 | v.fsIn(), v.fsIn()); |
| 590 | fragBuilder->codeAppendf("edgeAlpha = (%s.x*%s.x - %s.y);", v.fsIn(), v.fsIn(), |
| 591 | v.fsIn()); |
| 592 | fragBuilder->codeAppendf("edgeAlpha = " |
| 593 | "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);}"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 594 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 595 | fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 596 | } |
| 597 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 598 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 599 | const GrShaderCaps&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 600 | GrProcessorKeyBuilder* b) { |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 601 | const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 602 | b->add32(SkToBool(qee.usesLocalCoords() && qee.localMatrix().hasPerspective())); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 603 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 604 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 605 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 606 | const GrPrimitiveProcessor& gp, |
| 607 | FPCoordTransformIter&& transformIter) override { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 608 | const QuadEdgeEffect& qe = gp.cast<QuadEdgeEffect>(); |
| 609 | if (qe.color() != fColor) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 610 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 611 | GrColorToRGBAFloat(qe.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 612 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 613 | fColor = qe.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 614 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 615 | this->setTransformDataHelper(qe.fLocalMatrix, pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 616 | } |
| 617 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 618 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 619 | GrColor fColor; |
| 620 | UniformHandle fColorUniform; |
| 621 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 622 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 623 | }; |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 624 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 625 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 626 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 629 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 630 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 631 | } |
| 632 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 633 | private: |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 634 | QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix, bool usesLocalCoords) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 635 | : fColor(color) |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 636 | , fLocalMatrix(localMatrix) |
| 637 | , 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); |
| 640 | fInQuadEdge = &this->addVertexAttrib("inQuadEdge", kVec4f_GrVertexAttribType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 641 | } |
| 642 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 643 | const Attribute* fInPosition; |
| 644 | const Attribute* fInQuadEdge; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 645 | GrColor fColor; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 646 | SkMatrix fLocalMatrix; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 647 | bool fUsesLocalCoords; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 648 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 649 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 650 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 651 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 652 | }; |
| 653 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 654 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 655 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 656 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 657 | sk_sp<GrGeometryProcessor> QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 658 | // Doesn't work without derivative instructions. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 659 | return d->caps()->shaderCaps()->shaderDerivativeSupport() |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 660 | ? QuadEdgeEffect::Make(GrRandomColor(d->fRandom), |
| 661 | GrTest::TestMatrix(d->fRandom), |
| 662 | d->fRandom->nextBool()) |
| 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 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 669 | bool GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 670 | return (args.fCaps->shaderCaps()->shaderDerivativeSupport() && |
| 671 | (GrAAType::kCoverage == args.fAAType) && args.fShape->style().isSimpleFill() && |
| 672 | !args.fShape->inverseFilled() && args.fShape->knownToBeConvex()); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 673 | } |
| 674 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 675 | // extract the result vertices and indices from the GrAAConvexTessellator |
| 676 | static void extract_verts(const GrAAConvexTessellator& tess, |
| 677 | void* vertices, |
| 678 | size_t vertexStride, |
| 679 | GrColor color, |
| 680 | uint16_t* idxs, |
| 681 | bool tweakAlphaForCoverage) { |
| 682 | intptr_t verts = reinterpret_cast<intptr_t>(vertices); |
| 683 | |
| 684 | for (int i = 0; i < tess.numPts(); ++i) { |
| 685 | *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i); |
| 686 | } |
| 687 | |
| 688 | // Make 'verts' point to the colors |
| 689 | verts += sizeof(SkPoint); |
| 690 | for (int i = 0; i < tess.numPts(); ++i) { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 691 | if (tweakAlphaForCoverage) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 692 | SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| 693 | unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 694 | GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 695 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| 696 | } else { |
| 697 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 698 | *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 699 | tess.coverage(i); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | for (int i = 0; i < tess.numIndices(); ++i) { |
| 704 | idxs[i] = tess.index(i); |
| 705 | } |
| 706 | } |
| 707 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 708 | static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage, |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 709 | const SkMatrix& viewMatrix, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 710 | bool usesLocalCoords) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 711 | using namespace GrDefaultGeoProcFactory; |
joshualitt | e494a58 | 2015-08-03 09:32:36 -0700 | [diff] [blame] | 712 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 713 | Coverage::Type coverageType; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 714 | if (tweakAlphaForCoverage) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 715 | coverageType = Coverage::kSolid_Type; |
| 716 | } else { |
| 717 | coverageType = Coverage::kAttribute_Type; |
| 718 | } |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 719 | LocalCoords::Type localCoordsType = |
| 720 | usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 721 | return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType, |
| 722 | viewMatrix); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 725 | class AAConvexPathOp final : public GrLegacyMeshDrawOp { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 726 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 727 | DEFINE_OP_CLASS_ID |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 728 | static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, |
| 729 | const SkPath& path) { |
| 730 | return std::unique_ptr<GrLegacyMeshDrawOp>(new AAConvexPathOp(color, viewMatrix, path)); |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 731 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 732 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 733 | const char* name() const override { return "AAConvexPathOp"; } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 734 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 735 | SkString dumpInfo() const override { |
| 736 | SkString string; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 737 | string.appendf("Color: 0x%08x, Count: %d\n", fColor, fPaths.count()); |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 738 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 739 | string.append(INHERITED::dumpInfo()); |
| 740 | return string; |
| 741 | } |
| 742 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 743 | private: |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 744 | AAConvexPathOp(GrColor color, const SkMatrix& viewMatrix, const SkPath& path) |
| 745 | : INHERITED(ClassID()), fColor(color) { |
| 746 | fPaths.emplace_back(PathData{viewMatrix, path}); |
| 747 | this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); |
| 748 | } |
| 749 | |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 750 | void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color, |
| 751 | GrProcessorAnalysisCoverage* coverage) const override { |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 752 | color->setToConstant(fColor); |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 753 | *coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 754 | } |
| 755 | |
Brian Salomon | e7d3048 | 2017-03-29 12:09:15 -0400 | [diff] [blame] | 756 | void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override { |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 757 | optimizations.getOverrideColorIfSet(&fColor); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 758 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 759 | fUsesLocalCoords = optimizations.readsLocalCoords(); |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 760 | fLinesOnly = SkPath::kLine_SegmentMask == fPaths[0].fPath.getSegmentMasks(); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 761 | fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage(); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 762 | } |
| 763 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 764 | void prepareLinesOnlyDraws(Target* target) const { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 765 | bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 766 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 767 | // Setup GrGeometryProcessor |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 768 | sk_sp<GrGeometryProcessor> gp(create_fill_gp( |
| 769 | canTweakAlphaForCoverage, this->viewMatrix(), this->usesLocalCoords())); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 770 | if (!gp) { |
| 771 | SkDebugf("Could not create GrGeometryProcessor\n"); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 775 | size_t vertexStride = gp->getVertexStride(); |
| 776 | |
| 777 | SkASSERT(canTweakAlphaForCoverage ? |
| 778 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : |
| 779 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
| 780 | |
| 781 | GrAAConvexTessellator tess; |
| 782 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 783 | int instanceCount = fPaths.count(); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 784 | |
| 785 | for (int i = 0; i < instanceCount; i++) { |
| 786 | tess.rewind(); |
| 787 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 788 | const PathData& args = fPaths[i]; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 789 | |
| 790 | if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 791 | continue; |
| 792 | } |
| 793 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 794 | const GrBuffer* vertexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 795 | int firstVertex; |
| 796 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 797 | void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), &vertexBuffer, |
| 798 | &firstVertex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 799 | if (!verts) { |
| 800 | SkDebugf("Could not allocate vertices\n"); |
| 801 | return; |
| 802 | } |
| 803 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 804 | const GrBuffer* indexBuffer; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 805 | int firstIndex; |
| 806 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 807 | uint16_t* idxs = target->makeIndexSpace(tess.numIndices(), &indexBuffer, &firstIndex); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 808 | if (!idxs) { |
| 809 | SkDebugf("Could not allocate indices\n"); |
| 810 | return; |
| 811 | } |
| 812 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 813 | extract_verts(tess, verts, vertexStride, fColor, idxs, canTweakAlphaForCoverage); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 814 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 815 | GrMesh mesh; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 816 | mesh.fPrimitiveType = kTriangles_GrPrimitiveType; |
| 817 | mesh.fIndexBuffer.reset(indexBuffer); |
| 818 | mesh.fIndexCount = tess.numIndices(); |
| 819 | mesh.fBaseIndex = firstIndex; |
| 820 | mesh.fVertexBuffer.reset(vertexBuffer); |
| 821 | mesh.fVertexCount = tess.numPts(); |
| 822 | mesh.fBaseVertex = firstVertex; |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 823 | target->draw(gp.get(), this->pipeline(), mesh); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 824 | } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 825 | } |
| 826 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 827 | void onPrepareDraws(Target* target) const override { |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 828 | #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS |
| 829 | if (this->linesOnly()) { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 830 | this->prepareLinesOnlyDraws(target); |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 831 | return; |
| 832 | } |
| 833 | #endif |
| 834 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 835 | int instanceCount = fPaths.count(); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 836 | |
| 837 | SkMatrix invert; |
joshualitt | 7abe15d | 2015-02-20 12:40:45 -0800 | [diff] [blame] | 838 | if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 839 | SkDebugf("Could not invert viewmatrix\n"); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | // Setup GrGeometryProcessor |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 844 | sk_sp<GrGeometryProcessor> quadProcessor( |
| 845 | QuadEdgeEffect::Make(this->color(), invert, this->usesLocalCoords())); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 846 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 847 | // TODO generate all segments for all paths and use one vertex buffer |
| 848 | for (int i = 0; i < instanceCount; i++) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 849 | const PathData& args = fPaths[i]; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 850 | |
| 851 | // We use the fact that SkPath::transform path does subdivision based on |
| 852 | // perspective. Otherwise, we apply the view matrix when copying to the |
| 853 | // segment representation. |
| 854 | const SkMatrix* viewMatrix = &args.fViewMatrix; |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 855 | |
| 856 | // We avoid initializing the path unless we have to |
| 857 | const SkPath* pathPtr = &args.fPath; |
| 858 | SkTLazy<SkPath> tmpPath; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 859 | if (viewMatrix->hasPerspective()) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 860 | SkPath* tmpPathPtr = tmpPath.init(*pathPtr); |
| 861 | tmpPathPtr->setIsVolatile(true); |
| 862 | tmpPathPtr->transform(*viewMatrix); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 863 | viewMatrix = &SkMatrix::I(); |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 864 | pathPtr = tmpPathPtr; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | int vertexCount; |
| 868 | int indexCount; |
| 869 | enum { |
| 870 | kPreallocSegmentCnt = 512 / sizeof(Segment), |
| 871 | kPreallocDrawCnt = 4, |
| 872 | }; |
| 873 | SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
| 874 | SkPoint fanPt; |
| 875 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 876 | if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount, |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 877 | &indexCount)) { |
| 878 | continue; |
| 879 | } |
| 880 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 881 | GrMesh mesh; |
| 882 | mesh.fPrimitiveType = kTriangles_GrPrimitiveType; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 883 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 884 | const GrBuffer* vertexBuffer; |
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 | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 887 | vertexStride, vertexCount, &vertexBuffer, &mesh.fBaseVertex)); |
| 888 | mesh.fVertexBuffer.reset(vertexBuffer); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 889 | |
| 890 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 891 | SkDebugf("Could not allocate vertices\n"); |
| 892 | return; |
| 893 | } |
| 894 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 895 | const GrBuffer* indexBuffer; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 896 | uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &mesh.fBaseIndex); |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 897 | if (!idxs) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 898 | SkDebugf("Could not allocate indices\n"); |
| 899 | return; |
| 900 | } |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 901 | mesh.fIndexBuffer.reset(indexBuffer); |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 902 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 903 | SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
| 904 | create_vertices(segments, fanPt, &draws, verts, idxs); |
| 905 | |
robertphillips | 44c3128 | 2015-09-03 12:58:48 -0700 | [diff] [blame] | 906 | for (int j = 0; j < draws.count(); ++j) { |
| 907 | const Draw& draw = draws[j]; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 908 | mesh.fIndexCount = draw.fIndexCnt; |
| 909 | mesh.fVertexCount = draw.fVertexCnt; |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 910 | target->draw(quadProcessor.get(), this->pipeline(), mesh); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 911 | mesh.fBaseIndex += draw.fIndexCnt; |
| 912 | mesh.fBaseVertex += draw.fVertexCnt; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | } |
| 916 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 917 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 918 | AAConvexPathOp* that = t->cast<AAConvexPathOp>(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 919 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 920 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 921 | return false; |
| 922 | } |
| 923 | |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 924 | if (this->color() != that->color()) { |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 929 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 930 | return false; |
| 931 | } |
| 932 | |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 933 | if (this->linesOnly() != that->linesOnly()) { |
| 934 | return false; |
| 935 | } |
| 936 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 937 | // In the event of two ops, one who can tweak, one who cannot, we just fall back to not |
| 938 | // tweaking |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 939 | if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) { |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 940 | fCanTweakAlphaForCoverage = false; |
robertphillips | e16dfdb | 2015-05-08 04:46:51 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 943 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 944 | this->joinBounds(*that); |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 945 | return true; |
| 946 | } |
| 947 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 948 | GrColor color() const { return fColor; } |
| 949 | bool linesOnly() const { return fLinesOnly; } |
| 950 | bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 951 | bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; } |
| 952 | const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 953 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 954 | GrColor fColor; |
| 955 | bool fUsesLocalCoords; |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 956 | bool fLinesOnly; |
| 957 | bool fCanTweakAlphaForCoverage; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 958 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 959 | struct PathData { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 960 | SkMatrix fViewMatrix; |
| 961 | SkPath fPath; |
| 962 | }; |
| 963 | |
Brian Salomon | d0a0a65 | 2016-12-15 15:25:22 -0500 | [diff] [blame] | 964 | SkSTArray<1, PathData, true> fPaths; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 965 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 966 | typedef GrLegacyMeshDrawOp INHERITED; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 967 | }; |
| 968 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 969 | bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 970 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 971 | "GrAAConvexPathRenderer::onDrawPath"); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 972 | SkASSERT(GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType()); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 973 | SkASSERT(!args.fShape->isEmpty()); |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 974 | |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 975 | SkPath path; |
| 976 | args.fShape->asPath(&path); |
bsalomon@google.com | af90f7f | 2012-03-05 20:50:10 +0000 | [diff] [blame] | 977 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 978 | std::unique_ptr<GrLegacyMeshDrawOp> op = |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 979 | AAConvexPathOp::Make(args.fPaint.getColor(), *args.fViewMatrix, path); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 980 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 981 | GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType); |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 982 | pipelineBuilder.setUserStencil(args.fUserStencilSettings); |
| 983 | |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 984 | args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip, |
| 985 | std::move(op)); |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 986 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 987 | return true; |
joshualitt | 27f398f | 2015-02-05 14:39:01 -0800 | [diff] [blame] | 988 | |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 989 | } |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 990 | |
| 991 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 992 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 993 | #if GR_TEST_UTILS |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 994 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 995 | GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(AAConvexPathOp) { |
bsalomon | f170309 | 2016-06-29 18:41:53 -0700 | [diff] [blame] | 996 | GrColor color = GrRandomColor(random); |
| 997 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 998 | SkPath path = GrTest::TestPathConvex(random); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 999 | |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 1000 | return AAConvexPathOp::Make(color, viewMatrix, path); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | #endif |