OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #include "chrome/browser/android/vr_shell/ui_scene.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene.h" |
6 | 6 |
7 #define _USE_MATH_DEFINES // For M_PI in MSVC. | 7 #define _USE_MATH_DEFINES // For M_PI in MSVC. |
8 #include <cmath> | 8 #include <cmath> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 10, 0}), new_point); | 152 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 10, 0}), new_point); |
153 | 153 |
154 // Check with screen tilt (use 90 degrees for simplicity). | 154 // Check with screen tilt (use 90 degrees for simplicity). |
155 scene.UpdateTransforms(M_PI / 2, 0); | 155 scene.UpdateTransforms(M_PI / 2, 0); |
156 new_origin = MatrixVectorMul(child->transform.to_world, origin); | 156 new_origin = MatrixVectorMul(child->transform.to_world, origin); |
157 new_point = MatrixVectorMul(child->transform.to_world, point); | 157 new_point = MatrixVectorMul(child->transform.to_world, point); |
158 EXPECT_VEC3F_NEAR(gvr::Vec3f({6, 0, 10}), new_origin); | 158 EXPECT_VEC3F_NEAR(gvr::Vec3f({6, 0, 10}), new_origin); |
159 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 0, 10}), new_point); | 159 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 0, 10}), new_point); |
160 } | 160 } |
161 | 161 |
| 162 TEST(UiScene, Opacity) { |
| 163 UiScene scene; |
| 164 std::unique_ptr<ContentRectangle> element; |
| 165 |
| 166 element.reset(new ContentRectangle); |
| 167 element->id = 0; |
| 168 element->opacity = 0.5; |
| 169 scene.AddUiElement(element); |
| 170 |
| 171 element.reset(new ContentRectangle); |
| 172 element->id = 1; |
| 173 element->parent_id = 0; |
| 174 element->opacity = 0.5; |
| 175 scene.AddUiElement(element); |
| 176 |
| 177 scene.UpdateTransforms(0, 0); |
| 178 EXPECT_EQ(scene.GetUiElementById(0)->computed_opacity, 0.5f); |
| 179 EXPECT_EQ(scene.GetUiElementById(1)->computed_opacity, 0.25f); |
| 180 } |
| 181 |
162 typedef struct { | 182 typedef struct { |
163 XAnchoring x_anchoring; | 183 XAnchoring x_anchoring; |
164 YAnchoring y_anchoring; | 184 YAnchoring y_anchoring; |
165 float expected_x; | 185 float expected_x; |
166 float expected_y; | 186 float expected_y; |
167 } AnchoringTestCase; | 187 } AnchoringTestCase; |
168 | 188 |
169 class AnchoringTest : public ::testing::TestWithParam<AnchoringTestCase> {}; | 189 class AnchoringTest : public ::testing::TestWithParam<AnchoringTestCase> {}; |
170 | 190 |
171 TEST_P(AnchoringTest, VerifyCorrectPosition) { | 191 TEST_P(AnchoringTest, VerifyCorrectPosition) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 addElement(&scene, 11); | 230 addElement(&scene, 11); |
211 | 231 |
212 base::DictionaryValue dict; | 232 base::DictionaryValue dict; |
213 | 233 |
214 dict.SetInteger("id", 10); | 234 dict.SetInteger("id", 10); |
215 dict.SetInteger("parentId", 11); | 235 dict.SetInteger("parentId", 11); |
216 dict.SetBoolean("visible", false); | 236 dict.SetBoolean("visible", false); |
217 dict.SetBoolean("hitTestable", false); | 237 dict.SetBoolean("hitTestable", false); |
218 dict.SetBoolean("lockToFov", true); | 238 dict.SetBoolean("lockToFov", true); |
219 dict.SetBoolean("contentQuad", true); | 239 dict.SetBoolean("contentQuad", true); |
| 240 dict.SetInteger("xAnchoring", XAnchoring::XLEFT); |
| 241 dict.SetInteger("yAnchoring", YAnchoring::YTOP); |
| 242 dict.SetDouble("opacity", 0.357); |
220 | 243 |
221 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue); | 244 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue); |
222 copy_rect->SetInteger("x", 100); | 245 copy_rect->SetInteger("x", 100); |
223 copy_rect->SetInteger("y", 101); | 246 copy_rect->SetInteger("y", 101); |
224 copy_rect->SetInteger("width", 102); | 247 copy_rect->SetInteger("width", 102); |
225 copy_rect->SetInteger("height", 103); | 248 copy_rect->SetInteger("height", 103); |
226 dict.Set("copyRect", std::move(copy_rect)); | 249 dict.Set("copyRect", std::move(copy_rect)); |
227 | 250 |
228 std::unique_ptr<base::DictionaryValue> size(new base::DictionaryValue); | 251 std::unique_ptr<base::DictionaryValue> size(new base::DictionaryValue); |
229 size->SetDouble("x", 200); | 252 size->SetDouble("x", 200); |
(...skipping 12 matching lines...) Expand all Loading... |
242 rotation->SetDouble("z", 402); | 265 rotation->SetDouble("z", 402); |
243 rotation->SetDouble("a", 403); | 266 rotation->SetDouble("a", 403); |
244 dict.Set("rotation", std::move(rotation)); | 267 dict.Set("rotation", std::move(rotation)); |
245 | 268 |
246 std::unique_ptr<base::DictionaryValue> translation(new base::DictionaryValue); | 269 std::unique_ptr<base::DictionaryValue> translation(new base::DictionaryValue); |
247 translation->SetDouble("x", 500); | 270 translation->SetDouble("x", 500); |
248 translation->SetDouble("y", 501); | 271 translation->SetDouble("y", 501); |
249 translation->SetDouble("z", 502); | 272 translation->SetDouble("z", 502); |
250 dict.Set("translation", std::move(translation)); | 273 dict.Set("translation", std::move(translation)); |
251 | 274 |
252 dict.SetInteger("xAnchoring", XAnchoring::XLEFT); | |
253 dict.SetInteger("yAnchoring", YAnchoring::YTOP); | |
254 | |
255 scene.AddUiElementFromDict(dict); | 275 scene.AddUiElementFromDict(dict); |
256 const auto *element = scene.GetUiElementById(10); | 276 const auto *element = scene.GetUiElementById(10); |
257 EXPECT_NE(element, nullptr); | 277 EXPECT_NE(element, nullptr); |
258 | 278 |
259 EXPECT_EQ(element->id, 10); | 279 EXPECT_EQ(element->id, 10); |
260 EXPECT_EQ(element->parent_id, 11); | 280 EXPECT_EQ(element->parent_id, 11); |
261 EXPECT_EQ(element->visible, false); | 281 EXPECT_EQ(element->visible, false); |
262 EXPECT_EQ(element->hit_testable, false); | 282 EXPECT_EQ(element->hit_testable, false); |
263 EXPECT_EQ(element->lock_to_fov, true); | 283 EXPECT_EQ(element->lock_to_fov, true); |
264 EXPECT_EQ(element->content_quad, true); | 284 EXPECT_EQ(element->content_quad, true); |
| 285 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT); |
| 286 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP); |
| 287 EXPECT_FLOAT_EQ(element->opacity, 0.357); |
265 | 288 |
266 EXPECT_EQ(element->copy_rect.x, 100); | 289 EXPECT_EQ(element->copy_rect.x, 100); |
267 EXPECT_EQ(element->copy_rect.y, 101); | 290 EXPECT_EQ(element->copy_rect.y, 101); |
268 EXPECT_EQ(element->copy_rect.width, 102); | 291 EXPECT_EQ(element->copy_rect.width, 102); |
269 EXPECT_EQ(element->copy_rect.height, 103); | 292 EXPECT_EQ(element->copy_rect.height, 103); |
270 | 293 |
271 EXPECT_FLOAT_EQ(element->size.x, 200); | 294 EXPECT_FLOAT_EQ(element->size.x, 200); |
272 EXPECT_FLOAT_EQ(element->size.y, 201); | 295 EXPECT_FLOAT_EQ(element->size.y, 201); |
273 EXPECT_FLOAT_EQ(element->size.z, 1); | 296 EXPECT_FLOAT_EQ(element->size.z, 1); |
274 | 297 |
275 EXPECT_FLOAT_EQ(element->scale.x, 300); | 298 EXPECT_FLOAT_EQ(element->scale.x, 300); |
276 EXPECT_FLOAT_EQ(element->scale.y, 301); | 299 EXPECT_FLOAT_EQ(element->scale.y, 301); |
277 EXPECT_FLOAT_EQ(element->scale.z, 302); | 300 EXPECT_FLOAT_EQ(element->scale.z, 302); |
278 | 301 |
279 EXPECT_FLOAT_EQ(element->rotation.x, 400); | 302 EXPECT_FLOAT_EQ(element->rotation.x, 400); |
280 EXPECT_FLOAT_EQ(element->rotation.y, 401); | 303 EXPECT_FLOAT_EQ(element->rotation.y, 401); |
281 EXPECT_FLOAT_EQ(element->rotation.z, 402); | 304 EXPECT_FLOAT_EQ(element->rotation.z, 402); |
282 EXPECT_FLOAT_EQ(element->rotation.angle, 403); | 305 EXPECT_FLOAT_EQ(element->rotation.angle, 403); |
283 | 306 |
284 EXPECT_FLOAT_EQ(element->translation.x, 500); | 307 EXPECT_FLOAT_EQ(element->translation.x, 500); |
285 EXPECT_FLOAT_EQ(element->translation.y, 501); | 308 EXPECT_FLOAT_EQ(element->translation.y, 501); |
286 EXPECT_FLOAT_EQ(element->translation.z, 502); | 309 EXPECT_FLOAT_EQ(element->translation.z, 502); |
287 | |
288 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT); | |
289 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP); | |
290 } | 310 } |
291 | 311 |
292 TEST(UiScene, AddAnimationFromDictionary) { | 312 TEST(UiScene, AddAnimationFromDictionary) { |
293 UiScene scene; | 313 UiScene scene; |
294 addElement(&scene, 0); | 314 addElement(&scene, 0); |
295 | 315 |
296 base::DictionaryValue dict; | 316 base::DictionaryValue dict; |
297 | 317 |
298 dict.SetInteger("id", 10); | 318 dict.SetInteger("id", 10); |
299 dict.SetInteger("meshId", 0); | 319 dict.SetInteger("meshId", 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 EXPECT_FLOAT_EQ(animation->from[0], 300); | 358 EXPECT_FLOAT_EQ(animation->from[0], 300); |
339 EXPECT_FLOAT_EQ(animation->from[1], 301); | 359 EXPECT_FLOAT_EQ(animation->from[1], 301); |
340 EXPECT_FLOAT_EQ(animation->from[2], 302); | 360 EXPECT_FLOAT_EQ(animation->from[2], 302); |
341 EXPECT_FLOAT_EQ(animation->from[3], 303); | 361 EXPECT_FLOAT_EQ(animation->from[3], 303); |
342 | 362 |
343 EXPECT_EQ(animation->start, 22345000); | 363 EXPECT_EQ(animation->start, 22345000); |
344 EXPECT_EQ(animation->duration, 54321000); | 364 EXPECT_EQ(animation->duration, 54321000); |
345 } | 365 } |
346 | 366 |
347 } // namespace vr_shell | 367 } // namespace vr_shell |
OLD | NEW |