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