[email protected] | b7a1b66 | 2012-01-18 14:12:18 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 5 | #include "ui/compositor/layer_animator.h" |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 6 | |
avi | 87b8b58 | 2015-12-24 21:35:25 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 9 | #include "base/logging.h" |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
ssid | 334fb87a | 2015-01-27 20:12:07 | [diff] [blame] | 11 | #include "base/trace_event/trace_event.h" |
loyso | e926437dd | 2016-01-14 22:55:30 | [diff] [blame] | 12 | #include "cc/animation/animation_events.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 13 | #include "cc/animation/animation_id_provider.h" |
loyso | 84122900 | 2015-12-21 10:03:24 | [diff] [blame] | 14 | #include "cc/animation/animation_player.h" |
| 15 | #include "cc/animation/animation_timeline.h" |
| 16 | #include "cc/animation/element_animations.h" |
| 17 | #include "cc/layers/layer_settings.h" |
[email protected] | de2cf8c | 2013-10-25 19:46:46 | [diff] [blame] | 18 | #include "cc/output/begin_frame_args.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 19 | #include "ui/compositor/compositor.h" |
| 20 | #include "ui/compositor/layer.h" |
| 21 | #include "ui/compositor/layer_animation_delegate.h" |
| 22 | #include "ui/compositor/layer_animation_observer.h" |
| 23 | #include "ui/compositor/layer_animation_sequence.h" |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 24 | #include "ui/compositor/layer_animator_collection.h" |
[email protected] | 0ed187e | 2011-10-21 20:07:42 | [diff] [blame] | 25 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 26 | #define SAFE_INVOKE_VOID(function, running_anim, ...) \ |
| 27 | if (running_anim.is_sequence_alive()) \ |
| 28 | function(running_anim.sequence(), ##__VA_ARGS__) |
| 29 | #define SAFE_INVOKE_BOOL(function, running_anim) \ |
| 30 | ((running_anim.is_sequence_alive()) \ |
| 31 | ? function(running_anim.sequence()) \ |
| 32 | : false) |
| 33 | #define SAFE_INVOKE_PTR(function, running_anim) \ |
| 34 | ((running_anim.is_sequence_alive()) \ |
| 35 | ? function(running_anim.sequence()) \ |
| 36 | : NULL) |
| 37 | |
[email protected] | 21445e47 | 2011-10-21 20:36:32 | [diff] [blame] | 38 | namespace ui { |
[email protected] | 0ed187e | 2011-10-21 20:07:42 | [diff] [blame] | 39 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 40 | namespace { |
| 41 | |
[email protected] | 98e2ed2 | 2012-11-21 14:02:23 | [diff] [blame] | 42 | const int kDefaultTransitionDurationMs = 120; |
[email protected] | 1778cbc | 2012-09-06 04:31:19 | [diff] [blame] | 43 | |
[email protected] | 9861f175 | 2012-06-01 07:16:14 | [diff] [blame] | 44 | } // namespace |
| 45 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 46 | // LayerAnimator public -------------------------------------------------------- |
| 47 | |
| 48 | LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
| 49 | : delegate_(NULL), |
| 50 | preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
[email protected] | 0d31625 | 2014-01-20 15:31:19 | [diff] [blame] | 51 | is_transition_duration_locked_(false), |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 52 | transition_duration_(transition_duration), |
[email protected] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 53 | tween_type_(gfx::Tween::LINEAR), |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 54 | is_started_(false), |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 55 | disable_timer_for_test_(false), |
| 56 | adding_animations_(false) { |
loyso | 84122900 | 2015-12-21 10:03:24 | [diff] [blame] | 57 | if (Layer::UILayerSettings().use_compositor_animation_timelines) { |
| 58 | animation_player_ = |
| 59 | cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); |
| 60 | } |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | LayerAnimator::~LayerAnimator() { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 64 | for (size_t i = 0; i < running_animations_.size(); ++i) { |
| 65 | if (running_animations_[i].is_sequence_alive()) |
| 66 | running_animations_[i].sequence()->OnAnimatorDestroyed(); |
| 67 | } |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 68 | ClearAnimationsInternal(); |
| 69 | delegate_ = NULL; |
loyso | ea53437 | 2016-02-03 05:20:19 | [diff] [blame] | 70 | DCHECK(!animation_player_ || !animation_player_->animation_timeline()); |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 73 | // static |
| 74 | LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
| 75 | return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
| 76 | } |
| 77 | |
| 78 | // static |
| 79 | LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
[email protected] | 98e2ed2 | 2012-11-21 14:02:23 | [diff] [blame] | 80 | return new LayerAnimator( |
| 81 | base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 7713e24 | 2012-11-15 17:43:19 | [diff] [blame] | 84 | // This macro provides the implementation for the setter and getter (well, |
| 85 | // the getter of the target value) for an animated property. For example, |
| 86 | // it is used for the implementations of SetTransform and GetTargetTransform. |
| 87 | // It is worth noting that SetFoo avoids invoking the usual animation machinery |
| 88 | // if the transition duration is zero -- in this case we just set the property |
| 89 | // on the layer animation delegate immediately. |
| 90 | #define ANIMATED_PROPERTY(type, property, name, member_type, member) \ |
| 91 | void LayerAnimator::Set##name(type value) { \ |
| 92 | base::TimeDelta duration = GetTransitionDuration(); \ |
[email protected] | df55f23 | 2012-11-20 22:35:43 | [diff] [blame] | 93 | if (duration == base::TimeDelta() && delegate() && \ |
| 94 | (preemption_strategy_ != ENQUEUE_NEW_ANIMATION)) { \ |
[email protected] | 7713e24 | 2012-11-15 17:43:19 | [diff] [blame] | 95 | StopAnimatingProperty(LayerAnimationElement::property); \ |
| 96 | delegate()->Set##name##FromAnimation(value); \ |
| 97 | return; \ |
| 98 | } \ |
| 99 | scoped_ptr<LayerAnimationElement> element( \ |
| 100 | LayerAnimationElement::Create##name##Element(value, duration)); \ |
| 101 | element->set_tween_type(tween_type_); \ |
| 102 | StartAnimation(new LayerAnimationSequence(element.release())); \ |
| 103 | } \ |
| 104 | \ |
| 105 | member_type LayerAnimator::GetTarget##name() const { \ |
| 106 | LayerAnimationElement::TargetValue target(delegate()); \ |
| 107 | GetTargetValue(&target); \ |
| 108 | return target.member; \ |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | 7713e24 | 2012-11-15 17:43:19 | [diff] [blame] | 111 | ANIMATED_PROPERTY( |
| 112 | const gfx::Transform&, TRANSFORM, Transform, gfx::Transform, transform); |
| 113 | ANIMATED_PROPERTY(const gfx::Rect&, BOUNDS, Bounds, gfx::Rect, bounds); |
| 114 | ANIMATED_PROPERTY(float, OPACITY, Opacity, float, opacity); |
| 115 | ANIMATED_PROPERTY(bool, VISIBILITY, Visibility, bool, visibility); |
| 116 | ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness); |
| 117 | ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale); |
| 118 | ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color); |
[email protected] | e81480f1f | 2012-10-11 23:06:45 | [diff] [blame] | 119 | |
[email protected] | 0d31625 | 2014-01-20 15:31:19 | [diff] [blame] | 120 | base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
| 121 | return transition_duration_; |
| 122 | } |
| 123 | |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 124 | void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 125 | if (delegate_ && is_started_) { |
| 126 | LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 127 | if (collection) |
| 128 | collection->StopAnimator(this); |
| 129 | } |
loyso | 1fbd9f9 | 2015-12-17 07:43:13 | [diff] [blame] | 130 | SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 131 | delegate_ = delegate; |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 132 | if (delegate_ && is_started_) { |
| 133 | LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 134 | if (collection) |
| 135 | collection->StartAnimator(this); |
| 136 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 137 | } |
| 138 | |
loyso | 1fbd9f9 | 2015-12-17 07:43:13 | [diff] [blame] | 139 | void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 140 | if (delegate_) { |
loyso | 84122900 | 2015-12-21 10:03:24 | [diff] [blame] | 141 | if (animation_player_) |
| 142 | DetachLayerFromAnimationPlayer(); |
| 143 | else |
| 144 | delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); |
loyso | 1fbd9f9 | 2015-12-17 07:43:13 | [diff] [blame] | 145 | } |
loyso | 84122900 | 2015-12-21 10:03:24 | [diff] [blame] | 146 | if (new_layer) { |
| 147 | if (animation_player_) |
| 148 | AttachLayerToAnimationPlayer(new_layer->id()); |
| 149 | else |
| 150 | new_layer->AddLayerAnimationEventObserver(this); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void LayerAnimator::SetCompositor(Compositor* compositor) { |
| 155 | DCHECK(compositor); |
| 156 | if (animation_player_) { |
| 157 | cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 158 | DCHECK(timeline); |
| 159 | timeline->AttachPlayer(animation_player_); |
| 160 | |
| 161 | DCHECK(delegate_->GetCcLayer()); |
| 162 | AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | void LayerAnimator::ResetCompositor(Compositor* compositor) { |
| 167 | DCHECK(compositor); |
| 168 | if (animation_player_) { |
| 169 | DetachLayerFromAnimationPlayer(); |
| 170 | |
| 171 | cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 172 | DCHECK(timeline); |
| 173 | timeline->DetachPlayer(animation_player_); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| 178 | DCHECK(animation_player_); |
| 179 | |
| 180 | if (!animation_player_->layer_id()) |
| 181 | animation_player_->AttachLayer(layer_id); |
| 182 | else |
| 183 | DCHECK_EQ(animation_player_->layer_id(), layer_id); |
| 184 | |
| 185 | if (animation_player_->element_animations()) { |
| 186 | animation_player_->element_animations() |
| 187 | ->layer_animation_controller() |
| 188 | ->AddEventObserver(this); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | void LayerAnimator::DetachLayerFromAnimationPlayer() { |
| 193 | DCHECK(animation_player_); |
| 194 | |
| 195 | if (animation_player_->element_animations()) { |
| 196 | animation_player_->element_animations() |
| 197 | ->layer_animation_controller() |
| 198 | ->RemoveEventObserver(this); |
| 199 | } |
| 200 | |
| 201 | if (animation_player_->layer_id()) |
| 202 | animation_player_->DetachLayer(); |
| 203 | } |
| 204 | |
| 205 | void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 206 | DCHECK(animation_player_); |
| 207 | animation_player_->AddAnimation(std::move(animation)); |
| 208 | } |
| 209 | |
| 210 | void LayerAnimator::RemoveThreadedAnimation(int animation_id) { |
| 211 | DCHECK(animation_player_); |
| 212 | animation_player_->RemoveAnimation(animation_id); |
loyso | 1fbd9f9 | 2015-12-17 07:43:13 | [diff] [blame] | 213 | } |
| 214 | |
loyso | 1fe980f | 2016-01-18 23:58:15 | [diff] [blame] | 215 | bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { |
| 216 | DCHECK(animation_player_); |
| 217 | return animation_player_->has_pending_animations_for_testing(); |
| 218 | } |
| 219 | |
loyso | d412744 | 2016-02-03 02:29:40 | [diff] [blame] | 220 | cc::AnimationPlayer* LayerAnimator::GetAnimationPlayerForTesting() const { |
| 221 | return animation_player_.get(); |
| 222 | } |
| 223 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 224 | void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 225 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 226 | OnScheduled(animation); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 227 | if (!StartSequenceImmediately(animation)) { |
| 228 | // Attempt to preempt a running animation. |
| 229 | switch (preemption_strategy_) { |
| 230 | case IMMEDIATELY_SET_NEW_TARGET: |
| 231 | ImmediatelySetNewTarget(animation); |
| 232 | break; |
| 233 | case IMMEDIATELY_ANIMATE_TO_NEW_TARGET: |
| 234 | ImmediatelyAnimateToNewTarget(animation); |
| 235 | break; |
| 236 | case ENQUEUE_NEW_ANIMATION: |
| 237 | EnqueueNewAnimation(animation); |
| 238 | break; |
| 239 | case REPLACE_QUEUED_ANIMATIONS: |
| 240 | ReplaceQueuedAnimations(animation); |
| 241 | break; |
| 242 | case BLEND_WITH_CURRENT_ANIMATION: { |
| 243 | // TODO(vollick) Add support for blended sequences and use them here. |
| 244 | NOTIMPLEMENTED(); |
| 245 | break; |
| 246 | } |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 247 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 248 | } |
| 249 | FinishAnyAnimationWithZeroDuration(); |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 250 | UpdateAnimationState(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 254 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 255 | OnScheduled(animation); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 256 | if (is_animating()) { |
| 257 | animation_queue_.push_back(make_linked_ptr(animation)); |
| 258 | ProcessQueue(); |
| 259 | } else { |
| 260 | StartSequenceImmediately(animation); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 261 | } |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 262 | UpdateAnimationState(); |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 265 | void LayerAnimator::StartTogether( |
| 266 | const std::vector<LayerAnimationSequence*>& animations) { |
| 267 | scoped_refptr<LayerAnimator> retain(this); |
| 268 | if (preemption_strategy_ == IMMEDIATELY_SET_NEW_TARGET) { |
| 269 | std::vector<LayerAnimationSequence*>::const_iterator iter; |
| 270 | for (iter = animations.begin(); iter != animations.end(); ++iter) { |
| 271 | StartAnimation(*iter); |
| 272 | } |
| 273 | return; |
| 274 | } |
[email protected] | d764fd3d | 2012-11-15 20:07:51 | [diff] [blame] | 275 | |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 276 | adding_animations_ = true; |
[email protected] | d764fd3d | 2012-11-15 20:07:51 | [diff] [blame] | 277 | if (!is_animating()) { |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 278 | LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 279 | if (collection && collection->HasActiveAnimators()) |
| 280 | last_step_time_ = collection->last_tick_time(); |
[email protected] | d764fd3d | 2012-11-15 20:07:51 | [diff] [blame] | 281 | else |
abhishek.ka | 7215854d | 2015-05-26 06:13:17 | [diff] [blame] | 282 | last_step_time_ = base::TimeTicks::Now(); |
[email protected] | d764fd3d | 2012-11-15 20:07:51 | [diff] [blame] | 283 | } |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 284 | |
| 285 | // Collect all the affected properties. |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 286 | LayerAnimationElement::AnimatableProperties animated_properties = |
| 287 | LayerAnimationElement::UNKNOWN; |
| 288 | |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 289 | std::vector<LayerAnimationSequence*>::const_iterator iter; |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 290 | for (iter = animations.begin(); iter != animations.end(); ++iter) |
| 291 | animated_properties |= (*iter)->properties(); |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 292 | |
| 293 | // Starting a zero duration pause that affects all the animated properties |
| 294 | // will prevent any of the sequences from animating until there are no |
| 295 | // running animations that affect any of these properties, as well as |
| 296 | // handle preemption strategy. |
| 297 | StartAnimation(new LayerAnimationSequence( |
| 298 | LayerAnimationElement::CreatePauseElement(animated_properties, |
| 299 | base::TimeDelta()))); |
| 300 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 301 | bool wait_for_group_start = false; |
| 302 | for (iter = animations.begin(); iter != animations.end(); ++iter) |
| 303 | wait_for_group_start |= (*iter)->IsFirstElementThreaded(); |
| 304 | |
| 305 | int group_id = cc::AnimationIdProvider::NextGroupId(); |
| 306 | |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 307 | // These animations (provided they don't animate any common properties) will |
| 308 | // now animate together if trivially scheduled. |
| 309 | for (iter = animations.begin(); iter != animations.end(); ++iter) { |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 310 | (*iter)->set_animation_group_id(group_id); |
| 311 | (*iter)->set_waiting_for_group_start(wait_for_group_start); |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 312 | ScheduleAnimation(*iter); |
| 313 | } |
| 314 | |
| 315 | adding_animations_ = false; |
| 316 | UpdateAnimationState(); |
| 317 | } |
| 318 | |
| 319 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 320 | void LayerAnimator::ScheduleTogether( |
| 321 | const std::vector<LayerAnimationSequence*>& animations) { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 322 | scoped_refptr<LayerAnimator> retain(this); |
| 323 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 324 | // Collect all the affected properties. |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 325 | LayerAnimationElement::AnimatableProperties animated_properties = |
| 326 | LayerAnimationElement::UNKNOWN; |
| 327 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 328 | std::vector<LayerAnimationSequence*>::const_iterator iter; |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 329 | for (iter = animations.begin(); iter != animations.end(); ++iter) |
| 330 | animated_properties |= (*iter)->properties(); |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 331 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 332 | // Scheduling a zero duration pause that affects all the animated properties |
| 333 | // will prevent any of the sequences from animating until there are no |
| 334 | // running animations that affect any of these properties. |
[email protected] | e4cbcc77 | 2012-03-07 18:59:31 | [diff] [blame] | 335 | ScheduleAnimation(new LayerAnimationSequence( |
| 336 | LayerAnimationElement::CreatePauseElement(animated_properties, |
| 337 | base::TimeDelta()))); |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 338 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 339 | bool wait_for_group_start = false; |
| 340 | for (iter = animations.begin(); iter != animations.end(); ++iter) |
| 341 | wait_for_group_start |= (*iter)->IsFirstElementThreaded(); |
| 342 | |
| 343 | int group_id = cc::AnimationIdProvider::NextGroupId(); |
| 344 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 345 | // These animations (provided they don't animate any common properties) will |
| 346 | // now animate together if trivially scheduled. |
| 347 | for (iter = animations.begin(); iter != animations.end(); ++iter) { |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 348 | (*iter)->set_animation_group_id(group_id); |
| 349 | (*iter)->set_waiting_for_group_start(wait_for_group_start); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 350 | ScheduleAnimation(*iter); |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 351 | } |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 352 | |
| 353 | UpdateAnimationState(); |
| 354 | } |
| 355 | |
[email protected] | 2a88c70 | 2012-09-04 23:15:02 | [diff] [blame] | 356 | void LayerAnimator::SchedulePauseForProperties( |
| 357 | base::TimeDelta duration, |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 358 | LayerAnimationElement::AnimatableProperties properties_to_pause) { |
[email protected] | 2a88c70 | 2012-09-04 23:15:02 | [diff] [blame] | 359 | ScheduleAnimation(new ui::LayerAnimationSequence( |
| 360 | ui::LayerAnimationElement::CreatePauseElement( |
| 361 | properties_to_pause, duration))); |
| 362 | } |
| 363 | |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 364 | bool LayerAnimator::IsAnimatingProperty( |
| 365 | LayerAnimationElement::AnimatableProperty property) const { |
| 366 | for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); |
| 367 | queue_iter != animation_queue_.end(); ++queue_iter) { |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 368 | if ((*queue_iter)->properties() & property) |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 369 | return true; |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 370 | } |
| 371 | return false; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 374 | void LayerAnimator::StopAnimatingProperty( |
| 375 | LayerAnimationElement::AnimatableProperty property) { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 376 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 377 | while (true) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 378 | // GetRunningAnimation purges deleted animations before searching, so we are |
| 379 | // guaranteed to find a live animation if any is returned at all. |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 380 | RunningAnimation* running = GetRunningAnimation(property); |
| 381 | if (!running) |
| 382 | break; |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 383 | // As was mentioned above, this sequence must be alive. |
| 384 | DCHECK(running->is_sequence_alive()); |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 385 | FinishAnimation(running->sequence(), false); |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 386 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 389 | void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { |
| 390 | if (!observers_.HasObserver(observer)) |
| 391 | observers_.AddObserver(observer); |
| 392 | } |
| 393 | |
| 394 | void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { |
| 395 | observers_.RemoveObserver(observer); |
[email protected] | 5cc8538d | 2011-11-07 15:24:54 | [diff] [blame] | 396 | // Remove the observer from all sequences as well. |
| 397 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 398 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 399 | (*queue_iter)->RemoveObserver(observer); |
| 400 | } |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 403 | void LayerAnimator::OnThreadedAnimationStarted( |
| 404 | const cc::AnimationEvent& event) { |
| 405 | LayerAnimationElement::AnimatableProperty property = |
[email protected] | cb67b82 | 2013-03-12 02:49:22 | [diff] [blame] | 406 | LayerAnimationElement::ToAnimatableProperty(event.target_property); |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 407 | |
| 408 | RunningAnimation* running = GetRunningAnimation(property); |
| 409 | if (!running) |
| 410 | return; |
| 411 | DCHECK(running->is_sequence_alive()); |
| 412 | |
[email protected] | cb67b82 | 2013-03-12 02:49:22 | [diff] [blame] | 413 | if (running->sequence()->animation_group_id() != event.group_id) |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 414 | return; |
| 415 | |
| 416 | running->sequence()->OnThreadedAnimationStarted(event); |
| 417 | if (!running->sequence()->waiting_for_group_start()) |
| 418 | return; |
| 419 | |
[email protected] | ac22516a | 2014-05-15 17:31:36 | [diff] [blame] | 420 | base::TimeTicks start_time = event.monotonic_time; |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 421 | |
| 422 | running->sequence()->set_waiting_for_group_start(false); |
| 423 | |
| 424 | // The call to GetRunningAnimation made above already purged deleted |
| 425 | // animations, so we are guaranteed that all the animations we iterate |
| 426 | // over now are alive. |
| 427 | for (RunningAnimations::iterator iter = running_animations_.begin(); |
| 428 | iter != running_animations_.end(); ++iter) { |
| 429 | // Ensure that each sequence is only Started once, regardless of the |
| 430 | // number of sequences in the group that have threaded first elements. |
[email protected] | cb67b82 | 2013-03-12 02:49:22 | [diff] [blame] | 431 | if (((*iter).sequence()->animation_group_id() == event.group_id) && |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 432 | !(*iter).sequence()->IsFirstElementThreaded() && |
| 433 | (*iter).sequence()->waiting_for_group_start()) { |
| 434 | (*iter).sequence()->set_start_time(start_time); |
| 435 | (*iter).sequence()->set_waiting_for_group_start(false); |
| 436 | (*iter).sequence()->Start(delegate()); |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 441 | void LayerAnimator::AddToCollection(LayerAnimatorCollection* collection) { |
| 442 | if (is_animating() && !is_started_) { |
| 443 | collection->StartAnimator(this); |
| 444 | is_started_ = true; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | void LayerAnimator::RemoveFromCollection(LayerAnimatorCollection* collection) { |
| 449 | if (is_animating() && is_started_) { |
| 450 | collection->StopAnimator(this); |
| 451 | is_started_ = false; |
| 452 | } |
| 453 | } |
| 454 | |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 455 | // LayerAnimator protected ----------------------------------------------------- |
| 456 | |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 457 | void LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 458 | base::TimeTicks now) { |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 459 | if (!delegate() || sequence->waiting_for_group_start()) |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 460 | return; |
| 461 | |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 462 | sequence->Progress(now, delegate()); |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 465 | void LayerAnimator::ProgressAnimationToEnd(LayerAnimationSequence* sequence) { |
[email protected] | 4a386e4 | 2012-12-05 01:19:30 | [diff] [blame] | 466 | if (!delegate()) |
| 467 | return; |
| 468 | |
| 469 | sequence->ProgressToEnd(delegate()); |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 472 | bool LayerAnimator::HasAnimation(LayerAnimationSequence* sequence) const { |
| 473 | for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); |
| 474 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 475 | if ((*queue_iter).get() == sequence) |
| 476 | return true; |
| 477 | } |
| 478 | return false; |
| 479 | } |
| 480 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 481 | // LayerAnimator private ------------------------------------------------------- |
| 482 | |
| 483 | void LayerAnimator::Step(base::TimeTicks now) { |
[email protected] | e4cbcc77 | 2012-03-07 18:59:31 | [diff] [blame] | 484 | TRACE_EVENT0("ui", "LayerAnimator::Step"); |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 485 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | e4cbcc77 | 2012-03-07 18:59:31 | [diff] [blame] | 486 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 487 | last_step_time_ = now; |
[email protected] | 1778cbc | 2012-09-06 04:31:19 | [diff] [blame] | 488 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 489 | PurgeDeletedAnimations(); |
| 490 | |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 491 | // We need to make a copy of the running animations because progressing them |
| 492 | // and finishing them may indirectly affect the collection of running |
| 493 | // animations. |
| 494 | RunningAnimations running_animations_copy = running_animations_; |
| 495 | for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 496 | if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 497 | continue; |
| 498 | |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 499 | if (running_animations_copy[i].sequence()->IsFinished(now)) { |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 500 | SAFE_INVOKE_VOID(FinishAnimation, running_animations_copy[i], false); |
| 501 | } else { |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 502 | SAFE_INVOKE_VOID(ProgressAnimation, running_animations_copy[i], now); |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 503 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 504 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 505 | } |
| 506 | |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 507 | void LayerAnimator::StopAnimatingInternal(bool abort) { |
| 508 | scoped_refptr<LayerAnimator> retain(this); |
ljagielski | 2057098 | 2015-01-07 20:32:55 | [diff] [blame] | 509 | while (is_animating() && delegate()) { |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 510 | // We're going to attempt to finish the first running animation. Let's |
| 511 | // ensure that it's valid. |
| 512 | PurgeDeletedAnimations(); |
| 513 | |
| 514 | // If we've purged all running animations, attempt to start one up. |
| 515 | if (running_animations_.empty()) |
| 516 | ProcessQueue(); |
| 517 | |
| 518 | DCHECK(!running_animations_.empty()); |
| 519 | |
| 520 | // Still no luck, let's just bail and clear all animations. |
| 521 | if (running_animations_.empty()) { |
| 522 | ClearAnimationsInternal(); |
| 523 | break; |
| 524 | } |
| 525 | |
| 526 | SAFE_INVOKE_VOID(FinishAnimation, running_animations_[0], abort); |
| 527 | } |
| 528 | } |
| 529 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 530 | void LayerAnimator::UpdateAnimationState() { |
| 531 | if (disable_timer_for_test_) |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 532 | return; |
| 533 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 534 | const bool should_start = is_animating(); |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 535 | LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 536 | if (collection) { |
| 537 | if (should_start && !is_started_) |
| 538 | collection->StartAnimator(this); |
| 539 | else if (!should_start && is_started_) |
| 540 | collection->StopAnimator(this); |
| 541 | is_started_ = should_start; |
| 542 | } else { |
| 543 | is_started_ = false; |
| 544 | } |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 545 | } |
| 546 | |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 547 | LayerAnimationSequence* LayerAnimator::RemoveAnimation( |
| 548 | LayerAnimationSequence* sequence) { |
| 549 | linked_ptr<LayerAnimationSequence> to_return; |
| 550 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 551 | bool is_running = false; |
| 552 | |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 553 | // First remove from running animations |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 554 | for (RunningAnimations::iterator iter = running_animations_.begin(); |
| 555 | iter != running_animations_.end(); ++iter) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 556 | if ((*iter).sequence() == sequence) { |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 557 | running_animations_.erase(iter); |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 558 | is_running = true; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 559 | break; |
[email protected] | 21445e47 | 2011-10-21 20:36:32 | [diff] [blame] | 560 | } |
| 561 | } |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 562 | |
| 563 | // Then remove from the queue |
| 564 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 565 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 566 | if ((*queue_iter) == sequence) { |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 567 | to_return = *queue_iter; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 568 | animation_queue_.erase(queue_iter); |
| 569 | break; |
| 570 | } |
| 571 | } |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 572 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 573 | if (!to_return.get() || |
| 574 | !to_return->waiting_for_group_start() || |
| 575 | !to_return->IsFirstElementThreaded()) |
| 576 | return to_return.release(); |
| 577 | |
| 578 | // The removed sequence may have been responsible for making other sequences |
| 579 | // wait for a group start. If no other sequences in the group have a |
| 580 | // threaded first element, the group no longer needs the additional wait. |
| 581 | bool is_wait_still_needed = false; |
| 582 | int group_id = to_return->animation_group_id(); |
| 583 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 584 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 585 | if (((*queue_iter)->animation_group_id() == group_id) && |
| 586 | (*queue_iter)->IsFirstElementThreaded()) { |
| 587 | is_wait_still_needed = true; |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if (is_wait_still_needed) |
| 593 | return to_return.release(); |
| 594 | |
| 595 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 596 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 597 | if ((*queue_iter)->animation_group_id() == group_id && |
| 598 | (*queue_iter)->waiting_for_group_start()) { |
| 599 | (*queue_iter)->set_waiting_for_group_start(false); |
| 600 | if (is_running) { |
| 601 | (*queue_iter)->set_start_time(last_step_time_); |
| 602 | (*queue_iter)->Start(delegate()); |
| 603 | } |
| 604 | } |
| 605 | } |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 606 | return to_return.release(); |
[email protected] | 0ed187e | 2011-10-21 20:07:42 | [diff] [blame] | 607 | } |
| 608 | |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 609 | void LayerAnimator::FinishAnimation( |
| 610 | LayerAnimationSequence* sequence, bool abort) { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 611 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 612 | scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 613 | if (abort) |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 614 | sequence->Abort(delegate()); |
[email protected] | 6f110e4 | 2012-12-18 00:21:14 | [diff] [blame] | 615 | else |
| 616 | ProgressAnimationToEnd(sequence); |
ljagielski | 2057098 | 2015-01-07 20:32:55 | [diff] [blame] | 617 | if (!delegate()) |
| 618 | return; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 619 | ProcessQueue(); |
| 620 | UpdateAnimationState(); |
[email protected] | 21445e47 | 2011-10-21 20:36:32 | [diff] [blame] | 621 | } |
[email protected] | 0ed187e | 2011-10-21 20:07:42 | [diff] [blame] | 622 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 623 | void LayerAnimator::FinishAnyAnimationWithZeroDuration() { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 624 | scoped_refptr<LayerAnimator> retain(this); |
[email protected] | 2ddfe43 | 2011-11-07 19:26:30 | [diff] [blame] | 625 | // Special case: if we've started a 0 duration animation, just finish it now |
| 626 | // and get rid of it. We need to make a copy because Progress may indirectly |
| 627 | // cause new animations to start running. |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 628 | RunningAnimations running_animations_copy = running_animations_; |
| 629 | for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 630 | if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 631 | continue; |
| 632 | |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 633 | if (running_animations_copy[i].sequence()->IsFinished( |
| 634 | running_animations_copy[i].sequence()->start_time())) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 635 | SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 636 | scoped_ptr<LayerAnimationSequence> removed( |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 637 | SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | ProcessQueue(); |
| 641 | UpdateAnimationState(); |
[email protected] | 21445e47 | 2011-10-21 20:36:32 | [diff] [blame] | 642 | } |
[email protected] | 0ed187e | 2011-10-21 20:07:42 | [diff] [blame] | 643 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 644 | void LayerAnimator::ClearAnimations() { |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 645 | scoped_refptr<LayerAnimator> retain(this); |
| 646 | ClearAnimationsInternal(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | LayerAnimator::RunningAnimation* LayerAnimator::GetRunningAnimation( |
| 650 | LayerAnimationElement::AnimatableProperty property) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 651 | PurgeDeletedAnimations(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 652 | for (RunningAnimations::iterator iter = running_animations_.begin(); |
| 653 | iter != running_animations_.end(); ++iter) { |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 654 | if ((*iter).sequence()->properties() & property) |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 655 | return &(*iter); |
| 656 | } |
| 657 | return NULL; |
| 658 | } |
| 659 | |
| 660 | void LayerAnimator::AddToQueueIfNotPresent(LayerAnimationSequence* animation) { |
| 661 | // If we don't have the animation in the queue yet, add it. |
| 662 | bool found_sequence = false; |
| 663 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 664 | queue_iter != animation_queue_.end(); ++queue_iter) { |
| 665 | if ((*queue_iter) == animation) { |
| 666 | found_sequence = true; |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if (!found_sequence) |
| 672 | animation_queue_.push_front(make_linked_ptr(animation)); |
| 673 | } |
| 674 | |
| 675 | void LayerAnimator::RemoveAllAnimationsWithACommonProperty( |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 676 | LayerAnimationSequence* sequence, bool abort) { |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 677 | // For all the running animations, if they animate the same property, |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 678 | // progress them to the end and remove them. Note, Aborting or Progressing |
| 679 | // animations may affect the collection of running animations, so we need to |
| 680 | // operate on a copy. |
| 681 | RunningAnimations running_animations_copy = running_animations_; |
| 682 | for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 683 | if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 684 | continue; |
| 685 | |
[email protected] | 712f4b64 | 2013-03-14 07:09:15 | [diff] [blame] | 686 | if (running_animations_copy[i].sequence()->HasConflictingProperty( |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 687 | sequence->properties())) { |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 688 | scoped_ptr<LayerAnimationSequence> removed( |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 689 | SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 690 | if (abort) |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 691 | running_animations_copy[i].sequence()->Abort(delegate()); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 692 | else |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 693 | SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 697 | // Same for the queued animations that haven't been started. Again, we'll |
| 698 | // need to operate on a copy. |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 699 | std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 700 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 701 | queue_iter != animation_queue_.end(); ++queue_iter) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 702 | sequences.push_back((*queue_iter)->AsWeakPtr()); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 703 | |
| 704 | for (size_t i = 0; i < sequences.size(); ++i) { |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 705 | if (!sequences[i].get() || !HasAnimation(sequences[i].get())) |
[email protected] | d59a369 | 2012-04-10 20:27:31 | [diff] [blame] | 706 | continue; |
| 707 | |
[email protected] | 712f4b64 | 2013-03-14 07:09:15 | [diff] [blame] | 708 | if (sequences[i]->HasConflictingProperty(sequence->properties())) { |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 709 | scoped_ptr<LayerAnimationSequence> removed( |
| 710 | RemoveAnimation(sequences[i].get())); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 711 | if (abort) |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 712 | sequences[i]->Abort(delegate()); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 713 | else |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 714 | ProgressAnimationToEnd(sequences[i].get()); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 720 | // Need to detect if our sequence gets destroyed. |
| 721 | base::WeakPtr<LayerAnimationSequence> weak_sequence_ptr = |
| 722 | sequence->AsWeakPtr(); |
| 723 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 724 | const bool abort = false; |
| 725 | RemoveAllAnimationsWithACommonProperty(sequence, abort); |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 726 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 727 | return; |
| 728 | |
[email protected] | d3ba37ab | 2012-02-09 19:53:13 | [diff] [blame] | 729 | LayerAnimationSequence* removed = RemoveAnimation(sequence); |
| 730 | DCHECK(removed == NULL || removed == sequence); |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 731 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 732 | return; |
| 733 | |
[email protected] | 4a386e4 | 2012-12-05 01:19:30 | [diff] [blame] | 734 | ProgressAnimationToEnd(sequence); |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 735 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 736 | return; |
| 737 | |
| 738 | delete sequence; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | void LayerAnimator::ImmediatelyAnimateToNewTarget( |
| 742 | LayerAnimationSequence* sequence) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 743 | // Need to detect if our sequence gets destroyed. |
| 744 | base::WeakPtr<LayerAnimationSequence> weak_sequence_ptr = |
| 745 | sequence->AsWeakPtr(); |
| 746 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 747 | const bool abort = true; |
| 748 | RemoveAllAnimationsWithACommonProperty(sequence, abort); |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 749 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 750 | return; |
| 751 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 752 | AddToQueueIfNotPresent(sequence); |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 753 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 754 | return; |
| 755 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 756 | StartSequenceImmediately(sequence); |
| 757 | } |
| 758 | |
| 759 | void LayerAnimator::EnqueueNewAnimation(LayerAnimationSequence* sequence) { |
| 760 | // It is assumed that if there was no conflicting animation, we would |
| 761 | // not have been called. No need to check for a collision; just |
| 762 | // add to the queue. |
| 763 | animation_queue_.push_back(make_linked_ptr(sequence)); |
| 764 | ProcessQueue(); |
| 765 | } |
| 766 | |
| 767 | void LayerAnimator::ReplaceQueuedAnimations(LayerAnimationSequence* sequence) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 768 | // Need to detect if our sequence gets destroyed. |
| 769 | base::WeakPtr<LayerAnimationSequence> weak_sequence_ptr = |
| 770 | sequence->AsWeakPtr(); |
| 771 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 772 | // Remove all animations that aren't running. Note: at each iteration i is |
| 773 | // incremented or an element is removed from the queue, so |
| 774 | // animation_queue_.size() - i is always decreasing and we are always making |
| 775 | // progress towards the loop terminating. |
| 776 | for (size_t i = 0; i < animation_queue_.size();) { |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 777 | if (!weak_sequence_ptr.get()) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 778 | break; |
| 779 | |
| 780 | PurgeDeletedAnimations(); |
| 781 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 782 | bool is_running = false; |
| 783 | for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 784 | iter != running_animations_.end(); ++iter) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 785 | if ((*iter).sequence() == animation_queue_[i].get()) { |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 786 | is_running = true; |
| 787 | break; |
| 788 | } |
| 789 | } |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 790 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 791 | if (!is_running) |
[email protected] | 300548c | 2012-06-17 08:54:55 | [diff] [blame] | 792 | delete RemoveAnimation(animation_queue_[i].get()); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 793 | else |
| 794 | ++i; |
| 795 | } |
| 796 | animation_queue_.push_back(make_linked_ptr(sequence)); |
| 797 | ProcessQueue(); |
| 798 | } |
| 799 | |
| 800 | void LayerAnimator::ProcessQueue() { |
| 801 | bool started_sequence = false; |
| 802 | do { |
| 803 | started_sequence = false; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 804 | // Build a list of all currently animated properties. |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 805 | LayerAnimationElement::AnimatableProperties animated = |
| 806 | LayerAnimationElement::UNKNOWN; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 807 | for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 808 | iter != running_animations_.end(); ++iter) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 809 | if (!(*iter).is_sequence_alive()) |
| 810 | continue; |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 811 | |
| 812 | animated |= (*iter).sequence()->properties(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Try to find an animation that doesn't conflict with an animated |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 816 | // property or a property that will be animated before it. Note: starting |
| 817 | // the animation may indirectly cause more animations to be started, so we |
| 818 | // need to operate on a copy. |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 819 | std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 820 | for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 821 | queue_iter != animation_queue_.end(); ++queue_iter) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 822 | sequences.push_back((*queue_iter)->AsWeakPtr()); |
[email protected] | f5cd9e5 | 2011-11-03 21:38:08 | [diff] [blame] | 823 | |
| 824 | for (size_t i = 0; i < sequences.size(); ++i) { |
[email protected] | 7ffde47 | 2013-06-04 06:42:19 | [diff] [blame] | 825 | if (!sequences[i].get() || !HasAnimation(sequences[i].get())) |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 826 | continue; |
| 827 | |
[email protected] | 712f4b64 | 2013-03-14 07:09:15 | [diff] [blame] | 828 | if (!sequences[i]->HasConflictingProperty(animated)) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 829 | StartSequenceImmediately(sequences[i].get()); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 830 | started_sequence = true; |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | // Animation couldn't be started. Add its properties to the collection so |
| 835 | // that we don't start a conflicting animation. For example, if our queue |
| 836 | // has the elements { {T,B}, {B} } (that is, an element that animates both |
| 837 | // the transform and the bounds followed by an element that animates the |
| 838 | // bounds), and we're currently animating the transform, we can't start |
| 839 | // the first element because it animates the transform, too. We cannot |
| 840 | // start the second element, either, because the first element animates |
| 841 | // bounds too, and needs to go first. |
[email protected] | e03193d | 2014-01-14 03:10:24 | [diff] [blame] | 842 | animated |= sequences[i]->properties(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | // If we started a sequence, try again. We may be able to start several. |
| 846 | } while (started_sequence); |
| 847 | } |
| 848 | |
| 849 | bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 850 | PurgeDeletedAnimations(); |
| 851 | |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 852 | // Ensure that no one is animating one of the sequence's properties already. |
| 853 | for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 854 | iter != running_animations_.end(); ++iter) { |
[email protected] | 712f4b64 | 2013-03-14 07:09:15 | [diff] [blame] | 855 | if ((*iter).sequence()->HasConflictingProperty(sequence->properties())) |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 856 | return false; |
| 857 | } |
| 858 | |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 859 | // All clear, actually start the sequence. |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 860 | // All LayerAnimators share the same LayerAnimatorCollection. Use the |
[email protected] | 1778cbc | 2012-09-06 04:31:19 | [diff] [blame] | 861 | // last_tick_time() from there to ensure animations started during the same |
| 862 | // event complete at the same time. |
| 863 | base::TimeTicks start_time; |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 864 | LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
[email protected] | d064ef8 | 2012-11-13 10:26:59 | [diff] [blame] | 865 | if (is_animating() || adding_animations_) |
[email protected] | 1778cbc | 2012-09-06 04:31:19 | [diff] [blame] | 866 | start_time = last_step_time_; |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 867 | else if (collection && collection->HasActiveAnimators()) |
| 868 | start_time = collection->last_tick_time(); |
[email protected] | 1778cbc | 2012-09-06 04:31:19 | [diff] [blame] | 869 | else |
abhishek.ka | 7215854d | 2015-05-26 06:13:17 | [diff] [blame] | 870 | start_time = base::TimeTicks::Now(); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 871 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 872 | if (!sequence->animation_group_id()) |
| 873 | sequence->set_animation_group_id(cc::AnimationIdProvider::NextGroupId()); |
| 874 | if (!sequence->waiting_for_group_start() || |
| 875 | sequence->IsFirstElementThreaded()) { |
| 876 | sequence->set_start_time(start_time); |
| 877 | sequence->Start(delegate()); |
| 878 | } |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 879 | running_animations_.push_back( |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 880 | RunningAnimation(sequence->AsWeakPtr())); |
[email protected] | b4db937 | 2011-10-24 14:44:19 | [diff] [blame] | 881 | |
| 882 | // Need to keep a reference to the animation. |
| 883 | AddToQueueIfNotPresent(sequence); |
| 884 | |
| 885 | // Ensure that animations get stepped at their start time. |
| 886 | Step(start_time); |
| 887 | |
| 888 | return true; |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 889 | } |
| 890 | |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 891 | void LayerAnimator::GetTargetValue( |
| 892 | LayerAnimationElement::TargetValue* target) const { |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 893 | for (AnimationQueue::const_iterator iter = animation_queue_.begin(); |
| 894 | iter != animation_queue_.end(); ++iter) { |
| 895 | (*iter)->GetTargetValue(target); |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 899 | void LayerAnimator::OnScheduled(LayerAnimationSequence* sequence) { |
| 900 | if (observers_.might_have_observers()) { |
brettw | 5a1613dc | 2015-06-02 05:34:43 | [diff] [blame] | 901 | base::ObserverListBase<LayerAnimationObserver>::Iterator it(&observers_); |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 902 | LayerAnimationObserver* obs; |
| 903 | while ((obs = it.GetNext()) != NULL) { |
| 904 | sequence->AddObserver(obs); |
| 905 | } |
| 906 | } |
| 907 | sequence->OnScheduled(); |
| 908 | } |
| 909 | |
[email protected] | 0d31625 | 2014-01-20 15:31:19 | [diff] [blame] | 910 | void LayerAnimator::SetTransitionDuration(base::TimeDelta duration) { |
| 911 | if (is_transition_duration_locked_) |
| 912 | return; |
| 913 | transition_duration_ = duration; |
[email protected] | 9861f175 | 2012-06-01 07:16:14 | [diff] [blame] | 914 | } |
| 915 | |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 916 | void LayerAnimator::ClearAnimationsInternal() { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 917 | PurgeDeletedAnimations(); |
| 918 | |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 919 | // Abort should never affect the set of running animations, but just in case |
| 920 | // clients are badly behaved, we will use a copy of the running animations. |
| 921 | RunningAnimations running_animations_copy = running_animations_; |
| 922 | for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 923 | if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 924 | continue; |
| 925 | |
| 926 | scoped_ptr<LayerAnimationSequence> removed( |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 927 | RemoveAnimation(running_animations_copy[i].sequence())); |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 928 | if (removed.get()) |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 929 | removed->Abort(delegate()); |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 930 | } |
| 931 | // This *should* have cleared the list of running animations. |
| 932 | DCHECK(running_animations_.empty()); |
| 933 | running_animations_.clear(); |
| 934 | animation_queue_.clear(); |
| 935 | UpdateAnimationState(); |
| 936 | } |
| 937 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 938 | void LayerAnimator::PurgeDeletedAnimations() { |
| 939 | for (size_t i = 0; i < running_animations_.size();) { |
| 940 | if (!running_animations_[i].is_sequence_alive()) |
| 941 | running_animations_.erase(running_animations_.begin() + i); |
| 942 | else |
| 943 | i++; |
| 944 | } |
| 945 | } |
| 946 | |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 947 | LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { |
| 948 | return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; |
| 949 | } |
| 950 | |
loyso | 1fbd9f9 | 2015-12-17 07:43:13 | [diff] [blame] | 951 | void LayerAnimator::OnAnimationStarted(const cc::AnimationEvent& event) { |
| 952 | OnThreadedAnimationStarted(event); |
| 953 | } |
| 954 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 955 | LayerAnimator::RunningAnimation::RunningAnimation( |
[email protected] | 3d75fed | 2012-12-15 18:47:38 | [diff] [blame] | 956 | const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 957 | : sequence_(sequence) { |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 958 | } |
| 959 | |
vmpstr | 0ae825e7 | 2016-02-25 20:31:31 | [diff] [blame^] | 960 | LayerAnimator::RunningAnimation::RunningAnimation( |
| 961 | const RunningAnimation& other) = default; |
| 962 | |
[email protected] | a48f30d | 2012-10-30 00:35:41 | [diff] [blame] | 963 | LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 964 | |
[email protected] | 710a98d | 2011-06-23 20:13:29 | [diff] [blame] | 965 | } // namespace ui |