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

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene.cc

Issue 2966793002: NOT FOR REVIEW - convert to cc animation
Patch Set: switch to transform operations Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/android/vr_shell/animation.h" 13 #include "cc/animation/animation_player.h"
14 #include "chrome/browser/android/vr_shell/easing.h"
15 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 14 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
16 15
17 namespace vr_shell { 16 namespace vr_shell {
18 17
19 namespace { 18 namespace {
20 19
21 void ApplyAnchoring(const UiElement& parent, 20 void ApplyAnchoring(const UiElement& parent,
22 XAnchoring x_anchoring, 21 XAnchoring x_anchoring,
23 YAnchoring y_anchoring, 22 YAnchoring y_anchoring,
24 gfx::Transform* transform) { 23 gfx::Transform* transform) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if ((*it)->fill() == Fill::CONTENT) { 71 if ((*it)->fill() == Fill::CONTENT) {
73 content_element_ = nullptr; 72 content_element_ = nullptr;
74 } 73 }
75 ui_elements_.erase(it); 74 ui_elements_.erase(it);
76 return; 75 return;
77 } 76 }
78 } 77 }
79 } 78 }
80 79
81 void UiScene::AddAnimation(int element_id, 80 void UiScene::AddAnimation(int element_id,
82 std::unique_ptr<Animation> animation) { 81 std::unique_ptr<cc::Animation> animation) {
83 UiElement* element = GetUiElementById(element_id); 82 UiElement* element = GetUiElementById(element_id);
84 CHECK_NE(element, nullptr); 83 element->animation_player().AddAnimation(std::move(animation));
85 for (const std::unique_ptr<Animation>& existing : element->animations()) {
86 CHECK_NE(existing->id, animation->id);
87 }
88 element->animations().emplace_back(std::move(animation));
89 } 84 }
90 85
91 void UiScene::RemoveAnimation(int element_id, int animation_id) { 86 void UiScene::RemoveAnimation(int element_id, int animation_id) {
92 UiElement* element = GetUiElementById(element_id); 87 UiElement* element = GetUiElementById(element_id);
93 CHECK_NE(element, nullptr); 88 element->animation_player().RemoveAnimation(animation_id);
94 auto& animations = element->animations();
95 for (auto it = animations.begin(); it != animations.end(); ++it) {
96 const Animation& existing_animation = **it;
97 if (existing_animation.id == animation_id) {
98 animations.erase(it);
99 return;
100 }
101 }
102 } 89 }
103 90
104 void UiScene::OnBeginFrame(const base::TimeTicks& current_time) { 91 void UiScene::OnBeginFrame(const base::TimeTicks& current_time) {
105 for (const auto& element : ui_elements_) { 92 for (const auto& element : ui_elements_) {
106 // Process all animations before calculating object transforms. 93 // Process all animations before calculating object transforms.
107 // TODO: eventually, we'd like to stop assuming that animations are 94 // TODO: eventually, we'd like to stop assuming that animations are
108 // element-level concepts. A single animation may simultaneously update 95 // element-level concepts. A single animation may simultaneously update
109 // properties on multiple elements, say. 96 // properties on multiple elements, say.
110 element->Animate(current_time); 97 element->Animate(current_time);
111 98
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 227 }
241 228
242 gfx::Transform transform; 229 gfx::Transform transform;
243 transform.Scale3d(element->size().x(), element->size().y(), 230 transform.Scale3d(element->size().x(), element->size().y(),
244 element->size().z()); 231 element->size().z());
245 element->set_computed_opacity(element->opacity()); 232 element->set_computed_opacity(element->opacity());
246 element->set_computed_lock_to_fov(element->lock_to_fov()); 233 element->set_computed_lock_to_fov(element->lock_to_fov());
247 234
248 // Compute an inheritable transformation that can be applied to this element, 235 // Compute an inheritable transformation that can be applied to this element,
249 // and it's children, if applicable. 236 // and it's children, if applicable.
250 gfx::Transform inheritable; 237 gfx::Transform inheritable = element->transform_operations().Apply();
251 inheritable.matrix().postScale(element->scale().x(), element->scale().y(), 238
252 element->scale().z());
253 inheritable.ConcatTransform(gfx::Transform(element->rotation()));
254 inheritable.matrix().postTranslate(element->translation().x(),
255 element->translation().y(),
256 element->translation().z());
257 if (parent) { 239 if (parent) {
258 ApplyAnchoring(*parent, element->x_anchoring(), element->y_anchoring(), 240 ApplyAnchoring(*parent, element->x_anchoring(), element->y_anchoring(),
259 &inheritable); 241 &inheritable);
260 ApplyRecursiveTransforms(parent); 242 ApplyRecursiveTransforms(parent);
261 inheritable.ConcatTransform(parent->inheritable_transform()); 243 inheritable.ConcatTransform(parent->inheritable_transform());
262 244
263 element->set_computed_opacity(element->computed_opacity() * 245 element->set_computed_opacity(element->computed_opacity() *
264 parent->opacity()); 246 parent->opacity());
265 element->set_computed_lock_to_fov(parent->lock_to_fov()); 247 element->set_computed_lock_to_fov(parent->lock_to_fov());
266 } 248 }
267 249
268 transform.ConcatTransform(inheritable); 250 // transform.ConcatTransform(inheritable);
269 251 element->set_screen_space_transform(transform * inheritable);
270 element->set_transform(transform);
271 element->set_inheritable_transform(inheritable); 252 element->set_inheritable_transform(inheritable);
272 element->set_dirty(false); 253 element->set_dirty(false);
273 } 254 }
274 255
275 // TODO(mthiesse): Move this to UiSceneManager. 256 // TODO(mthiesse): Move this to UiSceneManager.
276 void UiScene::OnGLInitialized() { 257 void UiScene::OnGLInitialized() {
277 gl_initialized_ = true; 258 gl_initialized_ = true;
278 for (auto& element : ui_elements_) { 259 for (auto& element : ui_elements_) {
279 element->Initialize(); 260 element->Initialize();
280 } 261 }
281 } 262 }
282 263
283 } // namespace vr_shell 264 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.h ('k') | chrome/browser/android/vr_shell/ui_scene_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698