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 "SkDashPathPriv.h" | 8 #include "SkDashPathPriv.h" |
9 #include "SkPathMeasure.h" | 9 #include "SkPathMeasure.h" |
10 #include "SkStrokeRec.h" | 10 #include "SkStrokeRec.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 fTangent.rotateCCW(&fNormal); | 169 fTangent.rotateCCW(&fNormal); |
170 fNormal.scale(SkScalarHalf(rec->getWidth())); | 170 fNormal.scale(SkScalarHalf(rec->getWidth())); |
171 | 171 |
172 // now estimate how many quads will be added to the path | 172 // now estimate how many quads will be added to the path |
173 // resulting segments = pathLen * intervalCount / intervalLen | 173 // resulting segments = pathLen * intervalCount / intervalLen |
174 // resulting points = 4 * segments | 174 // resulting points = 4 * segments |
175 | 175 |
176 SkScalar ptCount = SkScalarMulDiv(pathLength, | 176 SkScalar ptCount = SkScalarMulDiv(pathLength, |
177 SkIntToScalar(intervalCount), | 177 SkIntToScalar(intervalCount), |
178 intervalLength); | 178 intervalLength); |
179 ptCount = SkTMin(ptCount, SkDashPath::kMaxDashCount); | |
caryclark
2016/07/21 12:22:59
Don't need the SkDashPath:: prefix here
| |
179 int n = SkScalarCeilToInt(ptCount) << 2; | 180 int n = SkScalarCeilToInt(ptCount) << 2; |
180 dst->incReserve(n); | 181 dst->incReserve(n); |
181 | 182 |
182 // we will take care of the stroking | 183 // we will take care of the stroking |
183 rec->setFillStyle(); | 184 rec->setFillStyle(); |
184 return true; | 185 return true; |
185 } | 186 } |
186 | 187 |
187 void addSegment(SkScalar d0, SkScalar d1, SkPath* path) const { | 188 void addSegment(SkScalar d0, SkScalar d1, SkPath* path) const { |
188 SkASSERT(d0 < fPathLength); | 189 SkASSERT(d0 < fPathLength); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 int index = initialDashIndex; | 249 int index = initialDashIndex; |
249 | 250 |
250 // Since the path length / dash length ratio may be arbitrarily large, w e can exert | 251 // Since the path length / dash length ratio may be arbitrarily large, w e can exert |
251 // significant memory pressure while attempting to build the filtered pa th. To avoid this, | 252 // significant memory pressure while attempting to build the filtered pa th. To avoid this, |
252 // we simply give up dashing beyond a certain threshold. | 253 // we simply give up dashing beyond a certain threshold. |
253 // | 254 // |
254 // The original bug report (http://crbug.com/165432) is based on a path yielding more than | 255 // The original bug report (http://crbug.com/165432) is based on a path yielding more than |
255 // 90 million dash segments and crashing the memory allocator. A limit o f 1 million | 256 // 90 million dash segments and crashing the memory allocator. A limit o f 1 million |
256 // segments seems reasonable: at 2 verbs per segment * 9 bytes per verb, this caps the | 257 // segments seems reasonable: at 2 verbs per segment * 9 bytes per verb, this caps the |
257 // maximum dash memory overhead at roughly 17MB per path. | 258 // maximum dash memory overhead at roughly 17MB per path. |
258 static const SkScalar kMaxDashCount = 1000000; | |
259 dashCount += length * (count >> 1) / intervalLength; | 259 dashCount += length * (count >> 1) / intervalLength; |
260 if (dashCount > kMaxDashCount) { | 260 if (dashCount > kMaxDashCount) { |
261 dst->reset(); | 261 dst->reset(); |
262 return false; | 262 return false; |
263 } | 263 } |
264 | 264 |
265 // Using double precision to avoid looping indefinitely due to single pr ecision rounding | 265 // Using double precision to avoid looping indefinitely due to single pr ecision rounding |
266 // (for extreme path_length/dash_length ratios). See test_infinite_dash( ) unittest. | 266 // (for extreme path_length/dash_length ratios). See test_infinite_dash( ) unittest. |
267 double distance = 0; | 267 double distance = 0; |
268 double dlen = initialDashLength; | 268 double dlen = initialDashLength; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 SkScalar length = 0; | 336 SkScalar length = 0; |
337 for (int i = 0; i < count; i++) { | 337 for (int i = 0; i < count; i++) { |
338 if (intervals[i] < 0) { | 338 if (intervals[i] < 0) { |
339 return false; | 339 return false; |
340 } | 340 } |
341 length += intervals[i]; | 341 length += intervals[i]; |
342 } | 342 } |
343 // watch out for values that might make us go out of bounds | 343 // watch out for values that might make us go out of bounds |
344 return length > 0 && SkScalarIsFinite(phase) && SkScalarIsFinite(length); | 344 return length > 0 && SkScalarIsFinite(phase) && SkScalarIsFinite(length); |
345 } | 345 } |
OLD | NEW |