blob: 2d847ff134ef92f291dbd71eecf9565fb65462e6 [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 */
Cary Clark4533f3d2018-08-08 09:48:09 -04007#include "PathOpsDebug.h"
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +00008#include "PathOpsExtendedTest.h"
9#include "PathOpsThreadedCommon.h"
caryclark8f186432016-10-06 11:46:25 -070010#include "SkString.h"
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000011
caryclark8f186432016-10-06 11:46:25 -070012static int loopNo = 17;
13
14static void add_point(SkString* str, SkScalar x, SkScalar y) {
caryclark54359292015-03-26 07:52:43 -070015 int asInt = SkScalarRoundToInt(x);
16 if (SkIntToScalar(asInt) == x) {
caryclark8f186432016-10-06 11:46:25 -070017 str->appendf("%d", asInt);
caryclark54359292015-03-26 07:52:43 -070018 } else {
caryclark8f186432016-10-06 11:46:25 -070019 str->appendf("%1.9gf", x);
caryclark54359292015-03-26 07:52:43 -070020 }
caryclark8f186432016-10-06 11:46:25 -070021 str->appendf(",");
caryclark54359292015-03-26 07:52:43 -070022 asInt = SkScalarRoundToInt(y);
23 if (SkIntToScalar(asInt) == y) {
caryclark8f186432016-10-06 11:46:25 -070024 str->appendf("%d", asInt);
caryclark54359292015-03-26 07:52:43 -070025 } else {
caryclark8f186432016-10-06 11:46:25 -070026 str->appendf("%1.9gf", y);
caryclark54359292015-03-26 07:52:43 -070027 }
caryclark54359292015-03-26 07:52:43 -070028}
29
Cary Clark4533f3d2018-08-08 09:48:09 -040030static int gLoopsTestNo = 0;
31
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000032static void testOpLoopsMain(PathOpsThreadState* data) {
33#if DEBUG_SHOW_TEST_NAME
34 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
35#endif
36 SkASSERT(data);
37 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070038 SkString pathStr;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000039 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;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000054 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
55 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
56 pathA.close();
57 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
58 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
59 pathB.close();
60// SkDebugf("%s\n", pathStr);
caryclark8f186432016-10-06 11:46:25 -070061 if (state.fReporter->verbose()) {
62 pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
63 " const char* filename) {\n", loopNo);
64 pathStr.appendf(" SkPath path, pathB;\n");
65 pathStr.appendf(" path.moveTo(%d,%d);\n", a, b);
66 pathStr.appendf(" path.cubicTo(%d,%d, ", c, d);
67 add_point(&pathStr, endC.fX, endC.fY);
68 pathStr.appendf(", ");
69 add_point(&pathStr, endD.fX, endD.fY);
70 pathStr.appendf(");\n");
71 pathStr.appendf(" path.close();\n");
72 pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d);
73 pathStr.appendf(" pathB.cubicTo(");
74 add_point(&pathStr, endC.fX, endC.fY);
75 pathStr.appendf(", ");
76 add_point(&pathStr, endD.fX, endD.fY);
77 pathStr.appendf(", %d,%d);\n", a, b);
78 pathStr.appendf(" pathB.close();\n");
79 pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
80 " filename);\n");
81 pathStr.appendf("}\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050082 state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000083 }
Cary Clark4533f3d2018-08-08 09:48:09 -040084 SkString testName;
85 testName.printf("thread_loops%d", ++gLoopsTestNo);
86 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
87 if (PathOpsDebug::gCheckForDuplicateNames) return;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000088 }
89 }
90 }
91 }
92}
93
94DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
caryclark1049f122015-04-20 08:31:59 -070095 initializeTests(reporter, "loopOp");
mtklein406654b2014-09-03 15:34:37 -070096 PathOpsThreadedTestRunner testRunner(reporter);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000097 for (int a = 0; a < 6; ++a) { // outermost
98 for (int b = a + 1; b < 7; ++b) {
99 for (int c = 0 ; c < 6; ++c) {
100 for (int d = c + 1; d < 7; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -0700101 *testRunner.fRunnables.append() =
102 new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000103 }
104 }
105 if (!reporter->allowExtendedTest()) goto finish;
106 }
107 }
108finish:
109 testRunner.render();
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000110}