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

Side by Side Diff: ui/compositor/layer.cc

Issue 1533643003: CC Animations: Port UI Browser Compositor to use compositor animation timelines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eventobserver
Patch Set: Rebase. Created 5 years 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
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 scoped_refptr<cc::Layer> root_layer) { 148 scoped_refptr<cc::Layer> root_layer) {
149 // This function must only be called to set the compositor on the root ui 149 // This function must only be called to set the compositor on the root ui
150 // layer. 150 // layer.
151 DCHECK(compositor); 151 DCHECK(compositor);
152 DCHECK(!compositor_); 152 DCHECK(!compositor_);
153 DCHECK(compositor->root_layer() == this); 153 DCHECK(compositor->root_layer() == this);
154 DCHECK(!parent_); 154 DCHECK(!parent_);
155 155
156 compositor_ = compositor; 156 compositor_ = compositor;
157 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); 157 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
159 158
160 root_layer->AddChild(cc_layer_); 159 root_layer->AddChild(cc_layer_);
160 SetCompositorForAnimatorsInTree(compositor);
161 SendPendingThreadedAnimations(); 161 SendPendingThreadedAnimations();
162 } 162 }
163 163
164 void Layer::ResetCompositor() { 164 void Layer::ResetCompositor() {
165 DCHECK(!parent_); 165 DCHECK(!parent_);
166 if (compositor_) 166 if (compositor_) {
167 RemoveAnimatorsInTreeFromCollection( 167 ResetCompositorForAnimatorsInTree(compositor_);
168 compositor_->layer_animator_collection()); 168 compositor_ = nullptr;
169 compositor_ = nullptr; 169 }
170 } 170 }
171 171
172 void Layer::Add(Layer* child) { 172 void Layer::Add(Layer* child) {
173 DCHECK(!child->compositor_); 173 DCHECK(!child->compositor_);
174 if (child->parent_) 174 if (child->parent_)
175 child->parent_->Remove(child); 175 child->parent_->Remove(child);
176 child->parent_ = this; 176 child->parent_ = this;
177 children_.push_back(child); 177 children_.push_back(child);
178 cc_layer_->AddChild(child->cc_layer_); 178 cc_layer_->AddChild(child->cc_layer_);
179 child->OnDeviceScaleFactorChanged(device_scale_factor_); 179 child->OnDeviceScaleFactorChanged(device_scale_factor_);
180 if (GetCompositor()) 180 Compositor* compositor = GetCompositor();
181 if (compositor) {
182 child->SetCompositorForAnimatorsInTree(compositor);
181 child->SendPendingThreadedAnimations(); 183 child->SendPendingThreadedAnimations();
182 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); 184 }
183 if (collection)
184 child->AddAnimatorsInTreeToCollection(collection);
185 } 185 }
186 186
187 void Layer::Remove(Layer* child) { 187 void Layer::Remove(Layer* child) {
188 // Current bounds are used to calculate offsets when layers are reparented. 188 // Current bounds are used to calculate offsets when layers are reparented.
189 // Stop (and complete) an ongoing animation to update the bounds immediately. 189 // Stop (and complete) an ongoing animation to update the bounds immediately.
190 LayerAnimator* child_animator = child->animator_.get(); 190 LayerAnimator* child_animator = child->animator_.get();
191 if (child_animator) 191 if (child_animator)
192 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); 192 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS);
193 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); 193
194 if (collection) 194 Compositor* compositor = GetCompositor();
195 child->RemoveAnimatorsInTreeFromCollection(collection); 195 if (compositor)
196 child->ResetCompositorForAnimatorsInTree(compositor);
196 197
197 std::vector<Layer*>::iterator i = 198 std::vector<Layer*>::iterator i =
198 std::find(children_.begin(), children_.end(), child); 199 std::find(children_.begin(), children_.end(), child);
199 DCHECK(i != children_.end()); 200 DCHECK(i != children_.end());
200 children_.erase(i); 201 children_.erase(i);
201 child->parent_ = NULL; 202 child->parent_ = NULL;
202 child->cc_layer_->RemoveFromParent(); 203 child->cc_layer_->RemoveFromParent();
203 } 204 }
204 205
205 void Layer::StackAtTop(Layer* child) { 206 void Layer::StackAtTop(Layer* child) {
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 std::string name_; 814 std::string name_;
814 }; 815 };
815 816
816 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo( 817 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo(
817 cc::Layer* layer) { 818 cc::Layer* layer) {
818 return new LayerDebugInfo(name_); 819 return new LayerDebugInfo(name_);
819 } 820 }
820 821
821 void Layer::CollectAnimators( 822 void Layer::CollectAnimators(
822 std::vector<scoped_refptr<LayerAnimator>>* animators) { 823 std::vector<scoped_refptr<LayerAnimator>>* animators) {
823 if (IsAnimating()) 824 if (animator_ && animator_->is_animating())
824 animators->push_back(animator_); 825 animators->push_back(animator_);
825 for (auto* child : children_) 826 for (auto* child : children_)
826 child->CollectAnimators(animators); 827 child->CollectAnimators(animators);
827 } 828 }
828 829
829 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { 830 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) {
830 DCHECK_NE(child, other); 831 DCHECK_NE(child, other);
831 DCHECK_EQ(this, child->parent()); 832 DCHECK_EQ(this, child->parent());
832 DCHECK_EQ(this, other->parent()); 833 DCHECK_EQ(this, other->parent());
833 834
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 } 967 }
967 968
968 float Layer::GetDeviceScaleFactor() const { 969 float Layer::GetDeviceScaleFactor() const {
969 return device_scale_factor_; 970 return device_scale_factor_;
970 } 971 }
971 972
972 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { 973 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
973 DCHECK(cc_layer_); 974 DCHECK(cc_layer_);
974 // Until this layer has a compositor (and hence cc_layer_ has a 975 // Until this layer has a compositor (and hence cc_layer_ has a
975 // LayerTreeHost), addAnimation will fail. 976 // LayerTreeHost), addAnimation will fail.
976 if (GetCompositor()) 977 if (GetCompositor()) {
977 cc_layer_->AddAnimation(std::move(animation)); 978 if (UILayerSettings().use_compositor_animation_timelines) {
978 else 979 DCHECK(animator_);
980 animator_->AddThreadedAnimation(std::move(animation));
981 } else {
982 cc_layer_->AddAnimation(std::move(animation));
983 }
984 } else {
979 pending_threaded_animations_.push_back(std::move(animation)); 985 pending_threaded_animations_.push_back(std::move(animation));
986 }
980 } 987 }
981 988
982 void Layer::RemoveThreadedAnimation(int animation_id) { 989 void Layer::RemoveThreadedAnimation(int animation_id) {
983 DCHECK(cc_layer_); 990 DCHECK(cc_layer_);
984 if (pending_threaded_animations_.size() == 0) { 991 if (pending_threaded_animations_.size() == 0) {
985 cc_layer_->RemoveAnimation(animation_id); 992 if (UILayerSettings().use_compositor_animation_timelines) {
993 DCHECK(animator_);
994 animator_->RemoveThreadedAnimation(animation_id);
995 } else {
996 cc_layer_->RemoveAnimation(animation_id);
997 }
986 return; 998 return;
987 } 999 }
988 1000
989 pending_threaded_animations_.erase( 1001 pending_threaded_animations_.erase(
990 std::remove_if( 1002 std::remove_if(
991 pending_threaded_animations_.begin(), 1003 pending_threaded_animations_.begin(),
992 pending_threaded_animations_.end(), 1004 pending_threaded_animations_.end(),
993 [animation_id](const scoped_ptr<cc::Animation>& animation) { 1005 [animation_id](const scoped_ptr<cc::Animation>& animation) {
994 return animation->id() == animation_id; 1006 return animation->id() == animation_id;
995 }), 1007 }),
996 pending_threaded_animations_.end()); 1008 pending_threaded_animations_.end());
997 } 1009 }
998 1010
999 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { 1011 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
1000 Compositor* compositor = GetCompositor(); 1012 Compositor* compositor = GetCompositor();
1001 return compositor ? compositor->layer_animator_collection() : NULL; 1013 return compositor ? compositor->layer_animator_collection() : NULL;
1002 } 1014 }
1003 1015
1004 cc::Layer* Layer::GetCcLayer() const { 1016 cc::Layer* Layer::GetCcLayer() const {
1005 return cc_layer_; 1017 return cc_layer_;
1006 } 1018 }
1007 1019
1008 void Layer::SendPendingThreadedAnimations() { 1020 void Layer::SendPendingThreadedAnimations() {
1009 for (auto& animation : pending_threaded_animations_) 1021 for (auto& animation : pending_threaded_animations_) {
1010 cc_layer_->AddAnimation(std::move(animation)); 1022 if (UILayerSettings().use_compositor_animation_timelines) {
1023 DCHECK(animator_);
1024 animator_->AddThreadedAnimation(std::move(animation));
1025 } else {
1026 cc_layer_->AddAnimation(std::move(animation));
1027 }
1028 }
1011 pending_threaded_animations_.clear(); 1029 pending_threaded_animations_.clear();
1012 1030
1013 for (auto* child : children_) 1031 for (auto* child : children_)
1014 child->SendPendingThreadedAnimations(); 1032 child->SendPendingThreadedAnimations();
1015 } 1033 }
1016 1034
1017 void Layer::CreateCcLayer() { 1035 void Layer::CreateCcLayer() {
1018 if (type_ == LAYER_SOLID_COLOR) { 1036 if (type_ == LAYER_SOLID_COLOR) {
1019 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings()); 1037 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings());
1020 cc_layer_ = solid_color_layer_.get(); 1038 cc_layer_ = solid_color_layer_.get();
(...skipping 29 matching lines...) Expand all
1050 size.SetToMin(frame_size_in_dip_); 1068 size.SetToMin(frame_size_in_dip_);
1051 } 1069 }
1052 cc_layer_->SetBounds(size); 1070 cc_layer_->SetBounds(size);
1053 } 1071 }
1054 1072
1055 void Layer::RecomputePosition() { 1073 void Layer::RecomputePosition() {
1056 cc_layer_->SetPosition(gfx::PointF(bounds_.origin()) + 1074 cc_layer_->SetPosition(gfx::PointF(bounds_.origin()) +
1057 subpixel_position_offset_); 1075 subpixel_position_offset_);
1058 } 1076 }
1059 1077
1060 void Layer::AddAnimatorsInTreeToCollection( 1078 void Layer::SetCompositorForAnimatorsInTree(Compositor* compositor) {
1061 LayerAnimatorCollection* collection) { 1079 DCHECK(compositor);
1062 DCHECK(collection); 1080 LayerAnimatorCollection* collection = compositor->layer_animator_collection();
1063 if (IsAnimating()) 1081
1064 animator_->AddToCollection(collection); 1082 if (animator_) {
1083 if (animator_->is_animating())
1084 animator_->AddToCollection(collection);
1085 animator_->SetCompositor(compositor);
1086 }
1087
1065 for (auto* child : children_) 1088 for (auto* child : children_)
1066 child->AddAnimatorsInTreeToCollection(collection); 1089 child->SetCompositorForAnimatorsInTree(compositor);
1067 } 1090 }
1068 1091
1069 void Layer::RemoveAnimatorsInTreeFromCollection( 1092 void Layer::ResetCompositorForAnimatorsInTree(Compositor* compositor) {
1070 LayerAnimatorCollection* collection) { 1093 DCHECK(compositor);
1071 DCHECK(collection); 1094 LayerAnimatorCollection* collection = compositor->layer_animator_collection();
1072 if (IsAnimating()) 1095
1073 animator_->RemoveFromCollection(collection); 1096 if (animator_) {
1097 animator_->ResetCompositor(compositor);
1098 if (animator_->is_animating())
1099 animator_->RemoveFromCollection(collection);
1100 }
1101
1074 for (auto* child : children_) 1102 for (auto* child : children_)
1075 child->RemoveAnimatorsInTreeFromCollection(collection); 1103 child->ResetCompositorForAnimatorsInTree(compositor);
1076 }
1077
1078 bool Layer::IsAnimating() const {
1079 return animator_.get() && animator_->is_animating();
1080 } 1104 }
1081 1105
1082 } // namespace ui 1106 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698