Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: cc/animation/layer_animation_controller.cc

Issue 429223002: Reduced iterations for group-id check in MarkAnimationsForDeletions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reduced iterations for group-id check in MarkAnimationsForDeleteion Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
728 size_t animations_with_same_group_id_count_;
729 bool animations_with_same_group_id_reserved = false;
727 730
728 // Non-aborted animations are marked for deletion after a corresponding 731 // Non-aborted animations are marked for deletion after a corresponding
729 // AnimationEvent::Finished event is sent or received. This means that if 732 // 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 733 // 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. 734 // have received a finished event before marking them for deletion.
732 for (size_t i = 0; i < animations_.size(); i++) { 735 for (size_t i = 0; i < animations_.size(); i++) {
733 int group_id = animations_[i]->group(); 736 int group_id = animations_[i]->group();
734 if (animations_[i]->run_state() == Animation::Aborted) { 737 if (animations_[i]->run_state() == Animation::Aborted) {
735 if (events && !animations_[i]->is_impl_only()) { 738 if (events && !animations_[i]->is_impl_only()) {
736 AnimationEvent aborted_event(AnimationEvent::Aborted, 739 AnimationEvent aborted_event(AnimationEvent::Aborted,
(...skipping 12 matching lines...) Expand all
749 bool all_anims_with_same_id_are_finished = false; 752 bool all_anims_with_same_id_are_finished = false;
750 753
751 // Since deleting an animation on the main thread leads to its deletion 754 // 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 755 // 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. 756 // deletion once it has received a Finished event from the impl thread.
754 bool animation_i_will_send_or_has_received_finish_event = 757 bool animation_i_will_send_or_has_received_finish_event =
755 events || animations_[i]->received_finished_event(); 758 events || animations_[i]->received_finished_event();
756 // If an animation is finished, and not already marked for deletion, 759 // 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. 760 // find out if all other animations in the same group are also finished.
758 if (animations_[i]->run_state() == Animation::Finished && 761 if (animations_[i]->run_state() == Animation::Finished &&
759 animation_i_will_send_or_has_received_finish_event) { 762 animation_i_will_send_or_has_received_finish_event) {
ajuma 2014/07/30 15:22:47 What if you just create the animations_with_same_g
shreyas.g 2014/07/30 15:52:59 Thanks Ajuma. The problem here is that, if i decla
ajuma 2014/07/30 16:00:00 Hmm. Creating a vector for each animation in the m
shreyas.g 2014/08/01 08:44:04 Yes, clear is working now. I had previously tried
763 // Reset the count of marked animations in animations_with_same_group_id.
764 // This is done to avoid the usage of vector.clear() method
765 // which is a costly operation.
766 animations_with_same_group_id_count_ = 0;
760 all_anims_with_same_id_are_finished = true; 767 all_anims_with_same_id_are_finished = true;
761 for (size_t j = 0; j < animations_.size(); ++j) { 768 for (size_t j = 0; j < animations_.size(); ++j) {
762 bool animation_j_will_send_or_has_received_finish_event = 769 bool animation_j_will_send_or_has_received_finish_event =
763 events || animations_[j]->received_finished_event(); 770 events || animations_[j]->received_finished_event();
764 if (group_id == animations_[j]->group() && 771 if (group_id == animations_[j]->group()) {
765 (!animations_[j]->is_finished() || 772 if (!animations_[j]->is_finished() ||
766 (animations_[j]->run_state() == Animation::Finished && 773 (animations_[j]->run_state() == Animation::Finished &&
767 !animation_j_will_send_or_has_received_finish_event))) { 774 !animation_j_will_send_or_has_received_finish_event)) {
768 all_anims_with_same_id_are_finished = false; 775 all_anims_with_same_id_are_finished = false;
769 break; 776 break;
777 } else if (j >= i &&
778 animations_[j]->run_state() != Animation::Aborted) {
779 // Mark down the animations which belong to the same group
780 // and is not yet aborted. If this current iteration finds that all
781 // animations with same ID are finished, then the marked
782 // animations below will be set to waitingForDeletion in next
783 // iteration.
784 animations_with_same_group_id.push_back(j);
785 animations_with_same_group_id_count_++;
786 // The animation list belonging to same group needs to be only
787 // reserved in case atleast one other animation has the same ID
788 // and is not aborted yet. Once reserved, it can be used till the
789 // function exits. This avoids reserving in cases no other animation
790 // is marked in current iteration.
791 if (!animations_with_same_group_id_reserved) {
792 animations_with_same_group_id_reserved = true;
793 animations_with_same_group_id.reserve(animations_.size());
794 }
795 }
770 } 796 }
771 } 797 }
772 } 798 }
773 if (all_anims_with_same_id_are_finished) { 799 if (all_anims_with_same_id_are_finished) {
774 // We now need to remove all animations with the same group id as 800 // We now need to remove all animations with the same group id as
775 // group_id (and send along animation finished notifications, if 801 // group_id (and send along animation finished notifications, if
776 // necessary). 802 // necessary). Since the list is already maintained in anims_same_group
777 for (size_t j = i; j < animations_.size(); j++) { 803 // just need to traverse that list.
778 if (animations_[j]->group() == group_id && 804 for (size_t j = 0; j < animations_with_same_group_id_count_; j++) {
779 animations_[j]->run_state() != Animation::Aborted) { 805 size_t animation_index = animations_with_same_group_id[j];
780 if (events) { 806 if (events) {
781 AnimationEvent finished_event(AnimationEvent::Finished, 807 AnimationEvent finished_event(
782 id_, 808 AnimationEvent::Finished,
783 animations_[j]->group(), 809 id_,
784 animations_[j]->target_property(), 810 animations_[animation_index]->group(),
785 monotonic_time); 811 animations_[animation_index]->target_property(),
786 finished_event.is_impl_only = animations_[j]->is_impl_only(); 812 monotonic_time);
813 finished_event.is_impl_only =
814 animations_[animation_index]->is_impl_only();
787 if (finished_event.is_impl_only) 815 if (finished_event.is_impl_only)
788 NotifyAnimationFinished(finished_event); 816 NotifyAnimationFinished(finished_event);
789 else 817 else
790 events->push_back(finished_event); 818 events->push_back(finished_event);
791 } 819 }
792 animations_[j]->SetRunState(Animation::WaitingForDeletion, 820 animations_[animation_index]->SetRunState(
793 monotonic_time); 821 Animation::WaitingForDeletion, monotonic_time);
794 }
795 } 822 }
796 marked_animations_for_deletions = true; 823 marked_animations_for_deletions = true;
797 } 824 }
798 } 825 }
799 if (marked_animations_for_deletions) 826 if (marked_animations_for_deletions)
800 NotifyObserversAnimationWaitingForDeletion(); 827 NotifyObserversAnimationWaitingForDeletion();
801 } 828 }
802 829
803 static bool IsWaitingForDeletion(Animation* animation) { 830 static bool IsWaitingForDeletion(Animation* animation) {
804 return animation->run_state() == Animation::WaitingForDeletion; 831 return animation->run_state() == Animation::WaitingForDeletion;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 value_observers_); 1012 value_observers_);
986 LayerAnimationValueObserver* obs; 1013 LayerAnimationValueObserver* obs;
987 while ((obs = it.GetNext()) != NULL) 1014 while ((obs = it.GetNext()) != NULL)
988 if (obs->IsActive()) 1015 if (obs->IsActive())
989 return true; 1016 return true;
990 } 1017 }
991 return false; 1018 return false;
992 } 1019 }
993 1020
994 } // namespace cc 1021 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698