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 "PathOpsExtendedTest.h"
8 #include "PathOpsThreadedCommon.h"
9
testSimplifyDegeneratesMain(PathOpsThreadState * data)10 static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
11 SkASSERT(data);
12 PathOpsThreadState& state = *data;
13 char pathStr[1024];
14 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
15 if (progress) {
16 sk_bzero(pathStr, sizeof(pathStr));
17 }
18 int ax = state.fA & 0x03;
19 int ay = state.fA >> 2;
20 int bx = state.fB & 0x03;
21 int by = state.fB >> 2;
22 int cx = state.fC & 0x03;
23 int cy = state.fC >> 2;
24 for (int d = 0; d < 16; ++d) {
25 int dx = d & 0x03;
26 int dy = d >> 2;
27 for (int e = d ; e < 16; ++e) {
28 int ex = e & 0x03;
29 int ey = e >> 2;
30 for (int f = d ; f < 16; ++f) {
31 int fx = f & 0x03;
32 int fy = f >> 2;
33 if (state.fD && (ex - dx) * (fy - dy)
34 != (ey - dy) * (fx - dx)) {
35 continue;
36 }
37 SkPath path, out;
38 path.setFillType(SkPath::kWinding_FillType);
39 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
40 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
41 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
42 path.close();
43 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
44 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
45 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
46 path.close();
47 if (progress) {
48 char* str = pathStr;
49 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
52 str += sprintf(str, " path.close();\n");
53 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
55 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
56 str += sprintf(str, " path.close();\n");
57 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
58 }
59 testSimplify(path, false, out, state, pathStr);
60 path.setFillType(SkPath::kEvenOdd_FillType);
61 if (progress) {
62 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
63 }
64 testSimplify(path, true, out, state, pathStr);
65 }
66 }
67 }
68 }
69
DEF_TEST(PathOpsSimplifyDegeneratesThreaded,reporter)70 DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
71 int threadCount = initializeTests(reporter, "testDegenerates");
72 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
73 for (int a = 0; a < 16; ++a) {
74 int ax = a & 0x03;
75 int ay = a >> 2;
76 for (int b = a ; b < 16; ++b) {
77 int bx = b & 0x03;
78 int by = b >> 2;
79 for (int c = a ; c < 16; ++c) {
80 int cx = c & 0x03;
81 int cy = c >> 2;
82 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
83 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
84 (&testSimplifyDegeneratesMain, a, b, c, abcIsATriangle,
85 &testRunner));
86 }
87 if (!reporter->allowExtendedTest()) goto finish;
88 }
89 }
90 finish:
91 testRunner.render();
92 }
93