blob: db2e9ff9175b7b2bcdef03fa0b21d4c40fd25e79 [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"
Cary Clark8af4c402018-08-08 23:22:37 -040011#include <atomic>
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000012
caryclark8f186432016-10-06 11:46:25 -070013static int loopNo = 17;
14
15static void add_point(SkString* str, SkScalar x, SkScalar y) {
caryclark54359292015-03-26 07:52:43 -070016 int asInt = SkScalarRoundToInt(x);
17 if (SkIntToScalar(asInt) == x) {
caryclark8f186432016-10-06 11:46:25 -070018 str->appendf("%d", asInt);
caryclark54359292015-03-26 07:52:43 -070019 } else {
caryclark8f186432016-10-06 11:46:25 -070020 str->appendf("%1.9gf", x);
caryclark54359292015-03-26 07:52:43 -070021 }
caryclark8f186432016-10-06 11:46:25 -070022 str->appendf(",");
caryclark54359292015-03-26 07:52:43 -070023 asInt = SkScalarRoundToInt(y);
24 if (SkIntToScalar(asInt) == y) {
caryclark8f186432016-10-06 11:46:25 -070025 str->appendf("%d", asInt);
caryclark54359292015-03-26 07:52:43 -070026 } else {
caryclark8f186432016-10-06 11:46:25 -070027 str->appendf("%1.9gf", y);
caryclark54359292015-03-26 07:52:43 -070028 }
caryclark54359292015-03-26 07:52:43 -070029}
30
Cary Clark8af4c402018-08-08 23:22:37 -040031static std::atomic<int> gLoopsTestNo{0};
Cary Clark4533f3d2018-08-08 09:48:09 -040032
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000033static void testOpLoopsMain(PathOpsThreadState* data) {
34#if DEBUG_SHOW_TEST_NAME
35 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
36#endif
37 SkASSERT(data);
38 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070039 SkString pathStr;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000040 for (int a = 0 ; a < 6; ++a) {
41 for (int b = a + 1 ; b < 7; ++b) {
42 for (int c = 0 ; c < 6; ++c) {
43 for (int d = c + 1 ; d < 7; ++d) {
44 // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
45 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
46 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
47 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
48 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
49 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
50 SkPoint endC = { midA.fX + v.fY * state.fC / 3,
51 midA.fY + v.fX * state.fC / 3 };
52 SkPoint endD = { midB.fX - v.fY * state.fD / 3,
53 midB.fY + v.fX * state.fD / 3 };
54 SkPath pathA, pathB;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000055 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
56 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
57 pathA.close();
58 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
59 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
60 pathB.close();
61// SkDebugf("%s\n", pathStr);
caryclark8f186432016-10-06 11:46:25 -070062 if (state.fReporter->verbose()) {
63 pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
64 " const char* filename) {\n", loopNo);
65 pathStr.appendf(" SkPath path, pathB;\n");
66 pathStr.appendf(" path.moveTo(%d,%d);\n", a, b);
67 pathStr.appendf(" path.cubicTo(%d,%d, ", c, d);
68 add_point(&pathStr, endC.fX, endC.fY);
69 pathStr.appendf(", ");
70 add_point(&pathStr, endD.fX, endD.fY);
71 pathStr.appendf(");\n");
72 pathStr.appendf(" path.close();\n");
73 pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d);
74 pathStr.appendf(" pathB.cubicTo(");
75 add_point(&pathStr, endC.fX, endC.fY);
76 pathStr.appendf(", ");
77 add_point(&pathStr, endD.fX, endD.fY);
78 pathStr.appendf(", %d,%d);\n", a, b);
79 pathStr.appendf(" pathB.close();\n");
80 pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
81 " filename);\n");
82 pathStr.appendf("}\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050083 state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000084 }
Cary Clark4533f3d2018-08-08 09:48:09 -040085 SkString testName;
86 testName.printf("thread_loops%d", ++gLoopsTestNo);
87 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
88 if (PathOpsDebug::gCheckForDuplicateNames) return;
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();
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000111}