| 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_id_provider.h" | 10 #include "cc/animation_id_provider.h" |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 LayerAnimationSequence* sequence, bool abort) { | 575 LayerAnimationSequence* sequence, bool abort) { |
| 576 // For all the running animations, if they animate the same property, | 576 // For all the running animations, if they animate the same property, |
| 577 // progress them to the end and remove them. Note, Aborting or Progressing | 577 // progress them to the end and remove them. Note, Aborting or Progressing |
| 578 // animations may affect the collection of running animations, so we need to | 578 // animations may affect the collection of running animations, so we need to |
| 579 // operate on a copy. | 579 // operate on a copy. |
| 580 RunningAnimations running_animations_copy = running_animations_; | 580 RunningAnimations running_animations_copy = running_animations_; |
| 581 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 581 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
| 582 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 582 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
| 583 continue; | 583 continue; |
| 584 | 584 |
| 585 if (running_animations_copy[i].sequence()->HasCommonProperty( | 585 if (running_animations_copy[i].sequence()->HasConflictingProperty( |
| 586 sequence->properties())) { | 586 sequence->properties())) { |
| 587 scoped_ptr<LayerAnimationSequence> removed( | 587 scoped_ptr<LayerAnimationSequence> removed( |
| 588 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); | 588 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
| 589 if (abort) | 589 if (abort) |
| 590 running_animations_copy[i].sequence()->Abort(delegate()); | 590 running_animations_copy[i].sequence()->Abort(delegate()); |
| 591 else | 591 else |
| 592 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); | 592 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 | 595 |
| 596 // Same for the queued animations that haven't been started. Again, we'll | 596 // Same for the queued animations that haven't been started. Again, we'll |
| 597 // need to operate on a copy. | 597 // need to operate on a copy. |
| 598 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; | 598 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
| 599 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 599 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 600 queue_iter != animation_queue_.end(); ++queue_iter) | 600 queue_iter != animation_queue_.end(); ++queue_iter) |
| 601 sequences.push_back((*queue_iter)->AsWeakPtr()); | 601 sequences.push_back((*queue_iter)->AsWeakPtr()); |
| 602 | 602 |
| 603 for (size_t i = 0; i < sequences.size(); ++i) { | 603 for (size_t i = 0; i < sequences.size(); ++i) { |
| 604 if (!sequences[i] || !HasAnimation(sequences[i])) | 604 if (!sequences[i] || !HasAnimation(sequences[i])) |
| 605 continue; | 605 continue; |
| 606 | 606 |
| 607 if (sequences[i]->HasCommonProperty(sequence->properties())) { | 607 if (sequences[i]->HasConflictingProperty(sequence->properties())) { |
| 608 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequences[i])); | 608 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequences[i])); |
| 609 if (abort) | 609 if (abort) |
| 610 sequences[i]->Abort(delegate()); | 610 sequences[i]->Abort(delegate()); |
| 611 else | 611 else |
| 612 ProgressAnimationToEnd(sequences[i]); | 612 ProgressAnimationToEnd(sequences[i]); |
| 613 } | 613 } |
| 614 } | 614 } |
| 615 } | 615 } |
| 616 | 616 |
| 617 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { | 617 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // need to operate on a copy. | 715 // need to operate on a copy. |
| 716 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; | 716 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
| 717 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 717 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 718 queue_iter != animation_queue_.end(); ++queue_iter) | 718 queue_iter != animation_queue_.end(); ++queue_iter) |
| 719 sequences.push_back((*queue_iter)->AsWeakPtr()); | 719 sequences.push_back((*queue_iter)->AsWeakPtr()); |
| 720 | 720 |
| 721 for (size_t i = 0; i < sequences.size(); ++i) { | 721 for (size_t i = 0; i < sequences.size(); ++i) { |
| 722 if (!sequences[i] || !HasAnimation(sequences[i])) | 722 if (!sequences[i] || !HasAnimation(sequences[i])) |
| 723 continue; | 723 continue; |
| 724 | 724 |
| 725 if (!sequences[i]->HasCommonProperty(animated)) { | 725 if (!sequences[i]->HasConflictingProperty(animated)) { |
| 726 StartSequenceImmediately(sequences[i].get()); | 726 StartSequenceImmediately(sequences[i].get()); |
| 727 started_sequence = true; | 727 started_sequence = true; |
| 728 break; | 728 break; |
| 729 } | 729 } |
| 730 | 730 |
| 731 // Animation couldn't be started. Add its properties to the collection so | 731 // Animation couldn't be started. Add its properties to the collection so |
| 732 // that we don't start a conflicting animation. For example, if our queue | 732 // that we don't start a conflicting animation. For example, if our queue |
| 733 // has the elements { {T,B}, {B} } (that is, an element that animates both | 733 // has the elements { {T,B}, {B} } (that is, an element that animates both |
| 734 // the transform and the bounds followed by an element that animates the | 734 // the transform and the bounds followed by an element that animates the |
| 735 // bounds), and we're currently animating the transform, we can't start | 735 // bounds), and we're currently animating the transform, we can't start |
| 736 // the first element because it animates the transform, too. We cannot | 736 // the first element because it animates the transform, too. We cannot |
| 737 // start the second element, either, because the first element animates | 737 // start the second element, either, because the first element animates |
| 738 // bounds too, and needs to go first. | 738 // bounds too, and needs to go first. |
| 739 animated.insert(sequences[i]->properties().begin(), | 739 animated.insert(sequences[i]->properties().begin(), |
| 740 sequences[i]->properties().end()); | 740 sequences[i]->properties().end()); |
| 741 } | 741 } |
| 742 | 742 |
| 743 // If we started a sequence, try again. We may be able to start several. | 743 // If we started a sequence, try again. We may be able to start several. |
| 744 } while (started_sequence); | 744 } while (started_sequence); |
| 745 } | 745 } |
| 746 | 746 |
| 747 bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { | 747 bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { |
| 748 PurgeDeletedAnimations(); | 748 PurgeDeletedAnimations(); |
| 749 | 749 |
| 750 // Ensure that no one is animating one of the sequence's properties already. | 750 // Ensure that no one is animating one of the sequence's properties already. |
| 751 for (RunningAnimations::const_iterator iter = running_animations_.begin(); | 751 for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 752 iter != running_animations_.end(); ++iter) { | 752 iter != running_animations_.end(); ++iter) { |
| 753 if ((*iter).sequence()->HasCommonProperty(sequence->properties())) | 753 if ((*iter).sequence()->HasConflictingProperty(sequence->properties())) |
| 754 return false; | 754 return false; |
| 755 } | 755 } |
| 756 | 756 |
| 757 // All clear, actually start the sequence. Note: base::TimeTicks::Now has | 757 // All clear, actually start the sequence. Note: base::TimeTicks::Now has |
| 758 // a resolution that can be as bad as 15ms. If this causes glitches in the | 758 // a resolution that can be as bad as 15ms. If this causes glitches in the |
| 759 // animations, this can be switched to HighResNow() (animation uses Now() | 759 // animations, this can be switched to HighResNow() (animation uses Now() |
| 760 // internally). | 760 // internally). |
| 761 // All LayerAnimators share the same AnimationContainer. Use the | 761 // All LayerAnimators share the same AnimationContainer. Use the |
| 762 // last_tick_time() from there to ensure animations started during the same | 762 // last_tick_time() from there to ensure animations started during the same |
| 763 // event complete at the same time. | 763 // event complete at the same time. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } | 843 } |
| 844 | 844 |
| 845 LayerAnimator::RunningAnimation::RunningAnimation( | 845 LayerAnimator::RunningAnimation::RunningAnimation( |
| 846 const base::WeakPtr<LayerAnimationSequence>& sequence) | 846 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 847 : sequence_(sequence) { | 847 : sequence_(sequence) { |
| 848 } | 848 } |
| 849 | 849 |
| 850 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 850 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 851 | 851 |
| 852 } // namespace ui | 852 } // namespace ui |
| OLD | NEW |