blob: 8c4e03c4606847837dd794ad89698688c5c0d273 [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"
caryclark@google.com818b0cc2013-04-08 11:50:46 +00009
10// four rects, of four sizes
11// for 3 smaller sizes, tall, wide
12 // top upper mid lower bottom aligned (3 bits, 5 values)
13 // same with x (3 bits, 5 values)
14// not included, square, tall, wide (2 bits)
15// cw or ccw (1 bit)
16
caryclark@google.com66089e42013-04-10 15:55:37 +000017static void testSimplify4x4RectsMain(PathOpsThreadState* data)
caryclark@google.com818b0cc2013-04-08 11:50:46 +000018{
19 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000020 PathOpsThreadState& state = *data;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000021 char pathStr[1024]; // gdb: set print elements 400
caryclark@google.com8d0a5242013-07-16 16:11:16 +000022 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
23 if (progress) {
24 sk_bzero(pathStr, sizeof(pathStr));
25 }
caryclark@google.com66089e42013-04-10 15:55:37 +000026 int aShape = state.fA & 0x03;
27 SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
28 int bShape = state.fB & 0x03;
29 SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
30 int cShape = state.fC & 0x03;
31 SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
32 int dShape = state.fD & 0x03;
33 SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
34 for (int aXAlign = 0; aXAlign < 5; ++aXAlign) {
35 for (int aYAlign = 0; aYAlign < 5; ++aYAlign) {
36 for (int bXAlign = 0; bXAlign < 5; ++bXAlign) {
37 for (int bYAlign = 0; bYAlign < 5; ++bYAlign) {
38 for (int cXAlign = 0; cXAlign < 5; ++cXAlign) {
39 for (int cYAlign = 0; cYAlign < 5; ++cYAlign) {
40 for (int dXAlign = 0; dXAlign < 5; ++dXAlign) {
41 for (int dYAlign = 0; dYAlign < 5; ++dYAlign) {
42 SkPath path, out;
43 char* str = pathStr;
44 path.setFillType(SkPath::kWinding_FillType);
45 int l, t, r, b;
46 if (aShape) {
47 switch (aShape) {
48 case 1: // square
49 l = 0; r = 60;
50 t = 0; b = 60;
51 aXAlign = 5;
52 aYAlign = 5;
53 break;
54 case 2:
55 l = aXAlign * 12;
56 r = l + 30;
57 t = 0; b = 60;
58 aYAlign = 5;
59 break;
60 case 3:
61 l = 0; r = 60;
62 t = aYAlign * 12;
63 b = l + 30;
64 aXAlign = 5;
65 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000066 }
caryclark@google.com66089e42013-04-10 15:55:37 +000067 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
68 aCW);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000069 if (progress) {
70 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
71 " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : "");
72 }
caryclark@google.com66089e42013-04-10 15:55:37 +000073 } else {
74 aXAlign = 5;
75 aYAlign = 5;
76 }
77 if (bShape) {
78 switch (bShape) {
79 case 1: // square
80 l = bXAlign * 10;
81 r = l + 20;
82 t = bYAlign * 10;
83 b = l + 20;
84 break;
85 case 2:
86 l = bXAlign * 10;
87 r = l + 20;
88 t = 10; b = 40;
89 bYAlign = 5;
90 break;
91 case 3:
92 l = 10; r = 40;
93 t = bYAlign * 10;
94 b = l + 20;
95 bXAlign = 5;
96 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000097 }
caryclark@google.com66089e42013-04-10 15:55:37 +000098 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
99 bCW);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000100 if (progress) {
101 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
102 " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : "");
103 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000104 } else {
105 bXAlign = 5;
106 bYAlign = 5;
107 }
108 if (cShape) {
109 switch (cShape) {
110 case 1: // square
111 l = cXAlign * 6;
112 r = l + 12;
113 t = cYAlign * 6;
114 b = l + 12;
115 break;
116 case 2:
117 l = cXAlign * 6;
118 r = l + 12;
119 t = 20; b = 30;
120 cYAlign = 5;
121 break;
122 case 3:
123 l = 20; r = 30;
124 t = cYAlign * 6;
125 b = l + 20;
126 cXAlign = 5;
127 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000128 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000129 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
130 cCW);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000131 if (progress) {
132 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
133 " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : "");
134 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000135 } else {
136 cXAlign = 5;
137 cYAlign = 5;
138 }
139 if (dShape) {
140 switch (dShape) {
141 case 1: // square
142 l = dXAlign * 4;
143 r = l + 9;
144 t = dYAlign * 4;
145 b = l + 9;
146 break;
147 case 2:
148 l = dXAlign * 6;
149 r = l + 9;
150 t = 32; b = 36;
151 dYAlign = 5;
152 break;
153 case 3:
154 l = 32; r = 36;
155 t = dYAlign * 6;
156 b = l + 9;
157 dXAlign = 5;
158 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000159 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000160 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b),
161 dCW);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000162 if (progress) {
163 str += sprintf(str, " path.addRect(%d, %d, %d, %d,"
164 " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : "");
165 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000166 } else {
167 dXAlign = 5;
168 dYAlign = 5;
169 }
170 path.close();
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000171 if (progress) {
172 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
173 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000174 testSimplify(path, false, out, state, pathStr);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000175 if (progress) {
176 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
177 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000178 testSimplify(path, true, out, state, pathStr);
179 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000180 }
181 }
182 }
183 }
184 }
185 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000186 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000187}
188
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000189DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -0700190 initializeTests(reporter, "testLine");
191 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000192 for (int a = 0; a < 8; ++a) { // outermost
193 for (int b = a ; b < 8; ++b) {
194 for (int c = b ; c < 8; ++c) {
195 for (int d = c; d < 8; ++d) {
halcanary385fe4d2015-08-26 13:07:48 -0700196 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
197 &testSimplify4x4RectsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000198 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000199 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000200 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000201 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000202 }
203finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000204 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000205}