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

Unified Diff: ui/compositor/layer_animator.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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/layer_animator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer_animator.cc
diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc
index c298d0dcf87c90eb7d7101a9e7327841b581cb2b..2052782ed6830dd4fb07bf9aa26f55330859dcf1 100644
--- a/ui/compositor/layer_animator.cc
+++ b/ui/compositor/layer_animator.cc
@@ -8,6 +8,10 @@
#include "base/memory/scoped_ptr.h"
#include "base/trace_event/trace_event.h"
#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_timeline.h"
+#include "cc/animation/element_animations.h"
+#include "cc/layers/layer_settings.h"
#include "cc/output/begin_frame_args.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
@@ -47,6 +51,9 @@ LayerAnimator::LayerAnimator(base::TimeDelta transition_duration)
is_started_(false),
disable_timer_for_test_(false),
adding_animations_(false) {
+ if (Layer::UILayerSettings().use_compositor_animation_timelines)
piman 2015/12/17 05:37:28 nit: needs {}
loyso (OOO) 2015/12/17 05:53:53 Done.
+ animation_player_ =
+ cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
}
LayerAnimator::~LayerAnimator() {
@@ -110,12 +117,12 @@ base::TimeDelta LayerAnimator::GetTransitionDuration() const {
}
void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
- SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr);
if (delegate_ && is_started_) {
LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
if (collection)
collection->StopAnimator(this);
}
+ SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr);
loyso (OOO) 2015/12/17 05:53:53 I'll move this fix to the base "depends on" CL.
delegate_ = delegate;
if (delegate_ && is_started_) {
LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
@@ -126,11 +133,78 @@ void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
if (delegate_) {
+ if (animation_player_)
+ DetachLayerFromAnimationPlayer();
+ else
+ delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this);
+ }
+ if (new_layer) {
+ if (animation_player_)
+ AttachLayerToAnimationPlayer(new_layer->id());
+ else
+ new_layer->AddLayerAnimationEventObserver(this);
+ }
+}
+
+void LayerAnimator::SetCompositor(Compositor* compositor) {
+ DCHECK(compositor);
+ if (animation_player_) {
+ cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
+ DCHECK(timeline);
+ timeline->AttachPlayer(animation_player_);
+
DCHECK(delegate_->GetCcLayer());
- delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this);
+ AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id());
+ }
+}
+
+void LayerAnimator::ResetCompositor(Compositor* compositor) {
+ DCHECK(compositor);
+ if (animation_player_) {
+ DetachLayerFromAnimationPlayer();
+
+ cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
+ DCHECK(timeline);
+ timeline->DetachPlayer(animation_player_);
+ }
+}
+
+void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) {
+ DCHECK(animation_player_);
+
+ if (!animation_player_->layer_id())
+ animation_player_->AttachLayer(layer_id);
+ else
+ DCHECK_EQ(animation_player_->layer_id(), layer_id);
+
+ if (animation_player_->element_animations()) {
+ animation_player_->element_animations()
+ ->layer_animation_controller()
+ ->AddEventObserver(this);
+ }
+}
+
+void LayerAnimator::DetachLayerFromAnimationPlayer() {
+ DCHECK(animation_player_);
+
+ if (animation_player_->element_animations()) {
+ animation_player_->element_animations()
+ ->layer_animation_controller()
+ ->RemoveEventObserver(this);
}
- if (new_layer)
- new_layer->AddLayerAnimationEventObserver(this);
+
+ if (animation_player_->layer_id())
+ animation_player_->DetachLayer();
+}
+
+void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
+ DCHECK(animation_player_);
+ animation_player_->AddAnimation(std::move(animation));
+}
+
+void LayerAnimator::RemoveThreadedAnimation(int animation_id) {
+ DCHECK(animation_player_);
+ animation_player_->RemoveAnimation(animation_id);
}
void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) {
« no previous file with comments | « ui/compositor/layer_animator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698