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

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

Issue 1987123002: cc : Track transform animation changes on transform tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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/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 16 matching lines...) Expand all
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 potentially_animating_transform_for_active_elements_(false), 37 opacity_animation_(),
38 potentially_animating_transform_for_pending_elements_(false), 38 transform_animation_() {}
ajuma 2016/05/18 22:03:30 Are these lines needed (does the default initializ
jaydasika 2016/05/19 00:56:42 Removed
39 currently_running_opacity_animation_for_active_elements_(false),
40 currently_running_opacity_animation_for_pending_elements_(false),
41 potentially_animating_opacity_for_active_elements_(false),
42 potentially_animating_opacity_for_pending_elements_(false) {}
43 39
44 ElementAnimations::~ElementAnimations() {} 40 ElementAnimations::~ElementAnimations() {}
45 41
46 void ElementAnimations::SetAnimationHost(AnimationHost* host) { 42 void ElementAnimations::SetAnimationHost(AnimationHost* host) {
47 animation_host_ = host; 43 animation_host_ = host;
48 } 44 }
49 45
50 void ElementAnimations::SetElementId(ElementId element_id) { 46 void ElementAnimations::SetElementId(ElementId element_id) {
51 element_id_ = element_id; 47 element_id_ = element_id;
52 } 48 }
(...skipping 12 matching lines...) Expand all
65 if (animation_host_->mutator_host_client()->IsElementInList( 61 if (animation_host_->mutator_host_client()->IsElementInList(
66 element_id_, ElementListType::PENDING)) { 62 element_id_, ElementListType::PENDING)) {
67 set_has_element_in_pending_list(true); 63 set_has_element_in_pending_list(true);
68 } 64 }
69 } 65 }
70 66
71 void ElementAnimations::ClearAffectedElementTypes() { 67 void ElementAnimations::ClearAffectedElementTypes() {
72 DCHECK(animation_host_); 68 DCHECK(animation_host_);
73 69
74 if (has_element_in_active_list()) { 70 if (has_element_in_active_list()) {
75 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); 71 IsAnimatingChanged(ElementListType::ACTIVE, TargetProperty::TRANSFORM,
76 OnOpacityIsAnimatingChanged(ElementListType::ACTIVE, 72 AnimationChangeType::BOTH, false);
77 AnimationChangeType::BOTH, false); 73 IsAnimatingChanged(ElementListType::ACTIVE, TargetProperty::OPACITY,
74 AnimationChangeType::BOTH, false);
78 } 75 }
79 set_has_element_in_active_list(false); 76 set_has_element_in_active_list(false);
80 77
81 if (has_element_in_pending_list()) { 78 if (has_element_in_pending_list()) {
82 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); 79 IsAnimatingChanged(ElementListType::PENDING, TargetProperty::TRANSFORM,
83 OnOpacityIsAnimatingChanged(ElementListType::PENDING, 80 AnimationChangeType::BOTH, false);
84 AnimationChangeType::BOTH, false); 81 IsAnimatingChanged(ElementListType::PENDING, TargetProperty::OPACITY,
82 AnimationChangeType::BOTH, false);
85 } 83 }
86 set_has_element_in_pending_list(false); 84 set_has_element_in_pending_list(false);
87 85
88 animation_host_->DidDeactivateElementAnimations(this); 86 animation_host_->DidDeactivateElementAnimations(this);
89 UpdateActivation(FORCE_ACTIVATION); 87 UpdateActivation(FORCE_ACTIVATION);
90 } 88 }
91 89
92 void ElementAnimations::ElementRegistered(ElementId element_id, 90 void ElementAnimations::ElementRegistered(ElementId element_id,
93 ElementListType list_type) { 91 ElementListType list_type) {
94 DCHECK_EQ(element_id_, element_id); 92 DCHECK_EQ(element_id_, element_id);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 145
148 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { 146 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) {
149 bool added_transform_animation = 147 bool added_transform_animation =
150 animation->target_property() == TargetProperty::TRANSFORM; 148 animation->target_property() == TargetProperty::TRANSFORM;
151 bool added_opacity_animation = 149 bool added_opacity_animation =
152 animation->target_property() == TargetProperty::OPACITY; 150 animation->target_property() == TargetProperty::OPACITY;
153 animations_.push_back(std::move(animation)); 151 animations_.push_back(std::move(animation));
154 needs_to_start_animations_ = true; 152 needs_to_start_animations_ = true;
155 UpdateActivation(NORMAL_ACTIVATION); 153 UpdateActivation(NORMAL_ACTIVATION);
156 if (added_transform_animation) 154 if (added_transform_animation)
157 UpdatePotentiallyAnimatingTransform(); 155 UpdateClientAnimationState(TargetProperty::TRANSFORM);
158 if (added_opacity_animation) 156 if (added_opacity_animation)
159 UpdateAnimatingOpacity(); 157 UpdateClientAnimationState(TargetProperty::OPACITY);
160 } 158 }
161 159
162 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { 160 void ElementAnimations::Animate(base::TimeTicks monotonic_time) {
163 DCHECK(!monotonic_time.is_null()); 161 DCHECK(!monotonic_time.is_null());
164 if (!has_element_in_active_list() && !has_element_in_pending_list()) 162 if (!has_element_in_active_list() && !has_element_in_pending_list())
165 return; 163 return;
166 164
167 if (needs_to_start_animations_) 165 if (needs_to_start_animations_)
168 StartAnimations(monotonic_time); 166 StartAnimations(monotonic_time);
169 TickAnimations(monotonic_time); 167 TickAnimations(monotonic_time);
170 last_tick_time_ = monotonic_time; 168 last_tick_time_ = monotonic_time;
171 UpdateAnimatingOpacity(); 169 UpdateClientAnimationState(TargetProperty::OPACITY);
170 UpdateClientAnimationState(TargetProperty::TRANSFORM);
172 } 171 }
173 172
174 void ElementAnimations::AccumulatePropertyUpdates( 173 void ElementAnimations::AccumulatePropertyUpdates(
175 base::TimeTicks monotonic_time, 174 base::TimeTicks monotonic_time,
176 AnimationEvents* events) { 175 AnimationEvents* events) {
177 if (!events) 176 if (!events)
178 return; 177 return;
179 178
180 for (size_t i = 0; i < animations_.size(); ++i) { 179 for (size_t i = 0; i < animations_.size(); ++i) {
181 Animation* animation = animations_[i].get(); 180 Animation* animation = animations_[i].get();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { 280 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) {
282 return !animation->affects_active_elements() && 281 return !animation->affects_active_elements() &&
283 !animation->affects_pending_elements(); 282 !animation->affects_pending_elements();
284 }; 283 };
285 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), 284 animations_.erase(std::remove_if(animations_.begin(), animations_.end(),
286 affects_no_elements), 285 affects_no_elements),
287 animations_.end()); 286 animations_.end());
288 scroll_offset_animation_was_interrupted_ = false; 287 scroll_offset_animation_was_interrupted_ = false;
289 UpdateActivation(NORMAL_ACTIVATION); 288 UpdateActivation(NORMAL_ACTIVATION);
290 if (changed_transform_animation) 289 if (changed_transform_animation)
291 UpdatePotentiallyAnimatingTransform(); 290 UpdateClientAnimationState(TargetProperty::TRANSFORM);
292 if (changed_opacity_animation) 291 if (changed_opacity_animation)
293 UpdateAnimatingOpacity(); 292 UpdateClientAnimationState(TargetProperty::OPACITY);
294 } 293 }
295 294
296 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { 295 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) {
297 if (event.is_impl_only) { 296 if (event.is_impl_only) {
298 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, 297 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property,
299 event.group_id); 298 event.group_id);
300 return; 299 return;
301 } 300 }
302 301
303 for (size_t i = 0; i < animations_.size(); ++i) { 302 for (size_t i = 0; i < animations_.size(); ++i) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, 355 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property,
357 event.group_id); 356 event.group_id);
358 if (event.target_property == TargetProperty::TRANSFORM) 357 if (event.target_property == TargetProperty::TRANSFORM)
359 aborted_transform_animation = true; 358 aborted_transform_animation = true;
360 else if (event.target_property == TargetProperty::OPACITY) 359 else if (event.target_property == TargetProperty::OPACITY)
361 aborted_opacity_animation = true; 360 aborted_opacity_animation = true;
362 break; 361 break;
363 } 362 }
364 } 363 }
365 if (aborted_transform_animation) 364 if (aborted_transform_animation)
366 UpdatePotentiallyAnimatingTransform(); 365 UpdateClientAnimationState(TargetProperty::TRANSFORM);
367 if (aborted_opacity_animation) 366 if (aborted_opacity_animation)
368 UpdateAnimatingOpacity(); 367 UpdateClientAnimationState(TargetProperty::OPACITY);
369 } 368 }
370 369
371 void ElementAnimations::NotifyAnimationPropertyUpdate( 370 void ElementAnimations::NotifyAnimationPropertyUpdate(
372 const AnimationEvent& event) { 371 const AnimationEvent& event) {
373 bool notify_active_elements = true; 372 bool notify_active_elements = true;
374 bool notify_pending_elements = true; 373 bool notify_pending_elements = true;
375 switch (event.target_property) { 374 switch (event.target_property) {
376 case TargetProperty::OPACITY: 375 case TargetProperty::OPACITY:
377 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, 376 NotifyClientOpacityAnimated(event.opacity, notify_active_elements,
378 notify_pending_elements); 377 notify_pending_elements);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 [](const std::unique_ptr<Animation>& animation) { 641 [](const std::unique_ptr<Animation>& animation) {
643 return animation->run_state() == Animation::WAITING_FOR_DELETION && 642 return animation->run_state() == Animation::WAITING_FOR_DELETION &&
644 !animation->affects_pending_elements(); 643 !animation->affects_pending_elements();
645 }; 644 };
646 animations.erase( 645 animations.erase(
647 std::remove_if(animations.begin(), animations.end(), 646 std::remove_if(animations.begin(), animations.end(),
648 affects_active_only_and_is_waiting_for_deletion), 647 affects_active_only_and_is_waiting_for_deletion),
649 animations.end()); 648 animations.end());
650 649
651 if (removed_transform_animation) 650 if (removed_transform_animation)
652 element_animations_impl->UpdatePotentiallyAnimatingTransform(); 651 element_animations_impl->UpdateClientAnimationState(
652 TargetProperty::TRANSFORM);
653 if (removed_opacity_animation) 653 if (removed_opacity_animation)
654 element_animations_impl->UpdateAnimatingOpacity(); 654 element_animations_impl->UpdateClientAnimationState(
655 TargetProperty::OPACITY);
655 } 656 }
656 657
657 void ElementAnimations::PushPropertiesToImplThread( 658 void ElementAnimations::PushPropertiesToImplThread(
658 ElementAnimations* element_animations_impl) { 659 ElementAnimations* element_animations_impl) {
659 for (size_t i = 0; i < animations_.size(); ++i) { 660 for (size_t i = 0; i < animations_.size(); ++i) {
660 Animation* current_impl = 661 Animation* current_impl =
661 element_animations_impl->GetAnimationById(animations_[i]->id()); 662 element_animations_impl->GetAnimationById(animations_[i]->id());
662 if (current_impl) 663 if (current_impl)
663 animations_[i]->PushPropertiesTo(current_impl); 664 animations_[i]->PushPropertiesTo(current_impl);
664 } 665 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 if (!animations_[i]->is_finished() && 800 if (!animations_[i]->is_finished() &&
800 animations_[i]->IsFinishedAt(monotonic_time)) { 801 animations_[i]->IsFinishedAt(monotonic_time)) {
801 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); 802 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
802 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) 803 if (animations_[i]->target_property() == TargetProperty::TRANSFORM)
803 finished_transform_animation = true; 804 finished_transform_animation = true;
804 else if (animations_[i]->target_property() == TargetProperty::OPACITY) 805 else if (animations_[i]->target_property() == TargetProperty::OPACITY)
805 finished_opacity_animation = true; 806 finished_opacity_animation = true;
806 } 807 }
807 } 808 }
808 if (finished_transform_animation) 809 if (finished_transform_animation)
809 UpdatePotentiallyAnimatingTransform(); 810 UpdateClientAnimationState(TargetProperty::TRANSFORM);
810 if (finished_opacity_animation) 811 if (finished_opacity_animation)
811 UpdateAnimatingOpacity(); 812 UpdateClientAnimationState(TargetProperty::OPACITY);
812 } 813 }
813 814
814 void ElementAnimations::MarkAnimationsForDeletion( 815 void ElementAnimations::MarkAnimationsForDeletion(
815 base::TimeTicks monotonic_time, 816 base::TimeTicks monotonic_time,
816 AnimationEvents* events) { 817 AnimationEvents* events) {
817 bool marked_animations_for_deletions = false; 818 bool marked_animations_for_deletions = false;
818 std::vector<size_t> animations_with_same_group_id; 819 std::vector<size_t> animations_with_same_group_id;
819 820
820 animations_with_same_group_id.reserve(animations_.size()); 821 animations_with_same_group_id.reserve(animations_.size());
821 // Non-aborted animations are marked for deletion after a corresponding 822 // Non-aborted animations are marked for deletion after a corresponding
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 last_tick_time_); 954 last_tick_time_);
954 if (animation_impl->target_property() == TargetProperty::TRANSFORM) 955 if (animation_impl->target_property() == TargetProperty::TRANSFORM)
955 aborted_transform_animation = true; 956 aborted_transform_animation = true;
956 else if (animation_impl->target_property() == TargetProperty::OPACITY) 957 else if (animation_impl->target_property() == TargetProperty::OPACITY)
957 aborted_opacity_animation = true; 958 aborted_opacity_animation = true;
958 } 959 }
959 } 960 }
960 } 961 }
961 962
962 if (aborted_transform_animation) 963 if (aborted_transform_animation)
963 element_animations_impl->UpdatePotentiallyAnimatingTransform(); 964 element_animations_impl->UpdateClientAnimationState(
965 TargetProperty::TRANSFORM);
964 if (aborted_opacity_animation) 966 if (aborted_opacity_animation)
965 element_animations_impl->UpdateAnimatingOpacity(); 967 element_animations_impl->UpdateClientAnimationState(
968 TargetProperty::OPACITY);
966 } 969 }
967 970
968 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { 971 void ElementAnimations::PurgeAnimationsMarkedForDeletion() {
969 animations_.erase( 972 animations_.erase(
970 std::remove_if(animations_.begin(), animations_.end(), 973 std::remove_if(animations_.begin(), animations_.end(),
971 [](const std::unique_ptr<Animation>& animation) { 974 [](const std::unique_ptr<Animation>& animation) {
972 return animation->run_state() == 975 return animation->run_state() ==
973 Animation::WAITING_FOR_DELETION; 976 Animation::WAITING_FOR_DELETION;
974 }), 977 }),
975 animations_.end()); 978 animations_.end());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (notify_active_elements && has_element_in_active_list()) 1099 if (notify_active_elements && has_element_in_active_list())
1097 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); 1100 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset);
1098 if (notify_pending_elements && has_element_in_pending_list()) 1101 if (notify_pending_elements && has_element_in_pending_list())
1099 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); 1102 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset);
1100 } 1103 }
1101 1104
1102 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() { 1105 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() {
1103 OnAnimationWaitingForDeletion(); 1106 OnAnimationWaitingForDeletion();
1104 } 1107 }
1105 1108
1106 void ElementAnimations::NotifyClientTransformIsPotentiallyAnimatingChanged( 1109 void ElementAnimations::NotifyClientAnimationChanged(
1107 bool notify_active_elements, 1110 TargetProperty::Type property,
1108 bool notify_pending_elements) { 1111 ElementListType list_type,
1109 if (notify_active_elements && has_element_in_active_list()) 1112 bool notify_elements_about_potential_animation,
1110 OnTransformIsPotentiallyAnimatingChanged( 1113 bool notify_elements_about_running_animation) {
1111 ElementListType::ACTIVE, 1114 struct AnimationStateForClient* animation_state = nullptr;
1112 potentially_animating_transform_for_active_elements_); 1115 switch (property) {
1113 if (notify_pending_elements && has_element_in_pending_list()) 1116 case TargetProperty::OPACITY:
1114 OnTransformIsPotentiallyAnimatingChanged( 1117 animation_state = &opacity_animation_;
1115 ElementListType::PENDING, 1118 break;
1116 potentially_animating_transform_for_pending_elements_); 1119 case TargetProperty::TRANSFORM:
1117 } 1120 animation_state = &transform_animation_;
1121 break;
1122 default:
ajuma 2016/05/18 22:03:30 Please add a NOTREACHED here.
jaydasika 2016/05/19 00:56:42 Done.
1123 break;
1124 }
1118 1125
1119 void ElementAnimations::NotifyClientOpacityAnimationChanged( 1126 bool notify_elements_about_potential_and_running_animation =
1120 bool notify_active_elements_about_potential_animation, 1127 notify_elements_about_potential_animation &&
1121 bool notify_pending_elements_about_potential_animation, 1128 notify_elements_about_running_animation;
1122 bool notify_active_elements_about_running_animation, 1129 bool active = list_type == ElementListType::ACTIVE;
1123 bool notify_pending_elements_about_running_animation) { 1130 if (notify_elements_about_potential_and_running_animation) {
1124 bool notify_active_elements_about_potential_and_running_animation = 1131 bool potentially_animating =
1125 notify_active_elements_about_potential_animation && 1132 active ? animation_state->potentially_animating_for_active_elements
1126 notify_active_elements_about_running_animation; 1133 : animation_state->potentially_animating_for_pending_elements;
1127 bool notify_pending_elements_about_potential_and_running_animation = 1134 bool currently_animating =
1128 notify_pending_elements_about_potential_animation && 1135 active ? animation_state->currently_running_for_active_elements
1129 notify_pending_elements_about_running_animation; 1136 : animation_state->currently_running_for_pending_elements;
1130 if (has_element_in_active_list()) { 1137 DCHECK_EQ(potentially_animating, currently_animating);
1131 if (notify_active_elements_about_potential_and_running_animation) { 1138 IsAnimatingChanged(list_type, property, AnimationChangeType::BOTH,
1132 DCHECK_EQ(potentially_animating_opacity_for_active_elements_, 1139 potentially_animating);
1133 currently_running_opacity_animation_for_active_elements_); 1140 } else if (notify_elements_about_potential_animation) {
1134 OnOpacityIsAnimatingChanged( 1141 bool potentially_animating =
1135 ElementListType::ACTIVE, AnimationChangeType::BOTH, 1142 active ? animation_state->potentially_animating_for_active_elements
1136 potentially_animating_opacity_for_active_elements_); 1143 : animation_state->potentially_animating_for_pending_elements;
1137 } else if (notify_active_elements_about_potential_animation) { 1144 IsAnimatingChanged(list_type, property, AnimationChangeType::POTENTIAL,
1138 OnOpacityIsAnimatingChanged( 1145 potentially_animating);
1139 ElementListType::ACTIVE, AnimationChangeType::POTENTIAL, 1146 } else if (notify_elements_about_running_animation) {
1140 potentially_animating_opacity_for_active_elements_); 1147 bool currently_animating =
1141 } else if (notify_active_elements_about_running_animation) { 1148 active ? animation_state->currently_running_for_active_elements
1142 OnOpacityIsAnimatingChanged( 1149 : animation_state->currently_running_for_pending_elements;
1143 ElementListType::ACTIVE, AnimationChangeType::RUNNING, 1150 IsAnimatingChanged(list_type, property, AnimationChangeType::RUNNING,
1144 currently_running_opacity_animation_for_active_elements_); 1151 currently_animating);
1145 }
1146 }
1147 if (has_element_in_pending_list()) {
1148 if (notify_pending_elements_about_potential_and_running_animation) {
1149 DCHECK_EQ(potentially_animating_opacity_for_pending_elements_,
1150 currently_running_opacity_animation_for_pending_elements_);
1151 OnOpacityIsAnimatingChanged(
1152 ElementListType::PENDING, AnimationChangeType::BOTH,
1153 potentially_animating_opacity_for_pending_elements_);
1154 } else if (notify_pending_elements_about_potential_animation) {
1155 OnOpacityIsAnimatingChanged(
1156 ElementListType::PENDING, AnimationChangeType::POTENTIAL,
1157 potentially_animating_opacity_for_pending_elements_);
1158 } else if (notify_pending_elements_about_running_animation) {
1159 OnOpacityIsAnimatingChanged(
1160 ElementListType::PENDING, AnimationChangeType::RUNNING,
1161 currently_running_opacity_animation_for_pending_elements_);
1162 }
1163 } 1152 }
1164 } 1153 }
1165 1154
1166 void ElementAnimations::UpdatePotentiallyAnimatingTransform() { 1155 void ElementAnimations::UpdateClientAnimationState(
1167 bool was_potentially_animating_transform_for_active_elements = 1156 TargetProperty::Type property) {
1168 potentially_animating_transform_for_active_elements_; 1157 struct AnimationStateForClient* animation_state = nullptr;
1169 bool was_potentially_animating_transform_for_pending_elements = 1158 switch (property) {
1170 potentially_animating_transform_for_pending_elements_; 1159 case TargetProperty::OPACITY:
1160 animation_state = &opacity_animation_;
1161 break;
1162 case TargetProperty::TRANSFORM:
1163 animation_state = &transform_animation_;
1164 break;
1165 default:
1166 break;
1167 }
1168 bool was_currently_running_animation_for_active_elements =
1169 animation_state->currently_running_for_active_elements;
1170 bool was_currently_running_animation_for_pending_elements =
1171 animation_state->currently_running_for_pending_elements;
1172 bool was_potentially_animating_for_active_elements =
1173 animation_state->potentially_animating_for_active_elements;
1174 bool was_potentially_animating_for_pending_elements =
1175 animation_state->potentially_animating_for_pending_elements;
1171 1176
1172 potentially_animating_transform_for_active_elements_ = false; 1177 animation_state->Clear();
1173 potentially_animating_transform_for_pending_elements_ = false; 1178 DCHECK(was_potentially_animating_for_active_elements ||
1179 !was_currently_running_animation_for_active_elements);
1180 DCHECK(was_potentially_animating_for_pending_elements ||
1181 !was_currently_running_animation_for_pending_elements);
1174 1182
1175 for (const auto& animation : animations_) { 1183 for (const auto& animation : animations_) {
1176 if (!animation->is_finished() && 1184 if (!animation->is_finished() && animation->target_property() == property) {
1177 animation->target_property() == TargetProperty::TRANSFORM) { 1185 animation_state->potentially_animating_for_active_elements |=
1178 potentially_animating_transform_for_active_elements_ |=
1179 animation->affects_active_elements(); 1186 animation->affects_active_elements();
1180 potentially_animating_transform_for_pending_elements_ |= 1187 animation_state->potentially_animating_for_pending_elements |=
1181 animation->affects_pending_elements(); 1188 animation->affects_pending_elements();
1182 } 1189 animation_state->currently_running_for_active_elements =
1183 } 1190 animation_state->potentially_animating_for_active_elements &&
1184
1185 bool changed_for_active_elements =
1186 was_potentially_animating_transform_for_active_elements !=
1187 potentially_animating_transform_for_active_elements_;
1188 bool changed_for_pending_elements =
1189 was_potentially_animating_transform_for_pending_elements !=
1190 potentially_animating_transform_for_pending_elements_;
1191
1192 if (!changed_for_active_elements && !changed_for_pending_elements)
1193 return;
1194
1195 NotifyClientTransformIsPotentiallyAnimatingChanged(
1196 changed_for_active_elements, changed_for_pending_elements);
1197 }
1198
1199 void ElementAnimations::UpdateAnimatingOpacity() {
1200 bool was_currently_running_opacity_animation_for_active_elements =
1201 currently_running_opacity_animation_for_active_elements_;
1202 bool was_currently_running_opacity_animation_for_pending_elements =
1203 currently_running_opacity_animation_for_pending_elements_;
1204 bool was_potentially_animating_opacity_for_active_elements =
1205 potentially_animating_opacity_for_active_elements_;
1206 bool was_potentially_animating_opacity_for_pending_elements =
1207 potentially_animating_opacity_for_pending_elements_;
1208
1209 DCHECK(was_potentially_animating_opacity_for_active_elements ||
1210 !was_currently_running_opacity_animation_for_active_elements);
1211 DCHECK(was_potentially_animating_opacity_for_pending_elements ||
1212 !was_currently_running_opacity_animation_for_pending_elements);
1213 currently_running_opacity_animation_for_active_elements_ = false;
1214 currently_running_opacity_animation_for_pending_elements_ = false;
1215 potentially_animating_opacity_for_active_elements_ = false;
1216 potentially_animating_opacity_for_pending_elements_ = false;
1217
1218 for (const auto& animation : animations_) {
1219 if (!animation->is_finished() &&
1220 animation->target_property() == TargetProperty::OPACITY) {
1221 potentially_animating_opacity_for_active_elements_ |=
1222 animation->affects_active_elements();
1223 potentially_animating_opacity_for_pending_elements_ |=
1224 animation->affects_pending_elements();
1225 currently_running_opacity_animation_for_active_elements_ =
1226 potentially_animating_opacity_for_active_elements_ &&
1227 animation->InEffect(last_tick_time_); 1191 animation->InEffect(last_tick_time_);
1228 currently_running_opacity_animation_for_pending_elements_ = 1192 animation_state->currently_running_for_pending_elements =
1229 potentially_animating_opacity_for_pending_elements_ && 1193 animation_state->potentially_animating_for_pending_elements &&
1230 animation->InEffect(last_tick_time_); 1194 animation->InEffect(last_tick_time_);
1231 } 1195 }
1232 } 1196 }
1233 1197
1234 bool potentially_animating_changed_for_active_elements = 1198 bool potentially_animating_changed_for_active_elements =
1235 was_potentially_animating_opacity_for_active_elements != 1199 was_potentially_animating_for_active_elements !=
1236 potentially_animating_opacity_for_active_elements_; 1200 animation_state->potentially_animating_for_active_elements;
1237 bool potentially_animating_changed_for_pending_elements = 1201 bool potentially_animating_changed_for_pending_elements =
1238 was_potentially_animating_opacity_for_pending_elements != 1202 was_potentially_animating_for_pending_elements !=
1239 potentially_animating_opacity_for_pending_elements_; 1203 animation_state->potentially_animating_for_pending_elements;
1240 bool currently_running_animation_changed_for_active_elements = 1204 bool currently_running_animation_changed_for_active_elements =
1241 was_currently_running_opacity_animation_for_active_elements != 1205 was_currently_running_animation_for_active_elements !=
1242 currently_running_opacity_animation_for_active_elements_; 1206 animation_state->currently_running_for_active_elements;
1243 bool currently_running_animation_changed_for_pending_elements = 1207 bool currently_running_animation_changed_for_pending_elements =
1244 was_currently_running_opacity_animation_for_pending_elements != 1208 was_currently_running_animation_for_pending_elements !=
1245 currently_running_opacity_animation_for_pending_elements_; 1209 animation_state->currently_running_for_pending_elements;
1246 if (!potentially_animating_changed_for_active_elements && 1210 if (!potentially_animating_changed_for_active_elements &&
1247 !potentially_animating_changed_for_pending_elements && 1211 !potentially_animating_changed_for_pending_elements &&
1248 !currently_running_animation_changed_for_active_elements && 1212 !currently_running_animation_changed_for_active_elements &&
1249 !currently_running_animation_changed_for_pending_elements) 1213 !currently_running_animation_changed_for_pending_elements)
1250 return; 1214 return;
1251 NotifyClientOpacityAnimationChanged( 1215 if (has_element_in_active_list())
1252 potentially_animating_changed_for_active_elements, 1216 NotifyClientAnimationChanged(
1253 potentially_animating_changed_for_pending_elements, 1217 property, ElementListType::ACTIVE,
1254 currently_running_animation_changed_for_active_elements, 1218 potentially_animating_changed_for_active_elements,
1255 currently_running_animation_changed_for_pending_elements); 1219 currently_running_animation_changed_for_active_elements);
1220 if (has_element_in_pending_list())
1221 NotifyClientAnimationChanged(
1222 property, ElementListType::PENDING,
1223 potentially_animating_changed_for_pending_elements,
1224 currently_running_animation_changed_for_pending_elements);
1256 } 1225 }
1257 1226
1258 bool ElementAnimations::HasActiveAnimation() const { 1227 bool ElementAnimations::HasActiveAnimation() const {
1259 for (size_t i = 0; i < animations_.size(); ++i) { 1228 for (size_t i = 0; i < animations_.size(); ++i) {
1260 if (!animations_[i]->is_finished()) 1229 if (!animations_[i]->is_finished())
1261 return true; 1230 return true;
1262 } 1231 }
1263 return false; 1232 return false;
1264 } 1233 }
1265 1234
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 removed_transform_animation = true; 1295 removed_transform_animation = true;
1327 } else if ((*it)->target_property() == TargetProperty::OPACITY && 1296 } else if ((*it)->target_property() == TargetProperty::OPACITY &&
1328 !(*it)->is_finished()) { 1297 !(*it)->is_finished()) {
1329 removed_opacity_animation = true; 1298 removed_opacity_animation = true;
1330 } 1299 }
1331 } 1300 }
1332 1301
1333 animations_.erase(animations_to_remove, animations_.end()); 1302 animations_.erase(animations_to_remove, animations_.end());
1334 UpdateActivation(NORMAL_ACTIVATION); 1303 UpdateActivation(NORMAL_ACTIVATION);
1335 if (removed_transform_animation) 1304 if (removed_transform_animation)
1336 UpdatePotentiallyAnimatingTransform(); 1305 UpdateClientAnimationState(TargetProperty::TRANSFORM);
1337 if (removed_opacity_animation) 1306 if (removed_opacity_animation)
1338 UpdateAnimatingOpacity(); 1307 UpdateClientAnimationState(TargetProperty::OPACITY);
1339 } 1308 }
1340 1309
1341 void ElementAnimations::AbortAnimation(int animation_id) { 1310 void ElementAnimations::AbortAnimation(int animation_id) {
1342 bool aborted_transform_animation = false; 1311 bool aborted_transform_animation = false;
1343 bool aborted_opacity_animation = false; 1312 bool aborted_opacity_animation = false;
1344 if (Animation* animation = GetAnimationById(animation_id)) { 1313 if (Animation* animation = GetAnimationById(animation_id)) {
1345 if (!animation->is_finished()) { 1314 if (!animation->is_finished()) {
1346 animation->SetRunState(Animation::ABORTED, last_tick_time_); 1315 animation->SetRunState(Animation::ABORTED, last_tick_time_);
1347 if (animation->target_property() == TargetProperty::TRANSFORM) 1316 if (animation->target_property() == TargetProperty::TRANSFORM)
1348 aborted_transform_animation = true; 1317 aborted_transform_animation = true;
1349 else if (animation->target_property() == TargetProperty::OPACITY) 1318 else if (animation->target_property() == TargetProperty::OPACITY)
1350 aborted_opacity_animation = true; 1319 aborted_opacity_animation = true;
1351 } 1320 }
1352 } 1321 }
1353 if (aborted_transform_animation) 1322 if (aborted_transform_animation)
1354 UpdatePotentiallyAnimatingTransform(); 1323 UpdateClientAnimationState(TargetProperty::TRANSFORM);
1355 if (aborted_opacity_animation) 1324 if (aborted_opacity_animation)
1356 UpdateAnimatingOpacity(); 1325 UpdateClientAnimationState(TargetProperty::OPACITY);
1357 } 1326 }
1358 1327
1359 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, 1328 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property,
1360 bool needs_completion) { 1329 bool needs_completion) {
1361 if (needs_completion) 1330 if (needs_completion)
1362 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); 1331 DCHECK(target_property == TargetProperty::SCROLL_OFFSET);
1363 1332
1364 bool aborted_transform_animation = false; 1333 bool aborted_transform_animation = false;
1365 bool aborted_opacity_animation = false; 1334 bool aborted_opacity_animation = false;
1366 for (size_t i = 0; i < animations_.size(); ++i) { 1335 for (size_t i = 0; i < animations_.size(); ++i) {
1367 if (animations_[i]->target_property() == target_property && 1336 if (animations_[i]->target_property() == target_property &&
1368 !animations_[i]->is_finished()) { 1337 !animations_[i]->is_finished()) {
1369 // Currently only impl-only scroll offset animations can be completed on 1338 // Currently only impl-only scroll offset animations can be completed on
1370 // the main thread. 1339 // the main thread.
1371 if (needs_completion && animations_[i]->is_impl_only()) { 1340 if (needs_completion && animations_[i]->is_impl_only()) {
1372 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, 1341 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION,
1373 last_tick_time_); 1342 last_tick_time_);
1374 } else { 1343 } else {
1375 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); 1344 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_);
1376 } 1345 }
1377 if (target_property == TargetProperty::TRANSFORM) 1346 if (target_property == TargetProperty::TRANSFORM)
1378 aborted_transform_animation = true; 1347 aborted_transform_animation = true;
1379 else if (target_property == TargetProperty::OPACITY) 1348 else if (target_property == TargetProperty::OPACITY)
1380 aborted_opacity_animation = true; 1349 aborted_opacity_animation = true;
1381 } 1350 }
1382 } 1351 }
1383 if (aborted_transform_animation) 1352 if (aborted_transform_animation)
1384 UpdatePotentiallyAnimatingTransform(); 1353 UpdateClientAnimationState(TargetProperty::TRANSFORM);
1385 if (aborted_opacity_animation) 1354 if (aborted_opacity_animation)
1386 UpdateAnimatingOpacity(); 1355 UpdateClientAnimationState(TargetProperty::OPACITY);
1387 } 1356 }
1388 1357
1389 Animation* ElementAnimations::GetAnimation( 1358 Animation* ElementAnimations::GetAnimation(
1390 TargetProperty::Type target_property) const { 1359 TargetProperty::Type target_property) const {
1391 for (size_t i = 0; i < animations_.size(); ++i) { 1360 for (size_t i = 0; i < animations_.size(); ++i) {
1392 size_t index = animations_.size() - i - 1; 1361 size_t index = animations_.size() - i - 1;
1393 if (animations_[index]->target_property() == target_property) 1362 if (animations_[index]->target_property() == target_property)
1394 return animations_[index].get(); 1363 return animations_[index].get();
1395 } 1364 }
1396 return nullptr; 1365 return nullptr;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 element_id(), list_type, scroll_offset); 1409 element_id(), list_type, scroll_offset);
1441 } 1410 }
1442 1411
1443 void ElementAnimations::OnAnimationWaitingForDeletion() { 1412 void ElementAnimations::OnAnimationWaitingForDeletion() {
1444 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here. 1413 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here.
1445 // But we always do PushProperties in AnimationHost for now. crbug.com/604280 1414 // But we always do PushProperties in AnimationHost for now. crbug.com/604280
1446 DCHECK(animation_host()); 1415 DCHECK(animation_host());
1447 animation_host()->OnAnimationWaitingForDeletion(); 1416 animation_host()->OnAnimationWaitingForDeletion();
1448 } 1417 }
1449 1418
1450 void ElementAnimations::OnTransformIsPotentiallyAnimatingChanged( 1419 void ElementAnimations::IsAnimatingChanged(ElementListType list_type,
1451 ElementListType list_type, 1420 TargetProperty::Type property,
1452 bool is_animating) { 1421 AnimationChangeType change_type,
1453 DCHECK(element_id()); 1422 bool is_animating) {
1454 DCHECK(animation_host());
1455 DCHECK(animation_host()->mutator_host_client());
1456 animation_host()
1457 ->mutator_host_client()
1458 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type,
1459 is_animating);
1460 }
1461
1462 void ElementAnimations::OnOpacityIsAnimatingChanged(
1463 ElementListType list_type,
1464 AnimationChangeType change_type,
1465 bool is_animating) {
1466 if (!element_id()) 1423 if (!element_id())
1467 return; 1424 return;
1468 DCHECK(animation_host()); 1425 DCHECK(animation_host());
1469 if (animation_host()->mutator_host_client()) { 1426 if (animation_host()->mutator_host_client()) {
1470 animation_host()->mutator_host_client()->ElementOpacityIsAnimatingChanged( 1427 switch (property) {
1471 element_id(), list_type, change_type, is_animating); 1428 case TargetProperty::OPACITY:
1429 animation_host()
1430 ->mutator_host_client()
1431 ->ElementOpacityIsAnimatingChanged(element_id(), list_type,
1432 change_type, is_animating);
1433 break;
1434 case TargetProperty::TRANSFORM:
1435 animation_host()
1436 ->mutator_host_client()
1437 ->ElementTransformIsAnimatingChanged(element_id(), list_type,
1438 change_type, is_animating);
1439 break;
1440 default:
1441 break;
1442 }
1472 } 1443 }
1473 } 1444 }
1474 1445
1475 void ElementAnimations::NotifyPlayersAnimationStarted( 1446 void ElementAnimations::NotifyPlayersAnimationStarted(
1476 base::TimeTicks monotonic_time, 1447 base::TimeTicks monotonic_time,
1477 TargetProperty::Type target_property, 1448 TargetProperty::Type target_property,
1478 int group) { 1449 int group) {
1479 for (PlayersListNode* node = players_list_->head(); 1450 for (PlayersListNode* node = players_list_->head();
1480 node != players_list_->end(); node = node->next()) { 1451 node != players_list_->end(); node = node->next()) {
1481 AnimationPlayer* player = node->value(); 1452 AnimationPlayer* player = node->value();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 if (animation_host()) { 1496 if (animation_host()) {
1526 DCHECK(animation_host()->mutator_host_client()); 1497 DCHECK(animation_host()->mutator_host_client());
1527 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( 1498 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation(
1528 element_id()); 1499 element_id());
1529 } 1500 }
1530 1501
1531 return gfx::ScrollOffset(); 1502 return gfx::ScrollOffset();
1532 } 1503 }
1533 1504
1534 } // namespace cc 1505 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698