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