OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/animation/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/animation/animation.h" | 9 #include "cc/animation/animation.h" |
10 #include "cc/animation/animation_delegate.h" | 10 #include "cc/animation/animation_delegate.h" |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 animations_[i]->run_state() != Animation::Aborted && | 717 animations_[i]->run_state() != Animation::Aborted && |
718 animations_[i]->run_state() != Animation::WaitingForDeletion) | 718 animations_[i]->run_state() != Animation::WaitingForDeletion) |
719 animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 719 animations_[i]->SetRunState(Animation::Finished, monotonic_time); |
720 } | 720 } |
721 } | 721 } |
722 | 722 |
723 void LayerAnimationController::MarkAnimationsForDeletion( | 723 void LayerAnimationController::MarkAnimationsForDeletion( |
724 base::TimeTicks monotonic_time, | 724 base::TimeTicks monotonic_time, |
725 AnimationEventsVector* events) { | 725 AnimationEventsVector* events) { |
726 bool marked_animations_for_deletions = false; | 726 bool marked_animations_for_deletions = false; |
| 727 std::vector<size_t> animations_with_same_group_id; |
727 | 728 |
| 729 animations_with_same_group_id.reserve(animations_.size()); |
728 // Non-aborted animations are marked for deletion after a corresponding | 730 // Non-aborted animations are marked for deletion after a corresponding |
729 // AnimationEvent::Finished event is sent or received. This means that if | 731 // AnimationEvent::Finished event is sent or received. This means that if |
730 // we don't have an events vector, we must ensure that non-aborted animations | 732 // we don't have an events vector, we must ensure that non-aborted animations |
731 // have received a finished event before marking them for deletion. | 733 // have received a finished event before marking them for deletion. |
732 for (size_t i = 0; i < animations_.size(); i++) { | 734 for (size_t i = 0; i < animations_.size(); i++) { |
733 int group_id = animations_[i]->group(); | 735 int group_id = animations_[i]->group(); |
734 if (animations_[i]->run_state() == Animation::Aborted) { | 736 if (animations_[i]->run_state() == Animation::Aborted) { |
735 if (events && !animations_[i]->is_impl_only()) { | 737 if (events && !animations_[i]->is_impl_only()) { |
736 AnimationEvent aborted_event(AnimationEvent::Aborted, | 738 AnimationEvent aborted_event(AnimationEvent::Aborted, |
737 id_, | 739 id_, |
(...skipping 12 matching lines...) Expand all Loading... |
750 | 752 |
751 // Since deleting an animation on the main thread leads to its deletion | 753 // Since deleting an animation on the main thread leads to its deletion |
752 // on the impl thread, we only mark a Finished main thread animation for | 754 // on the impl thread, we only mark a Finished main thread animation for |
753 // deletion once it has received a Finished event from the impl thread. | 755 // deletion once it has received a Finished event from the impl thread. |
754 bool animation_i_will_send_or_has_received_finish_event = | 756 bool animation_i_will_send_or_has_received_finish_event = |
755 events || animations_[i]->received_finished_event(); | 757 events || animations_[i]->received_finished_event(); |
756 // If an animation is finished, and not already marked for deletion, | 758 // If an animation is finished, and not already marked for deletion, |
757 // find out if all other animations in the same group are also finished. | 759 // find out if all other animations in the same group are also finished. |
758 if (animations_[i]->run_state() == Animation::Finished && | 760 if (animations_[i]->run_state() == Animation::Finished && |
759 animation_i_will_send_or_has_received_finish_event) { | 761 animation_i_will_send_or_has_received_finish_event) { |
| 762 // Clear the animations_with_same_group_id if it was added for |
| 763 // the previous animation's iteration. |
| 764 if (animations_with_same_group_id.size() > 0) |
| 765 animations_with_same_group_id.clear(); |
760 all_anims_with_same_id_are_finished = true; | 766 all_anims_with_same_id_are_finished = true; |
761 for (size_t j = 0; j < animations_.size(); ++j) { | 767 for (size_t j = 0; j < animations_.size(); ++j) { |
762 bool animation_j_will_send_or_has_received_finish_event = | 768 bool animation_j_will_send_or_has_received_finish_event = |
763 events || animations_[j]->received_finished_event(); | 769 events || animations_[j]->received_finished_event(); |
764 if (group_id == animations_[j]->group() && | 770 if (group_id == animations_[j]->group()) { |
765 (!animations_[j]->is_finished() || | 771 if (!animations_[j]->is_finished() || |
766 (animations_[j]->run_state() == Animation::Finished && | 772 (animations_[j]->run_state() == Animation::Finished && |
767 !animation_j_will_send_or_has_received_finish_event))) { | 773 !animation_j_will_send_or_has_received_finish_event)) { |
768 all_anims_with_same_id_are_finished = false; | 774 all_anims_with_same_id_are_finished = false; |
769 break; | 775 break; |
| 776 } else if (j >= i && |
| 777 animations_[j]->run_state() != Animation::Aborted) { |
| 778 // Mark down the animations which belong to the same group |
| 779 // and is not yet aborted. If this current iteration finds that all |
| 780 // animations with same ID are finished, then the marked |
| 781 // animations below will be set to WaitingForDeletion in next |
| 782 // iteration. |
| 783 animations_with_same_group_id.push_back(j); |
| 784 } |
770 } | 785 } |
771 } | 786 } |
772 } | 787 } |
773 if (all_anims_with_same_id_are_finished) { | 788 if (all_anims_with_same_id_are_finished) { |
774 // We now need to remove all animations with the same group id as | 789 // We now need to remove all animations with the same group id as |
775 // group_id (and send along animation finished notifications, if | 790 // group_id (and send along animation finished notifications, if |
776 // necessary). | 791 // necessary). |
777 for (size_t j = i; j < animations_.size(); j++) { | 792 for (size_t j = 0; j < animations_with_same_group_id.size(); j++) { |
778 if (animations_[j]->group() == group_id && | 793 size_t animation_index = animations_with_same_group_id[j]; |
779 animations_[j]->run_state() != Animation::Aborted) { | |
780 if (events) { | 794 if (events) { |
781 AnimationEvent finished_event(AnimationEvent::Finished, | 795 AnimationEvent finished_event( |
782 id_, | 796 AnimationEvent::Finished, |
783 animations_[j]->group(), | 797 id_, |
784 animations_[j]->target_property(), | 798 animations_[animation_index]->group(), |
785 monotonic_time); | 799 animations_[animation_index]->target_property(), |
786 finished_event.is_impl_only = animations_[j]->is_impl_only(); | 800 monotonic_time); |
| 801 finished_event.is_impl_only = |
| 802 animations_[animation_index]->is_impl_only(); |
787 if (finished_event.is_impl_only) | 803 if (finished_event.is_impl_only) |
788 NotifyAnimationFinished(finished_event); | 804 NotifyAnimationFinished(finished_event); |
789 else | 805 else |
790 events->push_back(finished_event); | 806 events->push_back(finished_event); |
791 } | 807 } |
792 animations_[j]->SetRunState(Animation::WaitingForDeletion, | 808 animations_[animation_index]->SetRunState( |
793 monotonic_time); | 809 Animation::WaitingForDeletion, monotonic_time); |
794 } | |
795 } | 810 } |
796 marked_animations_for_deletions = true; | 811 marked_animations_for_deletions = true; |
797 } | 812 } |
798 } | 813 } |
799 if (marked_animations_for_deletions) | 814 if (marked_animations_for_deletions) |
800 NotifyObserversAnimationWaitingForDeletion(); | 815 NotifyObserversAnimationWaitingForDeletion(); |
801 } | 816 } |
802 | 817 |
803 static bool IsWaitingForDeletion(Animation* animation) { | 818 static bool IsWaitingForDeletion(Animation* animation) { |
804 return animation->run_state() == Animation::WaitingForDeletion; | 819 return animation->run_state() == Animation::WaitingForDeletion; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 value_observers_); | 1000 value_observers_); |
986 LayerAnimationValueObserver* obs; | 1001 LayerAnimationValueObserver* obs; |
987 while ((obs = it.GetNext()) != NULL) | 1002 while ((obs = it.GetNext()) != NULL) |
988 if (obs->IsActive()) | 1003 if (obs->IsActive()) |
989 return true; | 1004 return true; |
990 } | 1005 } |
991 return false; | 1006 return false; |
992 } | 1007 } |
993 | 1008 |
994 } // namespace cc | 1009 } // namespace cc |
OLD | NEW |