| OLD | NEW |
| 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/element_animations.h" | 5 #include "cc/animation/element_animations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 ElementAnimations::ElementAnimations() | 28 ElementAnimations::ElementAnimations() |
| 29 : players_list_(new PlayersList()), | 29 : players_list_(new PlayersList()), |
| 30 animation_host_(), | 30 animation_host_(), |
| 31 element_id_(), | 31 element_id_(), |
| 32 is_active_(false), | 32 is_active_(false), |
| 33 has_element_in_active_list_(false), | 33 has_element_in_active_list_(false), |
| 34 has_element_in_pending_list_(false), | 34 has_element_in_pending_list_(false), |
| 35 needs_to_start_animations_(false), | 35 needs_to_start_animations_(false), |
| 36 scroll_offset_animation_was_interrupted_(false) {} | 36 scroll_offset_animation_was_interrupted_(false), |
| 37 needs_push_properties_(false) {} |
| 37 | 38 |
| 38 ElementAnimations::~ElementAnimations() {} | 39 ElementAnimations::~ElementAnimations() {} |
| 39 | 40 |
| 40 void ElementAnimations::SetAnimationHost(AnimationHost* host) { | 41 void ElementAnimations::SetAnimationHost(AnimationHost* host) { |
| 41 animation_host_ = host; | 42 animation_host_ = host; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void ElementAnimations::SetElementId(ElementId element_id) { | 45 void ElementAnimations::SetElementId(ElementId element_id) { |
| 45 element_id_ = element_id; | 46 element_id_ = element_id; |
| 46 } | 47 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 116 } |
| 116 | 117 |
| 117 void ElementAnimations::RemovePlayer(AnimationPlayer* player) { | 118 void ElementAnimations::RemovePlayer(AnimationPlayer* player) { |
| 118 players_list_->RemoveObserver(player); | 119 players_list_->RemoveObserver(player); |
| 119 } | 120 } |
| 120 | 121 |
| 121 bool ElementAnimations::IsEmpty() const { | 122 bool ElementAnimations::IsEmpty() const { |
| 122 return !players_list_->might_have_observers(); | 123 return !players_list_->might_have_observers(); |
| 123 } | 124 } |
| 124 | 125 |
| 126 void ElementAnimations::SetNeedsPushProperties() { |
| 127 needs_push_properties_ = true; |
| 128 } |
| 129 |
| 125 void ElementAnimations::PushPropertiesTo( | 130 void ElementAnimations::PushPropertiesTo( |
| 126 scoped_refptr<ElementAnimations> element_animations_impl) { | 131 scoped_refptr<ElementAnimations> element_animations_impl) { |
| 127 DCHECK_NE(this, element_animations_impl); | 132 DCHECK_NE(this, element_animations_impl); |
| 133 |
| 134 if (!needs_push_properties_) |
| 135 return; |
| 136 needs_push_properties_ = false; |
| 137 |
| 128 if (!has_any_animation() && !element_animations_impl->has_any_animation()) | 138 if (!has_any_animation() && !element_animations_impl->has_any_animation()) |
| 129 return; | 139 return; |
| 130 MarkAbortedAnimationsForDeletion(element_animations_impl.get()); | 140 MarkAbortedAnimationsForDeletion(element_animations_impl.get()); |
| 131 PurgeAnimationsMarkedForDeletion(); | 141 PurgeAnimationsMarkedForDeletion(); |
| 132 PushNewAnimationsToImplThread(element_animations_impl.get()); | 142 PushNewAnimationsToImplThread(element_animations_impl.get()); |
| 133 | 143 |
| 134 // Remove finished impl side animations only after pushing, | 144 // Remove finished impl side animations only after pushing, |
| 135 // and only after the animations are deleted on the main thread | 145 // and only after the animations are deleted on the main thread |
| 136 // this insures we will never push an animation twice. | 146 // this insures we will never push an animation twice. |
| 137 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); | 147 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 else | 889 else |
| 880 events->events_.push_back(finished_event); | 890 events->events_.push_back(finished_event); |
| 881 } | 891 } |
| 882 animations_[animation_index]->SetRunState( | 892 animations_[animation_index]->SetRunState( |
| 883 Animation::WAITING_FOR_DELETION, monotonic_time); | 893 Animation::WAITING_FOR_DELETION, monotonic_time); |
| 884 } | 894 } |
| 885 marked_animations_for_deletions = true; | 895 marked_animations_for_deletions = true; |
| 886 } | 896 } |
| 887 } | 897 } |
| 888 if (marked_animations_for_deletions) | 898 if (marked_animations_for_deletions) |
| 889 NotifyClientAnimationWaitingForDeletion(); | 899 NotifyPlayersAnimationWaitingForDeletion(); |
| 890 } | 900 } |
| 891 | 901 |
| 892 void ElementAnimations::MarkAbortedAnimationsForDeletion( | 902 void ElementAnimations::MarkAbortedAnimationsForDeletion( |
| 893 ElementAnimations* element_animations_impl) const { | 903 ElementAnimations* element_animations_impl) const { |
| 894 bool aborted_transform_animation = false; | 904 bool aborted_transform_animation = false; |
| 895 bool aborted_opacity_animation = false; | 905 bool aborted_opacity_animation = false; |
| 896 bool aborted_filter_animation = false; | 906 bool aborted_filter_animation = false; |
| 897 auto& animations_impl = element_animations_impl->animations_; | 907 auto& animations_impl = element_animations_impl->animations_; |
| 898 for (const auto& animation_impl : animations_impl) { | 908 for (const auto& animation_impl : animations_impl) { |
| 899 // If the animation has been aborted on the main thread, mark it for | 909 // If the animation has been aborted on the main thread, mark it for |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 void ElementAnimations::NotifyClientScrollOffsetAnimated( | 1068 void ElementAnimations::NotifyClientScrollOffsetAnimated( |
| 1059 const gfx::ScrollOffset& scroll_offset, | 1069 const gfx::ScrollOffset& scroll_offset, |
| 1060 bool notify_active_elements, | 1070 bool notify_active_elements, |
| 1061 bool notify_pending_elements) { | 1071 bool notify_pending_elements) { |
| 1062 if (notify_active_elements && has_element_in_active_list()) | 1072 if (notify_active_elements && has_element_in_active_list()) |
| 1063 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); | 1073 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); |
| 1064 if (notify_pending_elements && has_element_in_pending_list()) | 1074 if (notify_pending_elements && has_element_in_pending_list()) |
| 1065 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); | 1075 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); |
| 1066 } | 1076 } |
| 1067 | 1077 |
| 1068 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() { | |
| 1069 OnAnimationWaitingForDeletion(); | |
| 1070 } | |
| 1071 | |
| 1072 void ElementAnimations::NotifyClientAnimationChanged( | 1078 void ElementAnimations::NotifyClientAnimationChanged( |
| 1073 TargetProperty::Type property, | 1079 TargetProperty::Type property, |
| 1074 ElementListType list_type, | 1080 ElementListType list_type, |
| 1075 bool notify_elements_about_potential_animation, | 1081 bool notify_elements_about_potential_animation, |
| 1076 bool notify_elements_about_running_animation) { | 1082 bool notify_elements_about_running_animation) { |
| 1077 struct PropertyAnimationState* animation_state = nullptr; | 1083 struct PropertyAnimationState* animation_state = nullptr; |
| 1078 switch (property) { | 1084 switch (property) { |
| 1079 case TargetProperty::OPACITY: | 1085 case TargetProperty::OPACITY: |
| 1080 animation_state = &opacity_animation_state_; | 1086 animation_state = &opacity_animation_state_; |
| 1081 break; | 1087 break; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 void ElementAnimations::OnScrollOffsetAnimated( | 1387 void ElementAnimations::OnScrollOffsetAnimated( |
| 1382 ElementListType list_type, | 1388 ElementListType list_type, |
| 1383 const gfx::ScrollOffset& scroll_offset) { | 1389 const gfx::ScrollOffset& scroll_offset) { |
| 1384 DCHECK(element_id()); | 1390 DCHECK(element_id()); |
| 1385 DCHECK(animation_host()); | 1391 DCHECK(animation_host()); |
| 1386 DCHECK(animation_host()->mutator_host_client()); | 1392 DCHECK(animation_host()->mutator_host_client()); |
| 1387 animation_host()->mutator_host_client()->SetElementScrollOffsetMutated( | 1393 animation_host()->mutator_host_client()->SetElementScrollOffsetMutated( |
| 1388 element_id(), list_type, scroll_offset); | 1394 element_id(), list_type, scroll_offset); |
| 1389 } | 1395 } |
| 1390 | 1396 |
| 1391 void ElementAnimations::OnAnimationWaitingForDeletion() { | |
| 1392 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here. | |
| 1393 // But we always do PushProperties in AnimationHost for now. crbug.com/604280 | |
| 1394 DCHECK(animation_host()); | |
| 1395 animation_host()->OnAnimationWaitingForDeletion(); | |
| 1396 } | |
| 1397 | |
| 1398 void ElementAnimations::IsAnimatingChanged(ElementListType list_type, | 1397 void ElementAnimations::IsAnimatingChanged(ElementListType list_type, |
| 1399 TargetProperty::Type property, | 1398 TargetProperty::Type property, |
| 1400 AnimationChangeType change_type, | 1399 AnimationChangeType change_type, |
| 1401 bool is_animating) { | 1400 bool is_animating) { |
| 1402 if (!element_id()) | 1401 if (!element_id()) |
| 1403 return; | 1402 return; |
| 1404 DCHECK(animation_host()); | 1403 DCHECK(animation_host()); |
| 1405 if (animation_host()->mutator_host_client()) { | 1404 if (animation_host()->mutator_host_client()) { |
| 1406 switch (property) { | 1405 switch (property) { |
| 1407 case TargetProperty::OPACITY: | 1406 case TargetProperty::OPACITY: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 void ElementAnimations::NotifyPlayersAnimationAborted( | 1453 void ElementAnimations::NotifyPlayersAnimationAborted( |
| 1455 base::TimeTicks monotonic_time, | 1454 base::TimeTicks monotonic_time, |
| 1456 TargetProperty::Type target_property, | 1455 TargetProperty::Type target_property, |
| 1457 int group) { | 1456 int group) { |
| 1458 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | 1457 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 1459 AnimationPlayer* player; | 1458 AnimationPlayer* player; |
| 1460 while ((player = it.GetNext()) != nullptr) | 1459 while ((player = it.GetNext()) != nullptr) |
| 1461 player->NotifyAnimationAborted(monotonic_time, target_property, group); | 1460 player->NotifyAnimationAborted(monotonic_time, target_property, group); |
| 1462 } | 1461 } |
| 1463 | 1462 |
| 1463 void ElementAnimations::NotifyPlayersAnimationWaitingForDeletion() { |
| 1464 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 1465 AnimationPlayer* player; |
| 1466 while ((player = it.GetNext()) != nullptr) |
| 1467 player->NotifyAnimationWaitingForDeletion(); |
| 1468 } |
| 1469 |
| 1464 void ElementAnimations::NotifyPlayersAnimationTakeover( | 1470 void ElementAnimations::NotifyPlayersAnimationTakeover( |
| 1465 base::TimeTicks monotonic_time, | 1471 base::TimeTicks monotonic_time, |
| 1466 TargetProperty::Type target_property, | 1472 TargetProperty::Type target_property, |
| 1467 double animation_start_time, | 1473 double animation_start_time, |
| 1468 std::unique_ptr<AnimationCurve> curve) { | 1474 std::unique_ptr<AnimationCurve> curve) { |
| 1469 DCHECK(curve); | 1475 DCHECK(curve); |
| 1470 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | 1476 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 1471 AnimationPlayer* player; | 1477 AnimationPlayer* player; |
| 1472 while ((player = it.GetNext()) != nullptr) { | 1478 while ((player = it.GetNext()) != nullptr) { |
| 1473 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); | 1479 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); |
| 1474 player->NotifyAnimationTakeover(monotonic_time, target_property, | 1480 player->NotifyAnimationTakeover(monotonic_time, target_property, |
| 1475 animation_start_time, | 1481 animation_start_time, |
| 1476 std::move(animation_curve)); | 1482 std::move(animation_curve)); |
| 1477 } | 1483 } |
| 1478 } | 1484 } |
| 1479 | 1485 |
| 1480 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { | 1486 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { |
| 1481 if (animation_host()) { | 1487 if (animation_host()) { |
| 1482 DCHECK(animation_host()->mutator_host_client()); | 1488 DCHECK(animation_host()->mutator_host_client()); |
| 1483 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1489 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 1484 element_id()); | 1490 element_id()); |
| 1485 } | 1491 } |
| 1486 | 1492 |
| 1487 return gfx::ScrollOffset(); | 1493 return gfx::ScrollOffset(); |
| 1488 } | 1494 } |
| 1489 | 1495 |
| 1490 } // namespace cc | 1496 } // namespace cc |
| OLD | NEW |