1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2012 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci#include "include/core/SkString.h"
8cb93a386Sopenharmony_ci#include "tests/PathOpsExtendedTest.h"
9cb93a386Sopenharmony_ci#include "tests/PathOpsThreadedCommon.h"
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_cistatic int quadTest = 66;
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_cistatic void testSimplifyQuadsMain(PathOpsThreadState* data)
14cb93a386Sopenharmony_ci{
15cb93a386Sopenharmony_ci    SkASSERT(data);
16cb93a386Sopenharmony_ci    PathOpsThreadState& state = *data;
17cb93a386Sopenharmony_ci    SkString pathStr;
18cb93a386Sopenharmony_ci    int ax = state.fA & 0x03;
19cb93a386Sopenharmony_ci    int ay = state.fA >> 2;
20cb93a386Sopenharmony_ci    int bx = state.fB & 0x03;
21cb93a386Sopenharmony_ci    int by = state.fB >> 2;
22cb93a386Sopenharmony_ci    int cx = state.fC & 0x03;
23cb93a386Sopenharmony_ci    int cy = state.fC >> 2;
24cb93a386Sopenharmony_ci    int dx = state.fD & 0x03;
25cb93a386Sopenharmony_ci    int dy = state.fD >> 2;
26cb93a386Sopenharmony_ci    for (int e = 0 ; e < 16; ++e) {
27cb93a386Sopenharmony_ci        int ex = e & 0x03;
28cb93a386Sopenharmony_ci        int ey = e >> 2;
29cb93a386Sopenharmony_ci        for (int f = e ; f < 16; ++f) {
30cb93a386Sopenharmony_ci            int fx = f & 0x03;
31cb93a386Sopenharmony_ci            int fy = f >> 2;
32cb93a386Sopenharmony_ci            for (int g = f ; g < 16; ++g) {
33cb93a386Sopenharmony_ci                int gx = g & 0x03;
34cb93a386Sopenharmony_ci                int gy = g >> 2;
35cb93a386Sopenharmony_ci                for (int h = g ; h < 16; ++h) {
36cb93a386Sopenharmony_ci                    int hx = h & 0x03;
37cb93a386Sopenharmony_ci                    int hy = h >> 2;
38cb93a386Sopenharmony_ci                    SkPath path, out;
39cb93a386Sopenharmony_ci                    path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
40cb93a386Sopenharmony_ci                    path.quadTo(SkIntToScalar(bx), SkIntToScalar(by),
41cb93a386Sopenharmony_ci                            SkIntToScalar(cx), SkIntToScalar(cy));
42cb93a386Sopenharmony_ci                    path.lineTo(SkIntToScalar(dx), SkIntToScalar(dy));
43cb93a386Sopenharmony_ci                    path.close();
44cb93a386Sopenharmony_ci                    path.moveTo(SkIntToScalar(ex), SkIntToScalar(ey));
45cb93a386Sopenharmony_ci                    path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
46cb93a386Sopenharmony_ci                    path.quadTo(SkIntToScalar(gx), SkIntToScalar(gy),
47cb93a386Sopenharmony_ci                            SkIntToScalar(hx), SkIntToScalar(hy));
48cb93a386Sopenharmony_ci                    path.close();
49cb93a386Sopenharmony_ci                    if (state.fReporter->verbose()) {
50cb93a386Sopenharmony_ci                        pathStr.printf("static void testQuads%d(skiatest::Reporter* reporter,"
51cb93a386Sopenharmony_ci                                "const char* filename) {\n", quadTest);
52cb93a386Sopenharmony_ci                        pathStr.appendf("    SkPath path;\n");
53cb93a386Sopenharmony_ci                        pathStr.appendf("    path.moveTo(%d, %d);\n", ax, ay);
54cb93a386Sopenharmony_ci                        pathStr.appendf("    path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy);
55cb93a386Sopenharmony_ci                        pathStr.appendf("    path.lineTo(%d, %d);\n", dx, dy);
56cb93a386Sopenharmony_ci                        pathStr.appendf("    path.close();\n");
57cb93a386Sopenharmony_ci                        pathStr.appendf("    path.moveTo(%d, %d);\n", ex, ey);
58cb93a386Sopenharmony_ci                        pathStr.appendf("    path.lineTo(%d, %d);\n", fx, fy);
59cb93a386Sopenharmony_ci                        pathStr.appendf("    path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy);
60cb93a386Sopenharmony_ci                        pathStr.appendf("    path.close();\n");
61cb93a386Sopenharmony_ci                        pathStr.appendf("    testSimplify(reporter, path, filename);\n");
62cb93a386Sopenharmony_ci                        pathStr.appendf("}\n");
63cb93a386Sopenharmony_ci                        state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
64cb93a386Sopenharmony_ci                    }
65cb93a386Sopenharmony_ci                    testSimplify(path, false, out, state, pathStr.c_str());
66cb93a386Sopenharmony_ci                    path.setFillType(SkPathFillType::kEvenOdd);
67cb93a386Sopenharmony_ci                    if (state.fReporter->verbose()) {
68cb93a386Sopenharmony_ci                        state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
69cb93a386Sopenharmony_ci                    }
70cb93a386Sopenharmony_ci                    testSimplify(path, true, out, state, pathStr.c_str());
71cb93a386Sopenharmony_ci                }
72cb93a386Sopenharmony_ci            }
73cb93a386Sopenharmony_ci        }
74cb93a386Sopenharmony_ci    }
75cb93a386Sopenharmony_ci}
76cb93a386Sopenharmony_ci
77cb93a386Sopenharmony_ciDEF_TEST(PathOpsSimplifyQuadsThreaded, reporter) {
78cb93a386Sopenharmony_ci    initializeTests(reporter, "testQuads");
79cb93a386Sopenharmony_ci    PathOpsThreadedTestRunner testRunner(reporter);
80cb93a386Sopenharmony_ci    int a = 0;
81cb93a386Sopenharmony_ci    for (; a < 16; ++a) {
82cb93a386Sopenharmony_ci        for (int b = a ; b < 16; ++b) {
83cb93a386Sopenharmony_ci            for (int c = b ; c < 16; ++c) {
84cb93a386Sopenharmony_ci                for (int d = c; d < 16; ++d) {
85cb93a386Sopenharmony_ci                    *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
86cb93a386Sopenharmony_ci                            &testSimplifyQuadsMain, a, b, c, d, &testRunner);
87cb93a386Sopenharmony_ci                }
88cb93a386Sopenharmony_ci                if (!reporter->allowExtendedTest()) goto finish;
89cb93a386Sopenharmony_ci            }
90cb93a386Sopenharmony_ci        }
91cb93a386Sopenharmony_ci    }
92cb93a386Sopenharmony_cifinish:
93cb93a386Sopenharmony_ci    testRunner.render();
94cb93a386Sopenharmony_ci}
95