| 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 LayerAnimationSequence* sequence, bool abort) { | 590 LayerAnimationSequence* sequence, bool abort) { |
| 591 // For all the running animations, if they animate the same property, | 591 // For all the running animations, if they animate the same property, |
| 592 // progress them to the end and remove them. Note, Aborting or Progressing | 592 // progress them to the end and remove them. Note, Aborting or Progressing |
| 593 // animations may affect the collection of running animations, so we need to | 593 // animations may affect the collection of running animations, so we need to |
| 594 // operate on a copy. | 594 // operate on a copy. |
| 595 RunningAnimations running_animations_copy = running_animations_; | 595 RunningAnimations running_animations_copy = running_animations_; |
| 596 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 596 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
| 597 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 597 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
| 598 continue; | 598 continue; |
| 599 | 599 |
| 600 if (running_animations_copy[i].sequence()->HasCommonProperty( | 600 if (running_animations_copy[i].sequence()->HasConflictingProperty( |
| 601 sequence->properties())) { | 601 sequence->properties())) { |
| 602 scoped_ptr<LayerAnimationSequence> removed( | 602 scoped_ptr<LayerAnimationSequence> removed( |
| 603 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); | 603 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
| 604 if (abort) | 604 if (abort) |
| 605 running_animations_copy[i].sequence()->Abort(delegate()); | 605 running_animations_copy[i].sequence()->Abort(delegate()); |
| 606 else | 606 else |
| 607 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); | 607 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 | 610 |
| 611 // Same for the queued animations that haven't been started. Again, we'll | 611 // Same for the queued animations that haven't been started. Again, we'll |
| 612 // need to operate on a copy. | 612 // need to operate on a copy. |
| 613 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; | 613 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
| 614 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 614 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 615 queue_iter != animation_queue_.end(); ++queue_iter) | 615 queue_iter != animation_queue_.end(); ++queue_iter) |
| 616 sequences.push_back((*queue_iter)->AsWeakPtr()); | 616 sequences.push_back((*queue_iter)->AsWeakPtr()); |
| 617 | 617 |
| 618 for (size_t i = 0; i < sequences.size(); ++i) { | 618 for (size_t i = 0; i < sequences.size(); ++i) { |
| 619 if (!sequences[i] || !HasAnimation(sequences[i])) | 619 if (!sequences[i] || !HasAnimation(sequences[i])) |
| 620 continue; | 620 continue; |
| 621 | 621 |
| 622 if (sequences[i]->HasCommonProperty(sequence->properties())) { | 622 if (sequences[i]->HasConflictingProperty(sequence->properties())) { |
| 623 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequences[i])); | 623 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequences[i])); |
| 624 if (abort) | 624 if (abort) |
| 625 sequences[i]->Abort(delegate()); | 625 sequences[i]->Abort(delegate()); |
| 626 else | 626 else |
| 627 ProgressAnimationToEnd(sequences[i]); | 627 ProgressAnimationToEnd(sequences[i]); |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 | 631 |
| 632 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { | 632 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 // need to operate on a copy. | 730 // need to operate on a copy. |
| 731 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; | 731 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
| 732 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 732 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 733 queue_iter != animation_queue_.end(); ++queue_iter) | 733 queue_iter != animation_queue_.end(); ++queue_iter) |
| 734 sequences.push_back((*queue_iter)->AsWeakPtr()); | 734 sequences.push_back((*queue_iter)->AsWeakPtr()); |
| 735 | 735 |
| 736 for (size_t i = 0; i < sequences.size(); ++i) { | 736 for (size_t i = 0; i < sequences.size(); ++i) { |
| 737 if (!sequences[i] || !HasAnimation(sequences[i])) | 737 if (!sequences[i] || !HasAnimation(sequences[i])) |
| 738 continue; | 738 continue; |
| 739 | 739 |
| 740 if (!sequences[i]->HasCommonProperty(animated)) { | 740 if (!sequences[i]->HasConflictingProperty(animated)) { |
| 741 StartSequenceImmediately(sequences[i].get()); | 741 StartSequenceImmediately(sequences[i].get()); |
| 742 started_sequence = true; | 742 started_sequence = true; |
| 743 break; | 743 break; |
| 744 } | 744 } |
| 745 | 745 |
| 746 // Animation couldn't be started. Add its properties to the collection so | 746 // Animation couldn't be started. Add its properties to the collection so |
| 747 // that we don't start a conflicting animation. For example, if our queue | 747 // that we don't start a conflicting animation. For example, if our queue |
| 748 // has the elements { {T,B}, {B} } (that is, an element that animates both | 748 // has the elements { {T,B}, {B} } (that is, an element that animates both |
| 749 // the transform and the bounds followed by an element that animates the | 749 // the transform and the bounds followed by an element that animates the |
| 750 // bounds), and we're currently animating the transform, we can't start | 750 // bounds), and we're currently animating the transform, we can't start |
| 751 // the first element because it animates the transform, too. We cannot | 751 // the first element because it animates the transform, too. We cannot |
| 752 // start the second element, either, because the first element animates | 752 // start the second element, either, because the first element animates |
| 753 // bounds too, and needs to go first. | 753 // bounds too, and needs to go first. |
| 754 animated.insert(sequences[i]->properties().begin(), | 754 animated.insert(sequences[i]->properties().begin(), |
| 755 sequences[i]->properties().end()); | 755 sequences[i]->properties().end()); |
| 756 } | 756 } |
| 757 | 757 |
| 758 // If we started a sequence, try again. We may be able to start several. | 758 // If we started a sequence, try again. We may be able to start several. |
| 759 } while (started_sequence); | 759 } while (started_sequence); |
| 760 } | 760 } |
| 761 | 761 |
| 762 bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { | 762 bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { |
| 763 PurgeDeletedAnimations(); | 763 PurgeDeletedAnimations(); |
| 764 | 764 |
| 765 // Ensure that no one is animating one of the sequence's properties already. | 765 // Ensure that no one is animating one of the sequence's properties already. |
| 766 for (RunningAnimations::const_iterator iter = running_animations_.begin(); | 766 for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 767 iter != running_animations_.end(); ++iter) { | 767 iter != running_animations_.end(); ++iter) { |
| 768 if ((*iter).sequence()->HasCommonProperty(sequence->properties())) | 768 if ((*iter).sequence()->HasConflictingProperty(sequence->properties())) |
| 769 return false; | 769 return false; |
| 770 } | 770 } |
| 771 | 771 |
| 772 // All clear, actually start the sequence. Note: base::TimeTicks::Now has | 772 // All clear, actually start the sequence. Note: base::TimeTicks::Now has |
| 773 // a resolution that can be as bad as 15ms. If this causes glitches in the | 773 // a resolution that can be as bad as 15ms. If this causes glitches in the |
| 774 // animations, this can be switched to HighResNow() (animation uses Now() | 774 // animations, this can be switched to HighResNow() (animation uses Now() |
| 775 // internally). | 775 // internally). |
| 776 // All LayerAnimators share the same AnimationContainer. Use the | 776 // All LayerAnimators share the same AnimationContainer. Use the |
| 777 // last_tick_time() from there to ensure animations started during the same | 777 // last_tick_time() from there to ensure animations started during the same |
| 778 // event complete at the same time. | 778 // event complete at the same time. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 } | 857 } |
| 858 | 858 |
| 859 LayerAnimator::RunningAnimation::RunningAnimation( | 859 LayerAnimator::RunningAnimation::RunningAnimation( |
| 860 const base::WeakPtr<LayerAnimationSequence>& sequence) | 860 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 861 : sequence_(sequence) { | 861 : sequence_(sequence) { |
| 862 } | 862 } |
| 863 | 863 |
| 864 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 864 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 865 | 865 |
| 866 } // namespace ui | 866 } // namespace ui |
| OLD | NEW |