| 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 |  */ | 
| Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame^] | 7 | #include "PathOpsDebug.h" | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 8 | #include "PathOpsExtendedTest.h" | 
 | 9 | #include "PathOpsThreadedCommon.h" | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 10 | #include "SkString.h" | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 11 |  | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 12 | static int loopNo = 17; | 
 | 13 |  | 
 | 14 | static void add_point(SkString* str, SkScalar x, SkScalar y) { | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 15 |     int asInt = SkScalarRoundToInt(x); | 
 | 16 |     if (SkIntToScalar(asInt) == x) { | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 17 |         str->appendf("%d", asInt); | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 18 |     } else { | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 19 |         str->appendf("%1.9gf", x); | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 20 |     } | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 21 |     str->appendf(","); | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 22 |     asInt = SkScalarRoundToInt(y); | 
 | 23 |     if (SkIntToScalar(asInt) == y) { | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 24 |         str->appendf("%d", asInt); | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 25 |     } else { | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 26 |         str->appendf("%1.9gf", y); | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 27 |     } | 
| caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 28 | } | 
 | 29 |  | 
| Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame^] | 30 | static int gLoopsTestNo = 0; | 
 | 31 |  | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 32 | static 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; | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 38 |     SkString pathStr; | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 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; | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 54 |         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); | 
| caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 61 |         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 Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 82 |             state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp); | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 83 |         } | 
| Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame^] | 84 |         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.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 88 |                 } | 
 | 89 |             } | 
 | 90 |         } | 
 | 91 |     } | 
 | 92 | } | 
 | 93 |  | 
 | 94 | DEF_TEST(PathOpsOpLoopsThreaded, reporter) { | 
| caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 95 |     initializeTests(reporter, "loopOp"); | 
| mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 96 |     PathOpsThreadedTestRunner testRunner(reporter); | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 97 |     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) { | 
| halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 101 |                     *testRunner.fRunnables.append() = | 
 | 102 |                             new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner); | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 103 |                 } | 
 | 104 |             } | 
 | 105 |             if (!reporter->allowExtendedTest()) goto finish; | 
 | 106 |         } | 
 | 107 |     } | 
 | 108 | finish: | 
 | 109 |     testRunner.render(); | 
| commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 110 | } |