Chromium Code Reviews| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 result = base::MakeUnique<easing::EaseInOut>(pow); | 136 result = base::MakeUnique<easing::EaseInOut>(pow); |
| 137 break; | 137 break; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 return result; | 140 return result; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ApplyAnchoring(const ContentRectangle& parent, | 143 void ApplyAnchoring(const ContentRectangle& parent, |
| 144 XAnchoring x_anchoring, | 144 XAnchoring x_anchoring, |
| 145 YAnchoring y_anchoring, | 145 YAnchoring y_anchoring, |
| 146 ReversibleTransform* transform) { | 146 Transform* transform) { |
| 147 // To anchor a child, use the parent's size to find its edge. | 147 // To anchor a child, use the parent's size to find its edge. |
| 148 float x_offset; | 148 float x_offset; |
| 149 switch (x_anchoring) { | 149 switch (x_anchoring) { |
| 150 case XLEFT: | 150 case XLEFT: |
| 151 x_offset = -0.5f * parent.size.x; | 151 x_offset = -0.5f * parent.size.x; |
| 152 break; | 152 break; |
| 153 case XRIGHT: | 153 case XRIGHT: |
| 154 x_offset = 0.5f * parent.size.x; | 154 x_offset = 0.5f * parent.size.x; |
| 155 break; | 155 break; |
| 156 case XNONE: | 156 case XNONE: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 RemoveAnimation(element_id, animation_id); | 323 RemoveAnimation(element_id, animation_id); |
| 324 break; | 324 break; |
| 325 } | 325 } |
| 326 case Command::UPDATE_BACKGROUND: | 326 case Command::UPDATE_BACKGROUND: |
| 327 UpdateBackgroundFromDict(*data); | 327 UpdateBackgroundFromDict(*data); |
| 328 break; | 328 break; |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 void UiScene::UpdateTransforms(float screen_tilt, int64_t time_in_micro) { | 333 void UiScene::UpdateTransforms(int64_t time_in_micro) { |
| 334 // Process all animations before calculating object transforms. | 334 // Process all animations before calculating object transforms. |
| 335 for (auto& element : ui_elements_) { | 335 for (auto& element : ui_elements_) { |
| 336 element->Animate(time_in_micro); | 336 element->Animate(time_in_micro); |
| 337 } | 337 } |
| 338 for (auto& element : ui_elements_) { | 338 for (auto& element : ui_elements_) { |
| 339 element->transform.MakeIdentity(); | 339 Transform transform; |
| 340 element->transform.Scale(element->size.x, element->size.y, element->size.z); | 340 transform.MakeIdentity(); |
| 341 transform.Scale(element->size.x, element->size.y, element->size.z); | |
| 341 element->computed_opacity = 1.0f; | 342 element->computed_opacity = 1.0f; |
| 342 ApplyRecursiveTransforms(*element.get(), &element->transform, | 343 ApplyRecursiveTransforms(*element.get(), &transform, |
| 343 &element->computed_opacity); | 344 &element->computed_opacity); |
| 344 element->transform.Rotate(1.0f, 0.0f, 0.0f, screen_tilt); | 345 element->SetTransform(transform); |
|
cjgrant
2017/03/03 21:30:34
Whoa, this looks broken, and the unit tests don't
mthiesse
2017/03/06 17:26:07
THAT explains a lot. I thought recentering was doi
cjgrant
2017/03/06 17:43:34
Oops, disregard, this block is fine.
cjgrant
2017/03/06 17:43:34
Since my original comment was not valid, I need to
mthiesse
2017/03/06 17:46:00
We can follow up offline and make sure I'm not cra
| |
| 345 } | 346 } |
| 346 } | 347 } |
| 347 | 348 |
| 348 ContentRectangle* UiScene::GetUiElementById(int element_id) { | 349 ContentRectangle* UiScene::GetUiElementById(int element_id) { |
| 349 for (auto& element : ui_elements_) { | 350 for (auto& element : ui_elements_) { |
| 350 if (element->id == element_id) { | 351 if (element->id == element_id) { |
| 351 return element.get(); | 352 return element.get(); |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 return nullptr; | 355 return nullptr; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 365 const std::vector<std::unique_ptr<ContentRectangle>>& UiScene::GetUiElements() | 366 const std::vector<std::unique_ptr<ContentRectangle>>& UiScene::GetUiElements() |
| 366 const { | 367 const { |
| 367 return ui_elements_; | 368 return ui_elements_; |
| 368 } | 369 } |
| 369 | 370 |
| 370 UiScene::UiScene() = default; | 371 UiScene::UiScene() = default; |
| 371 | 372 |
| 372 UiScene::~UiScene() = default; | 373 UiScene::~UiScene() = default; |
| 373 | 374 |
| 374 void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element, | 375 void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element, |
| 375 ReversibleTransform* transform, | 376 Transform* transform, |
| 376 float* opacity) { | 377 float* opacity) { |
| 377 transform->Scale(element.scale.x, element.scale.y, element.scale.z); | 378 transform->Scale(element.scale.x, element.scale.y, element.scale.z); |
| 378 transform->Rotate(element.rotation.x, element.rotation.y, element.rotation.z, | 379 transform->Rotate(element.rotation.x, element.rotation.y, element.rotation.z, |
| 379 element.rotation.angle); | 380 element.rotation.angle); |
| 380 transform->Translate(element.translation.x, element.translation.y, | 381 transform->Translate(element.translation.x, element.translation.y, |
| 381 element.translation.z); | 382 element.translation.z); |
| 382 *opacity *= element.opacity; | 383 *opacity *= element.opacity; |
| 383 | 384 |
| 384 if (element.parent_id >= 0) { | 385 if (element.parent_id >= 0) { |
| 385 const ContentRectangle* parent = GetUiElementById(element.parent_id); | 386 const ContentRectangle* parent = GetUiElementById(element.parent_id); |
| 386 CHECK(parent != nullptr); | 387 CHECK(parent != nullptr); |
| 387 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, | 388 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, |
| 388 transform); | 389 transform); |
| 390 | |
| 389 ApplyRecursiveTransforms(*parent, transform, opacity); | 391 ApplyRecursiveTransforms(*parent, transform, opacity); |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 | 394 |
| 393 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, | 395 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, |
| 394 ContentRectangle* element) { | 396 ContentRectangle* element) { |
| 395 int parent_id; | 397 int parent_id; |
| 396 | 398 |
| 397 if (ParseInt(dict, "parentId", &parent_id)) { | 399 if (ParseInt(dict, "parentId", &parent_id)) { |
| 398 CHECK_GE(parent_id, 0); | 400 CHECK_GE(parent_id, 0); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 content_element_ = element; | 458 content_element_ = element; |
| 457 break; | 459 break; |
| 458 default: | 460 default: |
| 459 element->fill = Fill::NONE; | 461 element->fill = Fill::NONE; |
| 460 break; | 462 break; |
| 461 } | 463 } |
| 462 } | 464 } |
| 463 } | 465 } |
| 464 | 466 |
| 465 } // namespace vr_shell | 467 } // namespace vr_shell |
| OLD | NEW |