OLD | NEW |
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_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
| 11 #include "cc/animation/animation_player.h" |
| 12 #include "cc/animation/animation_timeline.h" |
| 13 #include "cc/animation/element_animations.h" |
| 14 #include "cc/layers/layer_settings.h" |
11 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" |
12 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
13 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_delegate.h" | 18 #include "ui/compositor/layer_animation_delegate.h" |
15 #include "ui/compositor/layer_animation_observer.h" | 19 #include "ui/compositor/layer_animation_observer.h" |
16 #include "ui/compositor/layer_animation_sequence.h" | 20 #include "ui/compositor/layer_animation_sequence.h" |
17 #include "ui/compositor/layer_animator_collection.h" | 21 #include "ui/compositor/layer_animator_collection.h" |
18 | 22 |
19 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ | 23 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ |
20 if (running_anim.is_sequence_alive()) \ | 24 if (running_anim.is_sequence_alive()) \ |
(...skipping 19 matching lines...) Expand all Loading... |
40 | 44 |
41 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) | 45 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
42 : delegate_(NULL), | 46 : delegate_(NULL), |
43 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), | 47 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
44 is_transition_duration_locked_(false), | 48 is_transition_duration_locked_(false), |
45 transition_duration_(transition_duration), | 49 transition_duration_(transition_duration), |
46 tween_type_(gfx::Tween::LINEAR), | 50 tween_type_(gfx::Tween::LINEAR), |
47 is_started_(false), | 51 is_started_(false), |
48 disable_timer_for_test_(false), | 52 disable_timer_for_test_(false), |
49 adding_animations_(false) { | 53 adding_animations_(false) { |
| 54 if (Layer::UILayerSettings().use_compositor_animation_timelines) { |
| 55 animation_player_ = |
| 56 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); |
| 57 } |
50 } | 58 } |
51 | 59 |
52 LayerAnimator::~LayerAnimator() { | 60 LayerAnimator::~LayerAnimator() { |
53 for (size_t i = 0; i < running_animations_.size(); ++i) { | 61 for (size_t i = 0; i < running_animations_.size(); ++i) { |
54 if (running_animations_[i].is_sequence_alive()) | 62 if (running_animations_[i].is_sequence_alive()) |
55 running_animations_[i].sequence()->OnAnimatorDestroyed(); | 63 running_animations_[i].sequence()->OnAnimatorDestroyed(); |
56 } | 64 } |
57 ClearAnimationsInternal(); | 65 ClearAnimationsInternal(); |
58 delegate_ = NULL; | 66 delegate_ = NULL; |
59 } | 67 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 delegate_ = delegate; | 127 delegate_ = delegate; |
120 if (delegate_ && is_started_) { | 128 if (delegate_ && is_started_) { |
121 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 129 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
122 if (collection) | 130 if (collection) |
123 collection->StartAnimator(this); | 131 collection->StartAnimator(this); |
124 } | 132 } |
125 } | 133 } |
126 | 134 |
127 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 135 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
128 if (delegate_) { | 136 if (delegate_) { |
| 137 if (animation_player_) |
| 138 DetachLayerFromAnimationPlayer(); |
| 139 else |
| 140 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); |
| 141 } |
| 142 if (new_layer) { |
| 143 if (animation_player_) |
| 144 AttachLayerToAnimationPlayer(new_layer->id()); |
| 145 else |
| 146 new_layer->AddLayerAnimationEventObserver(this); |
| 147 } |
| 148 } |
| 149 |
| 150 void LayerAnimator::SetCompositor(Compositor* compositor) { |
| 151 DCHECK(compositor); |
| 152 if (animation_player_) { |
| 153 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 154 DCHECK(timeline); |
| 155 timeline->AttachPlayer(animation_player_); |
| 156 |
129 DCHECK(delegate_->GetCcLayer()); | 157 DCHECK(delegate_->GetCcLayer()); |
130 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); | 158 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
131 } | 159 } |
132 if (new_layer) | 160 } |
133 new_layer->AddLayerAnimationEventObserver(this); | 161 |
| 162 void LayerAnimator::ResetCompositor(Compositor* compositor) { |
| 163 DCHECK(compositor); |
| 164 if (animation_player_) { |
| 165 DetachLayerFromAnimationPlayer(); |
| 166 |
| 167 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 168 DCHECK(timeline); |
| 169 timeline->DetachPlayer(animation_player_); |
| 170 } |
| 171 } |
| 172 |
| 173 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| 174 DCHECK(animation_player_); |
| 175 |
| 176 if (!animation_player_->layer_id()) |
| 177 animation_player_->AttachLayer(layer_id); |
| 178 else |
| 179 DCHECK_EQ(animation_player_->layer_id(), layer_id); |
| 180 |
| 181 if (animation_player_->element_animations()) { |
| 182 animation_player_->element_animations() |
| 183 ->layer_animation_controller() |
| 184 ->AddEventObserver(this); |
| 185 } |
| 186 } |
| 187 |
| 188 void LayerAnimator::DetachLayerFromAnimationPlayer() { |
| 189 DCHECK(animation_player_); |
| 190 |
| 191 if (animation_player_->element_animations()) { |
| 192 animation_player_->element_animations() |
| 193 ->layer_animation_controller() |
| 194 ->RemoveEventObserver(this); |
| 195 } |
| 196 |
| 197 if (animation_player_->layer_id()) |
| 198 animation_player_->DetachLayer(); |
| 199 } |
| 200 |
| 201 void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 202 DCHECK(animation_player_); |
| 203 animation_player_->AddAnimation(std::move(animation)); |
| 204 } |
| 205 |
| 206 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { |
| 207 DCHECK(animation_player_); |
| 208 animation_player_->RemoveAnimation(animation_id); |
134 } | 209 } |
135 | 210 |
136 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 211 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
137 scoped_refptr<LayerAnimator> retain(this); | 212 scoped_refptr<LayerAnimator> retain(this); |
138 OnScheduled(animation); | 213 OnScheduled(animation); |
139 if (!StartSequenceImmediately(animation)) { | 214 if (!StartSequenceImmediately(animation)) { |
140 // Attempt to preempt a running animation. | 215 // Attempt to preempt a running animation. |
141 switch (preemption_strategy_) { | 216 switch (preemption_strategy_) { |
142 case IMMEDIATELY_SET_NEW_TARGET: | 217 case IMMEDIATELY_SET_NEW_TARGET: |
143 ImmediatelySetNewTarget(animation); | 218 ImmediatelySetNewTarget(animation); |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 } | 940 } |
866 | 941 |
867 LayerAnimator::RunningAnimation::RunningAnimation( | 942 LayerAnimator::RunningAnimation::RunningAnimation( |
868 const base::WeakPtr<LayerAnimationSequence>& sequence) | 943 const base::WeakPtr<LayerAnimationSequence>& sequence) |
869 : sequence_(sequence) { | 944 : sequence_(sequence) { |
870 } | 945 } |
871 | 946 |
872 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 947 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
873 | 948 |
874 } // namespace ui | 949 } // namespace ui |
OLD | NEW |