blob: 8d1e8db596e790690e14738e91aa517aabf3559c [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 testSimplifyTrianglesMain(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.com03610322013-04-18 15:58:21 +000015 state.fKey = "?";
caryclark@google.com66089e42013-04-10 15:55:37 +000016 int ax = state.fA & 0x03;
17 int ay = state.fA >> 2;
18 int bx = state.fB & 0x03;
19 int by = state.fB >> 2;
20 int cx = state.fC & 0x03;
21 int cy = state.fC >> 2;
22 for (int d = 0; d < 15; ++d) {
23 int dx = d & 0x03;
24 int dy = d >> 2;
25 for (int e = d + 1; e < 16; ++e) {
26 int ex = e & 0x03;
27 int ey = e >> 2;
28 for (int f = d + 1; f < 16; ++f) {
29 if (e == f) {
30 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000031 }
caryclark@google.com66089e42013-04-10 15:55:37 +000032 int fx = f & 0x03;
33 int fy = f >> 2;
34 if ((ex - dx) * (fy - dy) == (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 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.close();\n");
52 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
53 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
55 str += sprintf(str, " path.close();\n");
56 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
caryclark@google.com03610322013-04-18 15:58:21 +000057 ShowTestName(&state, d, e, f, 0);
caryclark@google.com66089e42013-04-10 15:55:37 +000058 testSimplify(path, false, out, state, pathStr);
59 path.setFillType(SkPath::kEvenOdd_FillType);
60 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
caryclark@google.com03610322013-04-18 15:58:21 +000061 ShowTestName(&state, d, e, f, 1);
caryclark@google.com66089e42013-04-10 15:55:37 +000062 testSimplify(path, true, out, state, pathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000063 }
64 }
caryclark@google.com66089e42013-04-10 15:55:37 +000065 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000066}
67
caryclark@google.comad65a3e2013-04-15 19:13:59 +000068static void PathOpsSimplifyTrianglesThreadedTest(skiatest::Reporter* reporter) {
caryclark@google.com16cfe402013-04-18 18:47:37 +000069 int threadCount = initializeTests(reporter, "testTriangles");
caryclark@google.com66089e42013-04-10 15:55:37 +000070 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000071 for (int a = 0; a < 15; ++a) {
72 int ax = a & 0x03;
73 int ay = a >> 2;
74 for (int b = a + 1; b < 16; ++b) {
75 int bx = b & 0x03;
76 int by = b >> 2;
77 for (int c = a + 1; c < 16; ++c) {
78 if (b == c) {
79 continue;
80 }
81 int cx = c & 0x03;
82 int cy = c >> 2;
83 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
84 continue;
85 }
caryclark@google.com66089e42013-04-10 15:55:37 +000086 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
87 (&testSimplifyTrianglesMain, a, b, c, 0, &testRunner));
caryclark@google.com818b0cc2013-04-08 11:50:46 +000088 }
caryclark@google.com66089e42013-04-10 15:55:37 +000089 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000090 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000091 }
92finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000093 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094}
95
96#include "TestClassDef.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000097DEFINE_TESTCLASS_SHORT(PathOpsSimplifyTrianglesThreadedTest)