• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PathOpsDebug.h"
8 #include "PathOpsExtendedTest.h"
9 #include "PathOpsThreadedCommon.h"
10 #include "SkString.h"
11 
12 #include <atomic>
13 
14 static int loopNo = 17;
15 
add_point(SkString * str,SkScalar x,SkScalar y)16 static void add_point(SkString* str, SkScalar x, SkScalar y) {
17     int asInt = SkScalarRoundToInt(x);
18     if (SkIntToScalar(asInt) == x) {
19         str->appendf("%d", asInt);
20     } else {
21         str->appendf("%1.9gf", x);
22     }
23     str->appendf(",");
24     asInt = SkScalarRoundToInt(y);
25     if (SkIntToScalar(asInt) == y) {
26         str->appendf("%d", asInt);
27     } else {
28         str->appendf("%1.9gf", y);
29     }
30 }
31 
32 static std::atomic<int> gLoopsTestNo{0};
33 
testOpLoopsMain(PathOpsThreadState * data)34 static void testOpLoopsMain(PathOpsThreadState* data) {
35 #if DEBUG_SHOW_TEST_NAME
36     strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
37 #endif
38     SkASSERT(data);
39     PathOpsThreadState& state = *data;
40     SkString pathStr;
41     for (int a = 0 ; a < 6; ++a) {
42         for (int b = a + 1 ; b < 7; ++b) {
43             for (int c = 0 ; c < 6; ++c) {
44                 for (int d = c + 1 ; d < 7; ++d) {
45         // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
46         SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
47         SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
48                          SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
49         SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
50                          SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
51         SkPoint endC = { midA.fX + v.fY * state.fC / 3,
52                           midA.fY + v.fX * state.fC / 3 };
53         SkPoint endD = { midB.fX - v.fY * state.fD / 3,
54                           midB.fY + v.fX * state.fD / 3 };
55         SkPath pathA, pathB;
56         pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
57         pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
58         pathA.close();
59         pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
60         pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
61         pathB.close();
62 //        SkDebugf("%s\n", pathStr);
63         if (state.fReporter->verbose()) {
64             pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
65                     " const char* filename) {\n", loopNo);
66             pathStr.appendf("    SkPath path, pathB;\n");
67             pathStr.appendf("    path.moveTo(%d,%d);\n", a, b);
68             pathStr.appendf("    path.cubicTo(%d,%d, ", c, d);
69             add_point(&pathStr, endC.fX, endC.fY);
70             pathStr.appendf(", ");
71             add_point(&pathStr, endD.fX, endD.fY);
72             pathStr.appendf(");\n");
73             pathStr.appendf("    path.close();\n");
74             pathStr.appendf("    pathB.moveTo(%d,%d);\n", c, d);
75             pathStr.appendf("    pathB.cubicTo(");
76             add_point(&pathStr, endC.fX, endC.fY);
77             pathStr.appendf(", ");
78             add_point(&pathStr, endD.fX, endD.fY);
79             pathStr.appendf(", %d,%d);\n", a, b);
80             pathStr.appendf("    pathB.close();\n");
81             pathStr.appendf("    testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
82                     " filename);\n");
83             pathStr.appendf("}\n");
84             state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
85         }
86         SkString testName;
87         testName.printf("thread_loops%d", ++gLoopsTestNo);
88         testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
89         if (PathOpsDebug::gCheckForDuplicateNames) return;
90                 }
91             }
92         }
93     }
94 }
95 
DEF_TEST(PathOpsOpLoopsThreaded,reporter)96 DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
97     initializeTests(reporter, "loopOp");
98     PathOpsThreadedTestRunner testRunner(reporter);
99     for (int a = 0; a < 6; ++a) {  // outermost
100         for (int b = a + 1; b < 7; ++b) {
101             for (int c = 0 ; c < 6; ++c) {
102                 for (int d = c + 1; d < 7; ++d) {
103                     *testRunner.fRunnables.append() =
104                             new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
105                 }
106             }
107             if (!reporter->allowExtendedTest()) goto finish;
108         }
109     }
110 finish:
111     testRunner.render();
112 }
113