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