blob: 0ac492b0666ca51bcbdc3951f17acae4405293d7 [file] [log] [blame]
caryclark1049f122015-04-20 08:31:59 -07001/*
2 * Copyright 2015 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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkString.h"
8#include "tests/PathOpsDebug.h"
9#include "tests/PathOpsExtendedTest.h"
10#include "tests/PathOpsThreadedCommon.h"
Hal Canary8a001442018-09-19 11:31:27 -040011
Cary Clark8af4c402018-08-08 23:22:37 -040012#include <atomic>
caryclark8f186432016-10-06 11:46:25 -070013
14static int loopNo = 4;
Cary Clark8af4c402018-08-08 23:22:37 -040015static std::atomic<int> gCirclesTestNo{0};
caryclark1049f122015-04-20 08:31:59 -070016
17static void testOpCirclesMain(PathOpsThreadState* data) {
18 SkASSERT(data);
Mike Reed7d34dc72019-11-26 12:17:17 -050019 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
caryclark1049f122015-04-20 08:31:59 -070020 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070021 SkString pathStr;
caryclark1049f122015-04-20 08:31:59 -070022 for (int a = 0 ; a < 6; ++a) {
23 for (int b = a + 1 ; b < 7; ++b) {
24 for (int c = 0 ; c < 6; ++c) {
25 for (int d = c + 1 ; d < 7; ++d) {
Mike Reed7d34dc72019-11-26 12:17:17 -050026 for (auto e : fts) {
27 for (auto f : fts) {
caryclark1049f122015-04-20 08:31:59 -070028 SkPath pathA, pathB;
Mike Reed7d34dc72019-11-26 12:17:17 -050029 pathA.setFillType(e);
caryclark1049f122015-04-20 08:31:59 -070030 pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC),
Mike Reed30bc5272019-11-22 18:34:02 +000031 state.fD ? SkPathDirection::kCW : SkPathDirection::kCCW);
Mike Reed7d34dc72019-11-26 12:17:17 -050032 pathB.setFillType(f);
caryclark1049f122015-04-20 08:31:59 -070033 pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c),
Mike Reed30bc5272019-11-22 18:34:02 +000034 d ? SkPathDirection::kCW : SkPathDirection::kCCW);
caryclark1049f122015-04-20 08:31:59 -070035 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070036 if (state.fReporter->verbose()) {
37 pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter,"
38 " const char* filename) {\n", loopNo);
39 pathStr.appendf(" SkPath path, pathB;\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050040 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
41 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
caryclark8f186432016-10-06 11:46:25 -070042 ? "EvenOdd" : "?UNDEFINED");
43 pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB,
Mike Reed30bc5272019-11-22 18:34:02 +000044 state.fC, state.fD ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
Mike Reed7d34dc72019-11-26 12:17:17 -050045 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
46 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
caryclark8f186432016-10-06 11:46:25 -070047 ? "EvenOdd" : "?UNDEFINED");
48 pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b,
Mike Reed30bc5272019-11-22 18:34:02 +000049 c, d ? "SkPathDirection::kCW" : "SkPathDirection::kCCW");
caryclark8f186432016-10-06 11:46:25 -070050 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
51 SkPathOpsDebug::OpStr((SkPathOp) op));
52 pathStr.appendf("}\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050053 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
caryclark1049f122015-04-20 08:31:59 -070054 }
Cary Clark4533f3d2018-08-08 09:48:09 -040055 SkString testName;
56 testName.printf("thread_circles%d", ++gCirclesTestNo);
57 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
caryclark8f186432016-10-06 11:46:25 -070058 if (state.fReporter->verbose()) {
59 ++loopNo;
60 goto skipToNext;
61 }
62 }
Cary Clark4533f3d2018-08-08 09:48:09 -040063 if (PathOpsDebug::gCheckForDuplicateNames) return;
caryclark1049f122015-04-20 08:31:59 -070064 }
65 }
66 }
caryclark8f186432016-10-06 11:46:25 -070067skipToNext: ;
caryclark1049f122015-04-20 08:31:59 -070068 }
69 }
70 }
71 }
72}
73
74DEF_TEST(PathOpsOpCircleThreaded, reporter) {
75 initializeTests(reporter, "circleOp");
76 PathOpsThreadedTestRunner testRunner(reporter);
77 for (int a = 0; a < 6; ++a) { // outermost
78 for (int b = a + 1; b < 7; ++b) {
79 for (int c = 0 ; c < 6; ++c) {
80 for (int d = 0; d < 2; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -070081 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
82 &testOpCirclesMain, a, b, c, d, &testRunner);
caryclark1049f122015-04-20 08:31:59 -070083 }
84 }
85 if (!reporter->allowExtendedTest()) goto finish;
86 }
87 }
88finish:
89 testRunner.render();
caryclark1049f122015-04-20 08:31:59 -070090}