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

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: 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) { 77 TEST(DrawPolygonConstructionTest, DISABLED_BackwardsWoundNormal) {
78 std::vector<gfx::Point3F> vertices; 78 std::vector<gfx::Point3F> vertices;
79 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 79 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
80 vertices.push_back(gfx::Point3F(10.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)); 81 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
83 83
84 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1); 84 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
85 EXPECT_NORMAL(polygon, 0.0f, 0.0f, -1.0f); 85 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
86 } 86 }
87 87
88 TEST(DrawPolygonConstructionTest, ClippedNormal) { 88 TEST(DrawPolygonConstructionTest, ClippedNormal) {
89 std::vector<gfx::Point3F> vertices; 89 std::vector<gfx::Point3F> vertices;
90 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f)); 90 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f));
91 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f)); 91 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f));
92 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 92 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
93 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 93 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
94 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 94 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
95 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 95 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
(...skipping 22 matching lines...) Expand all
118 sin(i * M_PI / 50) + 99.0f, 100.0f)); 118 sin(i * M_PI / 50) + 99.0f, 100.0f));
119 } 119 }
120 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3); 120 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3);
121 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 121 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
122 122
123 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4); 123 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4);
124 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 124 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
125 } 125 }
126 126
127 // A simple rect being transformed. 127 // A simple rect being transformed.
128 TEST(DrawPolygonConstructionTest, DizzyNormal) { 128 TEST(DrawPolygonConstructionTest, SimpleNormal) {
129 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f); 129 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
130 130
131 gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 131 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); 132 DrawPolygon polygon_i(NULL, src, transform_i, 1);
133 133
134 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f); 134 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f);
135 }
136
137 TEST(DrawPolygonConstructionTest, NormalInvertXY) {
138 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
135 139
136 gfx::Transform tranform_a(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 140 gfx::Transform tranform_a(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
Peter Mayo 2016/04/05 21:56:07 sp: tran-s-form
137 DrawPolygon polygon_a(NULL, src, tranform_a, 2); 141 DrawPolygon polygon_a(NULL, src, tranform_a, 2);
142
138 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); 143 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
Peter Mayo 2016/04/05 21:56:07 Wong - swapping Axes should not invert the normal.
144 }
145
146 TEST(DrawPolygonConstructionTest, NormalInvertXZ) {
147 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
139 148
140 gfx::Transform tranform_b(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); 149 gfx::Transform tranform_b(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
141 DrawPolygon polygon_b(NULL, src, tranform_b, 3); 150 DrawPolygon polygon_b(NULL, src, tranform_b, 3);
151
142 EXPECT_NORMAL(polygon_b, -1.0f, 0.0f, 0.0f); 152 EXPECT_NORMAL(polygon_b, -1.0f, 0.0f, 0.0f);
153 }
154
155 TEST(DrawPolygonConstructionTest, NormalRotate90) {
156 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
157
158 gfx::Transform tranform_b(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);
159 DrawPolygon polygon_b(NULL, src, tranform_b, 3);
160
161 EXPECT_NORMAL(polygon_b, 0.0f, 0.0f, 1.0f);
162 }
163
164 TEST(DrawPolygonConstructionTest, NormalInvertYZ) {
165 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
143 166
144 gfx::Transform tranform_c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1); 167 gfx::Transform tranform_c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
145 DrawPolygon polygon_c(NULL, src, tranform_c, 4); 168 DrawPolygon polygon_c(NULL, src, tranform_c, 4);
169
146 EXPECT_NORMAL(polygon_c, 0.0f, -1.0f, 0.0f); 170 EXPECT_NORMAL(polygon_c, 0.0f, -1.0f, 0.0f);
171 }
172
173 TEST(DrawPolygonConstructionTest, DISABLED_InvertXNormal) {
174 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
147 175
148 gfx::Transform tranform_d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 176 gfx::Transform tranform_d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
149 DrawPolygon polygon_d(NULL, src, tranform_d, 5); 177 DrawPolygon polygon_d(NULL, src, tranform_d, 5);
178
179 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
180 }
181
182 TEST(DrawPolygonConstructionTest, DISABLED_InvertYNormal) {
183 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
184
185 gfx::Transform tranform_d(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
186 DrawPolygon polygon_d(NULL, src, tranform_d, 5);
187
188 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
189 }
190
191 TEST(DrawPolygonConstructionTest, DISABLED_InvertZNormal) {
192 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
193
194 gfx::Transform tranform_e(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
195 DrawPolygon polygon_d(NULL, src, tranform_e, 5);
196
150 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f); 197 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f);
151 } 198 }
152 199
153 // Two quads are nearly touching but definitely ordered. Second one should 200 // Two quads are nearly touching but definitely ordered. Second one should
154 // compare in front. 201 // compare in front.
155 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) { 202 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) {
156 std::vector<gfx::Point3F> vertices_a; 203 std::vector<gfx::Point3F> vertices_a;
157 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 204 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)); 205 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)); 206 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 398
352 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here 399 // 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 400 // because some architectures (e.g., Arm64) employ a fused multiply-add
354 // instruction which causes rounding asymmetry and reduces precision. 401 // instruction which causes rounding asymmetry and reduces precision.
355 // http://crbug.com/401117. 402 // http://crbug.com/401117.
356 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); 403 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
357 } 404 }
358 405
359 } // namespace 406 } // namespace
360 } // namespace cc 407 } // 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