1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 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 = 4;
15cb93a386Sopenharmony_cistatic std::atomic<int> gCirclesTestNo{0};
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cistatic void testOpCirclesMain(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(e);
30cb93a386Sopenharmony_ci        pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC),
31cb93a386Sopenharmony_ci                state.fD ? SkPathDirection::kCW : SkPathDirection::kCCW);
32cb93a386Sopenharmony_ci        pathB.setFillType(f);
33cb93a386Sopenharmony_ci        pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c),
34cb93a386Sopenharmony_ci                d ? SkPathDirection::kCW : SkPathDirection::kCCW);
35cb93a386Sopenharmony_ci        for (int op = 0 ; op <= kXOR_SkPathOp; ++op)    {
36cb93a386Sopenharmony_ci            if (state.fReporter->verbose()) {
37cb93a386Sopenharmony_ci                pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter,"
38cb93a386Sopenharmony_ci                        " const char* filename) {\n", loopNo);
39cb93a386Sopenharmony_ci                pathStr.appendf("    SkPath path, pathB;\n");
40cb93a386Sopenharmony_ci                pathStr.appendf("    path.setFillType(SkPathFillType::k%s);\n",
41cb93a386Sopenharmony_ci                        e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
42cb93a386Sopenharmony_ci                        ? "EvenOdd" : "?UNDEFINED");
43cb93a386Sopenharmony_ci                pathStr.appendf("    path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB,
44cb93a386Sopenharmony_ci                        state.fC, state.fD ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
45cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.setFillType(SkPathFillType::k%s);\n",
46cb93a386Sopenharmony_ci                        f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
47cb93a386Sopenharmony_ci                        ? "EvenOdd" : "?UNDEFINED");
48cb93a386Sopenharmony_ci                pathStr.appendf("    pathB.addCircle(%d, %d, %d, %s);\n", a, b,
49cb93a386Sopenharmony_ci                        c, d ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
50cb93a386Sopenharmony_ci                pathStr.appendf("    testPathOp(reporter, path, pathB, %s, filename);\n",
51cb93a386Sopenharmony_ci                        SkPathOpsDebug::OpStr((SkPathOp) op));
52cb93a386Sopenharmony_ci                pathStr.appendf("}\n");
53cb93a386Sopenharmony_ci                state.outputProgress(pathStr.c_str(), (SkPathOp) op);
54cb93a386Sopenharmony_ci            }
55cb93a386Sopenharmony_ci            SkString testName;
56cb93a386Sopenharmony_ci            testName.printf("thread_circles%d", ++gCirclesTestNo);
57cb93a386Sopenharmony_ci            if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
58cb93a386Sopenharmony_ci                if (state.fReporter->verbose()) {
59cb93a386Sopenharmony_ci                    ++loopNo;
60cb93a386Sopenharmony_ci                    goto skipToNext;
61cb93a386Sopenharmony_ci                }
62cb93a386Sopenharmony_ci            }
63cb93a386Sopenharmony_ci            if (PathOpsDebug::gCheckForDuplicateNames) return;
64cb93a386Sopenharmony_ci        }
65cb93a386Sopenharmony_ci    }
66cb93a386Sopenharmony_ci                    }
67cb93a386Sopenharmony_ciskipToNext: ;
68cb93a386Sopenharmony_ci                }
69cb93a386Sopenharmony_ci            }
70cb93a386Sopenharmony_ci        }
71cb93a386Sopenharmony_ci    }
72cb93a386Sopenharmony_ci}
73cb93a386Sopenharmony_ci
74cb93a386Sopenharmony_ciDEF_TEST(PathOpsOpCircleThreaded, reporter) {
75cb93a386Sopenharmony_ci    initializeTests(reporter, "circleOp");
76cb93a386Sopenharmony_ci    PathOpsThreadedTestRunner testRunner(reporter);
77cb93a386Sopenharmony_ci    for (int a = 0; a < 6; ++a) {  // outermost
78cb93a386Sopenharmony_ci        for (int b = a + 1; b < 7; ++b) {
79cb93a386Sopenharmony_ci            for (int c = 0 ; c < 6; ++c) {
80cb93a386Sopenharmony_ci                for (int d = 0; d < 2; ++d) {
81cb93a386Sopenharmony_ci                    *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
82cb93a386Sopenharmony_ci                            &testOpCirclesMain, a, b, c, d, &testRunner);
83cb93a386Sopenharmony_ci                }
84cb93a386Sopenharmony_ci            }
85cb93a386Sopenharmony_ci            if (!reporter->allowExtendedTest()) goto finish;
86cb93a386Sopenharmony_ci        }
87cb93a386Sopenharmony_ci    }
88cb93a386Sopenharmony_cifinish:
89cb93a386Sopenharmony_ci    testRunner.render();
90cb93a386Sopenharmony_ci}
91