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

Unified Diff: chrome/browser/android/vr_shell/ui_scene.cc

Issue 2777633003: Avoid duplicate math when computing VR scene hierarchy. (Closed)
Patch Set: s/GetTransform()/mutable_transform()/ Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.h ('k') | chrome/browser/android/vr_shell/ui_scene_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/ui_scene.cc
diff --git a/chrome/browser/android/vr_shell/ui_scene.cc b/chrome/browser/android/vr_shell/ui_scene.cc
index eaba9e7346a49480d251651dc7f897d660626daa..34d6a3c383a2b1a7bde354c0bcc60bcb4d228ea4 100644
--- a/chrome/browser/android/vr_shell/ui_scene.cc
+++ b/chrome/browser/android/vr_shell/ui_scene.cc
@@ -328,20 +328,13 @@ void UiScene::HandleCommands(std::unique_ptr<base::ListValue> commands,
}
void UiScene::UpdateTransforms(int64_t time_in_micro) {
- // Process all animations before calculating object transforms.
for (auto& element : ui_elements_) {
+ // Process all animations before calculating object transforms.
element->Animate(time_in_micro);
+ element->dirty = true;
}
for (auto& element : ui_elements_) {
- Transform transform;
- transform.MakeIdentity();
- transform.Scale(element->size.x, element->size.y, element->size.z);
- element->computed_opacity = 1.0f;
- element->computed_lock_to_fov = false;
- ApplyRecursiveTransforms(*element.get(), &transform,
- &element->computed_opacity,
- &element->computed_lock_to_fov);
- element->SetTransform(transform);
+ ApplyRecursiveTransforms(element.get());
}
}
@@ -399,26 +392,44 @@ UiScene::UiScene() = default;
UiScene::~UiScene() = default;
-void UiScene::ApplyRecursiveTransforms(const ContentRectangle& element,
- Transform* transform,
- float* opacity,
- bool* lock_to_fov) {
- transform->Scale(element.scale.x, element.scale.y, element.scale.z);
- transform->Rotate(element.rotation.x, element.rotation.y, element.rotation.z,
- element.rotation.angle);
- transform->Translate(element.translation.x, element.translation.y,
- element.translation.z);
- *opacity *= element.opacity;
- // Head-locked state inherited from a parent element.
- *lock_to_fov = element.lock_to_fov;
-
- if (element.parent_id >= 0) {
- const ContentRectangle* parent = GetUiElementById(element.parent_id);
+void UiScene::ApplyRecursiveTransforms(ContentRectangle* element) {
+ if (!element->dirty)
+ return;
+
+ ContentRectangle* parent = nullptr;
+ if (element->parent_id >= 0) {
+ parent = GetUiElementById(element->parent_id);
CHECK(parent != nullptr);
- ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring,
- transform);
- ApplyRecursiveTransforms(*parent, transform, opacity, lock_to_fov);
}
+
+ Transform* transform = element->mutable_transform();
+ transform->MakeIdentity();
+ transform->Scale(element->size.x, element->size.y, element->size.z);
+ element->computed_opacity = element->opacity;
+ element->computed_lock_to_fov = element->lock_to_fov;
+
+ // Compute an inheritable transformation that can be applied to this element,
+ // and it's children, if applicable.
+ Transform* inheritable = &element->inheritable_transform;
+ inheritable->MakeIdentity();
+ inheritable->Scale(element->scale.x, element->scale.y, element->scale.z);
+ inheritable->Rotate(element->rotation.x, element->rotation.y,
+ element->rotation.z, element->rotation.angle);
+ inheritable->Translate(element->translation.x, element->translation.y,
+ element->translation.z);
+ if (parent) {
+ ApplyAnchoring(*parent, element->x_anchoring, element->y_anchoring,
+ inheritable);
+ ApplyRecursiveTransforms(parent);
+ inheritable->to_world = MatrixMul(parent->inheritable_transform.to_world,
+ inheritable->to_world);
+
+ element->computed_opacity *= parent->opacity;
+ element->computed_lock_to_fov = parent->lock_to_fov;
+ }
+
+ transform->to_world = MatrixMul(inheritable->to_world, transform->to_world);
+ element->dirty = false;
}
void UiScene::ApplyDictToElement(const base::DictionaryValue& dict,
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.h ('k') | chrome/browser/android/vr_shell/ui_scene_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698