blob: 7b4b7ce7cf488a1af1ec84f6a94d3206afa58870 [file] [log] [blame]
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +00001/*
2 * Copyright 2014 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
caryclark54359292015-03-26 07:52:43 -070010static int add_point(char* str, SkScalar x, SkScalar y) {
11 int result;
12 int asInt = SkScalarRoundToInt(x);
13 if (SkIntToScalar(asInt) == x) {
14 result = sprintf(str, "%d", asInt);
15 } else {
16 result = sprintf(str, "%1.9gf", x);
17 }
18 result += sprintf(str + result, ",");
19 asInt = SkScalarRoundToInt(y);
20 if (SkIntToScalar(asInt) == y) {
21 result += sprintf(str + result, "%d", asInt);
22 } else {
23 result += sprintf(str + result, "%1.9gf", y);
24 }
25 return result;
26}
27
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000028static void testOpLoopsMain(PathOpsThreadState* data) {
29#if DEBUG_SHOW_TEST_NAME
30 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
31#endif
32 SkASSERT(data);
33 PathOpsThreadState& state = *data;
34 char pathStr[1024]; // gdb: set print elements 400
35 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
36 if (progress) {
37 sk_bzero(pathStr, sizeof(pathStr));
38 }
39 for (int a = 0 ; a < 6; ++a) {
40 for (int b = a + 1 ; b < 7; ++b) {
41 for (int c = 0 ; c < 6; ++c) {
42 for (int d = c + 1 ; d < 7; ++d) {
43 // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
44 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
45 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
46 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
47 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
48 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
49 SkPoint endC = { midA.fX + v.fY * state.fC / 3,
50 midA.fY + v.fX * state.fC / 3 };
51 SkPoint endD = { midB.fX - v.fY * state.fD / 3,
52 midB.fY + v.fX * state.fD / 3 };
53 SkPath pathA, pathB;
54 if (progress) {
55 char* str = pathStr;
caryclark03b03ca2015-04-23 09:13:37 -070056 const int loopNo = 17;
caryclark54359292015-03-26 07:52:43 -070057 str += sprintf(str, "static void loop%d(skiatest::Reporter* reporter,"
58 " const char* filename) {\n", loopNo);
59 str += sprintf(str, " SkPath path, pathB;\n");
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000060 str += sprintf(str, " path.moveTo(%d,%d);\n", a, b);
caryclark54359292015-03-26 07:52:43 -070061 str += sprintf(str, " path.cubicTo(%d,%d, ", c, d);
62 str += add_point(str, endC.fX, endC.fY);
63 str += sprintf(str, ", ");
64 str += add_point(str, endD.fX, endD.fY);
65 str += sprintf(str, ");\n");
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000066 str += sprintf(str, " path.close();\n");
67 str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d);
caryclark54359292015-03-26 07:52:43 -070068 str += sprintf(str, " pathB.cubicTo(");
69 str += add_point(str, endC.fX, endC.fY);
70 str += sprintf(str, ", ");
71 str += add_point(str, endD.fX, endD.fY);
72 str += sprintf(str, ", %d,%d);\n", a, b);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000073 str += sprintf(str, " pathB.close();\n");
caryclark54359292015-03-26 07:52:43 -070074 str += sprintf(str, " testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
75 " filename);\n");
76 str += sprintf(str, "}\n");
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000077 }
78 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
79 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
80 pathA.close();
81 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
82 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
83 pathB.close();
84// SkDebugf("%s\n", pathStr);
85 if (progress) {
caryclark54359292015-03-26 07:52:43 -070086 outputProgress(state.fPathStr, pathStr, kIntersect_SkPathOp);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000087 }
caryclark38a017b2015-05-13 10:13:17 -070088 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops");
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000089 }
90 }
91 }
92 }
93}
94
95DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
caryclark1049f122015-04-20 08:31:59 -070096 initializeTests(reporter, "loopOp");
mtklein406654b2014-09-03 15:34:37 -070097 PathOpsThreadedTestRunner testRunner(reporter);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000098 for (int a = 0; a < 6; ++a) { // outermost
99 for (int b = a + 1; b < 7; ++b) {
100 for (int c = 0 ; c < 6; ++c) {
101 for (int d = c + 1; d < 7; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -0700102 *testRunner.fRunnables.append() =
103 new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000104 }
105 }
106 if (!reporter->allowExtendedTest()) goto finish;
107 }
108 }
109finish:
110 testRunner.render();
caryclark1049f122015-04-20 08:31:59 -0700111 ShowTestArray("loopOp");
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000112}