Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: cc/quads/draw_polygon_unittest.cc

Issue 1860823003: Enhance unit tests for normals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a comment for the DISABLED test with a direct bug Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // We would like to use M_PI on windows too. 5 // We would like to use M_PI on windows too.
6 #ifdef _WIN32 6 #ifdef _WIN32
7 #define _USE_MATH_DEFINES 7 #define _USE_MATH_DEFINES
8 #endif 8 #endif
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::vector<gfx::Point3F> vertices; 67 std::vector<gfx::Point3F> vertices;
68 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 68 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
69 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 69 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
70 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 70 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
71 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 71 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
72 72
73 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1); 73 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
74 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f); 74 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
75 } 75 }
76 76
77 TEST(DrawPolygonConstructionTest, InverseNormal) {
78 std::vector<gfx::Point3F> vertices;
79 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
80 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
81 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
83
84 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
85 EXPECT_NORMAL(polygon, 0.0f, 0.0f, -1.0f);
86 }
87
88 TEST(DrawPolygonConstructionTest, ClippedNormal) { 77 TEST(DrawPolygonConstructionTest, ClippedNormal) {
89 std::vector<gfx::Point3F> vertices; 78 std::vector<gfx::Point3F> vertices;
90 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f)); 79 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f));
91 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f)); 80 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f));
92 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 81 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
93 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
94 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 83 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
95 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 84 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
96 85
97 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1); 86 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
(...skipping 20 matching lines...) Expand all
118 sin(i * M_PI / 50) + 99.0f, 100.0f)); 107 sin(i * M_PI / 50) + 99.0f, 100.0f));
119 } 108 }
120 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3); 109 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3);
121 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 110 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
122 111
123 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4); 112 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4);
124 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 113 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
125 } 114 }
126 115
127 // A simple rect being transformed. 116 // A simple rect being transformed.
128 TEST(DrawPolygonConstructionTest, DizzyNormal) { 117 TEST(DrawPolygonConstructionTest, SimpleNormal) {
129 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f); 118 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
130 119
131 gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 120 gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
132 DrawPolygon polygon_i(NULL, src, transform_i, 1); 121 DrawPolygon polygon_i(NULL, src, transform_i, 1);
133 122
134 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f); 123 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f);
124 }
135 125
136 gfx::Transform tranform_a(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 126 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXY) {
137 DrawPolygon polygon_a(NULL, src, tranform_a, 2); 127 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
138 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
139 128
140 gfx::Transform tranform_b(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); 129 gfx::Transform transform(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
141 DrawPolygon polygon_b(NULL, src, tranform_b, 3); 130 DrawPolygon polygon_a(NULL, src, transform, 2);
142 EXPECT_NORMAL(polygon_b, -1.0f, 0.0f, 0.0f);
143 131
144 gfx::Transform tranform_c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1); 132 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, 1.0f);
145 DrawPolygon polygon_c(NULL, src, tranform_c, 4); 133 }
146 EXPECT_NORMAL(polygon_c, 0.0f, -1.0f, 0.0f);
147 134
148 gfx::Transform tranform_d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 135 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXZ) {
149 DrawPolygon polygon_d(NULL, src, tranform_d, 5); 136 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
137
138 gfx::Transform transform(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
139 DrawPolygon polygon_b(NULL, src, transform, 3);
140
141 EXPECT_NORMAL(polygon_b, 1.0f, 0.0f, 0.0f);
142 }
143
144 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertYZ) {
145 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
146
147 gfx::Transform transform(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
148 DrawPolygon polygon_c(NULL, src, transform, 4);
149
150 EXPECT_NORMAL(polygon_c, 0.0f, 1.0f, 0.0f);
151 }
152
153 TEST(DrawPolygonConstructionTest, NormalRotate90) {
154 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
155
156 gfx::Transform transform(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);
157 DrawPolygon polygon_b(NULL, src, transform, 3);
158
159 EXPECT_NORMAL(polygon_b, 0.0f, 0.0f, 1.0f);
160 }
161
162 // Bug https://bugs.chromium.org/p/chromium/issues/detail?id=595820
163 TEST(DrawPolygonConstructionTest, DISABLED_InvertXNormal) {
164 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
165
166 gfx::Transform transform(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
167 DrawPolygon polygon_d(NULL, src, transform, 5);
168
169 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
170 }
171
172 TEST(DrawPolygonConstructionTest, DISABLED_InvertYNormal) {
173 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
174
175 gfx::Transform transform(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
176 DrawPolygon polygon_d(NULL, src, transform, 5);
177
178 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
179 }
180
181 TEST(DrawPolygonConstructionTest, DISABLED_InvertZNormal) {
182 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
183
184 gfx::Transform transform(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
185 DrawPolygon polygon_d(NULL, src, transform, 5);
186
150 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f); 187 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f);
151 } 188 }
152 189
153 // Two quads are nearly touching but definitely ordered. Second one should 190 // Two quads are nearly touching but definitely ordered. Second one should
154 // compare in front. 191 // compare in front.
155 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) { 192 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) {
156 std::vector<gfx::Point3F> vertices_a; 193 std::vector<gfx::Point3F> vertices_a;
157 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 194 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
158 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 195 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
159 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 196 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 236
200 // Two quads are definitely not touching and so no split should occur. 237 // Two quads are definitely not touching and so no split should occur.
201 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) { 238 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) {
202 std::vector<gfx::Point3F> vertices_a; 239 std::vector<gfx::Point3F> vertices_a;
203 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 240 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
204 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 241 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
205 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 242 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
206 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 243 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
207 std::vector<gfx::Point3F> vertices_b; 244 std::vector<gfx::Point3F> vertices_b;
208 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); 245 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
246 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 15.0f));
209 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); 247 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f));
210 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); 248 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f));
211 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
212 249
213 CREATE_NEW_DRAW_POLYGON( 250 CREATE_NEW_DRAW_POLYGON(
214 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); 251 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
215 CREATE_NEW_DRAW_POLYGON( 252 CREATE_NEW_DRAW_POLYGON(
216 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); 253 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
217 254
218 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a)); 255 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a));
219 } 256 }
220 257
221 // One quad is resting against another, but doesn't cross its plane so no split 258 // One quad is resting against another, but doesn't cross its plane so no split
222 // should occur. 259 // should occur.
223 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) { 260 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) {
224 std::vector<gfx::Point3F> vertices_a; 261 std::vector<gfx::Point3F> vertices_a;
225 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 262 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
226 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 263 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
227 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 264 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
228 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 265 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
229 std::vector<gfx::Point3F> vertices_b; 266 std::vector<gfx::Point3F> vertices_b;
230 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); 267 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
268 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -10.0f));
231 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); 269 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f));
232 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); 270 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f));
233 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
234 271
235 CREATE_NEW_DRAW_POLYGON( 272 CREATE_NEW_DRAW_POLYGON(
236 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); 273 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
237 CREATE_NEW_DRAW_POLYGON( 274 CREATE_NEW_DRAW_POLYGON(
238 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); 275 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
239 276
240 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a)); 277 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a));
241 } 278 }
242 279
243 // One quad intersects another and becomes two pieces. 280 // One quad intersects another and becomes two pieces.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 388
352 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here 389 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here
353 // because some architectures (e.g., Arm64) employ a fused multiply-add 390 // because some architectures (e.g., Arm64) employ a fused multiply-add
354 // instruction which causes rounding asymmetry and reduces precision. 391 // instruction which causes rounding asymmetry and reduces precision.
355 // http://crbug.com/401117. 392 // http://crbug.com/401117.
356 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); 393 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
357 } 394 }
358 395
359 } // namespace 396 } // namespace
360 } // namespace cc 397 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698