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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer.cc
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index ca3ff288ee293a43b49d39bee0f6f97311e6a0cd..d57cc3bd533418fa90e9927a12609818793f2a35 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -142,10 +142,15 @@ void Layer::SetCompositor(Compositor* compositor) {
DCHECK(!compositor || !compositor_);
DCHECK(!compositor || compositor->root_layer() == this);
DCHECK(!parent_);
+ if (compositor_) {
+ RemoveAnimatorsInTreeFromCollection(
+ compositor_->layer_animator_collection());
+ }
compositor_ = compositor;
if (compositor) {
OnDeviceScaleFactorChanged(compositor->device_scale_factor());
SendPendingThreadedAnimations();
+ AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
}
}
@@ -159,15 +164,21 @@ void Layer::Add(Layer* child) {
child->OnDeviceScaleFactorChanged(device_scale_factor_);
if (GetCompositor())
child->SendPendingThreadedAnimations();
+ LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
+ if (collection)
+ child->AddAnimatorsInTreeToCollection(collection);
}
void Layer::Remove(Layer* child) {
// Current bounds are used to calculate offsets when layers are reparented.
// Stop (and complete) an ongoing animation to update the bounds immediately.
- if (child->GetAnimator()) {
- child->GetAnimator()->StopAnimatingProperty(
- ui::LayerAnimationElement::BOUNDS);
- }
+ LayerAnimator* child_animator = child->animator_;
+ if (child_animator)
+ child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS);
+ LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
+ if (collection)
+ child->RemoveAnimatorsInTreeFromCollection(collection);
+
std::vector<Layer*>::iterator i =
std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
@@ -605,6 +616,13 @@ void Layer::SendDamagedRects() {
children_[i]->SendDamagedRects();
}
+void Layer::CompleteAllAnimations() {
+ std::vector<scoped_refptr<LayerAnimator> > animators;
+ CollectAnimators(&animators);
+ std::for_each(animators.begin(), animators.end(),
+ std::mem_fun(&LayerAnimator::StopAnimating));
+}
+
void Layer::SuppressPaint() {
if (!delegate_)
return;
@@ -689,6 +707,15 @@ void Layer::OnAnimationStarted(const cc::AnimationEvent& event) {
animator_->OnThreadedAnimationStarted(event);
}
+void Layer::CollectAnimators(
+ std::vector<scoped_refptr<LayerAnimator> >* animators) {
+ if (IsAnimating())
+ animators->push_back(animator_);
+ std::for_each(children_.begin(), children_.end(),
+ std::bind2nd(std::mem_fun(&Layer::CollectAnimators),
+ animators));
+}
+
void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) {
DCHECK_NE(child, other);
DCHECK_EQ(this, child->parent());
@@ -873,6 +900,11 @@ void Layer::RemoveThreadedAnimation(int animation_id) {
pending_threaded_animations_.end());
}
+LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
+ Compositor* compositor = GetCompositor();
+ return compositor ? compositor->layer_animator_collection() : NULL;
+}
+
void Layer::SendPendingThreadedAnimations() {
for (cc::ScopedPtrVector<cc::Animation>::iterator it =
pending_threaded_animations_.begin();
@@ -930,4 +962,32 @@ void Layer::RecomputePosition() {
cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y()));
}
+void Layer::AddAnimatorsInTreeToCollection(
+ LayerAnimatorCollection* collection) {
+ DCHECK(collection);
+ if (IsAnimating())
+ animator_->AddToCollection(collection);
+ std::for_each(
+ children_.begin(),
+ children_.end(),
+ std::bind2nd(std::mem_fun(&Layer::AddAnimatorsInTreeToCollection),
+ collection));
+}
+
+void Layer::RemoveAnimatorsInTreeFromCollection(
+ LayerAnimatorCollection* collection) {
+ DCHECK(collection);
+ if (IsAnimating())
+ animator_->RemoveFromCollection(collection);
+ std::for_each(
+ children_.begin(),
+ children_.end(),
+ std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
+ collection));
+}
+
+bool Layer::IsAnimating() const {
+ return animator_ && animator_->is_animating();
+}
+
} // namespace ui
« 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