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