blob: 22997e7a9c2ea2f5cb0cc63fd604764309043eec [file] [log] [blame]
caryclark@google.com818b0cc2013-04-08 11:50:46 +00001/*
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"
caryclark@google.com66089e42013-04-10 15:55:37 +00008#include "PathOpsThreadedCommon.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +00009
caryclark@google.com66089e42013-04-10 15:55:37 +000010static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +000011 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000012 PathOpsThreadState& state = *data;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000013 char pathStr[1024];
14 sk_bzero(pathStr, sizeof(pathStr));
caryclark@google.com66089e42013-04-10 15:55:37 +000015 int ax = state.fA & 0x03;
16 int ay = state.fA >> 2;
17 int bx = state.fB & 0x03;
18 int by = state.fB >> 2;
19 int cx = state.fC & 0x03;
20 int cy = state.fC >> 2;
21 for (int d = 0; d < 16; ++d) {
22 int dx = d & 0x03;
23 int dy = d >> 2;
24 for (int e = d ; e < 16; ++e) {
25 int ex = e & 0x03;
26 int ey = e >> 2;
27 for (int f = d ; f < 16; ++f) {
28 int fx = f & 0x03;
29 int fy = f >> 2;
30 if (state.fD && (ex - dx) * (fy - dy)
31 != (ey - dy) * (fx - dx)) {
32 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000033 }
caryclark@google.com66089e42013-04-10 15:55:37 +000034 SkPath path, out;
35 path.setFillType(SkPath::kWinding_FillType);
36 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
37 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
38 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
39 path.close();
40 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
41 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
42 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
43 path.close();
44 char* str = pathStr;
45 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
46 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
47 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
48 str += sprintf(str, " path.close();\n");
49 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
52 str += sprintf(str, " path.close();\n");
53 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
54 testSimplify(path, false, out, state, pathStr);
55 path.setFillType(SkPath::kEvenOdd_FillType);
56 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
57 testSimplify(path, true, out, state, pathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000058 }
59 }
caryclark@google.com66089e42013-04-10 15:55:37 +000060 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000061}
62
caryclark@google.comad65a3e2013-04-15 19:13:59 +000063static void PathOpsSimplifyDegeneratesThreadedTest(skiatest::Reporter* reporter) {
caryclark@google.com16cfe402013-04-18 18:47:37 +000064 int threadCount = initializeTests(reporter, "testDegenerates");
caryclark@google.com66089e42013-04-10 15:55:37 +000065 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000066 for (int a = 0; a < 16; ++a) {
67 int ax = a & 0x03;
68 int ay = a >> 2;
69 for (int b = a ; b < 16; ++b) {
70 int bx = b & 0x03;
71 int by = b >> 2;
72 for (int c = a ; c < 16; ++c) {
73 int cx = c & 0x03;
74 int cy = c >> 2;
75 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
caryclark@google.com66089e42013-04-10 15:55:37 +000076 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
77 (&testSimplifyDegeneratesMain, a, b, c, abcIsATriangle,
78 &testRunner));
caryclark@google.com818b0cc2013-04-08 11:50:46 +000079 }
caryclark@google.com66089e42013-04-10 15:55:37 +000080 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000081 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000082 }
83finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000084 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000085}
86
87#include "TestClassDef.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000088DEFINE_TESTCLASS_SHORT(PathOpsSimplifyDegeneratesThreadedTest)