blob: e4534837200c3c209f09a9d55d27a40f55708c5e [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.comfa2aeee2013-07-15 13:29:13 +000018#if DEBUG_SHOW_TEST_NAME
19 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
20#endif
caryclark@google.com818b0cc2013-04-08 11:50:46 +000021 SkASSERT(data);
Mike Reed7d34dc72019-11-26 12:17:17 -050022 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
caryclark@google.com66089e42013-04-10 15:55:37 +000023 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070024 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000025 for (int a = 0 ; a < 6; ++a) {
26 for (int b = a + 1 ; b < 7; ++b) {
27 for (int c = 0 ; c < 6; ++c) {
28 for (int d = c + 1 ; d < 7; ++d) {
Mike Reed7d34dc72019-11-26 12:17:17 -050029 for (auto e : fts) {
30 for (auto f : fts) {
caryclark@google.com66089e42013-04-10 15:55:37 +000031 SkPath pathA, pathB;
Mike Reed7d34dc72019-11-26 12:17:17 -050032 pathA.setFillType((SkPathFillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000033 pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB));
caryclark@google.com66089e42013-04-10 15:55:37 +000034 pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b),
35 SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c));
caryclark@google.com66089e42013-04-10 15:55:37 +000036 pathA.close();
Mike Reed7d34dc72019-11-26 12:17:17 -050037 pathB.setFillType((SkPathFillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000038 pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b));
caryclark@google.com66089e42013-04-10 15:55:37 +000039 pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB),
40 SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC));
caryclark@google.com66089e42013-04-10 15:55:37 +000041 pathB.close();
caryclark54359292015-03-26 07:52:43 -070042 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070043 if (state.fReporter->verbose()) {
44 pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter,"
caryclark03b03ca2015-04-23 09:13:37 -070045 " const char* filename) {\n", loopNo);
caryclark8f186432016-10-06 11:46:25 -070046 pathStr.appendf(" SkPath path, pathB;\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050047 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
48 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
caryclark03b03ca2015-04-23 09:13:37 -070049 ? "EvenOdd" : "?UNDEFINED");
caryclark8f186432016-10-06 11:46:25 -070050 pathStr.appendf(" path.moveTo(%d,%d);\n", state.fA, state.fB);
51 pathStr.appendf(" path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD,
caryclark03b03ca2015-04-23 09:13:37 -070052 b, a, d, c);
caryclark8f186432016-10-06 11:46:25 -070053 pathStr.appendf(" path.close();\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050054 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
55 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
caryclark03b03ca2015-04-23 09:13:37 -070056 ? "EvenOdd" : "?UNDEFINED");
caryclark8f186432016-10-06 11:46:25 -070057 pathStr.appendf(" pathB.moveTo(%d,%d);\n", a, b);
58 pathStr.appendf(" pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d,
caryclark03b03ca2015-04-23 09:13:37 -070059 state.fB, state.fA, state.fD, state.fC);
caryclark8f186432016-10-06 11:46:25 -070060 pathStr.appendf(" pathB.close();\n");
61 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
caryclark03b03ca2015-04-23 09:13:37 -070062 SkPathOpsDebug::OpStr((SkPathOp) op));
caryclark8f186432016-10-06 11:46:25 -070063 pathStr.appendf("}\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050064 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
caryclark03b03ca2015-04-23 09:13:37 -070065 }
Cary Clark4533f3d2018-08-08 09:48:09 -040066 SkString testName;
67 testName.printf("thread_cubics%d", ++gCubicsTestNo);
68 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
caryclark8f186432016-10-06 11:46:25 -070069 if (state.fReporter->verbose()) {
caryclark03b03ca2015-04-23 09:13:37 -070070 ++loopNo;
71 goto skipToNext;
72 }
73 }
Cary Clark4533f3d2018-08-08 09:48:09 -040074 if (PathOpsDebug::gCheckForDuplicateNames) return;
caryclark@google.com66089e42013-04-10 15:55:37 +000075 }
76 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000077 }
caryclark03b03ca2015-04-23 09:13:37 -070078skipToNext: ;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000079 }
80 }
caryclark@google.com66089e42013-04-10 15:55:37 +000081 }
82 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000083}
84
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000085DEF_TEST(PathOpsOpCubicsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070086 initializeTests(reporter, "cubicOp");
87 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000088 for (int a = 0; a < 6; ++a) { // outermost
89 for (int b = a + 1; b < 7; ++b) {
90 for (int c = 0 ; c < 6; ++c) {
91 for (int d = c + 1; d < 7; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -070092 *testRunner.fRunnables.append() =
93 new PathOpsThreadedRunnable(&testOpCubicsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000095 }
caryclark@google.com66089e42013-04-10 15:55:37 +000096 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000097 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000098 }
99finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000100 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000101}