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 "SkDashPathEffect.h" | 8 #include "SkDashPathEffect.h" |
9 | 9 |
10 #include "SkDashPathPriv.h" | 10 #include "SkDashPathPriv.h" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkStrokeRec.h" | 13 #include "SkStrokeRec.h" |
14 | 14 |
15 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScal
ar phase) | 15 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScal
ar phase) |
16 : fPhase(0) | 16 : fPhase(0) |
17 , fInitialDashLength(0) | 17 , fInitialDashLength(-1) |
18 , fInitialDashIndex(0) | 18 , fInitialDashIndex(0) |
19 , fIntervalLength(0) { | 19 , fIntervalLength(0) { |
20 SkASSERT(intervals); | 20 SkASSERT(intervals); |
21 SkASSERT(count > 1 && SkAlign2(count) == count); | 21 SkASSERT(count > 1 && SkAlign2(count) == count); |
22 | 22 |
23 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count); | 23 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count); |
24 fCount = count; | 24 fCount = count; |
25 for (int i = 0; i < count; i++) { | 25 for (int i = 0; i < count; i++) { |
26 SkASSERT(intervals[i] >= 0); | 26 SkASSERT(intervals[i] >= 0); |
27 fIntervals[i] = intervals[i]; | 27 fIntervals[i] = intervals[i]; |
28 } | 28 } |
29 | 29 |
30 // set the internal data members | 30 // set the internal data members |
31 SkDashPath::CalcDashParameters(phase, fIntervals, fCount, | 31 fValidParameters = SkDashPath::CalcDashParameters(phase, fIntervals, fCount, |
32 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase); | 32 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase); |
33 } | 33 } |
34 | 34 |
35 SkDashPathEffect::~SkDashPathEffect() { | 35 SkDashPathEffect::~SkDashPathEffect() { |
36 sk_free(fIntervals); | 36 sk_free(fIntervals); |
37 } | 37 } |
38 | 38 |
39 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, | 39 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, |
40 SkStrokeRec* rec, const SkRect* cullRect) const { | 40 SkStrokeRec* rec, const SkRect* cullRect) const { |
| 41 if (!fValidParameters) { |
| 42 return false; |
| 43 } |
41 return SkDashPath::FilterDashPath(dst, src, rec, cullRect, fIntervals, fCoun
t, | 44 return SkDashPath::FilterDashPath(dst, src, rec, cullRect, fIntervals, fCoun
t, |
42 fInitialDashLength, fInitialDashIndex, fIn
tervalLength); | 45 fInitialDashLength, fInitialDashIndex, fIn
tervalLength); |
43 } | 46 } |
44 | 47 |
45 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) { | 48 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) { |
46 SkScalar radius = SkScalarHalf(rec.getWidth()); | 49 SkScalar radius = SkScalarHalf(rec.getWidth()); |
47 if (0 == radius) { | 50 if (0 == radius) { |
48 radius = SK_Scalar1; // hairlines | 51 radius = SK_Scalar1; // hairlines |
49 } | 52 } |
50 if (SkPaint::kMiter_Join == rec.getJoin()) { | 53 if (SkPaint::kMiter_Join == rec.getJoin()) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Currently asPoints is more restrictive then it needs to be. In the future | 158 // Currently asPoints is more restrictive then it needs to be. In the future |
156 // we need to: | 159 // we need to: |
157 // allow kRound_Cap capping (could allow rotations in the matrix with this) | 160 // allow kRound_Cap capping (could allow rotations in the matrix with this) |
158 // allow paths to be returned | 161 // allow paths to be returned |
159 bool SkDashPathEffect::asPoints(PointData* results, | 162 bool SkDashPathEffect::asPoints(PointData* results, |
160 const SkPath& src, | 163 const SkPath& src, |
161 const SkStrokeRec& rec, | 164 const SkStrokeRec& rec, |
162 const SkMatrix& matrix, | 165 const SkMatrix& matrix, |
163 const SkRect* cullRect) const { | 166 const SkRect* cullRect) const { |
164 // width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules
both out | 167 // width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules
both out |
165 if (fInitialDashLength < 0 || 0 >= rec.getWidth()) { | 168 if (!fValidParameters || 0 >= rec.getWidth()) { |
166 return false; | 169 return false; |
167 } | 170 } |
168 | 171 |
169 // TODO: this next test could be eased up. We could allow any number of | 172 // TODO: this next test could be eased up. We could allow any number of |
170 // intervals as long as all the ons match and all the offs match. | 173 // intervals as long as all the ons match and all the offs match. |
171 // Additionally, they do not necessarily need to be integers. | 174 // Additionally, they do not necessarily need to be integers. |
172 // We cannot allow arbitrary intervals since we want the returned points | 175 // We cannot allow arbitrary intervals since we want the returned points |
173 // to be uniformly sized. | 176 // to be uniformly sized. |
174 if (fCount != 2 || | 177 if (fCount != 2 || |
175 !SkScalarNearlyEqual(fIntervals[0], fIntervals[1]) || | 178 !SkScalarNearlyEqual(fIntervals[0], fIntervals[1]) || |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if ((count < 2) || !SkIsAlign2(count)) { | 394 if ((count < 2) || !SkIsAlign2(count)) { |
392 return nullptr; | 395 return nullptr; |
393 } | 396 } |
394 for (int i = 0; i < count; i++) { | 397 for (int i = 0; i < count; i++) { |
395 if (intervals[i] < 0) { | 398 if (intervals[i] < 0) { |
396 return nullptr; | 399 return nullptr; |
397 } | 400 } |
398 } | 401 } |
399 return new SkDashPathEffect(intervals, count, phase); | 402 return new SkDashPathEffect(intervals, count, phase); |
400 } | 403 } |
OLD | NEW |