• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 "include/core/SkString.h"
8 #include "tests/PathOpsExtendedTest.h"
9 #include "tests/PathOpsThreadedCommon.h"
10 
11 static int loopNo = 1;
12 
testSimplifyQuadralateralsMain(PathOpsThreadState * data)13 static void testSimplifyQuadralateralsMain(PathOpsThreadState* data)
14 {
15     SkASSERT(data);
16     PathOpsThreadState& state = *data;
17     SkString pathStr;
18     int ax = state.fA & 0x03;
19     int ay = state.fA >> 2;
20     int bx = state.fB & 0x03;
21     int by = state.fB >> 2;
22     int cx = state.fC & 0x03;
23     int cy = state.fC >> 2;
24     int dx = state.fD & 0x03;
25     int dy = state.fD >> 2;
26     for (int e = 0 ; e < 16; ++e) {
27         int ex = e & 0x03;
28         int ey = e >> 2;
29         for (int f = e ; f < 16; ++f) {
30             int fx = f & 0x03;
31             int fy = f >> 2;
32             for (int g = f ; g < 16; ++g) {
33                 int gx = g & 0x03;
34                 int gy = g >> 2;
35                 for (int h = g ; h < 16; ++h) {
36                     int hx = h & 0x03;
37                     int hy = h >> 2;
38                     SkPath path, out;
39                     path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
40                     path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
41                     path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
42                     path.lineTo(SkIntToScalar(dx), SkIntToScalar(dy));
43                     path.close();
44                     path.moveTo(SkIntToScalar(ex), SkIntToScalar(ey));
45                     path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
46                     path.lineTo(SkIntToScalar(gx), SkIntToScalar(gy));
47                     path.lineTo(SkIntToScalar(hx), SkIntToScalar(hy));
48                     path.close();
49                     if (state.fReporter->verbose()) {
50                         pathStr.printf("static void quadralateralSimplify%d(skiatest::Reporter*"
51                                 "reporter, const char* filename) {\n", loopNo);
52                         pathStr.appendf("    SkPath path;\n");
53                         pathStr.appendf("    path.moveTo(%d, %d);\n", ax, ay);
54                         pathStr.appendf("    path.lineTo(%d, %d);\n", bx, by);
55                         pathStr.appendf("    path.lineTo(%d, %d);\n", cx, cy);
56                         pathStr.appendf("    path.lineTo(%d, %d);\n", dx, dy);
57                         pathStr.appendf("    path.close();\n");
58                         pathStr.appendf("    path.moveTo(%d, %d);\n", ex, ey);
59                         pathStr.appendf("    path.lineTo(%d, %d);\n", fx, fy);
60                         pathStr.appendf("    path.lineTo(%d, %d);\n", gx, gy);
61                         pathStr.appendf("    path.lineTo(%d, %d);\n", hx, hy);
62                         pathStr.appendf("    path.close();\n");
63                         pathStr.appendf("    testPathSimplify(reporter, path, filename);\n");
64                         pathStr.appendf("}\n");
65                         state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
66                     }
67                     testSimplify(path, false, out, state, pathStr.c_str());
68                     path.setFillType(SkPathFillType::kEvenOdd);
69                     if (state.fReporter->verbose()) {
70                         state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
71                     }
72                     testSimplify(path, true, out, state, pathStr.c_str());
73                 }
74             }
75         }
76     }
77 }
78 
DEF_TEST(PathOpsSimplifyQuadralateralsThreaded,reporter)79 DEF_TEST(PathOpsSimplifyQuadralateralsThreaded, reporter) {
80     initializeTests(reporter, "testQuadralaterals");
81     PathOpsThreadedTestRunner testRunner(reporter);
82     for (int a = 0; a < 16; ++a) {
83         for (int b = a ; b < 16; ++b) {
84             for (int c = b ; c < 16; ++c) {
85                 for (int d = c; d < 16; ++d) {
86                     *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
87                             &testSimplifyQuadralateralsMain, a, b, c, d, &testRunner);
88                 }
89                 if (!reporter->allowExtendedTest()) goto finish;
90             }
91         }
92     }
93 finish:
94     testRunner.render();
95 }
96