blob: 57615727f8a03fb0af65fa3321eb772448e73d8d [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 */
7#include "PathOpsExtendedTest.h"
caryclark@google.com66089e42013-04-10 15:55:37 +00008#include "PathOpsThreadedCommon.h"
caryclark8f186432016-10-06 11:46:25 -07009#include "SkString.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +000010
11// four rects, of four sizes
12// for 3 smaller sizes, tall, wide
13 // top upper mid lower bottom aligned (3 bits, 5 values)
14 // same with x (3 bits, 5 values)
15// not included, square, tall, wide (2 bits)
16// cw or ccw (1 bit)
17
caryclark8f186432016-10-06 11:46:25 -070018static int loopNo = 6;
19
caryclark@google.com66089e42013-04-10 15:55:37 +000020static void testPathOpsRectsMain(PathOpsThreadState* data)
caryclark@google.com818b0cc2013-04-08 11:50:46 +000021{
22 SkASSERT(data);
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) {
29 for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
30 for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
31 SkPath pathA, pathB;
caryclark@google.com66089e42013-04-10 15:55:37 +000032 pathA.setFillType((SkPath::FillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000033 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
34 SkIntToScalar(state.fB), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000035 pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
36 SkIntToScalar(state.fD), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000037 pathA.close();
38 pathB.setFillType((SkPath::FillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000039 pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
40 SkIntToScalar(b), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000041 pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
42 SkIntToScalar(d), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000043 pathB.close();
caryclark54359292015-03-26 07:52:43 -070044 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070045 if (state.fReporter->verbose()) {
46 pathStr.printf(
47 "static void rects%d(skiatest::Reporter* reporter,"
48 "const char* filename) {\n", loopNo);
49 pathStr.appendf(" SkPath path, pathB;");
50 pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n",
51 e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
52 ? "EvenOdd" : "?UNDEFINED");
53 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
54 " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB);
55 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
56 " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD);
57 pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n",
58 f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
59 ? "EvenOdd" : "?UNDEFINED");
60 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
61 " SkPath::kCW_Direction);\n", a, a, b, b);
62 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
63 " SkPath::kCW_Direction);\n", c, c, d, d);
64 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
65 SkPathOpsDebug::OpStr((SkPathOp) op));
66 pathStr.appendf("}\n\n");
67 outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000068 }
caryclark8f186432016-10-06 11:46:25 -070069 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects")) {
70 if (state.fReporter->verbose()) {
71 ++loopNo;
72 goto skipToNext;
73 }
74 }
caryclark@google.com66089e42013-04-10 15:55:37 +000075 }
76 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000077 }
caryclark8f186432016-10-06 11:46:25 -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(PathOpsRectsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070086 initializeTests(reporter, "testOp");
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() = new PathOpsThreadedRunnable(
93 &testPathOpsRectsMain, 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}