OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "PathOpsExtendedTest.h" | 7 #include "PathOpsExtendedTest.h" |
8 #include "PathOpsThreadedCommon.h" | 8 #include "PathOpsThreadedCommon.h" |
| 9 #include "SkString.h" |
9 | 10 |
10 // four rects, of four sizes | 11 // four rects, of four sizes |
11 // for 3 smaller sizes, tall, wide | 12 // for 3 smaller sizes, tall, wide |
12 // top upper mid lower bottom aligned (3 bits, 5 values) | 13 // top upper mid lower bottom aligned (3 bits, 5 values) |
13 // same with x (3 bits, 5 values) | 14 // same with x (3 bits, 5 values) |
14 // not included, square, tall, wide (2 bits) | 15 // not included, square, tall, wide (2 bits) |
15 // cw or ccw (1 bit) | 16 // cw or ccw (1 bit) |
16 | 17 |
17 static void testSimplify4x4RectsMain(PathOpsThreadState* data) | 18 static void testSimplify4x4RectsMain(PathOpsThreadState* data) |
18 { | 19 { |
19 SkASSERT(data); | 20 SkASSERT(data); |
20 PathOpsThreadState& state = *data; | 21 PathOpsThreadState& state = *data; |
21 char pathStr[1024]; // gdb: set print elements 400 | |
22 bool progress = state.fReporter->verbose(); // FIXME: break out into its own
parameter? | |
23 if (progress) { | |
24 sk_bzero(pathStr, sizeof(pathStr)); | |
25 } | |
26 int aShape = state.fA & 0x03; | 22 int aShape = state.fA & 0x03; |
27 SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; | 23 SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; |
28 int bShape = state.fB & 0x03; | 24 int bShape = state.fB & 0x03; |
29 SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; | 25 SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; |
30 int cShape = state.fC & 0x03; | 26 int cShape = state.fC & 0x03; |
31 SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; | 27 SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; |
32 int dShape = state.fD & 0x03; | 28 int dShape = state.fD & 0x03; |
33 SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; | 29 SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; |
34 for (int aXAlign = 0; aXAlign < 5; ++aXAlign) { | 30 for (int aXAlign = 0; aXAlign < 5; ++aXAlign) { |
35 for (int aYAlign = 0; aYAlign < 5; ++aYAlign) { | 31 for (int aYAlign = 0; aYAlign < 5; ++aYAlign) { |
36 for (int bXAlign = 0; bXAlign < 5; ++bXAlign) { | 32 for (int bXAlign = 0; bXAlign < 5; ++bXAlign) { |
37 for (int bYAlign = 0; bYAlign < 5; ++bYAlign) { | 33 for (int bYAlign = 0; bYAlign < 5; ++bYAlign) { |
38 for (int cXAlign = 0; cXAlign < 5; ++cXAlign) { | 34 for (int cXAlign = 0; cXAlign < 5; ++cXAlign) { |
39 for (int cYAlign = 0; cYAlign < 5; ++cYAlign) { | 35 for (int cYAlign = 0; cYAlign < 5; ++cYAlign) { |
40 for (int dXAlign = 0; dXAlign < 5; ++dXAlign) { | 36 for (int dXAlign = 0; dXAlign < 5; ++dXAlign) { |
41 for (int dYAlign = 0; dYAlign < 5; ++dYAlign) { | 37 for (int dYAlign = 0; dYAlign < 5; ++dYAlign) { |
| 38 SkString pathStr; |
42 SkPath path, out; | 39 SkPath path, out; |
43 char* str = pathStr; | |
44 path.setFillType(SkPath::kWinding_FillType); | 40 path.setFillType(SkPath::kWinding_FillType); |
45 int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING, | 41 int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING, |
46 r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING; | 42 r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING; |
47 if (aShape) { | 43 if (aShape) { |
48 switch (aShape) { | 44 switch (aShape) { |
49 case 1: // square | 45 case 1: // square |
50 l = 0; r = 60; | 46 l = 0; r = 60; |
51 t = 0; b = 60; | 47 t = 0; b = 60; |
52 aXAlign = 5; | 48 aXAlign = 5; |
53 aYAlign = 5; | 49 aYAlign = 5; |
54 break; | 50 break; |
55 case 2: | 51 case 2: |
56 l = aXAlign * 12; | 52 l = aXAlign * 12; |
57 r = l + 30; | 53 r = l + 30; |
58 t = 0; b = 60; | 54 t = 0; b = 60; |
59 aYAlign = 5; | 55 aYAlign = 5; |
60 break; | 56 break; |
61 case 3: | 57 case 3: |
62 l = 0; r = 60; | 58 l = 0; r = 60; |
63 t = aYAlign * 12; | 59 t = aYAlign * 12; |
64 b = l + 30; | 60 b = l + 30; |
65 aXAlign = 5; | 61 aXAlign = 5; |
66 break; | 62 break; |
67 } | 63 } |
68 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), | 64 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), |
69 aCW); | 65 aCW); |
70 if (progress) { | 66 if (state.fReporter->verbose()) { |
71 str += sprintf(str, " path.addRect(%d, %d, %d, %d," | 67 pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
72 " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" :
""); | 68 " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" :
""); |
73 } | 69 } |
74 } else { | 70 } else { |
75 aXAlign = 5; | 71 aXAlign = 5; |
76 aYAlign = 5; | 72 aYAlign = 5; |
77 } | 73 } |
78 if (bShape) { | 74 if (bShape) { |
79 switch (bShape) { | 75 switch (bShape) { |
80 case 1: // square | 76 case 1: // square |
81 l = bXAlign * 10; | 77 l = bXAlign * 10; |
82 r = l + 20; | 78 r = l + 20; |
83 t = bYAlign * 10; | 79 t = bYAlign * 10; |
84 b = l + 20; | 80 b = l + 20; |
85 break; | 81 break; |
86 case 2: | 82 case 2: |
87 l = bXAlign * 10; | 83 l = bXAlign * 10; |
88 r = l + 20; | 84 r = l + 20; |
89 t = 10; b = 40; | 85 t = 10; b = 40; |
90 bYAlign = 5; | 86 bYAlign = 5; |
91 break; | 87 break; |
92 case 3: | 88 case 3: |
93 l = 10; r = 40; | 89 l = 10; r = 40; |
94 t = bYAlign * 10; | 90 t = bYAlign * 10; |
95 b = l + 20; | 91 b = l + 20; |
96 bXAlign = 5; | 92 bXAlign = 5; |
97 break; | 93 break; |
98 } | 94 } |
99 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), | 95 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), |
100 bCW); | 96 bCW); |
101 if (progress) { | 97 if (state.fReporter->verbose()) { |
102 str += sprintf(str, " path.addRect(%d, %d, %d, %d," | 98 pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
103 " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" :
""); | 99 " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" :
""); |
104 } | 100 } |
105 } else { | 101 } else { |
106 bXAlign = 5; | 102 bXAlign = 5; |
107 bYAlign = 5; | 103 bYAlign = 5; |
108 } | 104 } |
109 if (cShape) { | 105 if (cShape) { |
110 switch (cShape) { | 106 switch (cShape) { |
111 case 1: // square | 107 case 1: // square |
112 l = cXAlign * 6; | 108 l = cXAlign * 6; |
113 r = l + 12; | 109 r = l + 12; |
114 t = cYAlign * 6; | 110 t = cYAlign * 6; |
115 b = l + 12; | 111 b = l + 12; |
116 break; | 112 break; |
117 case 2: | 113 case 2: |
118 l = cXAlign * 6; | 114 l = cXAlign * 6; |
119 r = l + 12; | 115 r = l + 12; |
120 t = 20; b = 30; | 116 t = 20; b = 30; |
121 cYAlign = 5; | 117 cYAlign = 5; |
122 break; | 118 break; |
123 case 3: | 119 case 3: |
124 l = 20; r = 30; | 120 l = 20; r = 30; |
125 t = cYAlign * 6; | 121 t = cYAlign * 6; |
126 b = l + 20; | 122 b = l + 20; |
127 cXAlign = 5; | 123 cXAlign = 5; |
128 break; | 124 break; |
129 } | 125 } |
130 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), | 126 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), |
131 cCW); | 127 cCW); |
132 if (progress) { | 128 if (state.fReporter->verbose()) { |
133 str += sprintf(str, " path.addRect(%d, %d, %d, %d," | 129 pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
134 " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" :
""); | 130 " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" :
""); |
135 } | 131 } |
136 } else { | 132 } else { |
137 cXAlign = 5; | 133 cXAlign = 5; |
138 cYAlign = 5; | 134 cYAlign = 5; |
139 } | 135 } |
140 if (dShape) { | 136 if (dShape) { |
141 switch (dShape) { | 137 switch (dShape) { |
142 case 1: // square | 138 case 1: // square |
143 l = dXAlign * 4; | 139 l = dXAlign * 4; |
144 r = l + 9; | 140 r = l + 9; |
145 t = dYAlign * 4; | 141 t = dYAlign * 4; |
146 b = l + 9; | 142 b = l + 9; |
147 break; | 143 break; |
148 case 2: | 144 case 2: |
149 l = dXAlign * 6; | 145 l = dXAlign * 6; |
150 r = l + 9; | 146 r = l + 9; |
151 t = 32; b = 36; | 147 t = 32; b = 36; |
152 dYAlign = 5; | 148 dYAlign = 5; |
153 break; | 149 break; |
154 case 3: | 150 case 3: |
155 l = 32; r = 36; | 151 l = 32; r = 36; |
156 t = dYAlign * 6; | 152 t = dYAlign * 6; |
157 b = l + 9; | 153 b = l + 9; |
158 dXAlign = 5; | 154 dXAlign = 5; |
159 break; | 155 break; |
160 } | 156 } |
161 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), | 157 path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), S
kIntToScalar(b), |
162 dCW); | 158 dCW); |
163 if (progress) { | 159 if (state.fReporter->verbose()) { |
164 str += sprintf(str, " path.addRect(%d, %d, %d, %d," | 160 pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
165 " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" :
""); | 161 " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" :
""); |
166 } | 162 } |
167 } else { | 163 } else { |
168 dXAlign = 5; | 164 dXAlign = 5; |
169 dYAlign = 5; | 165 dYAlign = 5; |
170 } | 166 } |
171 path.close(); | 167 path.close(); |
172 if (progress) { | 168 if (state.fReporter->verbose()) { |
173 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); | 169 outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_Fil
lType); |
174 } | 170 } |
175 testSimplify(path, false, out, state, pathStr); | 171 testSimplify(path, false, out, state, pathStr.c_str()); |
176 if (progress) { | 172 if (state.fReporter->verbose()) { |
177 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); | 173 outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_Fil
lType); |
178 } | 174 } |
179 testSimplify(path, true, out, state, pathStr); | 175 testSimplify(path, true, out, state, pathStr.c_str()); |
180 } | 176 } |
181 } | 177 } |
182 } | 178 } |
183 } | 179 } |
184 } | 180 } |
185 } | 181 } |
186 } | 182 } |
187 } | 183 } |
188 } | 184 } |
189 | 185 |
190 DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) { | 186 DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) { |
191 initializeTests(reporter, "testLine"); | 187 initializeTests(reporter, "testLine"); |
192 PathOpsThreadedTestRunner testRunner(reporter); | 188 PathOpsThreadedTestRunner testRunner(reporter); |
193 for (int a = 0; a < 8; ++a) { // outermost | 189 for (int a = 0; a < 8; ++a) { // outermost |
194 for (int b = a ; b < 8; ++b) { | 190 for (int b = a ; b < 8; ++b) { |
195 for (int c = b ; c < 8; ++c) { | 191 for (int c = b ; c < 8; ++c) { |
196 for (int d = c; d < 8; ++d) { | 192 for (int d = c; d < 8; ++d) { |
197 *testRunner.fRunnables.append() = new PathOpsThreadedRunnabl
e( | 193 *testRunner.fRunnables.append() = new PathOpsThreadedRunnabl
e( |
198 &testSimplify4x4RectsMain, a, b, c, d, &testRunner); | 194 &testSimplify4x4RectsMain, a, b, c, d, &testRunner); |
199 } | 195 } |
200 if (!reporter->allowExtendedTest()) goto finish; | 196 if (!reporter->allowExtendedTest()) goto finish; |
201 } | 197 } |
202 } | 198 } |
203 } | 199 } |
204 finish: | 200 finish: |
205 testRunner.render(); | 201 testRunner.render(); |
206 } | 202 } |
OLD | NEW |