OLD | NEW |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
1 #include "PathOpsCubicIntersectionTestData.h" | 8 #include "PathOpsCubicIntersectionTestData.h" |
2 #include "PathOpsQuadIntersectionTestData.h" | 9 #include "PathOpsQuadIntersectionTestData.h" |
3 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
4 #include "SkPaint.h" | 11 #include "SkPaint.h" |
5 #include "SkPath.h" | 12 #include "SkPath.h" |
6 #include "SkRandom.h" | 13 #include "SkRandom.h" |
7 #include "SkStrokerPriv.h" | 14 #include "SkStrokerPriv.h" |
8 #include "SkTime.h" | 15 #include "SkTime.h" |
9 #include "Test.h" | 16 #include "Test.h" |
10 | 17 |
11 DEFINE_bool(timeout, true, "run until alloted time expires"); | 18 DEFINE_bool(timeout, true, "run until alloted time expires"); |
12 | 19 |
13 #define MS_TEST_DURATION 10 | 20 #define MS_TEST_DURATION 10 |
14 | 21 |
15 const SkScalar widths[] = {-FLT_MAX, -1, -0.1f, -FLT_EPSILON, 0, FLT_EPSILON, | 22 const SkScalar widths[] = {-FLT_MAX, -1, -0.1f, -FLT_EPSILON, 0, FLT_EPSILON, |
16 0.0000001f, 0.000001f, 0.00001f, 0.0001f, 0.001f, 0.01f, | 23 0.0000001f, 0.000001f, 0.00001f, 0.0001f, 0.001f, 0.01f, |
17 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 1, 1.1f, 2, 10, 10e2f, 10e3f, 10e4f, 10e5f
, 10e6f, 10e7f, | 24 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 1, 1.1f, 2, 10, 10e2f, 10e3f, 10e4f, 10e5f
, 10e6f, 10e7f, |
18 10e8f, 10e9f, 10e10f, 10e20f, FLT_MAX }; | 25 10e8f, 10e9f, 10e10f, 10e20f, FLT_MAX }; |
19 size_t widths_count = SK_ARRAY_COUNT(widths); | 26 size_t widths_count = SK_ARRAY_COUNT(widths); |
20 | 27 |
21 static void pathTest(const SkPath& path) { | 28 static void pathTest(const SkPath& path) { |
22 SkPaint p; | 29 SkPaint p; |
23 » SkPath fill; | 30 SkPath fill; |
24 p.setStyle(SkPaint::kStroke_Style); | 31 p.setStyle(SkPaint::kStroke_Style); |
25 for (size_t index = 0; index < widths_count; ++index) { | 32 for (size_t index = 0; index < widths_count; ++index) { |
26 p.setStrokeWidth(widths[index]); | 33 p.setStrokeWidth(widths[index]); |
27 p.getFillPath(path, &fill); | 34 p.getFillPath(path, &fill); |
28 } | 35 } |
29 } | 36 } |
30 | 37 |
31 static void cubicTest(const SkPoint c[4]) { | 38 static void cubicTest(const SkPoint c[4]) { |
32 » SkPath path; | 39 SkPath path; |
33 » path.moveTo(c[0].fX, c[0].fY); | 40 path.moveTo(c[0].fX, c[0].fY); |
34 » path.cubicTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY, c[3].fX, c[3].fY); | 41 path.cubicTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY, c[3].fX, c[3].fY); |
35 » pathTest(path); | 42 pathTest(path); |
36 } | 43 } |
37 | 44 |
38 static void quadTest(const SkPoint c[3]) { | 45 static void quadTest(const SkPoint c[3]) { |
39 » SkPath path; | 46 SkPath path; |
40 » path.moveTo(c[0].fX, c[0].fY); | 47 path.moveTo(c[0].fX, c[0].fY); |
41 » path.quadTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY); | 48 path.quadTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY); |
42 » pathTest(path); | 49 pathTest(path); |
43 } | 50 } |
44 | 51 |
45 static void cubicSetTest(const SkDCubic* dCubic, size_t count) { | 52 static void cubicSetTest(const SkDCubic* dCubic, size_t count) { |
46 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 53 skiatest::Timer timer; |
47 » for (size_t index = 0; index < count; ++index) { | 54 for (size_t index = 0; index < count; ++index) { |
48 » » const SkDCubic& d = dCubic[index]; | 55 const SkDCubic& d = dCubic[index]; |
49 » » SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[
1].fX, (float) d[1].fY}, | 56 SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (
float) d[1].fY}, |
50 {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].fX, (
float) d[3].fY} }; | 57 {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].fX, (
float) d[3].fY} }; |
51 » cubicTest(c); | 58 cubicTest(c); |
52 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 59 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
53 return; | 60 return; |
54 } | 61 } |
55 » } | 62 } |
56 } | 63 } |
57 | 64 |
58 static void cubicPairSetTest(const SkDCubic dCubic[][2], size_t count) { | 65 static void cubicPairSetTest(const SkDCubic dCubic[][2], size_t count) { |
59 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 66 skiatest::Timer timer; |
60 » for (size_t index = 0; index < count; ++index) { | 67 for (size_t index = 0; index < count; ++index) { |
61 » » for (int pair = 0; pair < 2; ++pair) { | 68 for (int pair = 0; pair < 2; ++pair) { |
62 » » » const SkDCubic& d = dCubic[index][pair]; | 69 const SkDCubic& d = dCubic[index][pair]; |
63 » » » SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(f
loat) d[1].fX, (float) d[1].fY}, | 70 SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].f
X, (float) d[1].fY}, |
64 {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].f
X, (float) d[3].fY} }; | 71 {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].f
X, (float) d[3].fY} }; |
65 » » » cubicTest(c); | 72 cubicTest(c); |
66 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 73 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
67 return; | 74 return; |
68 } | 75 } |
69 » » } | 76 } |
70 » } | 77 } |
71 } | 78 } |
72 | 79 |
73 static void quadSetTest(const SkDQuad* dQuad, size_t count) { | 80 static void quadSetTest(const SkDQuad* dQuad, size_t count) { |
74 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 81 skiatest::Timer timer; |
75 » for (size_t index = 0; index < count; ++index) { | 82 for (size_t index = 0; index < count; ++index) { |
76 » » const SkDQuad& d = dQuad[index]; | 83 const SkDQuad& d = dQuad[index]; |
77 » » SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[
1].fX, (float) d[1].fY}, | 84 SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (
float) d[1].fY}, |
78 {(float) d[2].fX, (float) d[2].fY} }; | 85 {(float) d[2].fX, (float) d[2].fY} }; |
79 » quadTest(c); | 86 quadTest(c); |
80 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 87 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
81 return; | 88 return; |
82 } | 89 } |
83 » } | 90 } |
84 } | 91 } |
85 | 92 |
86 static void quadPairSetTest(const SkDQuad dQuad[][2], size_t count) { | 93 static void quadPairSetTest(const SkDQuad dQuad[][2], size_t count) { |
87 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 94 skiatest::Timer timer; |
88 » for (size_t index = 0; index < count; ++index) { | 95 for (size_t index = 0; index < count; ++index) { |
89 » » for (int pair = 0; pair < 2; ++pair) { | 96 for (int pair = 0; pair < 2; ++pair) { |
90 » » » const SkDQuad& d = dQuad[index][pair]; | 97 const SkDQuad& d = dQuad[index][pair]; |
91 » » » SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(f
loat) d[1].fX, (float) d[1].fY}, | 98 SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].f
X, (float) d[1].fY}, |
92 {(float) d[2].fX, (float) d[2].fY} }; | 99 {(float) d[2].fX, (float) d[2].fY} }; |
93 » » » quadTest(c); | 100 quadTest(c); |
94 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 101 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
95 return; | 102 return; |
96 } | 103 } |
97 » » } | 104 } |
98 » } | 105 } |
99 } | 106 } |
100 | 107 |
101 DEF_TEST(QuadStrokerSet, reporter) { | 108 DEF_TEST(QuadStrokerSet, reporter) { |
102 » quadSetTest(quadraticLines, quadraticLines_count); | 109 quadSetTest(quadraticLines, quadraticLines_count); |
103 » quadSetTest(quadraticPoints, quadraticPoints_count); | 110 quadSetTest(quadraticPoints, quadraticPoints_count); |
104 » quadSetTest(quadraticModEpsilonLines, quadraticModEpsilonLines_count); | 111 quadSetTest(quadraticModEpsilonLines, quadraticModEpsilonLines_count); |
105 » quadPairSetTest(quadraticTests, quadraticTests_count); | 112 quadPairSetTest(quadraticTests, quadraticTests_count); |
106 } | 113 } |
107 | 114 |
108 DEF_TEST(CubicStrokerSet, reporter) { | 115 DEF_TEST(CubicStrokerSet, reporter) { |
109 » cubicSetTest(pointDegenerates, pointDegenerates_count); | 116 cubicSetTest(pointDegenerates, pointDegenerates_count); |
110 » cubicSetTest(notPointDegenerates, notPointDegenerates_count); | 117 cubicSetTest(notPointDegenerates, notPointDegenerates_count); |
111 » cubicSetTest(lines, lines_count); | 118 cubicSetTest(lines, lines_count); |
112 » cubicSetTest(notLines, notLines_count); | 119 cubicSetTest(notLines, notLines_count); |
113 » cubicSetTest(modEpsilonLines, modEpsilonLines_count); | 120 cubicSetTest(modEpsilonLines, modEpsilonLines_count); |
114 » cubicSetTest(lessEpsilonLines, lessEpsilonLines_count); | 121 cubicSetTest(lessEpsilonLines, lessEpsilonLines_count); |
115 » cubicSetTest(negEpsilonLines, negEpsilonLines_count); | 122 cubicSetTest(negEpsilonLines, negEpsilonLines_count); |
116 » cubicPairSetTest(tests, tests_count); | 123 cubicPairSetTest(tests, tests_count); |
117 } | 124 } |
118 | 125 |
119 static SkScalar unbounded(SkRandom& r) { | 126 static SkScalar unbounded(SkRandom& r) { |
120 uint32_t val = r.nextU(); | 127 uint32_t val = r.nextU(); |
121 return SkBits2Float(val); | 128 return SkBits2Float(val); |
122 } | 129 } |
123 | 130 |
124 static SkScalar unboundedPos(SkRandom& r) { | 131 static SkScalar unboundedPos(SkRandom& r) { |
125 uint32_t val = r.nextU() & 0x7fffffff; | 132 uint32_t val = r.nextU() & 0x7fffffff; |
126 return SkBits2Float(val); | 133 return SkBits2Float(val); |
127 } | 134 } |
128 | 135 |
129 DEF_TEST(QuadStrokerUnbounded, reporter) { | 136 DEF_TEST(QuadStrokerUnbounded, reporter) { |
130 SkRandom r; | 137 SkRandom r; |
131 SkPaint p; | 138 SkPaint p; |
132 p.setStyle(SkPaint::kStroke_Style); | 139 p.setStyle(SkPaint::kStroke_Style); |
133 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 140 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
134 int best = 0; | 141 int best = 0; |
135 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 142 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
136 #endif | 143 #endif |
137 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 144 skiatest::Timer timer; |
138 for (int i = 0; i < 1000000; ++i) { | 145 for (int i = 0; i < 1000000; ++i) { |
139 SkPath path, fill; | 146 SkPath path, fill; |
140 path.moveTo(unbounded(r), unbounded(r)); | 147 path.moveTo(unbounded(r), unbounded(r)); |
141 path.quadTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r)); | 148 path.quadTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r)); |
142 p.setStrokeWidth(unboundedPos(r)); | 149 p.setStrokeWidth(unboundedPos(r)); |
143 p.getFillPath(path, &fill); | 150 p.getFillPath(path, &fill); |
144 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 151 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
145 if (best < gMaxRecursion[2]) { | 152 if (best < gMaxRecursion[2]) { |
146 if (FLAGS_veryVerbose) { | 153 if (FLAGS_veryVerbose) { |
147 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], | 154 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], |
148 p.getStrokeWidth()); | 155 p.getStrokeWidth()); |
149 path.dumpHex(); | 156 path.dumpHex(); |
150 SkDebugf("fill:\n"); | 157 SkDebugf("fill:\n"); |
151 fill.dumpHex(); | 158 fill.dumpHex(); |
152 } | 159 } |
153 best = gMaxRecursion[2]; | 160 best = gMaxRecursion[2]; |
154 } | 161 } |
155 #endif | 162 #endif |
156 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 163 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
157 return; | 164 return; |
158 } | 165 } |
159 } | 166 } |
160 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 167 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
161 if (FLAGS_veryVerbose) { | 168 if (FLAGS_veryVerbose) { |
162 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); | 169 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
163 } | 170 } |
164 #endif | 171 #endif |
165 } | 172 } |
166 | 173 |
167 DEF_TEST(CubicStrokerUnbounded, reporter) { | 174 DEF_TEST(CubicStrokerUnbounded, reporter) { |
168 SkRandom r; | 175 SkRandom r; |
169 SkPaint p; | 176 SkPaint p; |
170 p.setStyle(SkPaint::kStroke_Style); | 177 p.setStyle(SkPaint::kStroke_Style); |
171 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 178 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
172 int bestTan = 0; | 179 int bestTan = 0; |
173 int bestCubic = 0; | 180 int bestCubic = 0; |
174 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 181 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
175 #endif | 182 #endif |
176 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 183 skiatest::Timer timer; |
177 for (int i = 0; i < 1000000; ++i) { | 184 for (int i = 0; i < 1000000; ++i) { |
178 SkPath path, fill; | 185 SkPath path, fill; |
179 path.moveTo(unbounded(r), unbounded(r)); | 186 path.moveTo(unbounded(r), unbounded(r)); |
180 path.cubicTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r), | 187 path.cubicTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r), |
181 unbounded(r), unbounded(r)); | 188 unbounded(r), unbounded(r)); |
182 p.setStrokeWidth(unboundedPos(r)); | 189 p.setStrokeWidth(unboundedPos(r)); |
183 p.getFillPath(path, &fill); | 190 p.getFillPath(path, &fill); |
184 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 191 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
185 if (bestTan < gMaxRecursion[0] || bestCubic < gMaxRecursion[1]) { | 192 if (bestTan < gMaxRecursion[0] || bestCubic < gMaxRecursion[1]) { |
186 if (FLAGS_veryVerbose) { | 193 if (FLAGS_veryVerbose) { |
187 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], | 194 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], |
188 gMaxRecursion[1], p.getStrokeWidth()); | 195 gMaxRecursion[1], p.getStrokeWidth()); |
189 path.dumpHex(); | 196 path.dumpHex(); |
190 SkDebugf("fill:\n"); | 197 SkDebugf("fill:\n"); |
191 fill.dumpHex(); | 198 fill.dumpHex(); |
192 } | 199 } |
193 bestTan = SkTMax(bestTan, gMaxRecursion[0]); | 200 bestTan = SkTMax(bestTan, gMaxRecursion[0]); |
194 bestCubic = SkTMax(bestCubic, gMaxRecursion[1]); | 201 bestCubic = SkTMax(bestCubic, gMaxRecursion[1]); |
195 } | 202 } |
196 #endif | 203 #endif |
197 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 204 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
198 return; | 205 return; |
199 } | 206 } |
200 } | 207 } |
201 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 208 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
202 if (FLAGS_veryVerbose) { | 209 if (FLAGS_veryVerbose) { |
203 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic)
; | 210 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic)
; |
204 } | 211 } |
205 #endif | 212 #endif |
206 } | 213 } |
207 | 214 |
208 DEF_TEST(QuadStrokerConstrained, reporter) { | 215 DEF_TEST(QuadStrokerConstrained, reporter) { |
209 SkRandom r; | 216 SkRandom r; |
210 SkPaint p; | 217 SkPaint p; |
211 p.setStyle(SkPaint::kStroke_Style); | 218 p.setStyle(SkPaint::kStroke_Style); |
212 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 219 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
213 int best = 0; | 220 int best = 0; |
214 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 221 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
215 #endif | 222 #endif |
216 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 223 skiatest::Timer timer; |
217 for (int i = 0; i < 1000000; ++i) { | 224 for (int i = 0; i < 1000000; ++i) { |
218 SkPath path, fill; | 225 SkPath path, fill; |
219 SkPoint quad[3]; | 226 SkPoint quad[3]; |
220 quad[0].fX = r.nextRangeF(0, 500); | 227 quad[0].fX = r.nextRangeF(0, 500); |
221 quad[0].fY = r.nextRangeF(0, 500); | 228 quad[0].fY = r.nextRangeF(0, 500); |
222 const SkScalar halfSquared = 0.5f * 0.5f; | 229 const SkScalar halfSquared = 0.5f * 0.5f; |
223 do { | 230 do { |
224 quad[1].fX = r.nextRangeF(0, 500); | 231 quad[1].fX = r.nextRangeF(0, 500); |
225 quad[1].fY = r.nextRangeF(0, 500); | 232 quad[1].fY = r.nextRangeF(0, 500); |
226 } while (quad[0].distanceToSqd(quad[1]) < halfSquared); | 233 } while (quad[0].distanceToSqd(quad[1]) < halfSquared); |
(...skipping 11 matching lines...) Expand all Loading... |
238 if (FLAGS_veryVerbose) { | 245 if (FLAGS_veryVerbose) { |
239 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], | 246 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], |
240 p.getStrokeWidth()); | 247 p.getStrokeWidth()); |
241 path.dumpHex(); | 248 path.dumpHex(); |
242 SkDebugf("fill:\n"); | 249 SkDebugf("fill:\n"); |
243 fill.dumpHex(); | 250 fill.dumpHex(); |
244 } | 251 } |
245 best = gMaxRecursion[2]; | 252 best = gMaxRecursion[2]; |
246 } | 253 } |
247 #endif | 254 #endif |
248 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 255 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
249 return; | 256 return; |
250 } | 257 } |
251 } | 258 } |
252 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 259 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
253 if (FLAGS_veryVerbose) { | 260 if (FLAGS_veryVerbose) { |
254 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); | 261 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
255 } | 262 } |
256 #endif | 263 #endif |
257 } | 264 } |
258 | 265 |
259 DEF_TEST(CubicStrokerConstrained, reporter) { | 266 DEF_TEST(CubicStrokerConstrained, reporter) { |
260 SkRandom r; | 267 SkRandom r; |
261 SkPaint p; | 268 SkPaint p; |
262 p.setStyle(SkPaint::kStroke_Style); | 269 p.setStyle(SkPaint::kStroke_Style); |
263 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 270 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
264 int bestTan = 0; | 271 int bestTan = 0; |
265 int bestCubic = 0; | 272 int bestCubic = 0; |
266 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 273 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
267 #endif | 274 #endif |
268 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 275 skiatest::Timer timer; |
269 for (int i = 0; i < 1000000; ++i) { | 276 for (int i = 0; i < 1000000; ++i) { |
270 SkPath path, fill; | 277 SkPath path, fill; |
271 SkPoint cubic[4]; | 278 SkPoint cubic[4]; |
272 cubic[0].fX = r.nextRangeF(0, 500); | 279 cubic[0].fX = r.nextRangeF(0, 500); |
273 cubic[0].fY = r.nextRangeF(0, 500); | 280 cubic[0].fY = r.nextRangeF(0, 500); |
274 const SkScalar halfSquared = 0.5f * 0.5f; | 281 const SkScalar halfSquared = 0.5f * 0.5f; |
275 do { | 282 do { |
276 cubic[1].fX = r.nextRangeF(0, 500); | 283 cubic[1].fX = r.nextRangeF(0, 500); |
277 cubic[1].fY = r.nextRangeF(0, 500); | 284 cubic[1].fY = r.nextRangeF(0, 500); |
278 } while (cubic[0].distanceToSqd(cubic[1]) < halfSquared); | 285 } while (cubic[0].distanceToSqd(cubic[1]) < halfSquared); |
(...skipping 18 matching lines...) Expand all Loading... |
297 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], | 304 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], |
298 gMaxRecursion[1], p.getStrokeWidth()); | 305 gMaxRecursion[1], p.getStrokeWidth()); |
299 path.dumpHex(); | 306 path.dumpHex(); |
300 SkDebugf("fill:\n"); | 307 SkDebugf("fill:\n"); |
301 fill.dumpHex(); | 308 fill.dumpHex(); |
302 } | 309 } |
303 bestTan = SkTMax(bestTan, gMaxRecursion[0]); | 310 bestTan = SkTMax(bestTan, gMaxRecursion[0]); |
304 bestCubic = SkTMax(bestCubic, gMaxRecursion[1]); | 311 bestCubic = SkTMax(bestCubic, gMaxRecursion[1]); |
305 } | 312 } |
306 #endif | 313 #endif |
307 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 314 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
308 return; | 315 return; |
309 } | 316 } |
310 } | 317 } |
311 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 318 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
312 if (FLAGS_veryVerbose) { | 319 if (FLAGS_veryVerbose) { |
313 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic)
; | 320 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic)
; |
314 } | 321 } |
315 #endif | 322 #endif |
316 } | 323 } |
317 | 324 |
318 DEF_TEST(QuadStrokerRange, reporter) { | 325 DEF_TEST(QuadStrokerRange, reporter) { |
319 SkRandom r; | 326 SkRandom r; |
320 SkPaint p; | 327 SkPaint p; |
321 p.setStyle(SkPaint::kStroke_Style); | 328 p.setStyle(SkPaint::kStroke_Style); |
322 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 329 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
323 int best = 0; | 330 int best = 0; |
324 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 331 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
325 #endif | 332 #endif |
326 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 333 skiatest::Timer timer; |
327 for (int i = 0; i < 1000000; ++i) { | 334 for (int i = 0; i < 1000000; ++i) { |
328 SkPath path, fill; | 335 SkPath path, fill; |
329 SkPoint quad[3]; | 336 SkPoint quad[3]; |
330 quad[0].fX = r.nextRangeF(0, 500); | 337 quad[0].fX = r.nextRangeF(0, 500); |
331 quad[0].fY = r.nextRangeF(0, 500); | 338 quad[0].fY = r.nextRangeF(0, 500); |
332 quad[1].fX = r.nextRangeF(0, 500); | 339 quad[1].fX = r.nextRangeF(0, 500); |
333 quad[1].fY = r.nextRangeF(0, 500); | 340 quad[1].fY = r.nextRangeF(0, 500); |
334 quad[2].fX = r.nextRangeF(0, 500); | 341 quad[2].fX = r.nextRangeF(0, 500); |
335 quad[2].fY = r.nextRangeF(0, 500); | 342 quad[2].fY = r.nextRangeF(0, 500); |
336 path.moveTo(quad[0].fX, quad[0].fY); | 343 path.moveTo(quad[0].fX, quad[0].fY); |
337 path.quadTo(quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY); | 344 path.quadTo(quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY); |
338 p.setStrokeWidth(r.nextRangeF(0, 500)); | 345 p.setStrokeWidth(r.nextRangeF(0, 500)); |
339 p.getFillPath(path, &fill); | 346 p.getFillPath(path, &fill); |
340 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 347 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
341 if (best < gMaxRecursion[2]) { | 348 if (best < gMaxRecursion[2]) { |
342 if (FLAGS_veryVerbose) { | 349 if (FLAGS_veryVerbose) { |
343 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], | 350 SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursi
on[2], |
344 p.getStrokeWidth()); | 351 p.getStrokeWidth()); |
345 path.dumpHex(); | 352 path.dumpHex(); |
346 SkDebugf("fill:\n"); | 353 SkDebugf("fill:\n"); |
347 fill.dumpHex(); | 354 fill.dumpHex(); |
348 } | 355 } |
349 best = gMaxRecursion[2]; | 356 best = gMaxRecursion[2]; |
350 } | 357 } |
351 #endif | 358 #endif |
352 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 359 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
353 return; | 360 return; |
354 } | 361 } |
355 } | 362 } |
356 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 363 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
357 if (FLAGS_verbose) { | 364 if (FLAGS_verbose) { |
358 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); | 365 SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
359 } | 366 } |
360 #endif | 367 #endif |
361 } | 368 } |
362 | 369 |
363 DEF_TEST(CubicStrokerRange, reporter) { | 370 DEF_TEST(CubicStrokerRange, reporter) { |
364 SkRandom r; | 371 SkRandom r; |
365 SkPaint p; | 372 SkPaint p; |
366 p.setStyle(SkPaint::kStroke_Style); | 373 p.setStyle(SkPaint::kStroke_Style); |
367 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 374 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
368 int best[2] = { 0 }; | 375 int best[2] = { 0 }; |
369 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); | 376 sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
370 #endif | 377 #endif |
371 SkMSec limit = SkTime::GetMSecs() + MS_TEST_DURATION; | 378 skiatest::Timer timer; |
372 for (int i = 0; i < 1000000; ++i) { | 379 for (int i = 0; i < 1000000; ++i) { |
373 SkPath path, fill; | 380 SkPath path, fill; |
374 path.moveTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500)); | 381 path.moveTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500)); |
375 path.cubicTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0,
500), | 382 path.cubicTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0,
500), |
376 r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0, 500)
); | 383 r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0, 500)
); |
377 p.setStrokeWidth(r.nextRangeF(0, 100)); | 384 p.setStrokeWidth(r.nextRangeF(0, 100)); |
378 p.getFillPath(path, &fill); | 385 p.getFillPath(path, &fill); |
379 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 386 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
380 if (best[0] < gMaxRecursion[0] || best[1] < gMaxRecursion[1]) { | 387 if (best[0] < gMaxRecursion[0] || best[1] < gMaxRecursion[1]) { |
381 if (FLAGS_veryVerbose) { | 388 if (FLAGS_veryVerbose) { |
382 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], | 389 SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMa
xRecursion[0], |
383 gMaxRecursion[1], p.getStrokeWidth()); | 390 gMaxRecursion[1], p.getStrokeWidth()); |
384 path.dumpHex(); | 391 path.dumpHex(); |
385 SkDebugf("fill:\n"); | 392 SkDebugf("fill:\n"); |
386 fill.dumpHex(); | 393 fill.dumpHex(); |
387 } | 394 } |
388 best[0] = SkTMax(best[0], gMaxRecursion[0]); | 395 best[0] = SkTMax(best[0], gMaxRecursion[0]); |
389 best[1] = SkTMax(best[1], gMaxRecursion[1]); | 396 best[1] = SkTMax(best[1], gMaxRecursion[1]); |
390 } | 397 } |
391 #endif | 398 #endif |
392 if (FLAGS_timeout && SkTime::GetMSecs() > limit) { | 399 if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
393 return; | 400 return; |
394 } | 401 } |
395 } | 402 } |
396 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 403 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
397 if (FLAGS_veryVerbose) { | 404 if (FLAGS_veryVerbose) { |
398 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, best[0], best[1]); | 405 SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, best[0], best[1]); |
399 } | 406 } |
400 #endif | 407 #endif |
401 } | 408 } |
402 | 409 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 path.dump(); | 450 path.dump(); |
444 SkDebugf("fill:\n"); | 451 SkDebugf("fill:\n"); |
445 fill.dump(); | 452 fill.dump(); |
446 } | 453 } |
447 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION | 454 #if defined(SK_DEBUG) && QUAD_STROKE_APPROXIMATION |
448 if (FLAGS_veryVerbose) { | 455 if (FLAGS_veryVerbose) { |
449 SkDebugf("max tan=%d cubic=%d\n", gMaxRecursion[0], gMaxRecursion[1]); | 456 SkDebugf("max tan=%d cubic=%d\n", gMaxRecursion[0], gMaxRecursion[1]); |
450 } | 457 } |
451 #endif | 458 #endif |
452 } | 459 } |
OLD | NEW |