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 testSimplifyTrianglesMain(PathOpsThreadState* data) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 11 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 12 | PathOpsThreadState& state = *data; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 13 | char pathStr[1024]; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 14 | bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? |
| 15 | if (progress) { |
| 16 | sk_bzero(pathStr, sizeof(pathStr)); |
| 17 | } |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 18 | state.fKey = "?"; |
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 | for (int d = 0; d < 15; ++d) { |
| 26 | int dx = d & 0x03; |
| 27 | int dy = d >> 2; |
| 28 | for (int e = d + 1; e < 16; ++e) { |
| 29 | int ex = e & 0x03; |
| 30 | int ey = e >> 2; |
| 31 | for (int f = d + 1; f < 16; ++f) { |
| 32 | if (e == f) { |
| 33 | continue; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 34 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 35 | int fx = f & 0x03; |
| 36 | int fy = f >> 2; |
| 37 | if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { |
| 38 | continue; |
| 39 | } |
| 40 | SkPath path, out; |
| 41 | path.setFillType(SkPath::kWinding_FillType); |
| 42 | path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); |
| 43 | path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); |
| 44 | path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); |
| 45 | path.close(); |
| 46 | path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); |
| 47 | path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); |
| 48 | path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); |
| 49 | path.close(); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 50 | if (progress) { |
| 51 | char* str = pathStr; |
| 52 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 53 | str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); |
| 54 | str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); |
| 55 | str += sprintf(str, " path.close();\n"); |
| 56 | str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); |
| 57 | str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); |
| 58 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 59 | str += sprintf(str, " path.close();\n"); |
| 60 | outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); |
| 61 | } |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 62 | ShowTestName(&state, d, e, f, 0); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 63 | testSimplify(path, false, out, state, pathStr); |
| 64 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 65 | if (progress) { |
| 66 | outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); |
| 67 | } |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 68 | ShowTestName(&state, d, e, f, 1); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 69 | testSimplify(path, true, out, state, pathStr); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 72 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 73 | } |
| 74 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 75 | static void PathOpsSimplifyTrianglesThreadedTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 16cfe40 | 2013-04-18 18:47:37 +0000 | [diff] [blame] | 76 | int threadCount = initializeTests(reporter, "testTriangles"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 77 | PathOpsThreadedTestRunner testRunner(reporter, threadCount); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 78 | for (int a = 0; a < 15; ++a) { |
| 79 | int ax = a & 0x03; |
| 80 | int ay = a >> 2; |
| 81 | for (int b = a + 1; b < 16; ++b) { |
| 82 | int bx = b & 0x03; |
| 83 | int by = b >> 2; |
| 84 | for (int c = a + 1; c < 16; ++c) { |
| 85 | if (b == c) { |
| 86 | continue; |
| 87 | } |
| 88 | int cx = c & 0x03; |
| 89 | int cy = c >> 2; |
| 90 | if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) { |
| 91 | continue; |
| 92 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 93 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 94 | (&testSimplifyTrianglesMain, a, b, c, 0, &testRunner)); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 95 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 96 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 97 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 98 | } |
| 99 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 100 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #include "TestClassDef.h" |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 104 | DEFINE_TESTCLASS_SHORT(PathOpsSimplifyTrianglesThreadedTest) |