caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | #include "PathOpsExtendedTest.h" |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 8 | #include "PathOpsThreadedCommon.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 9 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 10 | static void testSimplifyQuadsMain(PathOpsThreadState* data) |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 11 | { |
| 12 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 13 | PathOpsThreadState& state = *data; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 14 | char pathStr[1024]; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 15 | bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? |
| 16 | if (progress) { |
| 17 | sk_bzero(pathStr, sizeof(pathStr)); |
| 18 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 19 | int ax = state.fA & 0x03; |
| 20 | int ay = state.fA >> 2; |
| 21 | int bx = state.fB & 0x03; |
| 22 | int by = state.fB >> 2; |
| 23 | int cx = state.fC & 0x03; |
| 24 | int cy = state.fC >> 2; |
| 25 | int dx = state.fD & 0x03; |
| 26 | int dy = state.fD >> 2; |
| 27 | for (int e = 0 ; e < 16; ++e) { |
| 28 | int ex = e & 0x03; |
| 29 | int ey = e >> 2; |
| 30 | for (int f = e ; f < 16; ++f) { |
| 31 | int fx = f & 0x03; |
| 32 | int fy = f >> 2; |
| 33 | for (int g = f ; g < 16; ++g) { |
| 34 | int gx = g & 0x03; |
| 35 | int gy = g >> 2; |
| 36 | for (int h = g ; h < 16; ++h) { |
| 37 | int hx = h & 0x03; |
| 38 | int hy = h >> 2; |
| 39 | SkPath path, out; |
| 40 | path.setFillType(SkPath::kWinding_FillType); |
| 41 | path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); |
| 42 | path.quadTo(SkIntToScalar(bx), SkIntToScalar(by), |
| 43 | SkIntToScalar(cx), SkIntToScalar(cy)); |
| 44 | path.lineTo(SkIntToScalar(dx), SkIntToScalar(dy)); |
| 45 | path.close(); |
| 46 | path.moveTo(SkIntToScalar(ex), SkIntToScalar(ey)); |
| 47 | path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); |
| 48 | path.quadTo(SkIntToScalar(gx), SkIntToScalar(gy), |
| 49 | SkIntToScalar(hx), SkIntToScalar(hy)); |
| 50 | path.close(); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 51 | if (progress) { |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 52 | static int quadTest = 66; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 53 | char* str = pathStr; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 54 | str += sprintf(str, "static void testQuads%d(skiatest::Reporter* reporter," |
| 55 | "const char* filename) {\n", quadTest); |
| 56 | str += sprintf(str, " SkPath path;\n"); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 57 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 58 | str += sprintf(str, " path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy); |
| 59 | str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy); |
| 60 | str += sprintf(str, " path.close();\n"); |
| 61 | str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey); |
| 62 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 63 | str += sprintf(str, " path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy); |
| 64 | str += sprintf(str, " path.close();\n"); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 65 | str += sprintf(str, " testSimplify(reporter, path, filename);\n"); |
| 66 | str += sprintf(str, "}\n"); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 67 | outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); |
| 68 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 69 | testSimplify(path, false, out, state, pathStr); |
| 70 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 71 | if (progress) { |
| 72 | outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); |
| 73 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 74 | testSimplify(path, true, out, state, pathStr); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 78 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 79 | } |
| 80 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 81 | DEF_TEST(PathOpsSimplifyQuadsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 82 | initializeTests(reporter, "testQuads"); |
| 83 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 84 | int a = 0; |
| 85 | for (; a < 16; ++a) { |
| 86 | for (int b = a ; b < 16; ++b) { |
| 87 | for (int c = b ; c < 16; ++c) { |
| 88 | for (int d = c; d < 16; ++d) { |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 89 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 90 | (&testSimplifyQuadsMain, a, b, c, d, &testRunner)); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 91 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 92 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 93 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 94 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 95 | } |
| 96 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 97 | testRunner.render(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 98 | ShowTestArray("testQuads"); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 99 | } |