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