commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkString.h" |
| 8 | #include "tests/PathOpsDebug.h" |
| 9 | #include "tests/PathOpsExtendedTest.h" |
| 10 | #include "tests/PathOpsThreadedCommon.h" |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 11 | |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 12 | #include <atomic> |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 13 | |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 14 | static int loopNo = 17; |
| 15 | |
| 16 | static void add_point(SkString* str, SkScalar x, SkScalar y) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 17 | int asInt = SkScalarRoundToInt(x); |
| 18 | if (SkIntToScalar(asInt) == x) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 19 | str->appendf("%d", asInt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 20 | } else { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 21 | str->appendf("%1.9gf", x); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 22 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 23 | str->appendf(","); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 24 | asInt = SkScalarRoundToInt(y); |
| 25 | if (SkIntToScalar(asInt) == y) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 26 | str->appendf("%d", asInt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 27 | } else { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 28 | str->appendf("%1.9gf", y); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 29 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 32 | static std::atomic<int> gLoopsTestNo{0}; |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 33 | |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 34 | static void testOpLoopsMain(PathOpsThreadState* data) { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 35 | SkASSERT(data); |
| 36 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 37 | SkString pathStr; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 38 | for (int a = 0 ; a < 6; ++a) { |
| 39 | for (int b = a + 1 ; b < 7; ++b) { |
| 40 | for (int c = 0 ; c < 6; ++c) { |
| 41 | for (int d = c + 1 ; d < 7; ++d) { |
| 42 | // define 4 points that form two lines that often cross; one line is (a, b) (c, d) |
| 43 | SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; |
| 44 | SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, |
| 45 | SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; |
| 46 | SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, |
| 47 | SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; |
| 48 | SkPoint endC = { midA.fX + v.fY * state.fC / 3, |
| 49 | midA.fY + v.fX * state.fC / 3 }; |
| 50 | SkPoint endD = { midB.fX - v.fY * state.fD / 3, |
| 51 | midB.fY + v.fX * state.fD / 3 }; |
| 52 | SkPath pathA, pathB; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 53 | pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); |
| 54 | pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); |
| 55 | pathA.close(); |
| 56 | pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); |
| 57 | pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); |
| 58 | pathB.close(); |
| 59 | // SkDebugf("%s\n", pathStr); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 60 | if (state.fReporter->verbose()) { |
| 61 | pathStr.printf("static void loop%d(skiatest::Reporter* reporter," |
| 62 | " const char* filename) {\n", loopNo); |
| 63 | pathStr.appendf(" SkPath path, pathB;\n"); |
| 64 | pathStr.appendf(" path.moveTo(%d,%d);\n", a, b); |
| 65 | pathStr.appendf(" path.cubicTo(%d,%d, ", c, d); |
| 66 | add_point(&pathStr, endC.fX, endC.fY); |
| 67 | pathStr.appendf(", "); |
| 68 | add_point(&pathStr, endD.fX, endD.fY); |
| 69 | pathStr.appendf(");\n"); |
| 70 | pathStr.appendf(" path.close();\n"); |
| 71 | pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d); |
| 72 | pathStr.appendf(" pathB.cubicTo("); |
| 73 | add_point(&pathStr, endC.fX, endC.fY); |
| 74 | pathStr.appendf(", "); |
| 75 | add_point(&pathStr, endD.fX, endD.fY); |
| 76 | pathStr.appendf(", %d,%d);\n", a, b); |
| 77 | pathStr.appendf(" pathB.close();\n"); |
| 78 | pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp," |
| 79 | " filename);\n"); |
| 80 | pathStr.appendf("}\n"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 81 | state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 82 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 83 | SkString testName; |
| 84 | testName.printf("thread_loops%d", ++gLoopsTestNo); |
| 85 | testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str()); |
| 86 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | DEF_TEST(PathOpsOpLoopsThreaded, reporter) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 94 | initializeTests(reporter, "loopOp"); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 95 | PathOpsThreadedTestRunner testRunner(reporter); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 96 | for (int a = 0; a < 6; ++a) { // outermost |
| 97 | for (int b = a + 1; b < 7; ++b) { |
| 98 | for (int c = 0 ; c < 6; ++c) { |
| 99 | for (int d = c + 1; d < 7; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 100 | *testRunner.fRunnables.append() = |
| 101 | new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | if (!reporter->allowExtendedTest()) goto finish; |
| 105 | } |
| 106 | } |
| 107 | finish: |
| 108 | testRunner.render(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 109 | } |