| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 case Command::CONFIGURE_SCENE: | 321 case Command::CONFIGURE_SCENE: |
| 322 ParseColorf(*data, "backgroundColor", &background_color_); | 322 ParseColorf(*data, "backgroundColor", &background_color_); |
| 323 ParseFloat(*data, "backgroundDistance", &background_distance_); | 323 ParseFloat(*data, "backgroundDistance", &background_distance_); |
| 324 data->GetBoolean("drawWebVr", &webvr_rendering_enabled_); | 324 data->GetBoolean("drawWebVr", &webvr_rendering_enabled_); |
| 325 break; | 325 break; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 void UiScene::UpdateTransforms(int64_t time_in_micro) { | 330 void UiScene::UpdateTransforms(int64_t time_in_micro) { |
| 331 // Process all animations before calculating object transforms. | |
| 332 for (auto& element : ui_elements_) { | 331 for (auto& element : ui_elements_) { |
| 332 // Process all animations before calculating object transforms. |
| 333 element->Animate(time_in_micro); | 333 element->Animate(time_in_micro); |
| 334 element->dirty = true; |
| 334 } | 335 } |
| 335 for (auto& element : ui_elements_) { | 336 for (auto& element : ui_elements_) { |
| 336 Transform transform; | 337 ApplyRecursiveTransforms(element.get()); |
| 337 transform.MakeIdentity(); | |
| 338 transform.Scale(element->size.x, element->size.y, element->size.z); | |
| 339 element->computed_opacity = 1.0f; | |
| 340 element->computed_lock_to_fov = false; | |
| 341 ApplyRecursiveTransforms(*element.get(), &transform, | |
| 342 &element->computed_opacity, | |
| 343 &element->computed_lock_to_fov); | |
| 344 element->SetTransform(transform); | |
| 345 } | 338 } |
| 346 } | 339 } |
| 347 | 340 |
| 348 ContentRectangle* UiScene::GetUiElementById(int element_id) { | 341 ContentRectangle* UiScene::GetUiElementById(int element_id) { |
| 349 for (auto& element : ui_elements_) { | 342 for (auto& element : ui_elements_) { |
| 350 if (element->id == element_id) { | 343 if (element->id == element_id) { |
| 351 return element.get(); | 344 return element.get(); |
| 352 } | 345 } |
| 353 } | 346 } |
| 354 return nullptr; | 347 return nullptr; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 385 |
| 393 const std::vector<std::unique_ptr<ContentRectangle>>& UiScene::GetUiElements() | 386 const std::vector<std::unique_ptr<ContentRectangle>>& UiScene::GetUiElements() |
| 394 const { | 387 const { |
| 395 return ui_elements_; | 388 return ui_elements_; |
| 396 } | 389 } |
| 397 | 390 |
| 398 UiScene::UiScene() = default; | 391 UiScene::UiScene() = default; |
| 399 | 392 |
| 400 UiScene::~UiScene() = default; | 393 UiScene::~UiScene() = default; |
| 401 | 394 |
| 402 void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element, | 395 void UiScene::ApplyRecursiveTransforms(ContentRectangle* element) { |
| 403 Transform* transform, | 396 if (!element->dirty) |
| 404 float* opacity, | 397 return; |
| 405 bool* lock_to_fov) { | |
| 406 transform->Scale(element.scale.x, element.scale.y, element.scale.z); | |
| 407 transform->Rotate(element.rotation.x, element.rotation.y, element.rotation.z, | |
| 408 element.rotation.angle); | |
| 409 transform->Translate(element.translation.x, element.translation.y, | |
| 410 element.translation.z); | |
| 411 *opacity *= element.opacity; | |
| 412 // Head-locked state inherited from a parent element. | |
| 413 *lock_to_fov = element.lock_to_fov; | |
| 414 | 398 |
| 415 if (element.parent_id >= 0) { | 399 ContentRectangle* parent = nullptr; |
| 416 const ContentRectangle* parent = GetUiElementById(element.parent_id); | 400 if (element->parent_id >= 0) { |
| 401 parent = GetUiElementById(element->parent_id); |
| 417 CHECK(parent != nullptr); | 402 CHECK(parent != nullptr); |
| 418 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, | |
| 419 transform); | |
| 420 ApplyRecursiveTransforms(*parent, transform, opacity, lock_to_fov); | |
| 421 } | 403 } |
| 404 |
| 405 Transform* transform = element->GetTransform(); |
| 406 transform->MakeIdentity(); |
| 407 transform->Scale(element->size.x, element->size.y, element->size.z); |
| 408 element->computed_opacity = element->opacity; |
| 409 element->computed_lock_to_fov = element->lock_to_fov; |
| 410 |
| 411 // Compute an inheritable transformation that can be applied to this element, |
| 412 // and it's children, if applicable. |
| 413 Transform* inheritable = &element->inheritable_transform; |
| 414 inheritable->MakeIdentity(); |
| 415 inheritable->Scale(element->scale.x, element->scale.y, element->scale.z); |
| 416 inheritable->Rotate(element->rotation.x, element->rotation.y, |
| 417 element->rotation.z, element->rotation.angle); |
| 418 inheritable->Translate(element->translation.x, element->translation.y, |
| 419 element->translation.z); |
| 420 if (parent) { |
| 421 ApplyAnchoring(*parent, element->x_anchoring, element->y_anchoring, |
| 422 inheritable); |
| 423 ApplyRecursiveTransforms(parent); |
| 424 inheritable->to_world = MatrixMul( |
| 425 parent->inheritable_transform.to_world, inheritable->to_world); |
| 426 |
| 427 element->computed_opacity *= parent->opacity; |
| 428 element->computed_lock_to_fov = parent->lock_to_fov; |
| 429 } |
| 430 |
| 431 transform->to_world = MatrixMul(inheritable->to_world, transform->to_world); |
| 432 element->dirty = false; |
| 422 } | 433 } |
| 423 | 434 |
| 424 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, | 435 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, |
| 425 ContentRectangle* element) { | 436 ContentRectangle* element) { |
| 426 int parent_id; | 437 int parent_id; |
| 427 | 438 |
| 428 if (ParseInt(dict, "parentId", &parent_id)) { | 439 if (ParseInt(dict, "parentId", &parent_id)) { |
| 429 CHECK_GE(parent_id, 0); | 440 CHECK_GE(parent_id, 0); |
| 430 CHECK_NE(GetUiElementById(parent_id), nullptr); | 441 CHECK_NE(GetUiElementById(parent_id), nullptr); |
| 431 element->parent_id = parent_id; | 442 element->parent_id = parent_id; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 content_element_ = element; | 500 content_element_ = element; |
| 490 break; | 501 break; |
| 491 default: | 502 default: |
| 492 element->fill = Fill::NONE; | 503 element->fill = Fill::NONE; |
| 493 break; | 504 break; |
| 494 } | 505 } |
| 495 } | 506 } |
| 496 } | 507 } |
| 497 | 508 |
| 498 } // namespace vr_shell | 509 } // namespace vr_shell |
| OLD | NEW |