| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkStrokerPriv.h" | 10 #include "SkStrokerPriv.h" |
| 11 #include "SkGeometry.h" | 11 #include "SkGeometry.h" |
| 12 #include "SkPath.h" | 12 #include "SkPath.h" |
| 13 | 13 |
| 14 static void ButtCapper(SkPath* path, const SkPoint& pivot, | 14 static void ButtCapper(SkPath* path, const SkPoint& pivot, |
| 15 const SkVector& normal, const SkPoint& stop, | 15 const SkVector& normal, const SkPoint& stop, |
| 16 SkPath*) | 16 SkPath*) |
| 17 { | 17 { |
| 18 path->lineTo(stop.fX, stop.fY); | 18 path->lineTo(stop.fX, stop.fY); |
| 19 } | 19 } |
| 20 | 20 |
| 21 static void RoundCapper(SkPath* path, const SkPoint& pivot, | 21 static void RoundCapper(SkPath* path, const SkPoint& pivot, |
| 22 const SkVector& normal, const SkPoint& stop, | 22 const SkVector& normal, const SkPoint& stop, |
| 23 SkPath*) | 23 SkPath*) |
| 24 { | 24 { |
| 25 #ifdef SK_SUPPORT_LEGACY_ARCTO_QUADS | |
| 26 SkScalar px = pivot.fX; | |
| 27 SkScalar py = pivot.fY; | |
| 28 SkScalar nx = normal.fX; | |
| 29 SkScalar ny = normal.fY; | |
| 30 SkScalar sx = SkScalarMul(nx, CUBIC_ARC_FACTOR); | |
| 31 SkScalar sy = SkScalarMul(ny, CUBIC_ARC_FACTOR); | |
| 32 | |
| 33 path->cubicTo(px + nx + CWX(sx, sy), py + ny + CWY(sx, sy), | |
| 34 px + CWX(nx, ny) + sx, py + CWY(nx, ny) + sy, | |
| 35 px + CWX(nx, ny), py + CWY(nx, ny)); | |
| 36 path->cubicTo(px + CWX(nx, ny) - sx, py + CWY(nx, ny) - sy, | |
| 37 px - nx + CWX(sx, sy), py - ny + CWY(sx, sy), | |
| 38 stop.fX, stop.fY); | |
| 39 #else | |
| 40 SkVector parallel; | 25 SkVector parallel; |
| 41 normal.rotateCW(¶llel); | 26 normal.rotateCW(¶llel); |
| 42 | 27 |
| 43 SkPoint projectedCenter = pivot + parallel; | 28 SkPoint projectedCenter = pivot + parallel; |
| 44 | 29 |
| 45 path->conicTo(projectedCenter + normal, projectedCenter, SK_ScalarRoot2Over2
); | 30 path->conicTo(projectedCenter + normal, projectedCenter, SK_ScalarRoot2Over2
); |
| 46 path->conicTo(projectedCenter - normal, stop, SK_ScalarRoot2Over2); | 31 path->conicTo(projectedCenter - normal, stop, SK_ScalarRoot2Over2); |
| 47 #endif | |
| 48 } | 32 } |
| 49 | 33 |
| 50 static void SquareCapper(SkPath* path, const SkPoint& pivot, | 34 static void SquareCapper(SkPath* path, const SkPoint& pivot, |
| 51 const SkVector& normal, const SkPoint& stop, | 35 const SkVector& normal, const SkPoint& stop, |
| 52 SkPath* otherPath) | 36 SkPath* otherPath) |
| 53 { | 37 { |
| 54 SkVector parallel; | 38 SkVector parallel; |
| 55 normal.rotateCW(¶llel); | 39 normal.rotateCW(¶llel); |
| 56 | 40 |
| 57 if (otherPath) | 41 if (otherPath) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 { | 126 { |
| 143 SkTSwap<SkPath*>(outer, inner); | 127 SkTSwap<SkPath*>(outer, inner); |
| 144 before.negate(); | 128 before.negate(); |
| 145 after.negate(); | 129 after.negate(); |
| 146 dir = kCCW_SkRotationDirection; | 130 dir = kCCW_SkRotationDirection; |
| 147 } | 131 } |
| 148 | 132 |
| 149 SkMatrix matrix; | 133 SkMatrix matrix; |
| 150 matrix.setScale(radius, radius); | 134 matrix.setScale(radius, radius); |
| 151 matrix.postTranslate(pivot.fX, pivot.fY); | 135 matrix.postTranslate(pivot.fX, pivot.fY); |
| 152 #ifdef SK_SUPPORT_LEGACY_ARCTO_QUADS | |
| 153 SkPoint pts[kSkBuildQuadArcStorage]; | |
| 154 int count = SkBuildQuadArc(before, after, dir, &matrix, pts); | |
| 155 SkASSERT((count & 1) == 1); | |
| 156 if (count > 1) { | |
| 157 for (int i = 1; i < count; i += 2) { | |
| 158 outer->quadTo(pts[i].fX, pts[i].fY, pts[i+1].fX, pts[i+1].fY); | |
| 159 } | |
| 160 after.scale(radius); | |
| 161 HandleInnerJoin(inner, pivot, after); | |
| 162 } | |
| 163 #else | |
| 164 SkConic conics[SkConic::kMaxConicsForArc]; | 136 SkConic conics[SkConic::kMaxConicsForArc]; |
| 165 int count = SkConic::BuildUnitArc(before, after, dir, &matrix, conics); | 137 int count = SkConic::BuildUnitArc(before, after, dir, &matrix, conics); |
| 166 if (count > 0) { | 138 if (count > 0) { |
| 167 for (int i = 0; i < count; ++i) { | 139 for (int i = 0; i < count; ++i) { |
| 168 outer->conicTo(conics[i].fPts[1], conics[i].fPts[2], conics[i].fW); | 140 outer->conicTo(conics[i].fPts[1], conics[i].fPts[2], conics[i].fW); |
| 169 } | 141 } |
| 170 after.scale(radius); | 142 after.scale(radius); |
| 171 HandleInnerJoin(inner, pivot, after); | 143 HandleInnerJoin(inner, pivot, after); |
| 172 } | 144 } |
| 173 #endif | |
| 174 } | 145 } |
| 175 | 146 |
| 176 #define kOneOverSqrt2 (0.707106781f) | 147 #define kOneOverSqrt2 (0.707106781f) |
| 177 | 148 |
| 178 static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
Normal, | 149 static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
Normal, |
| 179 const SkPoint& pivot, const SkVector& afterUnitNormal, | 150 const SkPoint& pivot, const SkVector& afterUnitNormal, |
| 180 SkScalar radius, SkScalar invMiterLimit, | 151 SkScalar radius, SkScalar invMiterLimit, |
| 181 bool prevIsLine, bool currIsLine) | 152 bool prevIsLine, bool currIsLine) |
| 182 { | 153 { |
| 183 // negate the dot since we're using normals instead of tangents | 154 // negate the dot since we're using normals instead of tangents |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 242 |
| 272 SkStrokerPriv::JoinProc SkStrokerPriv::JoinFactory(SkPaint::Join join) | 243 SkStrokerPriv::JoinProc SkStrokerPriv::JoinFactory(SkPaint::Join join) |
| 273 { | 244 { |
| 274 static const SkStrokerPriv::JoinProc gJoiners[] = { | 245 static const SkStrokerPriv::JoinProc gJoiners[] = { |
| 275 MiterJoiner, RoundJoiner, BluntJoiner | 246 MiterJoiner, RoundJoiner, BluntJoiner |
| 276 }; | 247 }; |
| 277 | 248 |
| 278 SkASSERT((unsigned)join < SkPaint::kJoinCount); | 249 SkASSERT((unsigned)join < SkPaint::kJoinCount); |
| 279 return gJoiners[join]; | 250 return gJoiners[join]; |
| 280 } | 251 } |
| OLD | NEW |