| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
| 9 | 9 |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, | 91 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, |
| 92 const GrGLCaps&) { | 92 const GrGLCaps&) { |
| 93 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 93 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
| 94 GR_STATIC_ASSERT(GrConvexPolyEffect::kEdgeTypeCnt <= 4); | 94 GR_STATIC_ASSERT(GrConvexPolyEffect::kEdgeTypeCnt <= 4); |
| 95 return (cpe.getEdgeCount() << 2) | cpe.getEdgeType(); | 95 return (cpe.getEdgeCount() << 2) | cpe.getEdgeType(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 ////////////////////////////////////////////////////////////////////////////// | 98 ////////////////////////////////////////////////////////////////////////////// |
| 99 | 99 |
| 100 GrEffectRef* GrConvexPolyEffect::Create(EdgeType type, const SkPath& path) { | 100 GrEffectRef* GrConvexPolyEffect::Create(EdgeType type, const SkPath& path, const
SkVector* offset) { |
| 101 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 101 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
| 102 !path.isConvex() || | 102 !path.isConvex() || |
| 103 path.isInverseFillType()) { | 103 path.isInverseFillType()) { |
| 104 return NULL; | 104 return NULL; |
| 105 } | 105 } |
| 106 | 106 |
| 107 if (path.countPoints() > kMaxEdges) { | 107 if (path.countPoints() > kMaxEdges) { |
| 108 return NULL; | 108 return NULL; |
| 109 } | 109 } |
| 110 | 110 |
| 111 SkPoint pts[kMaxEdges]; | 111 SkPoint pts[kMaxEdges]; |
| 112 SkScalar edges[3 * kMaxEdges]; | 112 SkScalar edges[3 * kMaxEdges]; |
| 113 | 113 |
| 114 SkPath::Direction dir; | 114 SkPath::Direction dir; |
| 115 SkAssertResult(path.cheapComputeDirection(&dir)); | 115 SkAssertResult(path.cheapComputeDirection(&dir)); |
| 116 | 116 |
| 117 SkVector t; |
| 118 if (NULL == offset) { |
| 119 t.set(0, 0); |
| 120 } else { |
| 121 t = *offset; |
| 122 } |
| 123 |
| 117 int count = path.getPoints(pts, kMaxEdges); | 124 int count = path.getPoints(pts, kMaxEdges); |
| 118 int n = 0; | 125 int n = 0; |
| 119 for (int lastPt = count - 1, i = 0; i < count; lastPt = i++) { | 126 for (int lastPt = count - 1, i = 0; i < count; lastPt = i++) { |
| 120 if (pts[lastPt] != pts[i]) { | 127 if (pts[lastPt] != pts[i]) { |
| 121 SkVector v = pts[i] - pts[lastPt]; | 128 SkVector v = pts[i] - pts[lastPt]; |
| 122 v.normalize(); | 129 v.normalize(); |
| 123 if (SkPath::kCCW_Direction == dir) { | 130 if (SkPath::kCCW_Direction == dir) { |
| 124 edges[3 * n] = v.fY; | 131 edges[3 * n] = v.fY; |
| 125 edges[3 * n + 1] = -v.fX; | 132 edges[3 * n + 1] = -v.fX; |
| 126 } else { | 133 } else { |
| 127 edges[3 * n] = -v.fY; | 134 edges[3 * n] = -v.fY; |
| 128 edges[3 * n + 1] = v.fX; | 135 edges[3 * n + 1] = v.fX; |
| 129 } | 136 } |
| 130 edges[3 * n + 2] = -(edges[3 * n] * pts[i].fX + edges[3 * n + 1] * p
ts[i].fY); | 137 SkPoint p = pts[i] + t; |
| 138 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); |
| 131 ++n; | 139 ++n; |
| 132 } | 140 } |
| 133 } | 141 } |
| 134 return Create(type, n, edges); | 142 return Create(type, n, edges); |
| 135 } | 143 } |
| 136 | 144 |
| 137 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 145 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 138 | 146 |
| 139 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | 147 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { |
| 140 *validFlags = 0; | 148 *validFlags = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 GrTexture*[]) { | 183 GrTexture*[]) { |
| 176 EdgeType edgeType = static_cast<EdgeType>(random->nextULessThan(kEdgeTypeCnt
)); | 184 EdgeType edgeType = static_cast<EdgeType>(random->nextULessThan(kEdgeTypeCnt
)); |
| 177 int count = random->nextULessThan(kMaxEdges) + 1; | 185 int count = random->nextULessThan(kMaxEdges) + 1; |
| 178 SkScalar edges[kMaxEdges * 3]; | 186 SkScalar edges[kMaxEdges * 3]; |
| 179 for (int i = 0; i < 3 * count; ++i) { | 187 for (int i = 0; i < 3 * count; ++i) { |
| 180 edges[i] = random->nextSScalar1(); | 188 edges[i] = random->nextSScalar1(); |
| 181 } | 189 } |
| 182 | 190 |
| 183 return GrConvexPolyEffect::Create(edgeType, count, edges); | 191 return GrConvexPolyEffect::Create(edgeType, count, edges); |
| 184 } | 192 } |
| OLD | NEW |