Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/utils/SkDashPath.cpp

Issue 1805963002: allow one zero length dash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use explicit bad params flag Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkDashPathEffect.cpp ('k') | src/utils/SkDashPathPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkDashPathPriv.h" 8 #include "SkDashPathPriv.h"
9 #include "SkPathMeasure.h" 9 #include "SkPathMeasure.h"
10 #include "SkStrokeRec.h" 10 #include "SkStrokeRec.h"
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 } 25 }
26 // If we get here, phase "appears" to be larger than our length. This 26 // If we get here, phase "appears" to be larger than our length. This
27 // shouldn't happen with perfect precision, but we can accumulate errors 27 // shouldn't happen with perfect precision, but we can accumulate errors
28 // during the initial length computation (rounding can make our sum be too 28 // during the initial length computation (rounding can make our sum be too
29 // big or too small. In that event, we just have to eat the error here. 29 // big or too small. In that event, we just have to eat the error here.
30 *index = 0; 30 *index = 0;
31 return intervals[0]; 31 return intervals[0];
32 } 32 }
33 33
34 void SkDashPath::CalcDashParameters(SkScalar phase, const SkScalar intervals[], int32_t count, 34 bool SkDashPath::CalcDashParameters(SkScalar phase, const SkScalar intervals[], int32_t count,
35 SkScalar* initialDashLength, int32_t* initia lDashIndex, 35 SkScalar* initialDashLength, int32_t* initia lDashIndex,
36 SkScalar* intervalLength, SkScalar* adjusted Phase) { 36 SkScalar* intervalLength, SkScalar* adjusted Phase) {
37 SkScalar len = 0; 37 SkScalar len = 0;
38 for (int i = 0; i < count; i++) { 38 for (int i = 0; i < count; i++) {
39 len += intervals[i]; 39 len += intervals[i];
40 } 40 }
41 *intervalLength = len; 41 *intervalLength = len;
42 42
43 // watch out for values that might make us go out of bounds 43 // watch out for values that might make us go out of bounds
44 if ((len > 0) && SkScalarIsFinite(phase) && SkScalarIsFinite(len)) { 44 if ((len <= 0) || !SkScalarIsFinite(phase) || !SkScalarIsFinite(len)) {
45 return false;
46 }
45 47
46 // Adjust phase to be between 0 and len, "flipping" phase if negative. 48 // Adjust phase to be between 0 and len, "flipping" phase if negative.
47 // e.g., if len is 100, then phase of -20 (or -120) is equivalent to 80 49 // e.g., if len is 100, then phase of -20 (or -120) is equivalent to 80
48 if (adjustedPhase) { 50 if (adjustedPhase) {
49 if (phase < 0) { 51 if (phase < 0) {
50 phase = -phase; 52 phase = -phase;
51 if (phase > len) { 53 if (phase > len) {
52 phase = SkScalarMod(phase, len);
53 }
54 phase = len - phase;
55
56 // Due to finite precision, it's possible that phase == len,
57 // even after the subtract (if len >>> phase), so fix that here.
58 // This fixes http://crbug.com/124652 .
59 SkASSERT(phase <= len);
60 if (phase == len) {
61 phase = 0;
62 }
63 } else if (phase >= len) {
64 phase = SkScalarMod(phase, len); 54 phase = SkScalarMod(phase, len);
65 } 55 }
66 *adjustedPhase = phase; 56 phase = len - phase;
57
58 // Due to finite precision, it's possible that phase == len,
59 // even after the subtract (if len >>> phase), so fix that here.
60 // This fixes http://crbug.com/124652 .
61 SkASSERT(phase <= len);
62 if (phase == len) {
63 phase = 0;
64 }
65 } else if (phase >= len) {
66 phase = SkScalarMod(phase, len);
67 } 67 }
68 SkASSERT(phase >= 0 && phase < len); 68 *adjustedPhase = phase;
69 }
70 SkASSERT(phase >= 0 && phase < len);
69 71
70 *initialDashLength = find_first_interval(intervals, phase, 72 *initialDashLength = find_first_interval(intervals, phase,
71 initialDashIndex, count); 73 initialDashIndex, count);
72 74
73 SkASSERT(*initialDashLength >= 0); 75 SkASSERT(*initialDashLength >= 0);
74 SkASSERT(*initialDashIndex >= 0 && *initialDashIndex < count); 76 SkASSERT(*initialDashIndex >= 0 && *initialDashIndex < count);
75 } else { 77 return true;
76 *initialDashLength = -1; // signal bad dash intervals
77 }
78 } 78 }
79 79
80 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) { 80 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) {
81 SkScalar radius = SkScalarHalf(rec.getWidth()); 81 SkScalar radius = SkScalarHalf(rec.getWidth());
82 if (0 == radius) { 82 if (0 == radius) {
83 radius = SK_Scalar1; // hairlines 83 radius = SK_Scalar1; // hairlines
84 } 84 }
85 if (SkPaint::kMiter_Join == rec.getJoin()) { 85 if (SkPaint::kMiter_Join == rec.getJoin()) {
86 radius = SkScalarMul(radius, rec.getMiter()); 86 radius = SkScalarMul(radius, rec.getMiter());
87 } 87 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 SkVector fTangent; 216 SkVector fTangent;
217 SkVector fNormal; 217 SkVector fNormal;
218 SkScalar fPathLength; 218 SkScalar fPathLength;
219 }; 219 };
220 220
221 221
222 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec , 222 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec ,
223 const SkRect* cullRect, const SkScalar aInterval s[], 223 const SkRect* cullRect, const SkScalar aInterval s[],
224 int32_t count, SkScalar initialDashLength, int32 _t initialDashIndex, 224 int32_t count, SkScalar initialDashLength, int32 _t initialDashIndex,
225 SkScalar intervalLength) { 225 SkScalar intervalLength) {
226 226
robertphillips 2016/03/16 19:00:52 Is this comment right - was it ever right?
caryclark 2016/03/16 19:19:19 Done.
227 // we do nothing if the src wants to be filled, or if our dashlength is 0 227 // we do nothing if the src wants to be filled, or if our dashlength is 0
228 if (rec->isFillStyle() || initialDashLength < 0) { 228 if (rec->isFillStyle()) {
229 return false; 229 return false;
230 } 230 }
231 231
232 const SkScalar* intervals = aIntervals; 232 const SkScalar* intervals = aIntervals;
233 SkScalar dashCount = 0; 233 SkScalar dashCount = 0;
234 int segCount = 0; 234 int segCount = 0;
235 235
236 SkPath cullPathStorage; 236 SkPath cullPathStorage;
237 const SkPath* srcPtr = &src; 237 const SkPath* srcPtr = &src;
238 if (cull_path(src, *rec, cullRect, intervalLength, &cullPathStorage)) { 238 if (cull_path(src, *rec, cullRect, intervalLength, &cullPathStorage)) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (index == count) { 298 if (index == count) {
299 index = 0; 299 index = 0;
300 } 300 }
301 301
302 // fetch our next dlen 302 // fetch our next dlen
303 dlen = intervals[index]; 303 dlen = intervals[index];
304 } 304 }
305 305
306 // extend if we ended on a segment and we need to join up with the (skip ped) initial segment 306 // extend if we ended on a segment and we need to join up with the (skip ped) initial segment
307 if (meas.isClosed() && is_even(initialDashIndex) && 307 if (meas.isClosed() && is_even(initialDashIndex) &&
308 initialDashLength > 0) { 308 initialDashLength >= 0) {
309 meas.getSegment(0, initialDashLength, dst, !addedSegment); 309 meas.getSegment(0, initialDashLength, dst, !addedSegment);
310 ++segCount; 310 ++segCount;
311 } 311 }
312 } while (meas.nextContour()); 312 } while (meas.nextContour());
313 313
314 if (segCount > 1) { 314 if (segCount > 1) {
315 dst->setConvexity(SkPath::kConcave_Convexity); 315 dst->setConvexity(SkPath::kConcave_Convexity);
316 } 316 }
317 317
318 return true; 318 return true;
319 } 319 }
320 320
321 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec , 321 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec ,
322 const SkRect* cullRect, const SkPathEffect::Dash Info& info) { 322 const SkRect* cullRect, const SkPathEffect::Dash Info& info) {
323 SkScalar initialDashLength = 0; 323 SkScalar initialDashLength = 0;
324 int32_t initialDashIndex = 0; 324 int32_t initialDashIndex = 0;
325 SkScalar intervalLength = 0; 325 SkScalar intervalLength = 0;
326 CalcDashParameters(info.fPhase, info.fIntervals, info.fCount, 326 if (!CalcDashParameters(info.fPhase, info.fIntervals, info.fCount,
327 &initialDashLength, &initialDashIndex, &intervalLength); 327 &initialDashLength, &initialDashIndex, &intervalLength)) {
328 return false;
329 }
328 return FilterDashPath(dst, src, rec, cullRect, info.fIntervals, info.fCount, initialDashLength, 330 return FilterDashPath(dst, src, rec, cullRect, info.fIntervals, info.fCount, initialDashLength,
329 initialDashIndex, intervalLength); 331 initialDashIndex, intervalLength);
330 } 332 }
OLDNEW
« no previous file with comments | « src/effects/SkDashPathEffect.cpp ('k') | src/utils/SkDashPathPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698