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