xref: /aosp_15_r20/external/skia/tests/PathOpsSimplifyRectThreadedTest.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 
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/private/base/SkMacros.h"
14 #include "include/private/base/SkTDArray.h"
15 #include "tests/PathOpsExtendedTest.h"
16 #include "tests/PathOpsThreadedCommon.h"
17 #include "tests/Test.h"
18 
19 // four rects, of four sizes
20 // for 3 smaller sizes, tall, wide
21     // top upper mid lower bottom aligned (3 bits, 5 values)
22     // same with x (3 bits, 5 values)
23 // not included, square, tall, wide (2 bits)
24 // cw or ccw (1 bit)
25 
testSimplify4x4RectsMain(PathOpsThreadState * data)26 static void testSimplify4x4RectsMain(PathOpsThreadState* data)
27 {
28     SkASSERT(data);
29     PathOpsThreadState& state = *data;
30     int aShape = state.fA & 0x03;
31     SkPathDirection aCW = state.fA >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW;
32     int bShape = state.fB & 0x03;
33     SkPathDirection bCW = state.fB >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW;
34     int cShape = state.fC & 0x03;
35     SkPathDirection cCW = state.fC >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW;
36     int dShape = state.fD & 0x03;
37     SkPathDirection dCW = state.fD >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW;
38     for (int aXAlign = 0; aXAlign < 5; ++aXAlign) {
39         for (int aYAlign = 0; aYAlign < 5; ++aYAlign) {
40             for (int bXAlign = 0; bXAlign < 5; ++bXAlign) {
41                 for (int bYAlign = 0; bYAlign < 5; ++bYAlign) {
42                     for (int cXAlign = 0; cXAlign < 5; ++cXAlign) {
43                          for (int cYAlign = 0; cYAlign < 5; ++cYAlign) {
44                             for (int dXAlign = 0; dXAlign < 5; ++dXAlign) {
45     for (int dYAlign = 0; dYAlign < 5; ++dYAlign) {
46         SkString pathStr;
47         SkPath path, out;
48         int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING,
49             r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING;
50         if (aShape) {
51             switch (aShape) {
52                 case 1:  // square
53                     l =  0; r = 60;
54                     t =  0; b = 60;
55                     aXAlign = 5;
56                     aYAlign = 5;
57                     break;
58                 case 2:
59                     l =  aXAlign * 12;
60                     r =  l + 30;
61                     t =  0; b = 60;
62                     aYAlign = 5;
63                     break;
64                 case 3:
65                     l =  0; r = 60;
66                     t =  aYAlign * 12;
67                     b =  l + 30;
68                     aXAlign = 5;
69                     break;
70             }
71             path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
72                     aCW);
73             if (state.fReporter->verbose()) {
74                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
75                         " SkPathDirection::kC%sW);\n", l, t, r, b,
76                                 aCW == SkPathDirection::kCCW ? "C" : "");
77             }
78         } else {
79             aXAlign = 5;
80             aYAlign = 5;
81         }
82         if (bShape) {
83             switch (bShape) {
84                 case 1:  // square
85                     l =  bXAlign * 10;
86                     r =  l + 20;
87                     t =  bYAlign * 10;
88                     b =  l + 20;
89                     break;
90                 case 2:
91                     l =  bXAlign * 10;
92                     r =  l + 20;
93                     t =  10; b = 40;
94                     bYAlign = 5;
95                     break;
96                 case 3:
97                     l =  10; r = 40;
98                     t =  bYAlign * 10;
99                     b =  l + 20;
100                     bXAlign = 5;
101                     break;
102             }
103             path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
104                     bCW);
105             if (state.fReporter->verbose()) {
106                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
107                         " SkPathDirection::kC%sW);\n", l, t, r, b,
108                                 bCW == SkPathDirection::kCCW ? "C" : "");
109             }
110         } else {
111             bXAlign = 5;
112             bYAlign = 5;
113         }
114         if (cShape) {
115             switch (cShape) {
116                 case 1:  // square
117                     l =  cXAlign * 6;
118                     r =  l + 12;
119                     t =  cYAlign * 6;
120                     b =  l + 12;
121                     break;
122                 case 2:
123                     l =  cXAlign * 6;
124                     r =  l + 12;
125                     t =  20; b = 30;
126                     cYAlign = 5;
127                     break;
128                 case 3:
129                     l =  20; r = 30;
130                     t =  cYAlign * 6;
131                     b =  l + 20;
132                     cXAlign = 5;
133                     break;
134             }
135             path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
136                     cCW);
137             if (state.fReporter->verbose()) {
138                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
139                         " SkPathDirection::kC%sW);\n", l, t, r, b,
140                                 cCW == SkPathDirection::kCCW ? "C" : "");
141             }
142         } else {
143             cXAlign = 5;
144             cYAlign = 5;
145         }
146         if (dShape) {
147             switch (dShape) {
148                 case 1:  // square
149                     l =  dXAlign * 4;
150                     r =  l + 9;
151                     t =  dYAlign * 4;
152                     b =  l + 9;
153                     break;
154                 case 2:
155                     l =  dXAlign * 6;
156                     r =  l + 9;
157                     t =  32; b = 36;
158                     dYAlign = 5;
159                     break;
160                 case 3:
161                     l =  32; r = 36;
162                     t =  dYAlign * 6;
163                     b =  l + 9;
164                     dXAlign = 5;
165                     break;
166             }
167             path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
168                     dCW);
169             if (state.fReporter->verbose()) {
170                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
171                         " SkPathDirection::kC%sW);\n", l, t, r, b,
172                                 dCW == SkPathDirection::kCCW ? "C" : "");
173             }
174         } else {
175             dXAlign = 5;
176             dYAlign = 5;
177         }
178         path.close();
179         if (state.fReporter->verbose()) {
180             state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
181         }
182         testSimplify(path, false, out, state, pathStr.c_str());
183         if (state.fReporter->verbose()) {
184             state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
185         }
186         testSimplify(path, true, out, state, pathStr.c_str());
187     }
188                             }
189                         }
190                     }
191                 }
192             }
193         }
194     }
195 }
196 
DEF_TEST(PathOpsSimplifyRectsThreaded,reporter)197 DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) {
198     initializeTests(reporter, "testLine");
199     PathOpsThreadedTestRunner testRunner(reporter);
200     for (int a = 0; a < 8; ++a) {  // outermost
201         for (int b = a ; b < 8; ++b) {
202             for (int c = b ; c < 8; ++c) {
203                 for (int d = c; d < 8; ++d) {
204                     *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
205                             &testSimplify4x4RectsMain, a, b, c, d, &testRunner);
206                 }
207                 if (!reporter->allowExtendedTest()) goto finish;
208             }
209         }
210     }
211 finish:
212     testRunner.render();
213 }
214