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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
11 #include "cc/output/begin_frame_args.h" | 11 #include "cc/output/begin_frame_args.h" |
12 #include "ui/compositor/compositor.h" | 12 #include "ui/compositor/compositor.h" |
13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_delegate.h" | 14 #include "ui/compositor/layer_animation_delegate.h" |
15 #include "ui/compositor/layer_animation_observer.h" | 15 #include "ui/compositor/layer_animation_observer.h" |
16 #include "ui/compositor/layer_animation_sequence.h" | 16 #include "ui/compositor/layer_animation_sequence.h" |
17 #include "ui/gfx/animation/animation_container.h" | 17 #include "ui/compositor/layer_animator_collection.h" |
18 #include "ui/gfx/frame_time.h" | 18 #include "ui/gfx/frame_time.h" |
19 | 19 |
20 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ | 20 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ |
21 if (running_anim.is_sequence_alive()) \ | 21 if (running_anim.is_sequence_alive()) \ |
22 function(running_anim.sequence(), ##__VA_ARGS__) | 22 function(running_anim.sequence(), ##__VA_ARGS__) |
23 #define SAFE_INVOKE_BOOL(function, running_anim) \ | 23 #define SAFE_INVOKE_BOOL(function, running_anim) \ |
24 ((running_anim.is_sequence_alive()) \ | 24 ((running_anim.is_sequence_alive()) \ |
25 ? function(running_anim.sequence()) \ | 25 ? function(running_anim.sequence()) \ |
26 : false) | 26 : false) |
27 #define SAFE_INVOKE_PTR(function, running_anim) \ | 27 #define SAFE_INVOKE_PTR(function, running_anim) \ |
28 ((running_anim.is_sequence_alive()) \ | 28 ((running_anim.is_sequence_alive()) \ |
29 ? function(running_anim.sequence()) \ | 29 ? function(running_anim.sequence()) \ |
30 : NULL) | 30 : NULL) |
31 | 31 |
32 namespace ui { | 32 namespace ui { |
33 | 33 |
34 class LayerAnimator; | |
35 | |
36 namespace { | 34 namespace { |
37 | 35 |
38 const int kDefaultTransitionDurationMs = 120; | 36 const int kDefaultTransitionDurationMs = 120; |
39 const int kTimerIntervalMs = 10; | |
40 | |
41 // Returns the AnimationContainer we're added to. | |
42 gfx::AnimationContainer* GetAnimationContainer() { | |
43 static gfx::AnimationContainer* container = NULL; | |
44 if (!container) { | |
45 container = new gfx::AnimationContainer(); | |
46 container->AddRef(); | |
47 } | |
48 return container; | |
49 } | |
50 | 37 |
51 } // namespace | 38 } // namespace |
52 | 39 |
53 // LayerAnimator public -------------------------------------------------------- | 40 // LayerAnimator public -------------------------------------------------------- |
54 | 41 |
55 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) | 42 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
56 : delegate_(NULL), | 43 : delegate_(NULL), |
57 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), | 44 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
58 is_transition_duration_locked_(false), | 45 is_transition_duration_locked_(false), |
59 transition_duration_(transition_duration), | 46 transition_duration_(transition_duration), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 if (preemption_strategy_ == IMMEDIATELY_SET_NEW_TARGET) { | 161 if (preemption_strategy_ == IMMEDIATELY_SET_NEW_TARGET) { |
175 std::vector<LayerAnimationSequence*>::const_iterator iter; | 162 std::vector<LayerAnimationSequence*>::const_iterator iter; |
176 for (iter = animations.begin(); iter != animations.end(); ++iter) { | 163 for (iter = animations.begin(); iter != animations.end(); ++iter) { |
177 StartAnimation(*iter); | 164 StartAnimation(*iter); |
178 } | 165 } |
179 return; | 166 return; |
180 } | 167 } |
181 | 168 |
182 adding_animations_ = true; | 169 adding_animations_ = true; |
183 if (!is_animating()) { | 170 if (!is_animating()) { |
184 if (GetAnimationContainer()->is_running()) | 171 LayerAnimatorCollection* collection = |
185 last_step_time_ = GetAnimationContainer()->last_tick_time(); | 172 LayerAnimatorCollection::GetInstance(); |
173 if (collection->HasActiveAnimators()) | |
174 last_step_time_ = collection->last_tick_time(); | |
186 else | 175 else |
187 last_step_time_ = gfx::FrameTime::Now(); | 176 last_step_time_ = gfx::FrameTime::Now(); |
188 } | 177 } |
189 | 178 |
190 // Collect all the affected properties. | 179 // Collect all the affected properties. |
191 LayerAnimationElement::AnimatableProperties animated_properties = | 180 LayerAnimationElement::AnimatableProperties animated_properties = |
192 LayerAnimationElement::UNKNOWN; | 181 LayerAnimationElement::UNKNOWN; |
193 | 182 |
194 std::vector<LayerAnimationSequence*>::const_iterator iter; | 183 std::vector<LayerAnimationSequence*>::const_iterator iter; |
195 for (iter = animations.begin(); iter != animations.end(); ++iter) | 184 for (iter = animations.begin(); iter != animations.end(); ++iter) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 continue; | 377 continue; |
389 | 378 |
390 if (running_animations_copy[i].sequence()->IsFinished(now)) { | 379 if (running_animations_copy[i].sequence()->IsFinished(now)) { |
391 SAFE_INVOKE_VOID(FinishAnimation, running_animations_copy[i], false); | 380 SAFE_INVOKE_VOID(FinishAnimation, running_animations_copy[i], false); |
392 } else { | 381 } else { |
393 SAFE_INVOKE_VOID(ProgressAnimation, running_animations_copy[i], now); | 382 SAFE_INVOKE_VOID(ProgressAnimation, running_animations_copy[i], now); |
394 } | 383 } |
395 } | 384 } |
396 } | 385 } |
397 | 386 |
398 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { | |
399 // Do nothing. | |
400 } | |
401 | |
402 base::TimeDelta LayerAnimator::GetTimerInterval() const { | |
403 return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); | |
404 } | |
405 | |
406 void LayerAnimator::StopAnimatingInternal(bool abort) { | 387 void LayerAnimator::StopAnimatingInternal(bool abort) { |
407 scoped_refptr<LayerAnimator> retain(this); | 388 scoped_refptr<LayerAnimator> retain(this); |
408 while (is_animating()) { | 389 while (is_animating()) { |
409 // We're going to attempt to finish the first running animation. Let's | 390 // We're going to attempt to finish the first running animation. Let's |
410 // ensure that it's valid. | 391 // ensure that it's valid. |
411 PurgeDeletedAnimations(); | 392 PurgeDeletedAnimations(); |
412 | 393 |
413 // If we've purged all running animations, attempt to start one up. | 394 // If we've purged all running animations, attempt to start one up. |
414 if (running_animations_.empty()) | 395 if (running_animations_.empty()) |
415 ProcessQueue(); | 396 ProcessQueue(); |
416 | 397 |
417 DCHECK(!running_animations_.empty()); | 398 DCHECK(!running_animations_.empty()); |
418 | 399 |
419 // Still no luck, let's just bail and clear all animations. | 400 // Still no luck, let's just bail and clear all animations. |
420 if (running_animations_.empty()) { | 401 if (running_animations_.empty()) { |
421 ClearAnimationsInternal(); | 402 ClearAnimationsInternal(); |
422 break; | 403 break; |
423 } | 404 } |
424 | 405 |
425 SAFE_INVOKE_VOID(FinishAnimation, running_animations_[0], abort); | 406 SAFE_INVOKE_VOID(FinishAnimation, running_animations_[0], abort); |
426 } | 407 } |
427 } | 408 } |
428 | 409 |
429 void LayerAnimator::UpdateAnimationState() { | 410 void LayerAnimator::UpdateAnimationState() { |
430 if (disable_timer_for_test_) | 411 if (disable_timer_for_test_) |
431 return; | 412 return; |
432 | 413 |
433 const bool should_start = is_animating(); | 414 const bool should_start = is_animating(); |
434 if (should_start && !is_started_) | 415 if (should_start && !is_started_) |
435 GetAnimationContainer()->Start(this); | 416 LayerAnimatorCollection::GetInstance()->StartAnimator(this); |
436 else if (!should_start && is_started_) | 417 else if (!should_start && is_started_) |
437 GetAnimationContainer()->Stop(this); | 418 LayerAnimatorCollection::GetInstance()->StopAnimator(this); |
438 | 419 |
439 is_started_ = should_start; | 420 is_started_ = should_start; |
440 } | 421 } |
441 | 422 |
442 LayerAnimationSequence* LayerAnimator::RemoveAnimation( | 423 LayerAnimationSequence* LayerAnimator::RemoveAnimation( |
443 LayerAnimationSequence* sequence) { | 424 LayerAnimationSequence* sequence) { |
444 linked_ptr<LayerAnimationSequence> to_return; | 425 linked_ptr<LayerAnimationSequence> to_return; |
445 | 426 |
446 bool is_running = false; | 427 bool is_running = false; |
447 | 428 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 for (RunningAnimations::const_iterator iter = running_animations_.begin(); | 727 for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
747 iter != running_animations_.end(); ++iter) { | 728 iter != running_animations_.end(); ++iter) { |
748 if ((*iter).sequence()->HasConflictingProperty(sequence->properties())) | 729 if ((*iter).sequence()->HasConflictingProperty(sequence->properties())) |
749 return false; | 730 return false; |
750 } | 731 } |
751 | 732 |
752 // All clear, actually start the sequence. Note: base::TimeTicks::Now has | 733 // All clear, actually start the sequence. Note: base::TimeTicks::Now has |
753 // a resolution that can be as bad as 15ms. If this causes glitches in the | 734 // a resolution that can be as bad as 15ms. If this causes glitches in the |
754 // animations, this can be switched to HighResNow() (animation uses Now() | 735 // animations, this can be switched to HighResNow() (animation uses Now() |
755 // internally). | 736 // internally). |
756 // All LayerAnimators share the same AnimationContainer. Use the | 737 // All LayerAnimators share the same LayerAnimatorCollection. Use the |
757 // last_tick_time() from there to ensure animations started during the same | 738 // last_tick_time() from there to ensure animations started during the same |
758 // event complete at the same time. | 739 // event complete at the same time. |
759 base::TimeTicks start_time; | 740 base::TimeTicks start_time; |
760 if (is_animating() || adding_animations_) | 741 if (is_animating() || adding_animations_) |
761 start_time = last_step_time_; | 742 start_time = last_step_time_; |
762 else if (GetAnimationContainer()->is_running()) | 743 else if (LayerAnimatorCollection::GetInstance()->HasActiveAnimators()) |
763 start_time = GetAnimationContainer()->last_tick_time(); | 744 start_time = LayerAnimatorCollection::GetInstance()->last_tick_time(); |
ajuma
2014/05/23 17:10:00
It's possible for LayerAnimatorCollection to have
sadrul
2014/05/23 18:02:42
Done.
| |
764 else | 745 else |
765 start_time = gfx::FrameTime::Now(); | 746 start_time = gfx::FrameTime::Now(); |
766 | 747 |
767 if (!sequence->animation_group_id()) | 748 if (!sequence->animation_group_id()) |
768 sequence->set_animation_group_id(cc::AnimationIdProvider::NextGroupId()); | 749 sequence->set_animation_group_id(cc::AnimationIdProvider::NextGroupId()); |
769 if (!sequence->waiting_for_group_start() || | 750 if (!sequence->waiting_for_group_start() || |
770 sequence->IsFirstElementThreaded()) { | 751 sequence->IsFirstElementThreaded()) { |
771 sequence->set_start_time(start_time); | 752 sequence->set_start_time(start_time); |
772 sequence->Start(delegate()); | 753 sequence->Start(delegate()); |
773 } | 754 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 } | 821 } |
841 | 822 |
842 LayerAnimator::RunningAnimation::RunningAnimation( | 823 LayerAnimator::RunningAnimation::RunningAnimation( |
843 const base::WeakPtr<LayerAnimationSequence>& sequence) | 824 const base::WeakPtr<LayerAnimationSequence>& sequence) |
844 : sequence_(sequence) { | 825 : sequence_(sequence) { |
845 } | 826 } |
846 | 827 |
847 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 828 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
848 | 829 |
849 } // namespace ui | 830 } // namespace ui |
OLD | NEW |