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

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

Issue 2796013003: cc: Push Animation Finished State and Use Finished State for IsCompleted (Closed)
Patch Set: clear events before update state in unittest Created 3 years, 8 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 | cc/animation/animation_player_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/animation_player.h" 5 #include "cc/animation/animation_player.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "cc/animation/animation_delegate.h" 10 #include "cc/animation/animation_delegate.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 animations_[i]->set_received_finished_event(true); 367 animations_[i]->set_received_finished_event(true);
368 368
369 if (animation_delegate_) { 369 if (animation_delegate_) {
370 animation_delegate_->NotifyAnimationFinished( 370 animation_delegate_->NotifyAnimationFinished(
371 event.monotonic_time, event.target_property, event.group_id); 371 event.monotonic_time, event.target_property, event.group_id);
372 } 372 }
373 return true; 373 return true;
374 } 374 }
375 } 375 }
376 376
377 // This is for the case when an animation is already removed on main thread,
378 // but the impl version of it sent a finished event and is now waiting for
379 // deletion. We would need to delete that animation during push properties.
380 SetNeedsPushProperties();
377 return false; 381 return false;
378 } 382 }
379 383
380 bool AnimationPlayer::NotifyAnimationFinishedForTesting( 384 bool AnimationPlayer::NotifyAnimationFinishedForTesting(
381 TargetProperty::Type target_property, 385 TargetProperty::Type target_property,
382 int group_id) { 386 int group_id) {
383 AnimationEvent event(AnimationEvent::FINISHED, element_id_, group_id, 387 AnimationEvent event(AnimationEvent::FINISHED, element_id_, group_id,
384 target_property, base::TimeTicks()); 388 target_property, base::TimeTicks());
385 return NotifyAnimationFinished(event); 389 return NotifyAnimationFinished(event);
386 } 390 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 } 792 }
789 793
790 void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) { 794 void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
791 bool animation_finished = false; 795 bool animation_finished = false;
792 796
793 for (size_t i = 0; i < animations_.size(); ++i) { 797 for (size_t i = 0; i < animations_.size(); ++i) {
794 if (!animations_[i]->is_finished() && 798 if (!animations_[i]->is_finished() &&
795 animations_[i]->IsFinishedAt(monotonic_time)) { 799 animations_[i]->IsFinishedAt(monotonic_time)) {
796 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); 800 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
797 animation_finished = true; 801 animation_finished = true;
802 SetNeedsPushProperties();
803 }
804 if (!animations_[i]->affects_active_elements() &&
805 !animations_[i]->affects_pending_elements()) {
806 switch (animations_[i]->run_state()) {
807 case Animation::WAITING_FOR_TARGET_AVAILABILITY:
808 case Animation::STARTING:
809 case Animation::RUNNING:
810 case Animation::PAUSED:
811 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
812 animation_finished = true;
813 break;
814 default:
815 break;
816 }
798 } 817 }
799 } 818 }
800 819
801 DCHECK(element_animations_); 820 DCHECK(element_animations_);
802 if (animation_finished) 821 if (animation_finished)
803 element_animations_->UpdateClientAnimationState(); 822 element_animations_->UpdateClientAnimationState();
804 } 823 }
805 824
806 void AnimationPlayer::ActivateAnimations() { 825 void AnimationPlayer::ActivateAnimations() {
807 bool animation_activated = false; 826 bool animation_activated = false;
808 827
809 for (size_t i = 0; i < animations_.size(); ++i) { 828 for (size_t i = 0; i < animations_.size(); ++i) {
810 if (animations_[i]->affects_active_elements() != 829 if (animations_[i]->affects_active_elements() !=
811 animations_[i]->affects_pending_elements()) { 830 animations_[i]->affects_pending_elements()) {
812 animation_activated = true; 831 animation_activated = true;
813 } 832 }
814 animations_[i]->set_affects_active_elements( 833 animations_[i]->set_affects_active_elements(
815 animations_[i]->affects_pending_elements()); 834 animations_[i]->affects_pending_elements());
816 } 835 }
817 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) {
818 return !animation->affects_active_elements() &&
819 !animation->affects_pending_elements();
820 };
821 base::EraseIf(animations_, affects_no_elements);
822 836
823 if (animation_activated) 837 if (animation_activated)
824 element_animations_->UpdateClientAnimationState(); 838 element_animations_->UpdateClientAnimationState();
825 839
826 scroll_offset_animation_was_interrupted_ = false; 840 scroll_offset_animation_was_interrupted_ = false;
827 UpdateTickingState(UpdateTickingType::NORMAL); 841 UpdateTickingState(UpdateTickingType::NORMAL);
828 } 842 }
829 843
830 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const { 844 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const {
831 for (size_t i = 0; i < animations_.size(); ++i) { 845 for (size_t i = 0; i < animations_.size(); ++i) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 to_add->set_affects_active_elements(false); 1158 to_add->set_affects_active_elements(false);
1145 animation_player_impl->AddAnimation(std::move(to_add)); 1159 animation_player_impl->AddAnimation(std::move(to_add));
1146 } 1160 }
1147 } 1161 }
1148 1162
1149 static bool IsCompleted(Animation* animation, 1163 static bool IsCompleted(Animation* animation,
1150 const AnimationPlayer* main_thread_player) { 1164 const AnimationPlayer* main_thread_player) {
1151 if (animation->is_impl_only()) { 1165 if (animation->is_impl_only()) {
1152 return (animation->run_state() == Animation::WAITING_FOR_DELETION); 1166 return (animation->run_state() == Animation::WAITING_FOR_DELETION);
1153 } else { 1167 } else {
1154 return !main_thread_player->GetAnimationById(animation->id()); 1168 Animation* main_thread_animation =
1169 main_thread_player->GetAnimationById(animation->id());
1170 return !main_thread_animation || main_thread_animation->is_finished();
1155 } 1171 }
1156 } 1172 }
1157 1173
1158 void AnimationPlayer::RemoveAnimationsCompletedOnMainThread( 1174 void AnimationPlayer::RemoveAnimationsCompletedOnMainThread(
1159 AnimationPlayer* animation_player_impl) const { 1175 AnimationPlayer* animation_player_impl) const {
1160 bool animation_completed = false; 1176 bool animation_completed = false;
1161 1177
1162 // Animations removed on the main thread should no longer affect pending 1178 // Animations removed on the main thread should no longer affect pending
1163 // elements, and should stop affecting active elements after the next call 1179 // elements, and should stop affecting active elements after the next call
1164 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed 1180 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed
(...skipping 24 matching lines...) Expand all
1189 if (current_impl) 1205 if (current_impl)
1190 animations_[i]->PushPropertiesTo(current_impl); 1206 animations_[i]->PushPropertiesTo(current_impl);
1191 } 1207 }
1192 1208
1193 animation_player_impl->scroll_offset_animation_was_interrupted_ = 1209 animation_player_impl->scroll_offset_animation_was_interrupted_ =
1194 scroll_offset_animation_was_interrupted_; 1210 scroll_offset_animation_was_interrupted_;
1195 scroll_offset_animation_was_interrupted_ = false; 1211 scroll_offset_animation_was_interrupted_ = false;
1196 } 1212 }
1197 1213
1198 } // namespace cc 1214 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/animation/animation_player_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698