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