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 */
7
8 #include "include/core/SkPath.h"
9 #include "include/core/SkPathTypes.h"
10 #include "include/core/SkScalar.h"
11 #include "include/core/SkString.h"
12 #include "include/core/SkTypes.h"
13 #include "include/pathops/SkPathOps.h"
14 #include "include/private/base/SkTDArray.h"
15 #include "src/pathops/SkPathOpsDebug.h"
16 #include "tests/PathOpsDebug.h"
17 #include "tests/PathOpsExtendedTest.h"
18 #include "tests/PathOpsThreadedCommon.h"
19 #include "tests/Test.h"
20
21 #include <atomic>
22
23 static int loopNo = 4;
24 static std::atomic<int> gCirclesTestNo{0};
25
testOpCirclesMain(PathOpsThreadState * data)26 static void testOpCirclesMain(PathOpsThreadState* data) {
27 SkASSERT(data);
28 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
29 PathOpsThreadState& state = *data;
30 SkString pathStr;
31 for (int a = 0 ; a < 6; ++a) {
32 for (int b = a + 1 ; b < 7; ++b) {
33 for (int c = 0 ; c < 6; ++c) {
34 for (int d = c + 1 ; d < 7; ++d) {
35 for (auto e : fts) {
36 for (auto f : fts) {
37 SkPath pathA, pathB;
38 pathA.setFillType(e);
39 pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC),
40 state.fD ? SkPathDirection::kCW : SkPathDirection::kCCW);
41 pathB.setFillType(f);
42 pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c),
43 d ? SkPathDirection::kCW : SkPathDirection::kCCW);
44 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
45 if (state.fReporter->verbose()) {
46 pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter,"
47 " const char* filename) {\n", loopNo);
48 pathStr.appendf(" SkPath path, pathB;\n");
49 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
50 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
51 ? "EvenOdd" : "?UNDEFINED");
52 pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB,
53 state.fC, state.fD ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
54 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
55 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
56 ? "EvenOdd" : "?UNDEFINED");
57 pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b,
58 c, d ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
59 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
60 SkPathOpsDebug::OpStr((SkPathOp) op));
61 pathStr.appendf("}\n");
62 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
63 }
64 SkString testName;
65 testName.printf("thread_circles%d", ++gCirclesTestNo);
66 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
67 if (state.fReporter->verbose()) {
68 ++loopNo;
69 goto skipToNext;
70 }
71 }
72 if (PathOpsDebug::gCheckForDuplicateNames) return;
73 }
74 }
75 }
76 skipToNext: ;
77 }
78 }
79 }
80 }
81 }
82
DEF_TEST(PathOpsOpCircleThreaded,reporter)83 DEF_TEST(PathOpsOpCircleThreaded, reporter) {
84 initializeTests(reporter, "circleOp");
85 PathOpsThreadedTestRunner testRunner(reporter);
86 for (int a = 0; a < 6; ++a) { // outermost
87 for (int b = a + 1; b < 7; ++b) {
88 for (int c = 0 ; c < 6; ++c) {
89 for (int d = 0; d < 2; ++d) {
90 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
91 &testOpCirclesMain, a, b, c, d, &testRunner);
92 }
93 }
94 if (!reporter->allowExtendedTest()) goto finish;
95 }
96 }
97 finish:
98 testRunner.render();
99 }
100