xref: /aosp_15_r20/external/skia/tests/PathOpsSimplifyTrianglesThreadedTest.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/private/base/SkTDArray.h"
13 #include "tests/PathOpsExtendedTest.h"
14 #include "tests/PathOpsThreadedCommon.h"
15 #include "tests/Test.h"
16 
testSimplifyTrianglesMain(PathOpsThreadState * data)17 static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
18     SkASSERT(data);
19     PathOpsThreadState& state = *data;
20     state.fKey = "?";
21     int ax = state.fA & 0x03;
22     int ay = state.fA >> 2;
23     int bx = state.fB & 0x03;
24     int by = state.fB >> 2;
25     int cx = state.fC & 0x03;
26     int cy = state.fC >> 2;
27     for (int d = 0; d < 15; ++d) {
28         int dx = d & 0x03;
29         int dy = d >> 2;
30         for (int e = d + 1; e < 16; ++e) {
31             int ex = e & 0x03;
32             int ey = e >> 2;
33             for (int f = d + 1; f < 16; ++f) {
34                 if (e == f) {
35                     continue;
36                 }
37                 int fx = f & 0x03;
38                 int fy = f >> 2;
39                 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
40                     continue;
41                 }
42                 SkString pathStr;
43                 SkPath path, out;
44                 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
45                 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
46                 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
47                 path.close();
48                 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
49                 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
50                 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
51                 path.close();
52                 if (state.fReporter->verbose()) {
53                     pathStr.appendf("    path.moveTo(%d, %d);\n", ax, ay);
54                     pathStr.appendf("    path.lineTo(%d, %d);\n", bx, by);
55                     pathStr.appendf("    path.lineTo(%d, %d);\n", cx, cy);
56                     pathStr.appendf("    path.close();\n");
57                     pathStr.appendf("    path.moveTo(%d, %d);\n", dx, dy);
58                     pathStr.appendf("    path.lineTo(%d, %d);\n", ex, ey);
59                     pathStr.appendf("    path.lineTo(%d, %d);\n", fx, fy);
60                     pathStr.appendf("    path.close();\n");
61                     state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
62                 }
63                 testSimplify(path, false, out, state, pathStr.c_str());
64                 path.setFillType(SkPathFillType::kEvenOdd);
65                 if (state.fReporter->verbose()) {
66                     state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
67                 }
68                 testSimplify(path, true, out, state, pathStr.c_str());
69             }
70         }
71     }
72 }
73 
DEF_TEST(PathOpsSimplifyTrianglesThreaded,reporter)74 DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
75     initializeTests(reporter, "testTriangles");
76     PathOpsThreadedTestRunner testRunner(reporter);
77     for (int a = 0; a < 15; ++a) {
78         int ax = a & 0x03;
79         int ay = a >> 2;
80         for (int b = a + 1; b < 16; ++b) {
81             int bx = b & 0x03;
82             int by = b >> 2;
83             for (int c = a + 1; c < 16; ++c) {
84                 if (b == c) {
85                     continue;
86                 }
87                 int cx = c & 0x03;
88                 int cy = c >> 2;
89                 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
90                     continue;
91                 }
92                 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
93                         &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
94             }
95             if (!reporter->allowExtendedTest()) goto finish;
96         }
97     }
98 finish:
99     testRunner.render();
100 }
101