blob: d692c4465b37a201d4d4afff30ddd374db44838d [file] [log] [blame]
caryclark@google.com818b0cc2013-04-08 11:50:46 +00001/*
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 */
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>
caryclark@google.com818b0cc2013-04-08 11:50:46 +000013
caryclark08bc8482015-04-24 09:08:57 -070014static int loopNo = 158;
Cary Clark8af4c402018-08-08 23:22:37 -040015static std::atomic<int> gCubicsTestNo{0};
caryclark03b03ca2015-04-23 09:13:37 -070016
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000017static void testOpCubicsMain(PathOpsThreadState* data) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +000018 SkASSERT(data);
Mike Reed7d34dc72019-11-26 12:17:17 -050019 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
caryclark@google.com66089e42013-04-10 15:55:37 +000020 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070021 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000022 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) {
caryclark@google.com66089e42013-04-10 15:55:37 +000028 SkPath pathA, pathB;
Mike Reed7d34dc72019-11-26 12:17:17 -050029 pathA.setFillType((SkPathFillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000030 pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB));
caryclark@google.com66089e42013-04-10 15:55:37 +000031 pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b),
32 SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c));
caryclark@google.com66089e42013-04-10 15:55:37 +000033 pathA.close();
Mike Reed7d34dc72019-11-26 12:17:17 -050034 pathB.setFillType((SkPathFillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000035 pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b));
caryclark@google.com66089e42013-04-10 15:55:37 +000036 pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB),
37 SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC));
caryclark@google.com66089e42013-04-10 15:55:37 +000038 pathB.close();
caryclark54359292015-03-26 07:52:43 -070039 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070040 if (state.fReporter->verbose()) {
41 pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter,"
caryclark03b03ca2015-04-23 09:13:37 -070042 " const char* filename) {\n", loopNo);
caryclark8f186432016-10-06 11:46:25 -070043 pathStr.appendf(" SkPath path, pathB;\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050044 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
45 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
caryclark03b03ca2015-04-23 09:13:37 -070046 ? "EvenOdd" : "?UNDEFINED");
caryclark8f186432016-10-06 11:46:25 -070047 pathStr.appendf(" path.moveTo(%d,%d);\n", state.fA, state.fB);
48 pathStr.appendf(" path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD,
caryclark03b03ca2015-04-23 09:13:37 -070049 b, a, d, c);
caryclark8f186432016-10-06 11:46:25 -070050 pathStr.appendf(" path.close();\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050051 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
52 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
caryclark03b03ca2015-04-23 09:13:37 -070053 ? "EvenOdd" : "?UNDEFINED");
caryclark8f186432016-10-06 11:46:25 -070054 pathStr.appendf(" pathB.moveTo(%d,%d);\n", a, b);
55 pathStr.appendf(" pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d,
caryclark03b03ca2015-04-23 09:13:37 -070056 state.fB, state.fA, state.fD, state.fC);
caryclark8f186432016-10-06 11:46:25 -070057 pathStr.appendf(" pathB.close();\n");
58 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
caryclark03b03ca2015-04-23 09:13:37 -070059 SkPathOpsDebug::OpStr((SkPathOp) op));
caryclark8f186432016-10-06 11:46:25 -070060 pathStr.appendf("}\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050061 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
caryclark03b03ca2015-04-23 09:13:37 -070062 }
Cary Clark4533f3d2018-08-08 09:48:09 -040063 SkString testName;
64 testName.printf("thread_cubics%d", ++gCubicsTestNo);
65 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
caryclark8f186432016-10-06 11:46:25 -070066 if (state.fReporter->verbose()) {
caryclark03b03ca2015-04-23 09:13:37 -070067 ++loopNo;
68 goto skipToNext;
69 }
70 }
Cary Clark4533f3d2018-08-08 09:48:09 -040071 if (PathOpsDebug::gCheckForDuplicateNames) return;
caryclark@google.com66089e42013-04-10 15:55:37 +000072 }
73 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000074 }
caryclark03b03ca2015-04-23 09:13:37 -070075skipToNext: ;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000076 }
77 }
caryclark@google.com66089e42013-04-10 15:55:37 +000078 }
79 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000080}
81
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000082DEF_TEST(PathOpsOpCubicsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070083 initializeTests(reporter, "cubicOp");
84 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000085 for (int a = 0; a < 6; ++a) { // outermost
86 for (int b = a + 1; b < 7; ++b) {
87 for (int c = 0 ; c < 6; ++c) {
88 for (int d = c + 1; d < 7; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -070089 *testRunner.fRunnables.append() =
90 new PathOpsThreadedRunnable(&testOpCubicsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000091 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000092 }
caryclark@google.com66089e42013-04-10 15:55:37 +000093 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000095 }
96finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000097 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000098}