OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkMath.h" | 10 #include "SkMath.h" |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkScalar.h" | 12 #include "SkScalar.h" |
13 | 13 |
14 /* | 14 /* |
15 Duplicates lots of code from gpu/src/GrPathUtils.cpp | 15 Duplicates lots of code from gpu/src/GrPathUtils.cpp |
16 It'd be nice not to do so, but that code's set up currently to only have | 16 It'd be nice not to do so, but that code's set up currently to only have |
17 a single implementation. | 17 a single implementation. |
18 */ | 18 */ |
19 | 19 |
20 // Sk uses 6, Gr (implicitly) used 10, both apparently arbitrarily. | 20 // Sk uses 6, Gr (implicitly) used 10, both apparently arbitrarily. |
21 #define MAX_COEFF_SHIFT 6 | 21 #define MAX_COEFF_SHIFT 6 |
22 static const uint32_t MAX_POINTS_PER_CURVE = 1 << MAX_COEFF_SHIFT; | 22 static const uint32_t MAX_POINTS_PER_CURVE = 1 << MAX_COEFF_SHIFT; |
23 | 23 |
24 // max + 0.5 min has error [0.0, 0.12] | 24 // max + 0.5 min has error [0.0, 0.12] |
25 // max + 0.375 min has error [-.03, 0.07] | 25 // max + 0.375 min has error [-.03, 0.07] |
26 // 0.96043387 max + 0.397824735 min has error [-.06, +.05] | 26 // 0.96043387 max + 0.397824735 min has error [-.06, +.05] |
27 // For determining the maximum possible number of points to use in | 27 // For determining the maximum possible number of points to use in |
28 // drawing a quadratic, we want to err on the high side. | 28 // drawing a quadratic, we want to err on the high side. |
29 static inline int cheap_distance(SkScalar dx, SkScalar dy) { | 29 static inline int cheap_distance(SkScalar dx, SkScalar dy) { |
30 int idx = SkAbs32(SkScalarRound(dx)); | 30 int idx = SkAbs32(SkScalarRoundToInt(dx)); |
31 int idy = SkAbs32(SkScalarRound(dy)); | 31 int idy = SkAbs32(SkScalarRoundToInt(dy)); |
32 if (idx > idy) { | 32 if (idx > idy) { |
33 idx += idy >> 1; | 33 idx += idy >> 1; |
34 } else { | 34 } else { |
35 idx = idy + (idx >> 1); | 35 idx = idy + (idx >> 1); |
36 } | 36 } |
37 return idx; | 37 return idx; |
38 } | 38 } |
39 | 39 |
40 static inline int estimate_distance(const SkPoint points[]) { | 40 static inline int estimate_distance(const SkPoint points[]) { |
41 return cheap_distance(points[1].fX * 2 - points[2].fX - points[0].fX, | 41 return cheap_distance(points[1].fX * 2 - points[2].fX - points[0].fX, |
(...skipping 30 matching lines...) Expand all Loading... |
72 return estimate_pointCount(distance); | 72 return estimate_pointCount(distance); |
73 } | 73 } |
74 | 74 |
75 static uint32_t quadraticPointCount_EC(const SkPoint points[], SkScalar tol) { | 75 static uint32_t quadraticPointCount_EC(const SkPoint points[], SkScalar tol) { |
76 int distance = estimate_distance(points); | 76 int distance = estimate_distance(points); |
77 return compute_pointCount(SkIntToScalar(distance), tol); | 77 return compute_pointCount(SkIntToScalar(distance), tol); |
78 } | 78 } |
79 | 79 |
80 static uint32_t quadraticPointCount_CE(const SkPoint points[]) { | 80 static uint32_t quadraticPointCount_CE(const SkPoint points[]) { |
81 SkScalar distance = compute_distance(points); | 81 SkScalar distance = compute_distance(points); |
82 return estimate_pointCount(SkScalarRound(distance)); | 82 return estimate_pointCount(SkScalarRoundToInt(distance)); |
83 } | 83 } |
84 | 84 |
85 static uint32_t quadraticPointCount_CC(const SkPoint points[], SkScalar tol) { | 85 static uint32_t quadraticPointCount_CC(const SkPoint points[], SkScalar tol) { |
86 SkScalar distance = compute_distance(points); | 86 SkScalar distance = compute_distance(points); |
87 return compute_pointCount(distance, tol); | 87 return compute_pointCount(distance, tol); |
88 } | 88 } |
89 | 89 |
90 // Curve from samplecode/SampleSlides.cpp | 90 // Curve from samplecode/SampleSlides.cpp |
91 static const int gXY[] = { | 91 static const int gXY[] = { |
92 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 | 92 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 one_d_pe(gSawtooth, SK_ARRAY_COUNT(gSawtooth), reporter); | 158 one_d_pe(gSawtooth, SK_ARRAY_COUNT(gSawtooth), reporter); |
159 one_d_pe(gOvalish, SK_ARRAY_COUNT(gOvalish), reporter); | 159 one_d_pe(gOvalish, SK_ARRAY_COUNT(gOvalish), reporter); |
160 one_d_pe(gSharpSawtooth, SK_ARRAY_COUNT(gSharpSawtooth), reporter); | 160 one_d_pe(gSharpSawtooth, SK_ARRAY_COUNT(gSharpSawtooth), reporter); |
161 one_d_pe(gRibbon, SK_ARRAY_COUNT(gRibbon), reporter); | 161 one_d_pe(gRibbon, SK_ARRAY_COUNT(gRibbon), reporter); |
162 } | 162 } |
163 | 163 |
164 DEF_TEST(PathCoverage, reporter) { | 164 DEF_TEST(PathCoverage, reporter) { |
165 TestQuadPointCount(reporter); | 165 TestQuadPointCount(reporter); |
166 | 166 |
167 } | 167 } |
OLD | NEW |