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