blob: c9d6bddfd69f2db2f00de727bfd74407a6f944bf [file] [log] [blame]
caryclark@google.comd88e0892012-03-27 13:23:51 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00003#include "SkBitmap.h"
4#include "SkCanvas.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00005#include <assert.h>
6#include <pthread.h>
caryclark@google.com198e0542012-03-30 18:47:02 +00007
caryclark@google.comd88e0892012-03-27 13:23:51 +00008static void* testSimplify4x4QuadralateralsMain(void* data)
9{
10 char pathStr[1024];
11 bzero(pathStr, sizeof(pathStr));
12 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +000013 State4& state = *(State4*) data;
caryclark@google.comd88e0892012-03-27 13:23:51 +000014 int ax = state.a & 0x03;
15 int ay = state.a >> 2;
16 int bx = state.b & 0x03;
17 int by = state.b >> 2;
18 int cx = state.c & 0x03;
19 int cy = state.c >> 2;
20 int dx = state.d & 0x03;
21 int dy = state.d >> 2;
22 for (int e = 0 ; e < 16; ++e) {
23 int ex = e & 0x03;
24 int ey = e >> 2;
25 for (int f = e ; f < 16; ++f) {
26 int fx = f & 0x03;
27 int fy = f >> 2;
28 for (int g = f ; g < 16; ++g) {
29 int gx = g & 0x03;
30 int gy = g >> 2;
31 for (int h = g ; h < 16; ++h) {
32 int hx = h & 0x03;
33 int hy = h >> 2;
34 SkPath path, out;
35 path.setFillType(SkPath::kWinding_FillType);
36 path.moveTo(ax, ay);
37 path.lineTo(bx, by);
38 path.lineTo(cx, cy);
39 path.lineTo(dx, dy);
40 path.close();
41 path.moveTo(ex, ey);
42 path.lineTo(fx, fy);
43 path.lineTo(gx, gy);
44 path.lineTo(hx, hy);
45 path.close();
46 if (1) { // gdb: set print elements 400
47 char* str = pathStr;
48 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
49 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy);
52 str += sprintf(str, " path.close();\n");
53 str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
55 str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy);
56 str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy);
57 str += sprintf(str, " path.close();");
58 }
caryclark@google.com198e0542012-03-30 18:47:02 +000059 if (!testSimplify(path, true, out, state.bitmap, state.canvas)) {
caryclark@google.comd88e0892012-03-27 13:23:51 +000060 SkDebugf("*/\n{ SkPath::kWinding_FillType, %d, %d, %d, %d,"
61 " %d, %d, %d, %d },\n/*\n", state.a, state.b, state.c, state.d,
62 e, f, g, h);
63 }
64 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com198e0542012-03-30 18:47:02 +000065 if (!testSimplify(path, true, out, state.bitmap, state.canvas)) {
caryclark@google.comd88e0892012-03-27 13:23:51 +000066 SkDebugf("*/\n{ SkPath::kEvenOdd_FillType, %d, %d, %d, %d,"
67 " %d, %d, %d, %d },\n/*\n", state.a, state.b, state.c, state.d,
68 e, f, g, h);
69 }
70 }
71 }
72 }
73 }
74 return NULL;
75}
76
caryclark@google.com78e17132012-04-17 11:40:34 +000077const int maxThreads = gRunTestsInOneThread ? 1 : 24;
caryclark@google.comd88e0892012-03-27 13:23:51 +000078
79void Simplify4x4QuadralateralsThreaded_Test()
80{
caryclark@google.com78e17132012-04-17 11:40:34 +000081 State4 threadState[maxThreads];
caryclark@google.comd88e0892012-03-27 13:23:51 +000082 int threadIndex = 0;
83 for (int a = 0; a < 16; ++a) {
84 for (int b = a ; b < 16; ++b) {
85 for (int c = b ; c < 16; ++c) {
86 for (int d = c; d < 16; ++d) {
caryclark@google.com78e17132012-04-17 11:40:34 +000087 State4* statePtr = &threadState[threadIndex];
caryclark@google.comd88e0892012-03-27 13:23:51 +000088 statePtr->a = a;
89 statePtr->b = b;
90 statePtr->c = c;
91 statePtr->d = d;
92 if (maxThreads > 1) {
93 createThread(statePtr, testSimplify4x4QuadralateralsMain);
94 if (++threadIndex >= maxThreads) {
95 waitForCompletion(threadState, threadIndex);
96 }
97 } else {
98 testSimplify4x4QuadralateralsMain(statePtr);
99 }
100 }
101 }
102 }
103 }
104 waitForCompletion(threadState, threadIndex);
105}
106
107
108static void* testSimplify4x4NondegeneratesMain(void* data) {
109 char pathStr[1024];
110 bzero(pathStr, sizeof(pathStr));
111 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +0000112 State4& state = *(State4*) data;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000113 int ax = state.a & 0x03;
114 int ay = state.a >> 2;
115 int bx = state.b & 0x03;
116 int by = state.b >> 2;
117 int cx = state.c & 0x03;
118 int cy = state.c >> 2;
119 for (int d = 0; d < 15; ++d) {
120 int dx = d & 0x03;
121 int dy = d >> 2;
122 for (int e = d + 1; e < 16; ++e) {
123 int ex = e & 0x03;
124 int ey = e >> 2;
125 for (int f = d + 1; f < 16; ++f) {
126 if (e == f) {
127 continue;
128 }
129 int fx = f & 0x03;
130 int fy = f >> 2;
131 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
132 continue;
133 }
134 SkPath path, out;
135 path.setFillType(SkPath::kWinding_FillType);
136 path.moveTo(ax, ay);
137 path.lineTo(bx, by);
138 path.lineTo(cx, cy);
139 path.close();
140 path.moveTo(dx, dy);
141 path.lineTo(ex, ey);
142 path.lineTo(fx, fy);
143 path.close();
144 if (1) {
145 char* str = pathStr;
146 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
147 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
148 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
149 str += sprintf(str, " path.close();\n");
150 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
151 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
152 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
153 str += sprintf(str, " path.close();");
154 }
caryclark@google.com198e0542012-03-30 18:47:02 +0000155 testSimplify(path, true, out, state.bitmap, state.canvas);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000156 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com198e0542012-03-30 18:47:02 +0000157 testSimplify(path, true, out, state.bitmap, state.canvas);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000158 }
159 }
160 }
161 return NULL;
162}
163
164void SimplifyNondegenerate4x4TrianglesThreaded_Test() {
caryclark@google.com78e17132012-04-17 11:40:34 +0000165 State4 threadState[maxThreads];
caryclark@google.comd88e0892012-03-27 13:23:51 +0000166 int threadIndex = 0;
167 for (int a = 0; a < 15; ++a) {
168 int ax = a & 0x03;
169 int ay = a >> 2;
170 for (int b = a + 1; b < 16; ++b) {
171 int bx = b & 0x03;
172 int by = b >> 2;
173 for (int c = a + 1; c < 16; ++c) {
174 if (b == c) {
175 continue;
176 }
177 int cx = c & 0x03;
178 int cy = c >> 2;
179 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
180 continue;
181 }
caryclark@google.com78e17132012-04-17 11:40:34 +0000182 State4* statePtr = &threadState[threadIndex];
caryclark@google.comd88e0892012-03-27 13:23:51 +0000183 statePtr->a = a;
184 statePtr->b = b;
185 statePtr->c = c;
186 if (maxThreads > 1) {
187 createThread(statePtr, testSimplify4x4NondegeneratesMain);
188 if (++threadIndex >= maxThreads) {
189 waitForCompletion(threadState, threadIndex);
190 }
191 } else {
192 testSimplify4x4NondegeneratesMain(statePtr);
193 }
194 }
195 }
196 }
197 waitForCompletion(threadState, threadIndex);
198}
199
200static void* testSimplify4x4DegeneratesMain(void* data) {
201 char pathStr[1024];
202 bzero(pathStr, sizeof(pathStr));
203 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +0000204 State4& state = *(State4*) data;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000205 int ax = state.a & 0x03;
206 int ay = state.a >> 2;
207 int bx = state.b & 0x03;
208 int by = state.b >> 2;
209 int cx = state.c & 0x03;
210 int cy = state.c >> 2;
211 for (int d = 0; d < 16; ++d) {
212 int dx = d & 0x03;
213 int dy = d >> 2;
214 for (int e = d ; e < 16; ++e) {
215 int ex = e & 0x03;
216 int ey = e >> 2;
217 for (int f = d ; f < 16; ++f) {
218 int fx = f & 0x03;
219 int fy = f >> 2;
220 if (state.abcIsATriangle && (ex - dx) * (fy - dy)
221 != (ey - dy) * (fx - dx)) {
222 continue;
223 }
224 SkPath path, out;
225 path.setFillType(SkPath::kWinding_FillType);
226 path.moveTo(ax, ay);
227 path.lineTo(bx, by);
228 path.lineTo(cx, cy);
229 path.close();
230 path.moveTo(dx, dy);
231 path.lineTo(ex, ey);
232 path.lineTo(fx, fy);
233 path.close();
234 if (1) {
235 char* str = pathStr;
236 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
237 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
238 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
239 str += sprintf(str, " path.close();\n");
240 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
241 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
242 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
243 str += sprintf(str, " path.close();");
244 }
caryclark@google.com198e0542012-03-30 18:47:02 +0000245 testSimplify(path, true, out, state.bitmap, state.canvas);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000246 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com198e0542012-03-30 18:47:02 +0000247 testSimplify(path, true, out, state.bitmap, state.canvas);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000248 }
249 }
250 }
251 return NULL;
252}
253
254void SimplifyDegenerate4x4TrianglesThreaded_Test() {
caryclark@google.com78e17132012-04-17 11:40:34 +0000255 State4 threadState[maxThreads];
caryclark@google.comd88e0892012-03-27 13:23:51 +0000256 int threadIndex = 0;
257 for (int a = 0; a < 16; ++a) {
258 int ax = a & 0x03;
259 int ay = a >> 2;
260 for (int b = a ; b < 16; ++b) {
261 int bx = b & 0x03;
262 int by = b >> 2;
263 for (int c = a ; c < 16; ++c) {
264 int cx = c & 0x03;
265 int cy = c >> 2;
caryclark@google.com78e17132012-04-17 11:40:34 +0000266 State4* statePtr = &threadState[threadIndex];
caryclark@google.comd88e0892012-03-27 13:23:51 +0000267 statePtr->abcIsATriangle = (bx - ax) * (cy - ay)
268 != (by - ay) * (cx - ax);
269 statePtr->a = a;
270 statePtr->b = b;
271 statePtr->c = c;
272 if (maxThreads > 1) {
273 createThread(statePtr, testSimplify4x4DegeneratesMain);
274 if (++threadIndex >= maxThreads) {
275 waitForCompletion(threadState, threadIndex);
276 }
277 } else {
278 testSimplify4x4DegeneratesMain(statePtr);
279 }
280 }
281 }
282 }
283 waitForCompletion(threadState, threadIndex);
284}
285