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 | |
ajuma
2014/08/01 15:26:47
Nit: WaitingForDeletion
shreyas.g
2014/08/01 15:43:39
Done.
| |
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). Since the list is already maintained in anims_same_group |
777 for (size_t j = i; j < animations_.size(); j++) { | 792 // just need to traverse that list. |
ajuma
2014/08/01 15:26:47
Nit: This additional comment isn't needed, the nam
shreyas.g
2014/08/01 15:43:39
Done.
| |
778 if (animations_[j]->group() == group_id && | 793 for (size_t j = 0; j < animations_with_same_group_id.size(); j++) { |
779 animations_[j]->run_state() != Animation::Aborted) { | 794 size_t animation_index = animations_with_same_group_id[j]; |
780 if (events) { | 795 if (events) { |
781 AnimationEvent finished_event(AnimationEvent::Finished, | 796 AnimationEvent finished_event( |
782 id_, | 797 AnimationEvent::Finished, |
783 animations_[j]->group(), | 798 id_, |
784 animations_[j]->target_property(), | 799 animations_[animation_index]->group(), |
785 monotonic_time); | 800 animations_[animation_index]->target_property(), |
786 finished_event.is_impl_only = animations_[j]->is_impl_only(); | 801 monotonic_time); |
802 finished_event.is_impl_only = | |
803 animations_[animation_index]->is_impl_only(); | |
787 if (finished_event.is_impl_only) | 804 if (finished_event.is_impl_only) |
788 NotifyAnimationFinished(finished_event); | 805 NotifyAnimationFinished(finished_event); |
789 else | 806 else |
790 events->push_back(finished_event); | 807 events->push_back(finished_event); |
791 } | 808 } |
792 animations_[j]->SetRunState(Animation::WaitingForDeletion, | 809 animations_[animation_index]->SetRunState( |
793 monotonic_time); | 810 Animation::WaitingForDeletion, monotonic_time); |
794 } | |
795 } | 811 } |
796 marked_animations_for_deletions = true; | 812 marked_animations_for_deletions = true; |
797 } | 813 } |
798 } | 814 } |
799 if (marked_animations_for_deletions) | 815 if (marked_animations_for_deletions) |
800 NotifyObserversAnimationWaitingForDeletion(); | 816 NotifyObserversAnimationWaitingForDeletion(); |
801 } | 817 } |
802 | 818 |
803 static bool IsWaitingForDeletion(Animation* animation) { | 819 static bool IsWaitingForDeletion(Animation* animation) { |
804 return animation->run_state() == Animation::WaitingForDeletion; | 820 return animation->run_state() == Animation::WaitingForDeletion; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 value_observers_); | 1001 value_observers_); |
986 LayerAnimationValueObserver* obs; | 1002 LayerAnimationValueObserver* obs; |
987 while ((obs = it.GetNext()) != NULL) | 1003 while ((obs = it.GetNext()) != NULL) |
988 if (obs->IsActive()) | 1004 if (obs->IsActive()) |
989 return true; | 1005 return true; |
990 } | 1006 } |
991 return false; | 1007 return false; |
992 } | 1008 } |
993 | 1009 |
994 } // namespace cc | 1010 } // namespace cc |
OLD | NEW |