OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/android/vr_shell/animation.h" | 8 #include "chrome/browser/android/vr_shell/animation.h" |
9 #include "chrome/browser/android/vr_shell/easing.h" | 9 #include "chrome/browser/android/vr_shell/easing.h" |
10 #include "chrome/browser/android/vr_shell/ui_elements.h" | 10 #include "chrome/browser/android/vr_shell/ui_elements.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 break; | 89 break; |
90 case Animation::Property::SCALE: | 90 case Animation::Property::SCALE: |
91 ParseFloats(dict, {"x", "y", "z"}, vec); | 91 ParseFloats(dict, {"x", "y", "z"}, vec); |
92 break; | 92 break; |
93 case Animation::Property::ROTATION: | 93 case Animation::Property::ROTATION: |
94 ParseFloats(dict, {"x", "y", "z", "a"}, vec); | 94 ParseFloats(dict, {"x", "y", "z", "a"}, vec); |
95 break; | 95 break; |
96 case Animation::Property::TRANSLATION: | 96 case Animation::Property::TRANSLATION: |
97 ParseFloats(dict, {"x", "y", "z"}, vec); | 97 ParseFloats(dict, {"x", "y", "z"}, vec); |
98 break; | 98 break; |
| 99 case Animation::Property::OPACITY: |
| 100 ParseFloats(dict, {"x"}, vec); |
| 101 break; |
99 } | 102 } |
100 } | 103 } |
101 | 104 |
102 std::unique_ptr<easing::Easing> ParseEasing( | 105 std::unique_ptr<easing::Easing> ParseEasing( |
103 const base::DictionaryValue& dict) { | 106 const base::DictionaryValue& dict) { |
104 easing::EasingType easingType; | 107 easing::EasingType easingType; |
105 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); | 108 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); |
106 std::unique_ptr<easing::Easing> result; | 109 std::unique_ptr<easing::Easing> result; |
107 | 110 |
108 switch (easingType) { | 111 switch (easingType) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 320 } |
318 | 321 |
319 void UiScene::UpdateTransforms(float screen_tilt, int64_t time_in_micro) { | 322 void UiScene::UpdateTransforms(float screen_tilt, int64_t time_in_micro) { |
320 // Process all animations before calculating object transforms. | 323 // Process all animations before calculating object transforms. |
321 for (auto& element : ui_elements_) { | 324 for (auto& element : ui_elements_) { |
322 element->Animate(time_in_micro); | 325 element->Animate(time_in_micro); |
323 } | 326 } |
324 for (auto& element : ui_elements_) { | 327 for (auto& element : ui_elements_) { |
325 element->transform.MakeIdentity(); | 328 element->transform.MakeIdentity(); |
326 element->transform.Scale(element->size.x, element->size.y, element->size.z); | 329 element->transform.Scale(element->size.x, element->size.y, element->size.z); |
327 ApplyRecursiveTransforms(*element.get(), &element->transform); | 330 element->computed_opacity = 1.0f; |
| 331 ApplyRecursiveTransforms(*element.get(), &element->transform, |
| 332 &element->computed_opacity); |
328 element->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); | 333 element->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); |
329 } | 334 } |
330 } | 335 } |
331 | 336 |
332 ContentRectangle* UiScene::GetUiElementById(int element_id) { | 337 ContentRectangle* UiScene::GetUiElementById(int element_id) { |
333 for (auto& element : ui_elements_) { | 338 for (auto& element : ui_elements_) { |
334 if (element->id == element_id) { | 339 if (element->id == element_id) { |
335 return element.get(); | 340 return element.get(); |
336 } | 341 } |
337 } | 342 } |
338 return nullptr; | 343 return nullptr; |
339 } | 344 } |
340 | 345 |
341 ContentRectangle* UiScene::GetContentQuad() { | 346 ContentRectangle* UiScene::GetContentQuad() { |
342 return content_element_; | 347 return content_element_; |
343 } | 348 } |
344 | 349 |
345 const std::vector<std::unique_ptr<ContentRectangle>>& | 350 const std::vector<std::unique_ptr<ContentRectangle>>& |
346 UiScene::GetUiElements() const { | 351 UiScene::GetUiElements() const { |
347 return ui_elements_; | 352 return ui_elements_; |
348 } | 353 } |
349 | 354 |
350 UiScene::UiScene() = default; | 355 UiScene::UiScene() = default; |
351 | 356 |
352 UiScene::~UiScene() = default; | 357 UiScene::~UiScene() = default; |
353 | 358 |
354 void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element, | 359 void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element, |
355 ReversibleTransform* transform) { | 360 ReversibleTransform* transform, |
| 361 float* opacity) { |
356 transform->Scale(element.scale.x, element.scale.y, element.scale.z); | 362 transform->Scale(element.scale.x, element.scale.y, element.scale.z); |
357 transform->Rotate(element.rotation.x, element.rotation.y, | 363 transform->Rotate(element.rotation.x, element.rotation.y, |
358 element.rotation.z, element.rotation.angle); | 364 element.rotation.z, element.rotation.angle); |
359 transform->Translate(element.translation.x, element.translation.y, | 365 transform->Translate(element.translation.x, element.translation.y, |
360 element.translation.z); | 366 element.translation.z); |
| 367 *opacity *= element.opacity; |
361 | 368 |
362 if (element.parent_id >= 0) { | 369 if (element.parent_id >= 0) { |
363 const ContentRectangle* parent = GetUiElementById(element.parent_id); | 370 const ContentRectangle* parent = GetUiElementById(element.parent_id); |
364 CHECK(parent != nullptr); | 371 CHECK(parent != nullptr); |
365 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, | 372 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, |
366 transform); | 373 transform); |
367 ApplyRecursiveTransforms(*parent, transform); | 374 ApplyRecursiveTransforms(*parent, transform, opacity); |
368 } | 375 } |
369 } | 376 } |
370 | 377 |
371 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, | 378 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, |
372 ContentRectangle *element) { | 379 ContentRectangle *element) { |
373 int parent_id; | 380 int parent_id; |
374 if (dict.GetInteger("parentId", &parent_id)) { | 381 if (dict.GetInteger("parentId", &parent_id)) { |
375 CHECK_GE(parent_id, 0); | 382 CHECK_GE(parent_id, 0); |
376 CHECK_NE(GetUiElementById(parent_id), nullptr); | 383 CHECK_NE(GetUiElementById(parent_id), nullptr); |
377 element->parent_id = parent_id; | 384 element->parent_id = parent_id; |
378 } | 385 } |
379 | 386 |
380 dict.GetBoolean("visible", &element->visible); | 387 dict.GetBoolean("visible", &element->visible); |
381 dict.GetBoolean("hitTestable", &element->hit_testable); | 388 dict.GetBoolean("hitTestable", &element->hit_testable); |
382 dict.GetBoolean("lockToFov", &element->lock_to_fov); | 389 dict.GetBoolean("lockToFov", &element->lock_to_fov); |
383 ParseRecti(dict, "copyRect", &element->copy_rect); | 390 ParseRecti(dict, "copyRect", &element->copy_rect); |
384 Parse2DVec3f(dict, "size", &element->size); | 391 Parse2DVec3f(dict, "size", &element->size); |
385 ParseVec3f(dict, "scale", &element->scale); | 392 ParseVec3f(dict, "scale", &element->scale); |
386 ParseRotationAxisAngle(dict, "rotation", &element->rotation); | 393 ParseRotationAxisAngle(dict, "rotation", &element->rotation); |
387 ParseVec3f(dict, "translation", &element->translation); | 394 ParseVec3f(dict, "translation", &element->translation); |
| 395 double opacity; |
| 396 if (dict.GetDouble("opacity", &opacity)) { |
| 397 element->opacity = opacity; |
| 398 } |
388 | 399 |
389 if (dict.GetBoolean("contentQuad", &element->content_quad)) { | 400 if (dict.GetBoolean("contentQuad", &element->content_quad)) { |
390 if (element->content_quad) { | 401 if (element->content_quad) { |
391 CHECK_EQ(content_element_, nullptr); | 402 CHECK_EQ(content_element_, nullptr); |
392 content_element_ = element; | 403 content_element_ = element; |
393 } else { | 404 } else { |
394 if (content_element_ == element) { | 405 if (content_element_ == element) { |
395 content_element_ = nullptr; | 406 content_element_ = nullptr; |
396 } | 407 } |
397 } | 408 } |
398 } | 409 } |
399 | 410 |
400 if (dict.GetInteger("xAnchoring", | 411 if (dict.GetInteger("xAnchoring", |
401 reinterpret_cast<int*>(&element->x_anchoring))) { | 412 reinterpret_cast<int*>(&element->x_anchoring))) { |
402 CHECK_GE(element->parent_id, 0); | 413 CHECK_GE(element->parent_id, 0); |
403 } | 414 } |
404 if (dict.GetInteger("yAnchoring", | 415 if (dict.GetInteger("yAnchoring", |
405 reinterpret_cast<int*>(&element->y_anchoring))) { | 416 reinterpret_cast<int*>(&element->y_anchoring))) { |
406 CHECK_GE(element->parent_id, 0); | 417 CHECK_GE(element->parent_id, 0); |
407 } | 418 } |
408 } | 419 } |
409 | 420 |
410 } // namespace vr_shell | 421 } // namespace vr_shell |
OLD | NEW |