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

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

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 | Annotate | Revision Log
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 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 float Layer::opacity() const { 135 float Layer::opacity() const {
136 return cc_layer_->opacity(); 136 return cc_layer_->opacity();
137 } 137 }
138 138
139 void Layer::SetCompositor(Compositor* compositor) { 139 void Layer::SetCompositor(Compositor* compositor) {
140 // This function must only be called to set the compositor on the root layer, 140 // This function must only be called to set the compositor on the root layer,
141 // or to reset it. 141 // or to reset it.
142 DCHECK(!compositor || !compositor_); 142 DCHECK(!compositor || !compositor_);
143 DCHECK(!compositor || compositor->root_layer() == this); 143 DCHECK(!compositor || compositor->root_layer() == this);
144 DCHECK(!parent_); 144 DCHECK(!parent_);
145 if (compositor_) {
146 RemoveAnimatorsInTreeFromCollection(
147 compositor_->layer_animator_collection());
148 }
145 compositor_ = compositor; 149 compositor_ = compositor;
146 if (compositor) { 150 if (compositor) {
147 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); 151 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
148 SendPendingThreadedAnimations(); 152 SendPendingThreadedAnimations();
153 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
149 } 154 }
150 } 155 }
151 156
152 void Layer::Add(Layer* child) { 157 void Layer::Add(Layer* child) {
153 DCHECK(!child->compositor_); 158 DCHECK(!child->compositor_);
154 if (child->parent_) 159 if (child->parent_)
155 child->parent_->Remove(child); 160 child->parent_->Remove(child);
156 child->parent_ = this; 161 child->parent_ = this;
157 children_.push_back(child); 162 children_.push_back(child);
158 cc_layer_->AddChild(child->cc_layer_); 163 cc_layer_->AddChild(child->cc_layer_);
159 child->OnDeviceScaleFactorChanged(device_scale_factor_); 164 child->OnDeviceScaleFactorChanged(device_scale_factor_);
160 if (GetCompositor()) 165 if (GetCompositor())
161 child->SendPendingThreadedAnimations(); 166 child->SendPendingThreadedAnimations();
167 LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
168 if (collection)
169 child->AddAnimatorsInTreeToCollection(collection);
162 } 170 }
163 171
164 void Layer::Remove(Layer* child) { 172 void Layer::Remove(Layer* child) {
173 LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
174 if (collection)
175 child->RemoveAnimatorsInTreeFromCollection(collection);
ajuma 2014/06/02 14:53:22 This should be moved to after the StopAnimatingPro
sadrul 2014/06/02 17:53:44 Done.
165 // Current bounds are used to calculate offsets when layers are reparented. 176 // Current bounds are used to calculate offsets when layers are reparented.
166 // Stop (and complete) an ongoing animation to update the bounds immediately. 177 // Stop (and complete) an ongoing animation to update the bounds immediately.
167 if (child->GetAnimator()) { 178 LayerAnimator* child_animator = child->animator_;
168 child->GetAnimator()->StopAnimatingProperty( 179 if (child_animator)
169 ui::LayerAnimationElement::BOUNDS); 180 child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS);
170 }
171 std::vector<Layer*>::iterator i = 181 std::vector<Layer*>::iterator i =
172 std::find(children_.begin(), children_.end(), child); 182 std::find(children_.begin(), children_.end(), child);
173 DCHECK(i != children_.end()); 183 DCHECK(i != children_.end());
174 children_.erase(i); 184 children_.erase(i);
175 child->parent_ = NULL; 185 child->parent_ = NULL;
176 child->cc_layer_->RemoveFromParent(); 186 child->cc_layer_->RemoveFromParent();
177 } 187 }
178 188
179 void Layer::StackAtTop(Layer* child) { 189 void Layer::StackAtTop(Layer* child) {
180 if (children_.size() <= 1 || child == children_.back()) 190 if (children_.size() <= 1 || child == children_.back())
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 876 }
867 877
868 pending_threaded_animations_.erase( 878 pending_threaded_animations_.erase(
869 cc::remove_if(&pending_threaded_animations_, 879 cc::remove_if(&pending_threaded_animations_,
870 pending_threaded_animations_.begin(), 880 pending_threaded_animations_.begin(),
871 pending_threaded_animations_.end(), 881 pending_threaded_animations_.end(),
872 HasAnimationId(animation_id)), 882 HasAnimationId(animation_id)),
873 pending_threaded_animations_.end()); 883 pending_threaded_animations_.end());
874 } 884 }
875 885
886 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
887 Compositor* compositor = GetCompositor();
888 return compositor ? compositor->layer_animator_collection() : NULL;
889 }
890
876 void Layer::SendPendingThreadedAnimations() { 891 void Layer::SendPendingThreadedAnimations() {
877 for (cc::ScopedPtrVector<cc::Animation>::iterator it = 892 for (cc::ScopedPtrVector<cc::Animation>::iterator it =
878 pending_threaded_animations_.begin(); 893 pending_threaded_animations_.begin();
879 it != pending_threaded_animations_.end(); 894 it != pending_threaded_animations_.end();
880 ++it) 895 ++it)
881 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); 896 cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
882 897
883 pending_threaded_animations_.clear(); 898 pending_threaded_animations_.clear();
884 899
885 for (size_t i = 0; i < children_.size(); ++i) 900 for (size_t i = 0; i < children_.size(); ++i)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 size.SetToMin(frame_size_in_dip_); 938 size.SetToMin(frame_size_in_dip_);
924 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_); 939 delegated_renderer_layer_->SetDisplaySize(frame_size_in_dip_);
925 } 940 }
926 cc_layer_->SetBounds(size); 941 cc_layer_->SetBounds(size);
927 } 942 }
928 943
929 void Layer::RecomputePosition() { 944 void Layer::RecomputePosition() {
930 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); 945 cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y()));
931 } 946 }
932 947
948 void Layer::AddAnimatorsInTreeToCollection(
949 LayerAnimatorCollection* collection) {
950 DCHECK(collection);
951 if (IsAnimating())
952 collection->StartAnimator(animator_.get());
ajuma 2014/06/02 14:53:22 LayerAnimator::is_started_ will have a stale value
sadrul 2014/06/02 17:53:44 Done.
953 std::for_each(
954 children_.begin(),
955 children_.end(),
956 std::bind2nd(std::mem_fun(&Layer::AddAnimatorsInTreeToCollection),
957 collection));
958 }
959
960 void Layer::RemoveAnimatorsInTreeFromCollection(
961 LayerAnimatorCollection* collection) {
962 DCHECK(collection);
963 if (IsAnimating())
964 collection->StopAnimator(animator_.get());
965 std::for_each(
966 children_.begin(),
967 children_.end(),
968 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
969 collection));
970 }
971
972 bool Layer::IsAnimating() const {
973 return animator_ && animator_->is_animating();
974 }
975
933 } // namespace ui 976 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698