Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "PathOpsExtendedTest.h" | 7 #include "PathOpsExtendedTest.h" |
| 8 #include "PathOpsThreadedCommon.h" | 8 #include "PathOpsThreadedCommon.h" |
| 9 #include "SkString.h" | |
| 9 | 10 |
| 10 static int add_point(char* str, SkScalar x, SkScalar y) { | 11 static int loopNo = 17; |
|
scroggo
2016/10/06 14:42:00
nit: gLoopNo
| |
| 11 int result; | 12 |
| 13 static void add_point(SkString* str, SkScalar x, SkScalar y) { | |
| 12 int asInt = SkScalarRoundToInt(x); | 14 int asInt = SkScalarRoundToInt(x); |
| 13 if (SkIntToScalar(asInt) == x) { | 15 if (SkIntToScalar(asInt) == x) { |
| 14 result = sprintf(str, "%d", asInt); | 16 str->appendf("%d", asInt); |
| 15 } else { | 17 } else { |
| 16 result = sprintf(str, "%1.9gf", x); | 18 str->appendf("%1.9gf", x); |
| 17 } | 19 } |
| 18 result += sprintf(str + result, ","); | 20 str->appendf(","); |
| 19 asInt = SkScalarRoundToInt(y); | 21 asInt = SkScalarRoundToInt(y); |
| 20 if (SkIntToScalar(asInt) == y) { | 22 if (SkIntToScalar(asInt) == y) { |
| 21 result += sprintf(str + result, "%d", asInt); | 23 str->appendf("%d", asInt); |
| 22 } else { | 24 } else { |
| 23 result += sprintf(str + result, "%1.9gf", y); | 25 str->appendf("%1.9gf", y); |
| 24 } | 26 } |
| 25 return result; | |
| 26 } | 27 } |
| 27 | 28 |
| 28 static void testOpLoopsMain(PathOpsThreadState* data) { | 29 static void testOpLoopsMain(PathOpsThreadState* data) { |
| 29 #if DEBUG_SHOW_TEST_NAME | 30 #if DEBUG_SHOW_TEST_NAME |
| 30 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); | 31 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); |
| 31 #endif | 32 #endif |
| 32 SkASSERT(data); | 33 SkASSERT(data); |
| 33 PathOpsThreadState& state = *data; | 34 PathOpsThreadState& state = *data; |
| 34 char pathStr[1024]; // gdb: set print elements 400 | 35 SkString pathStr; |
| 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) { | 36 for (int a = 0 ; a < 6; ++a) { |
| 40 for (int b = a + 1 ; b < 7; ++b) { | 37 for (int b = a + 1 ; b < 7; ++b) { |
| 41 for (int c = 0 ; c < 6; ++c) { | 38 for (int c = 0 ; c < 6; ++c) { |
| 42 for (int d = c + 1 ; d < 7; ++d) { | 39 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) | 40 // 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)}; | 41 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; |
| 45 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, | 42 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, |
| 46 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; | 43 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; |
| 47 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, | 44 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, |
| 48 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; | 45 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; |
| 49 SkPoint endC = { midA.fX + v.fY * state.fC / 3, | 46 SkPoint endC = { midA.fX + v.fY * state.fC / 3, |
| 50 midA.fY + v.fX * state.fC / 3 }; | 47 midA.fY + v.fX * state.fC / 3 }; |
| 51 SkPoint endD = { midB.fX - v.fY * state.fD / 3, | 48 SkPoint endD = { midB.fX - v.fY * state.fD / 3, |
| 52 midB.fY + v.fX * state.fD / 3 }; | 49 midB.fY + v.fX * state.fD / 3 }; |
| 53 SkPath pathA, pathB; | 50 SkPath pathA, pathB; |
| 54 if (progress) { | |
| 55 char* str = pathStr; | |
| 56 const int loopNo = 17; | |
| 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"); | |
| 60 str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); | |
| 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"); | |
| 66 str += sprintf(str, " path.close();\n"); | |
| 67 str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); | |
| 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); | |
| 73 str += sprintf(str, " pathB.close();\n"); | |
| 74 str += sprintf(str, " testPathOp(reporter, path, pathB, kIntersec t_SkPathOp," | |
| 75 " filename);\n"); | |
| 76 str += sprintf(str, "}\n"); | |
| 77 } | |
| 78 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); | 51 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); |
| 79 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD .fX, endD.fY); | 52 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD .fX, endD.fY); |
| 80 pathA.close(); | 53 pathA.close(); |
| 81 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); | 54 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); |
| 82 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIn tToScalar(b)); | 55 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIn tToScalar(b)); |
| 83 pathB.close(); | 56 pathB.close(); |
| 84 // SkDebugf("%s\n", pathStr); | 57 // SkDebugf("%s\n", pathStr); |
| 85 if (progress) { | 58 if (state.fReporter->verbose()) { |
| 86 outputProgress(state.fPathStr, pathStr, kIntersect_SkPathOp); | 59 pathStr.printf("static void loop%d(skiatest::Reporter* reporter," |
| 60 " const char* filename) {\n", loopNo); | |
| 61 pathStr.appendf(" SkPath path, pathB;\n"); | |
| 62 pathStr.appendf(" path.moveTo(%d,%d);\n", a, b); | |
| 63 pathStr.appendf(" path.cubicTo(%d,%d, ", c, d); | |
| 64 add_point(&pathStr, endC.fX, endC.fY); | |
| 65 pathStr.appendf(", "); | |
| 66 add_point(&pathStr, endD.fX, endD.fY); | |
| 67 pathStr.appendf(");\n"); | |
| 68 pathStr.appendf(" path.close();\n"); | |
| 69 pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d); | |
| 70 pathStr.appendf(" pathB.cubicTo("); | |
| 71 add_point(&pathStr, endC.fX, endC.fY); | |
| 72 pathStr.appendf(", "); | |
| 73 add_point(&pathStr, endD.fX, endD.fY); | |
| 74 pathStr.appendf(", %d,%d);\n", a, b); | |
| 75 pathStr.appendf(" pathB.close();\n"); | |
| 76 pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_Sk PathOp," | |
| 77 " filename);\n"); | |
| 78 pathStr.appendf("}\n"); | |
| 79 outputProgress(state.fPathStr, pathStr.c_str(), kIntersect_SkPathOp) ; | |
| 87 } | 80 } |
| 88 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); | 81 testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); |
| 89 } | 82 } |
| 90 } | 83 } |
| 91 } | 84 } |
| 92 } | 85 } |
| 93 } | 86 } |
| 94 | 87 |
| 95 DEF_TEST(PathOpsOpLoopsThreaded, reporter) { | 88 DEF_TEST(PathOpsOpLoopsThreaded, reporter) { |
| 96 initializeTests(reporter, "loopOp"); | 89 initializeTests(reporter, "loopOp"); |
| 97 PathOpsThreadedTestRunner testRunner(reporter); | 90 PathOpsThreadedTestRunner testRunner(reporter); |
| 98 for (int a = 0; a < 6; ++a) { // outermost | 91 for (int a = 0; a < 6; ++a) { // outermost |
| 99 for (int b = a + 1; b < 7; ++b) { | 92 for (int b = a + 1; b < 7; ++b) { |
| 100 for (int c = 0 ; c < 6; ++c) { | 93 for (int c = 0 ; c < 6; ++c) { |
| 101 for (int d = c + 1; d < 7; ++d) { | 94 for (int d = c + 1; d < 7; ++d) { |
| 102 *testRunner.fRunnables.append() = | 95 *testRunner.fRunnables.append() = |
| 103 new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner); | 96 new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner); |
| 104 } | 97 } |
| 105 } | 98 } |
| 106 if (!reporter->allowExtendedTest()) goto finish; | 99 if (!reporter->allowExtendedTest()) goto finish; |
| 107 } | 100 } |
| 108 } | 101 } |
| 109 finish: | 102 finish: |
| 110 testRunner.render(); | 103 testRunner.render(); |
| 111 } | 104 } |
| OLD | NEW |