OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkBuffer.h" | 8 #include "SkBuffer.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 static int build_arc_points(const SkRect& oval, const SkVector& start, const SkV
ector& stop, | 927 static int build_arc_points(const SkRect& oval, const SkVector& start, const SkV
ector& stop, |
928 SkRotationDirection dir, SkPoint pts[kSkBuildQuadArc
Storage]) { | 928 SkRotationDirection dir, SkPoint pts[kSkBuildQuadArc
Storage]) { |
929 SkMatrix matrix; | 929 SkMatrix matrix; |
930 | 930 |
931 matrix.setScale(SkScalarHalf(oval.width()), SkScalarHalf(oval.height())); | 931 matrix.setScale(SkScalarHalf(oval.width()), SkScalarHalf(oval.height())); |
932 matrix.postTranslate(oval.centerX(), oval.centerY()); | 932 matrix.postTranslate(oval.centerX(), oval.centerY()); |
933 | 933 |
934 return SkBuildQuadArc(start, stop, dir, &matrix, pts); | 934 return SkBuildQuadArc(start, stop, dir, &matrix, pts); |
935 } | 935 } |
936 #else | 936 #else |
| 937 /** |
| 938 * If this returns 0, then the caller should just line-to the singlePt, else it
should |
| 939 * ignore singlePt and append the specified number of conics. |
| 940 */ |
937 static int build_arc_conics(const SkRect& oval, const SkVector& start, const SkV
ector& stop, | 941 static int build_arc_conics(const SkRect& oval, const SkVector& start, const SkV
ector& stop, |
938 SkRotationDirection dir, SkConic conics[SkConic::kMa
xConicsForArc]) { | 942 SkRotationDirection dir, SkConic conics[SkConic::kMa
xConicsForArc], |
| 943 SkPoint* singlePt) { |
939 SkMatrix matrix; | 944 SkMatrix matrix; |
940 | 945 |
941 matrix.setScale(SkScalarHalf(oval.width()), SkScalarHalf(oval.height())); | 946 matrix.setScale(SkScalarHalf(oval.width()), SkScalarHalf(oval.height())); |
942 matrix.postTranslate(oval.centerX(), oval.centerY()); | 947 matrix.postTranslate(oval.centerX(), oval.centerY()); |
943 | 948 |
944 return SkConic::BuildUnitArc(start, stop, dir, &matrix, conics); | 949 int count = SkConic::BuildUnitArc(start, stop, dir, &matrix, conics); |
| 950 if (0 == count) { |
| 951 matrix.mapXY(start.x(), start.y(), singlePt); |
| 952 } |
| 953 return count; |
945 } | 954 } |
946 #endif | 955 #endif |
947 | 956 |
948 void SkPath::addRoundRect(const SkRect& rect, const SkScalar radii[], | 957 void SkPath::addRoundRect(const SkRect& rect, const SkScalar radii[], |
949 Direction dir) { | 958 Direction dir) { |
950 SkRRect rrect; | 959 SkRRect rrect; |
951 rrect.setRectRadii(rect, (const SkVector*) radii); | 960 rrect.setRectRadii(rect, (const SkVector*) radii); |
952 this->addRRect(rrect, dir); | 961 this->addRRect(rrect, dir); |
953 } | 962 } |
954 | 963 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 SkPoint pts[kSkBuildQuadArcStorage]; | 1178 SkPoint pts[kSkBuildQuadArcStorage]; |
1170 int count = build_arc_points(oval, startV, stopV, dir, pts); | 1179 int count = build_arc_points(oval, startV, stopV, dir, pts); |
1171 SkASSERT((count & 1) == 1); | 1180 SkASSERT((count & 1) == 1); |
1172 | 1181 |
1173 this->incReserve(count); | 1182 this->incReserve(count); |
1174 forceMoveTo ? this->moveTo(pts[0]) : this->lineTo(pts[0]); | 1183 forceMoveTo ? this->moveTo(pts[0]) : this->lineTo(pts[0]); |
1175 for (int i = 1; i < count; i += 2) { | 1184 for (int i = 1; i < count; i += 2) { |
1176 this->quadTo(pts[i], pts[i+1]); | 1185 this->quadTo(pts[i], pts[i+1]); |
1177 } | 1186 } |
1178 #else | 1187 #else |
| 1188 SkPoint singlePt; |
1179 SkConic conics[SkConic::kMaxConicsForArc]; | 1189 SkConic conics[SkConic::kMaxConicsForArc]; |
1180 int count = build_arc_conics(oval, startV, stopV, dir, conics); | 1190 int count = build_arc_conics(oval, startV, stopV, dir, conics, &singlePt); |
1181 if (count) { | 1191 if (count) { |
1182 this->incReserve(count * 2 + 1); | 1192 this->incReserve(count * 2 + 1); |
1183 const SkPoint& pt = conics[0].fPts[0]; | 1193 const SkPoint& pt = conics[0].fPts[0]; |
1184 forceMoveTo ? this->moveTo(pt) : this->lineTo(pt); | 1194 forceMoveTo ? this->moveTo(pt) : this->lineTo(pt); |
1185 for (int i = 0; i < count; ++i) { | 1195 for (int i = 0; i < count; ++i) { |
1186 this->conicTo(conics[i].fPts[1], conics[i].fPts[2], conics[i].fW); | 1196 this->conicTo(conics[i].fPts[1], conics[i].fPts[2], conics[i].fW); |
1187 } | 1197 } |
| 1198 } else { |
| 1199 forceMoveTo ? this->moveTo(singlePt) : this->lineTo(singlePt); |
1188 } | 1200 } |
1189 #endif | 1201 #endif |
1190 } | 1202 } |
1191 | 1203 |
1192 void SkPath::addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle
) { | 1204 void SkPath::addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle
) { |
1193 if (oval.isEmpty() || 0 == sweepAngle) { | 1205 if (oval.isEmpty() || 0 == sweepAngle) { |
1194 return; | 1206 return; |
1195 } | 1207 } |
1196 | 1208 |
1197 const SkScalar kFullCircleAngle = SkIntToScalar(360); | 1209 const SkScalar kFullCircleAngle = SkIntToScalar(360); |
(...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2774 switch (this->getFillType()) { | 2786 switch (this->getFillType()) { |
2775 case SkPath::kEvenOdd_FillType: | 2787 case SkPath::kEvenOdd_FillType: |
2776 case SkPath::kInverseEvenOdd_FillType: | 2788 case SkPath::kInverseEvenOdd_FillType: |
2777 w &= 1; | 2789 w &= 1; |
2778 break; | 2790 break; |
2779 default: | 2791 default: |
2780 break; | 2792 break; |
2781 } | 2793 } |
2782 return SkToBool(w); | 2794 return SkToBool(w); |
2783 } | 2795 } |
OLD | NEW |