blob: 384d1b0cce447e246bf8ecc44c654fb78f27b61e [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
caryclark@google.com66089e42013-04-10 15:55:37 +000018static void testSimplify4x4RectsMain(PathOpsThreadState* data)
caryclark@google.com818b0cc2013-04-08 11:50:46 +000019{
20 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000021 PathOpsThreadState& state = *data;
caryclark@google.com66089e42013-04-10 15:55:37 +000022 int aShape = state.fA & 0x03;
23 SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
24 int bShape = state.fB & 0x03;
25 SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
26 int cShape = state.fC & 0x03;
27 SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
28 int dShape = state.fD & 0x03;
29 SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
30 for (int aXAlign = 0; aXAlign < 5; ++aXAlign) {
31 for (int aYAlign = 0; aYAlign < 5; ++aYAlign) {
32 for (int bXAlign = 0; bXAlign < 5; ++bXAlign) {
33 for (int bYAlign = 0; bYAlign < 5; ++bYAlign) {
34 for (int cXAlign = 0; cXAlign < 5; ++cXAlign) {
35 for (int cYAlign = 0; cYAlign < 5; ++cYAlign) {
36 for (int dXAlign = 0; dXAlign < 5; ++dXAlign) {
37 for (int dYAlign = 0; dYAlign < 5; ++dYAlign) {
caryclark8f186432016-10-06 11:46:25 -070038 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000039 SkPath path, out;
caryclark@google.com66089e42013-04-10 15:55:37 +000040 path.setFillType(SkPath::kWinding_FillType);
robertphillips73add932016-04-07 09:01:20 -070041 int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING,
42 r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING;
caryclark@google.com66089e42013-04-10 15:55:37 +000043 if (aShape) {
44 switch (aShape) {
45 case 1: // square
46 l = 0; r = 60;
47 t = 0; b = 60;
48 aXAlign = 5;
49 aYAlign = 5;
50 break;
51 case 2:
52 l = aXAlign * 12;
53 r = l + 30;
54 t = 0; b = 60;
55 aYAlign = 5;
56 break;
57 case 3:
58 l = 0; r = 60;
59 t = aYAlign * 12;
60 b = l + 30;
61 aXAlign = 5;
62 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000063 }
caryclark@google.com66089e42013-04-10 15:55:37 +000064 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
65 aCW);
caryclark8f186432016-10-06 11:46:25 -070066 if (state.fReporter->verbose()) {
67 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
caryclark@google.com8d0a5242013-07-16 16:11:16 +000068 " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : "");
69 }
caryclark@google.com66089e42013-04-10 15:55:37 +000070 } else {
71 aXAlign = 5;
72 aYAlign = 5;
73 }
74 if (bShape) {
75 switch (bShape) {
76 case 1: // square
77 l = bXAlign * 10;
78 r = l + 20;
79 t = bYAlign * 10;
80 b = l + 20;
81 break;
82 case 2:
83 l = bXAlign * 10;
84 r = l + 20;
85 t = 10; b = 40;
86 bYAlign = 5;
87 break;
88 case 3:
89 l = 10; r = 40;
90 t = bYAlign * 10;
91 b = l + 20;
92 bXAlign = 5;
93 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094 }
caryclark@google.com66089e42013-04-10 15:55:37 +000095 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
96 bCW);
caryclark8f186432016-10-06 11:46:25 -070097 if (state.fReporter->verbose()) {
98 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
caryclark@google.com8d0a5242013-07-16 16:11:16 +000099 " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : "");
100 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000101 } else {
102 bXAlign = 5;
103 bYAlign = 5;
104 }
105 if (cShape) {
106 switch (cShape) {
107 case 1: // square
108 l = cXAlign * 6;
109 r = l + 12;
110 t = cYAlign * 6;
111 b = l + 12;
112 break;
113 case 2:
114 l = cXAlign * 6;
115 r = l + 12;
116 t = 20; b = 30;
117 cYAlign = 5;
118 break;
119 case 3:
120 l = 20; r = 30;
121 t = cYAlign * 6;
122 b = l + 20;
123 cXAlign = 5;
124 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000125 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000126 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
127 cCW);
caryclark8f186432016-10-06 11:46:25 -0700128 if (state.fReporter->verbose()) {
129 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000130 " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : "");
131 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000132 } else {
133 cXAlign = 5;
134 cYAlign = 5;
135 }
136 if (dShape) {
137 switch (dShape) {
138 case 1: // square
139 l = dXAlign * 4;
140 r = l + 9;
141 t = dYAlign * 4;
142 b = l + 9;
143 break;
144 case 2:
145 l = dXAlign * 6;
146 r = l + 9;
147 t = 32; b = 36;
148 dYAlign = 5;
149 break;
150 case 3:
151 l = 32; r = 36;
152 t = dYAlign * 6;
153 b = l + 9;
154 dXAlign = 5;
155 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000156 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000157 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
158 dCW);
caryclark8f186432016-10-06 11:46:25 -0700159 if (state.fReporter->verbose()) {
160 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000161 " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : "");
162 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000163 } else {
164 dXAlign = 5;
165 dYAlign = 5;
166 }
167 path.close();
caryclark8f186432016-10-06 11:46:25 -0700168 if (state.fReporter->verbose()) {
Mike Reedff80c2a2017-01-07 11:16:28 -0500169 state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000170 }
caryclark8f186432016-10-06 11:46:25 -0700171 testSimplify(path, false, out, state, pathStr.c_str());
172 if (state.fReporter->verbose()) {
Mike Reedff80c2a2017-01-07 11:16:28 -0500173 state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000174 }
caryclark8f186432016-10-06 11:46:25 -0700175 testSimplify(path, true, out, state, pathStr.c_str());
caryclark@google.com66089e42013-04-10 15:55:37 +0000176 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000177 }
178 }
179 }
180 }
181 }
182 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000183 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000184}
185
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000186DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -0700187 initializeTests(reporter, "testLine");
188 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000189 for (int a = 0; a < 8; ++a) { // outermost
190 for (int b = a ; b < 8; ++b) {
191 for (int c = b ; c < 8; ++c) {
192 for (int d = c; d < 8; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -0700193 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
194 &testSimplify4x4RectsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000195 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000196 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000197 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000198 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000199 }
200finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000201 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000202}