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 | */ |
| 7 | #include "PathOpsExtendedTest.h" |
| 8 | #include "PathOpsThreadedCommon.h" |
| 9 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 10 | static 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.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 28 | static 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; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 56 | const int loopNo = 7; |
| 57 | 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.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 60 | str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 61 | 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.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 66 | str += sprintf(str, " path.close();\n"); |
| 67 | str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 68 | 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.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 73 | str += sprintf(str, " pathB.close();\n"); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 74 | str += sprintf(str, " testPathOp(reporter, path, pathB, kIntersect_SkPathOp," |
| 75 | " filename);\n"); |
| 76 | str += sprintf(str, "}\n"); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 77 | } |
| 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) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 86 | outputProgress(state.fPathStr, pathStr, kIntersect_SkPathOp); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 87 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 88 | testThreadedPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | DEF_TEST(PathOpsOpLoopsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 96 | initializeTests(reporter, "cubicOp"); |
| 97 | PathOpsThreadedTestRunner testRunner(reporter); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 98 | 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) { |
| 102 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 103 | (&testOpLoopsMain, a, b, c, d, &testRunner)); |
| 104 | } |
| 105 | } |
| 106 | if (!reporter->allowExtendedTest()) goto finish; |
| 107 | } |
| 108 | } |
| 109 | finish: |
| 110 | testRunner.render(); |
| 111 | ShowTestArray(); |
| 112 | } |
| 113 | |
| 114 | DEF_TEST(PathOpsOpLoops, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 115 | initializeTests(reporter, "cubicOp"); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 116 | PathOpsThreadState state; |
| 117 | state.fReporter = reporter; |
| 118 | SkBitmap bitmap; |
| 119 | state.fBitmap = &bitmap; |
| 120 | char pathStr[PATH_STR_SIZE]; |
| 121 | state.fPathStr = pathStr; |
| 122 | for (state.fA = 0; state.fA < 6; ++state.fA) { // outermost |
| 123 | for (state.fB = state.fA + 1; state.fB < 7; ++state.fB) { |
| 124 | for (state.fC = 0 ; state.fC < 6; ++state.fC) { |
| 125 | for (state.fD = state.fC + 1; state.fD < 7; ++state.fD) { |
| 126 | testOpLoopsMain(&state); |
| 127 | } |
| 128 | } |
| 129 | if (!reporter->allowExtendedTest()) goto finish; |
| 130 | } |
| 131 | } |
| 132 | finish: |
| 133 | ShowTestArray(); |
| 134 | } |