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/PathOpsDebug.h"
9cb93a386Sopenharmony_ci#include "tests/PathOpsExtendedTest.h"
10cb93a386Sopenharmony_ci#include "tests/PathOpsThreadedCommon.h"
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci#include <atomic>
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cistatic int loopNo = 158;
15cb93a386Sopenharmony_cistatic std::atomic<int> gCubicsTestNo{0};
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cistatic void testOpCubicsMain(PathOpsThreadState* data) {
18cb93a386Sopenharmony_ci    SkASSERT(data);
19cb93a386Sopenharmony_ci    const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
20cb93a386Sopenharmony_ci    PathOpsThreadState& state = *data;
21cb93a386Sopenharmony_ci    SkString pathStr;
22cb93a386Sopenharmony_ci    for (int a = 0 ; a < 6; ++a) {
23cb93a386Sopenharmony_ci        for (int b = a + 1 ; b < 7; ++b) {
24cb93a386Sopenharmony_ci            for (int c = 0 ; c < 6; ++c) {
25cb93a386Sopenharmony_ci                for (int d = c + 1 ; d < 7; ++d) {
26cb93a386Sopenharmony_ci                    for (auto e : fts) {
27cb93a386Sopenharmony_ci    for (auto f : fts) {
28cb93a386Sopenharmony_ci        SkPath pathA, pathB;
29cb93a386Sopenharmony_ci        pathA.setFillType((SkPathFillType) e);
30cb93a386Sopenharmony_ci        pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB));
31cb93a386Sopenharmony_ci        pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b),
32cb93a386Sopenharmony_ci                SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c));
33cb93a386Sopenharmony_ci        pathA.close();
34cb93a386Sopenharmony_ci        pathB.setFillType((SkPathFillType) f);
35cb93a386Sopenharmony_ci        pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b));
36cb93a386Sopenharmony_ci        pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB),
37cb93a386Sopenharmony_ci                SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC));
38cb93a386Sopenharmony_ci        pathB.close();
39cb93a386Sopenharmony_ci        for (int op = 0 ; op <= kXOR_SkPathOp; ++op)    {
40cb93a386Sopenharmony_ci            if (state.fReporter->verbose()) {
41cb93a386Sopenharmony_ci                pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter,"
42cb93a386Sopenharmony_ci                        " const char* filename) {\n", loopNo);
43cb93a386Sopenharmony_ci                pathStr.appendf("    SkPath path, pathB;\n");
44cb93a386Sopenharmony_ci                pathStr.appendf("    path.setFillType(SkPathFillType::k%s);\n",
45cb93a386Sopenharmony_ci                        e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
46cb93a386Sopenharmony_ci                        ? "EvenOdd" : "?UNDEFINED");
47cb93a386Sopenharmony_ci                pathStr.appendf("    path.moveTo(%d,%d);\n", state.fA, state.fB);
48cb93a386Sopenharmony_ci                pathStr.appendf("    path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD,
49cb93a386Sopenharmony_ci                        b, a, d, c);
50cb93a386Sopenharmony_ci                pathStr.appendf("    path.close();\n");
51cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.setFillType(SkPathFillType::k%s);\n",
52cb93a386Sopenharmony_ci                        f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
53cb93a386Sopenharmony_ci                        ? "EvenOdd" : "?UNDEFINED");
54cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.moveTo(%d,%d);\n", a, b);
55cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d,
56cb93a386Sopenharmony_ci                        state.fB, state.fA, state.fD, state.fC);
57cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.close();\n");
58cb93a386Sopenharmony_ci                pathStr.appendf("    testPathOp(reporter, path, pathB, %s, filename);\n",
59cb93a386Sopenharmony_ci                        SkPathOpsDebug::OpStr((SkPathOp) op));
60cb93a386Sopenharmony_ci                pathStr.appendf("}\n");
61cb93a386Sopenharmony_ci                state.outputProgress(pathStr.c_str(), (SkPathOp) op);
62cb93a386Sopenharmony_ci            }
63cb93a386Sopenharmony_ci            SkString testName;
64cb93a386Sopenharmony_ci            testName.printf("thread_cubics%d", ++gCubicsTestNo);
65cb93a386Sopenharmony_ci            if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
66cb93a386Sopenharmony_ci                if (state.fReporter->verbose()) {
67cb93a386Sopenharmony_ci                    ++loopNo;
68cb93a386Sopenharmony_ci                    goto skipToNext;
69cb93a386Sopenharmony_ci                }
70cb93a386Sopenharmony_ci            }
71cb93a386Sopenharmony_ci            if (PathOpsDebug::gCheckForDuplicateNames) return;
72cb93a386Sopenharmony_ci        }
73cb93a386Sopenharmony_ci    }
74cb93a386Sopenharmony_ci                    }
75cb93a386Sopenharmony_ciskipToNext: ;
76cb93a386Sopenharmony_ci                }
77cb93a386Sopenharmony_ci            }
78cb93a386Sopenharmony_ci        }
79cb93a386Sopenharmony_ci    }
80cb93a386Sopenharmony_ci}
81cb93a386Sopenharmony_ci
82cb93a386Sopenharmony_ciDEF_TEST(PathOpsOpCubicsThreaded, reporter) {
83cb93a386Sopenharmony_ci    initializeTests(reporter, "cubicOp");
84cb93a386Sopenharmony_ci    PathOpsThreadedTestRunner testRunner(reporter);
85cb93a386Sopenharmony_ci    for (int a = 0; a < 6; ++a) {  // outermost
86cb93a386Sopenharmony_ci        for (int b = a + 1; b < 7; ++b) {
87cb93a386Sopenharmony_ci            for (int c = 0 ; c < 6; ++c) {
88cb93a386Sopenharmony_ci                for (int d = c + 1; d < 7; ++d) {
89cb93a386Sopenharmony_ci                    *testRunner.fRunnables.append() =
90cb93a386Sopenharmony_ci                            new PathOpsThreadedRunnable(&testOpCubicsMain, a, b, c, d, &testRunner);
91cb93a386Sopenharmony_ci                }
92cb93a386Sopenharmony_ci            }
93cb93a386Sopenharmony_ci            if (!reporter->allowExtendedTest()) goto finish;
94cb93a386Sopenharmony_ci        }
95cb93a386Sopenharmony_ci    }
96cb93a386Sopenharmony_cifinish:
97cb93a386Sopenharmony_ci    testRunner.render();
98cb93a386Sopenharmony_ci}
99