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