caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 7 | #include "PathOpsDebug.h" |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 8 | #include "PathOpsExtendedTest.h" |
| 9 | #include "PathOpsThreadedCommon.h" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 10 | #include "SkString.h" |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 11 | #include <atomic> |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 12 | |
| 13 | static int loopNo = 4; |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 14 | static std::atomic<int> gCirclesTestNo{0}; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 15 | |
| 16 | static void testOpCirclesMain(PathOpsThreadState* data) { |
| 17 | SkASSERT(data); |
| 18 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 19 | SkString pathStr; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 20 | for (int a = 0 ; a < 6; ++a) { |
| 21 | for (int b = a + 1 ; b < 7; ++b) { |
| 22 | for (int c = 0 ; c < 6; ++c) { |
| 23 | for (int d = c + 1 ; d < 7; ++d) { |
| 24 | for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { |
| 25 | for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { |
| 26 | SkPath pathA, pathB; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 27 | pathA.setFillType((SkPath::FillType) e); |
| 28 | pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC), |
| 29 | state.fD ? SkPath::kCW_Direction : SkPath::kCCW_Direction); |
| 30 | pathB.setFillType((SkPath::FillType) f); |
| 31 | pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c), |
| 32 | d ? SkPath::kCW_Direction : SkPath::kCCW_Direction); |
| 33 | for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 34 | if (state.fReporter->verbose()) { |
| 35 | pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter," |
| 36 | " const char* filename) {\n", loopNo); |
| 37 | pathStr.appendf(" SkPath path, pathB;\n"); |
| 38 | pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", |
| 39 | e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType |
| 40 | ? "EvenOdd" : "?UNDEFINED"); |
| 41 | pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB, |
| 42 | state.fC, state.fD ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); |
| 43 | pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n", |
| 44 | f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType |
| 45 | ? "EvenOdd" : "?UNDEFINED"); |
| 46 | pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b, |
| 47 | c, d ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); |
| 48 | pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", |
| 49 | SkPathOpsDebug::OpStr((SkPathOp) op)); |
| 50 | pathStr.appendf("}\n"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 51 | state.outputProgress(pathStr.c_str(), (SkPathOp) op); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 52 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 53 | SkString testName; |
| 54 | testName.printf("thread_circles%d", ++gCirclesTestNo); |
| 55 | if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 56 | if (state.fReporter->verbose()) { |
| 57 | ++loopNo; |
| 58 | goto skipToNext; |
| 59 | } |
| 60 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 61 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 65 | skipToNext: ; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | DEF_TEST(PathOpsOpCircleThreaded, reporter) { |
| 73 | initializeTests(reporter, "circleOp"); |
| 74 | PathOpsThreadedTestRunner testRunner(reporter); |
| 75 | for (int a = 0; a < 6; ++a) { // outermost |
| 76 | for (int b = a + 1; b < 7; ++b) { |
| 77 | for (int c = 0 ; c < 6; ++c) { |
| 78 | for (int d = 0; d < 2; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 79 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 80 | &testOpCirclesMain, a, b, c, d, &testRunner); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | if (!reporter->allowExtendedTest()) goto finish; |
| 84 | } |
| 85 | } |
| 86 | finish: |
| 87 | testRunner.render(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 88 | } |