| 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 "ui/base/animation/animation_container.h" | 10 #include "ui/base/animation/animation_container.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace ui { | 29 namespace ui { |
| 30 | 30 |
| 31 class LayerAnimator; | 31 class LayerAnimator; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const int kDefaultTransitionDurationMs = 120; | 35 const int kDefaultTransitionDurationMs = 120; |
| 36 const int kTimerIntervalMs = 10; | 36 const int kTimerIntervalMs = 10; |
| 37 | 37 |
| 38 } // namespace |
| 39 |
| 40 namespace internal { |
| 41 |
| 38 // Returns the AnimationContainer we're added to. | 42 // Returns the AnimationContainer we're added to. |
| 39 ui::AnimationContainer* GetAnimationContainer() { | 43 ui::AnimationContainer* GetLayerAnimationContainer() { |
| 40 static ui::AnimationContainer* container = NULL; | 44 static ui::AnimationContainer* container = NULL; |
| 41 if (!container) { | 45 if (!container) { |
| 42 container = new AnimationContainer(); | 46 container = new AnimationContainer(); |
| 43 container->AddRef(); | 47 container->AddRef(); |
| 44 } | 48 } |
| 45 return container; | 49 return container; |
| 46 } | 50 } |
| 47 | 51 |
| 48 } // namespace | 52 } // namespace internal |
| 49 | 53 |
| 50 // static | 54 // static |
| 51 bool LayerAnimator::disable_animations_for_test_ = false; | 55 bool LayerAnimator::disable_animations_for_test_ = false; |
| 52 // static | 56 // static |
| 53 bool LayerAnimator::slow_animation_mode_ = false; | 57 bool LayerAnimator::slow_animation_mode_ = false; |
| 54 // static | 58 // static |
| 55 int LayerAnimator::slow_animation_scale_factor_ = 4; | 59 int LayerAnimator::slow_animation_scale_factor_ = 4; |
| 56 | 60 |
| 57 // LayerAnimator public -------------------------------------------------------- | 61 // LayerAnimator public -------------------------------------------------------- |
| 58 | 62 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (preemption_strategy_ == IMMEDIATELY_SET_NEW_TARGET) { | 177 if (preemption_strategy_ == IMMEDIATELY_SET_NEW_TARGET) { |
| 174 std::vector<LayerAnimationSequence*>::const_iterator iter; | 178 std::vector<LayerAnimationSequence*>::const_iterator iter; |
| 175 for (iter = animations.begin(); iter != animations.end(); ++iter) { | 179 for (iter = animations.begin(); iter != animations.end(); ++iter) { |
| 176 StartAnimation(*iter); | 180 StartAnimation(*iter); |
| 177 } | 181 } |
| 178 return; | 182 return; |
| 179 } | 183 } |
| 180 | 184 |
| 181 adding_animations_ = true; | 185 adding_animations_ = true; |
| 182 if (!is_animating()) { | 186 if (!is_animating()) { |
| 183 if (GetAnimationContainer()->is_running()) | 187 if (internal::GetLayerAnimationContainer()->is_running()) |
| 184 last_step_time_ = GetAnimationContainer()->last_tick_time(); | 188 last_step_time_ = |
| 189 internal::GetLayerAnimationContainer()->last_tick_time(); |
| 185 else | 190 else |
| 186 last_step_time_ = base::TimeTicks::Now(); | 191 last_step_time_ = base::TimeTicks::Now(); |
| 187 } | 192 } |
| 188 | 193 |
| 189 // Collect all the affected properties. | 194 // Collect all the affected properties. |
| 190 LayerAnimationElement::AnimatableProperties animated_properties; | 195 LayerAnimationElement::AnimatableProperties animated_properties; |
| 191 std::vector<LayerAnimationSequence*>::const_iterator iter; | 196 std::vector<LayerAnimationSequence*>::const_iterator iter; |
| 192 for (iter = animations.begin(); iter != animations.end(); ++iter) { | 197 for (iter = animations.begin(); iter != animations.end(); ++iter) { |
| 193 animated_properties.insert((*iter)->properties().begin(), | 198 animated_properties.insert((*iter)->properties().begin(), |
| 194 (*iter)->properties().end()); | 199 (*iter)->properties().end()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 base::TimeDelta LayerAnimator::GetTimerInterval() const { | 387 base::TimeDelta LayerAnimator::GetTimerInterval() const { |
| 383 return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); | 388 return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); |
| 384 } | 389 } |
| 385 | 390 |
| 386 void LayerAnimator::UpdateAnimationState() { | 391 void LayerAnimator::UpdateAnimationState() { |
| 387 if (disable_timer_for_test_) | 392 if (disable_timer_for_test_) |
| 388 return; | 393 return; |
| 389 | 394 |
| 390 const bool should_start = is_animating(); | 395 const bool should_start = is_animating(); |
| 391 if (should_start && !is_started_) | 396 if (should_start && !is_started_) |
| 392 GetAnimationContainer()->Start(this); | 397 internal::GetLayerAnimationContainer()->Start(this); |
| 393 else if (!should_start && is_started_) | 398 else if (!should_start && is_started_) |
| 394 GetAnimationContainer()->Stop(this); | 399 internal::GetLayerAnimationContainer()->Stop(this); |
| 395 | 400 |
| 396 is_started_ = should_start; | 401 is_started_ = should_start; |
| 397 } | 402 } |
| 398 | 403 |
| 399 LayerAnimationSequence* LayerAnimator::RemoveAnimation( | 404 LayerAnimationSequence* LayerAnimator::RemoveAnimation( |
| 400 LayerAnimationSequence* sequence) { | 405 LayerAnimationSequence* sequence) { |
| 401 linked_ptr<LayerAnimationSequence> to_return; | 406 linked_ptr<LayerAnimationSequence> to_return; |
| 402 | 407 |
| 403 // First remove from running animations | 408 // First remove from running animations |
| 404 for (RunningAnimations::iterator iter = running_animations_.begin(); | 409 for (RunningAnimations::iterator iter = running_animations_.begin(); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 // All clear, actually start the sequence. Note: base::TimeTicks::Now has | 673 // All clear, actually start the sequence. Note: base::TimeTicks::Now has |
| 669 // a resolution that can be as bad as 15ms. If this causes glitches in the | 674 // a resolution that can be as bad as 15ms. If this causes glitches in the |
| 670 // animations, this can be switched to HighResNow() (animation uses Now() | 675 // animations, this can be switched to HighResNow() (animation uses Now() |
| 671 // internally). | 676 // internally). |
| 672 // All LayerAnimators share the same AnimationContainer. Use the | 677 // All LayerAnimators share the same AnimationContainer. Use the |
| 673 // last_tick_time() from there to ensure animations started during the same | 678 // last_tick_time() from there to ensure animations started during the same |
| 674 // event complete at the same time. | 679 // event complete at the same time. |
| 675 base::TimeTicks start_time; | 680 base::TimeTicks start_time; |
| 676 if (is_animating() || adding_animations_) | 681 if (is_animating() || adding_animations_) |
| 677 start_time = last_step_time_; | 682 start_time = last_step_time_; |
| 678 else if (GetAnimationContainer()->is_running()) | 683 else if (internal::GetLayerAnimationContainer()->is_running()) |
| 679 start_time = GetAnimationContainer()->last_tick_time(); | 684 start_time = internal::GetLayerAnimationContainer()->last_tick_time(); |
| 680 else | 685 else |
| 681 start_time = base::TimeTicks::Now(); | 686 start_time = base::TimeTicks::Now(); |
| 682 | 687 |
| 683 running_animations_.push_back( | 688 running_animations_.push_back( |
| 684 RunningAnimation(sequence->AsWeakPtr(), start_time)); | 689 RunningAnimation(sequence->AsWeakPtr(), start_time)); |
| 685 | 690 |
| 686 // Need to keep a reference to the animation. | 691 // Need to keep a reference to the animation. |
| 687 AddToQueueIfNotPresent(sequence); | 692 AddToQueueIfNotPresent(sequence); |
| 688 | 693 |
| 689 // Ensure that animations get stepped at their start time. | 694 // Ensure that animations get stepped at their start time. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 LayerAnimator::RunningAnimation::RunningAnimation( | 754 LayerAnimator::RunningAnimation::RunningAnimation( |
| 750 const base::WeakPtr<LayerAnimationSequence>& sequence, | 755 const base::WeakPtr<LayerAnimationSequence>& sequence, |
| 751 base::TimeTicks start_time) | 756 base::TimeTicks start_time) |
| 752 : sequence_(sequence), | 757 : sequence_(sequence), |
| 753 start_time_(start_time) { | 758 start_time_(start_time) { |
| 754 } | 759 } |
| 755 | 760 |
| 756 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 761 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 757 | 762 |
| 758 } // namespace ui | 763 } // namespace ui |
| OLD | NEW |