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 | |
| 10 | // four rects, of four sizes |
| 11 | // for 3 smaller sizes, tall, wide |
| 12 | // top upper mid lower bottom aligned (3 bits, 5 values) |
| 13 | // same with x (3 bits, 5 values) |
| 14 | // not included, square, tall, wide (2 bits) |
| 15 | // cw or ccw (1 bit) |
| 16 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 17 | static void testPathOpsRectsMain(PathOpsThreadState* data) |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 18 | { |
| 19 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 20 | PathOpsThreadState& state = *data; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 21 | char pathStr[1024]; // gdb: set print elements 400 |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 22 | bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? |
| 23 | if (progress) { |
| 24 | sk_bzero(pathStr, sizeof(pathStr)); |
| 25 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 26 | for (int a = 0 ; a < 6; ++a) { |
| 27 | for (int b = a + 1 ; b < 7; ++b) { |
| 28 | for (int c = 0 ; c < 6; ++c) { |
| 29 | for (int d = c + 1 ; d < 7; ++d) { |
| 30 | for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { |
| 31 | for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 32 | static int testNum = 6; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 33 | if (progress) { |
| 34 | char* str = pathStr; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 35 | str += sprintf(str, |
| 36 | "static void rects%d(skiatest::Reporter* reporter, const char* filename) {\n", |
| 37 | testNum); |
| 38 | str += sprintf(str, " SkPath path, pathB;"); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 39 | str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", |
| 40 | e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType |
| 41 | ? "EvenOdd" : "?UNDEFINED"); |
| 42 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 43 | " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB); |
| 44 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 45 | " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD); |
| 46 | str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", |
| 47 | f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType |
| 48 | ? "EvenOdd" : "?UNDEFINED"); |
| 49 | str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," |
| 50 | " SkPath::kCW_Direction);\n", a, a, b, b); |
| 51 | str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," |
| 52 | " SkPath::kCW_Direction);\n", c, c, d, d); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 53 | str += sprintf(str, |
| 54 | " testPathOp(reporter, path, pathB, kDifference_SkPathOp, filename);\n"); |
| 55 | str += sprintf(str, "}\n\n"); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 56 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 57 | SkPath pathA, pathB; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 58 | pathA.setFillType((SkPath::FillType) e); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 59 | pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), |
| 60 | SkIntToScalar(state.fB), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 61 | pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), |
| 62 | SkIntToScalar(state.fD), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 63 | pathA.close(); |
| 64 | pathB.setFillType((SkPath::FillType) f); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 65 | pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), |
| 66 | SkIntToScalar(b), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 67 | pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), |
| 68 | SkIntToScalar(d), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 69 | pathB.close(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 70 | for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 71 | if (progress) { |
| 72 | outputProgress(state.fPathStr, pathStr, (SkPathOp) op); |
| 73 | } |
caryclark | 38a017b | 2015-05-13 10:13:17 -0700 | [diff] [blame] | 74 | testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 82 | } |
| 83 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 84 | DEF_TEST(PathOpsRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 85 | initializeTests(reporter, "testOp"); |
| 86 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 87 | for (int a = 0; a < 6; ++a) { // outermost |
| 88 | for (int b = a + 1; b < 7; ++b) { |
| 89 | for (int c = 0 ; c < 6; ++c) { |
| 90 | for (int d = c + 1; d < 7; ++d) { |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 91 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 92 | (&testPathOpsRectsMain, a, b, c, d, &testRunner)); |
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 | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 95 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 96 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 97 | } |
| 98 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 99 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 100 | } |