| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "cc/animation/animation.h" | 12 #include "cc/animation/animation.h" |
| 13 #include "cc/animation/animation_delegate.h" | 13 #include "cc/animation/animation_delegate.h" |
| 14 #include "cc/animation/animation_events.h" |
| 14 #include "cc/animation/animation_registrar.h" | 15 #include "cc/animation/animation_registrar.h" |
| 15 #include "cc/animation/keyframed_animation_curve.h" | 16 #include "cc/animation/keyframed_animation_curve.h" |
| 16 #include "cc/animation/layer_animation_value_observer.h" | 17 #include "cc/animation/layer_animation_value_observer.h" |
| 17 #include "cc/animation/layer_animation_value_provider.h" | 18 #include "cc/animation/layer_animation_value_provider.h" |
| 18 #include "cc/animation/scroll_offset_animation_curve.h" | 19 #include "cc/animation/scroll_offset_animation_curve.h" |
| 19 #include "cc/output/filter_operations.h" | 20 #include "cc/output/filter_operations.h" |
| 20 #include "ui/gfx/geometry/box_f.h" | 21 #include "ui/gfx/geometry/box_f.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return; | 197 return; |
| 197 | 198 |
| 198 if (needs_to_start_animations_) | 199 if (needs_to_start_animations_) |
| 199 StartAnimations(monotonic_time); | 200 StartAnimations(monotonic_time); |
| 200 TickAnimations(monotonic_time); | 201 TickAnimations(monotonic_time); |
| 201 last_tick_time_ = monotonic_time; | 202 last_tick_time_ = monotonic_time; |
| 202 } | 203 } |
| 203 | 204 |
| 204 void LayerAnimationController::AccumulatePropertyUpdates( | 205 void LayerAnimationController::AccumulatePropertyUpdates( |
| 205 base::TimeTicks monotonic_time, | 206 base::TimeTicks monotonic_time, |
| 206 AnimationEventsVector* events) { | 207 AnimationEvents* events) { |
| 207 if (!events) | 208 if (!events) |
| 208 return; | 209 return; |
| 209 | 210 |
| 210 for (size_t i = 0; i < animations_.size(); ++i) { | 211 for (size_t i = 0; i < animations_.size(); ++i) { |
| 211 Animation* animation = animations_[i].get(); | 212 Animation* animation = animations_[i].get(); |
| 212 if (!animation->is_impl_only()) | 213 if (!animation->is_impl_only()) |
| 213 continue; | 214 continue; |
| 214 | 215 |
| 215 if (!animation->InEffect(monotonic_time)) | 216 if (!animation->InEffect(monotonic_time)) |
| 216 continue; | 217 continue; |
| 217 | 218 |
| 218 base::TimeDelta trimmed = | 219 base::TimeDelta trimmed = |
| 219 animation->TrimTimeToCurrentIteration(monotonic_time); | 220 animation->TrimTimeToCurrentIteration(monotonic_time); |
| 220 switch (animation->target_property()) { | 221 switch (animation->target_property()) { |
| 221 case Animation::OPACITY: { | 222 case Animation::OPACITY: { |
| 222 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 223 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
| 223 animation->group(), Animation::OPACITY, | 224 animation->group(), Animation::OPACITY, |
| 224 monotonic_time); | 225 monotonic_time); |
| 225 const FloatAnimationCurve* float_animation_curve = | 226 const FloatAnimationCurve* float_animation_curve = |
| 226 animation->curve()->ToFloatAnimationCurve(); | 227 animation->curve()->ToFloatAnimationCurve(); |
| 227 event.opacity = float_animation_curve->GetValue(trimmed); | 228 event.opacity = float_animation_curve->GetValue(trimmed); |
| 228 event.is_impl_only = true; | 229 event.is_impl_only = true; |
| 229 events->push_back(event); | 230 events->events_.push_back(event); |
| 230 break; | 231 break; |
| 231 } | 232 } |
| 232 | 233 |
| 233 case Animation::TRANSFORM: { | 234 case Animation::TRANSFORM: { |
| 234 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 235 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
| 235 animation->group(), Animation::TRANSFORM, | 236 animation->group(), Animation::TRANSFORM, |
| 236 monotonic_time); | 237 monotonic_time); |
| 237 const TransformAnimationCurve* transform_animation_curve = | 238 const TransformAnimationCurve* transform_animation_curve = |
| 238 animation->curve()->ToTransformAnimationCurve(); | 239 animation->curve()->ToTransformAnimationCurve(); |
| 239 event.transform = transform_animation_curve->GetValue(trimmed); | 240 event.transform = transform_animation_curve->GetValue(trimmed); |
| 240 event.is_impl_only = true; | 241 event.is_impl_only = true; |
| 241 events->push_back(event); | 242 events->events_.push_back(event); |
| 242 break; | 243 break; |
| 243 } | 244 } |
| 244 | 245 |
| 245 case Animation::FILTER: { | 246 case Animation::FILTER: { |
| 246 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, | 247 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, |
| 247 animation->group(), Animation::FILTER, | 248 animation->group(), Animation::FILTER, |
| 248 monotonic_time); | 249 monotonic_time); |
| 249 const FilterAnimationCurve* filter_animation_curve = | 250 const FilterAnimationCurve* filter_animation_curve = |
| 250 animation->curve()->ToFilterAnimationCurve(); | 251 animation->curve()->ToFilterAnimationCurve(); |
| 251 event.filters = filter_animation_curve->GetValue(trimmed); | 252 event.filters = filter_animation_curve->GetValue(trimmed); |
| 252 event.is_impl_only = true; | 253 event.is_impl_only = true; |
| 253 events->push_back(event); | 254 events->events_.push_back(event); |
| 254 break; | 255 break; |
| 255 } | 256 } |
| 256 | 257 |
| 257 case Animation::BACKGROUND_COLOR: { | 258 case Animation::BACKGROUND_COLOR: { |
| 258 break; | 259 break; |
| 259 } | 260 } |
| 260 | 261 |
| 261 case Animation::SCROLL_OFFSET: { | 262 case Animation::SCROLL_OFFSET: { |
| 262 // Impl-side changes to scroll offset are already sent back to the | 263 // Impl-side changes to scroll offset are already sent back to the |
| 263 // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE | 264 // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE |
| 264 // isn't needed. | 265 // isn't needed. |
| 265 break; | 266 break; |
| 266 } | 267 } |
| 267 } | 268 } |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 | 271 |
| 271 void LayerAnimationController::UpdateState(bool start_ready_animations, | 272 void LayerAnimationController::UpdateState(bool start_ready_animations, |
| 272 AnimationEventsVector* events) { | 273 AnimationEvents* events) { |
| 273 if (!HasActiveValueObserver()) | 274 if (!HasActiveValueObserver()) |
| 274 return; | 275 return; |
| 275 | 276 |
| 276 // Animate hasn't been called, this happens if an observer has been added | 277 // Animate hasn't been called, this happens if an observer has been added |
| 277 // between the Commit and Draw phases. | 278 // between the Commit and Draw phases. |
| 278 if (last_tick_time_ == base::TimeTicks()) | 279 if (last_tick_time_ == base::TimeTicks()) |
| 279 return; | 280 return; |
| 280 | 281 |
| 281 if (start_ready_animations) | 282 if (start_ready_animations) |
| 282 PromoteStartedAnimations(last_tick_time_, events); | 283 PromoteStartedAnimations(last_tick_time_, events); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 869 } |
| 869 } else { | 870 } else { |
| 870 needs_to_start_animations_ = true; | 871 needs_to_start_animations_ = true; |
| 871 } | 872 } |
| 872 } | 873 } |
| 873 } | 874 } |
| 874 } | 875 } |
| 875 | 876 |
| 876 void LayerAnimationController::PromoteStartedAnimations( | 877 void LayerAnimationController::PromoteStartedAnimations( |
| 877 base::TimeTicks monotonic_time, | 878 base::TimeTicks monotonic_time, |
| 878 AnimationEventsVector* events) { | 879 AnimationEvents* events) { |
| 879 for (size_t i = 0; i < animations_.size(); ++i) { | 880 for (size_t i = 0; i < animations_.size(); ++i) { |
| 880 if (animations_[i]->run_state() == Animation::STARTING && | 881 if (animations_[i]->run_state() == Animation::STARTING && |
| 881 animations_[i]->affects_active_observers()) { | 882 animations_[i]->affects_active_observers()) { |
| 882 animations_[i]->SetRunState(Animation::RUNNING, monotonic_time); | 883 animations_[i]->SetRunState(Animation::RUNNING, monotonic_time); |
| 883 if (!animations_[i]->has_set_start_time() && | 884 if (!animations_[i]->has_set_start_time() && |
| 884 !animations_[i]->needs_synchronized_start_time()) | 885 !animations_[i]->needs_synchronized_start_time()) |
| 885 animations_[i]->set_start_time(monotonic_time); | 886 animations_[i]->set_start_time(monotonic_time); |
| 886 if (events) { | 887 if (events) { |
| 887 base::TimeTicks start_time; | 888 base::TimeTicks start_time; |
| 888 if (animations_[i]->has_set_start_time()) | 889 if (animations_[i]->has_set_start_time()) |
| 889 start_time = animations_[i]->start_time(); | 890 start_time = animations_[i]->start_time(); |
| 890 else | 891 else |
| 891 start_time = monotonic_time; | 892 start_time = monotonic_time; |
| 892 AnimationEvent started_event( | 893 AnimationEvent started_event( |
| 893 AnimationEvent::STARTED, id_, animations_[i]->group(), | 894 AnimationEvent::STARTED, id_, animations_[i]->group(), |
| 894 animations_[i]->target_property(), start_time); | 895 animations_[i]->target_property(), start_time); |
| 895 started_event.is_impl_only = animations_[i]->is_impl_only(); | 896 started_event.is_impl_only = animations_[i]->is_impl_only(); |
| 896 if (started_event.is_impl_only) | 897 if (started_event.is_impl_only) |
| 897 NotifyAnimationStarted(started_event); | 898 NotifyAnimationStarted(started_event); |
| 898 else | 899 else |
| 899 events->push_back(started_event); | 900 events->events_.push_back(started_event); |
| 900 } | 901 } |
| 901 } | 902 } |
| 902 } | 903 } |
| 903 } | 904 } |
| 904 | 905 |
| 905 void LayerAnimationController::MarkFinishedAnimations( | 906 void LayerAnimationController::MarkFinishedAnimations( |
| 906 base::TimeTicks monotonic_time) { | 907 base::TimeTicks monotonic_time) { |
| 907 bool finished_transform_animation = false; | 908 bool finished_transform_animation = false; |
| 908 for (size_t i = 0; i < animations_.size(); ++i) { | 909 for (size_t i = 0; i < animations_.size(); ++i) { |
| 909 if (!animations_[i]->is_finished() && | 910 if (!animations_[i]->is_finished() && |
| 910 animations_[i]->IsFinishedAt(monotonic_time)) { | 911 animations_[i]->IsFinishedAt(monotonic_time)) { |
| 911 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 912 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
| 912 if (animations_[i]->target_property() == Animation::TRANSFORM) { | 913 if (animations_[i]->target_property() == Animation::TRANSFORM) { |
| 913 finished_transform_animation = true; | 914 finished_transform_animation = true; |
| 914 } | 915 } |
| 915 } | 916 } |
| 916 } | 917 } |
| 917 if (finished_transform_animation) | 918 if (finished_transform_animation) |
| 918 UpdatePotentiallyAnimatingTransform(); | 919 UpdatePotentiallyAnimatingTransform(); |
| 919 } | 920 } |
| 920 | 921 |
| 921 void LayerAnimationController::MarkAnimationsForDeletion( | 922 void LayerAnimationController::MarkAnimationsForDeletion( |
| 922 base::TimeTicks monotonic_time, | 923 base::TimeTicks monotonic_time, |
| 923 AnimationEventsVector* events) { | 924 AnimationEvents* events) { |
| 924 bool marked_animations_for_deletions = false; | 925 bool marked_animations_for_deletions = false; |
| 925 std::vector<size_t> animations_with_same_group_id; | 926 std::vector<size_t> animations_with_same_group_id; |
| 926 | 927 |
| 927 animations_with_same_group_id.reserve(animations_.size()); | 928 animations_with_same_group_id.reserve(animations_.size()); |
| 928 // Non-aborted animations are marked for deletion after a corresponding | 929 // Non-aborted animations are marked for deletion after a corresponding |
| 929 // AnimationEvent::FINISHED event is sent or received. This means that if | 930 // AnimationEvent::FINISHED event is sent or received. This means that if |
| 930 // we don't have an events vector, we must ensure that non-aborted animations | 931 // we don't have an events vector, we must ensure that non-aborted animations |
| 931 // have received a finished event before marking them for deletion. | 932 // have received a finished event before marking them for deletion. |
| 932 for (size_t i = 0; i < animations_.size(); i++) { | 933 for (size_t i = 0; i < animations_.size(); i++) { |
| 933 int group_id = animations_[i]->group(); | 934 int group_id = animations_[i]->group(); |
| 934 if (animations_[i]->run_state() == Animation::ABORTED) { | 935 if (animations_[i]->run_state() == Animation::ABORTED) { |
| 935 if (events && !animations_[i]->is_impl_only()) { | 936 if (events && !animations_[i]->is_impl_only()) { |
| 936 AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id, | 937 AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id, |
| 937 animations_[i]->target_property(), | 938 animations_[i]->target_property(), |
| 938 monotonic_time); | 939 monotonic_time); |
| 939 events->push_back(aborted_event); | 940 events->events_.push_back(aborted_event); |
| 940 } | 941 } |
| 941 // If on the compositor or on the main thread and received finish event, | 942 // If on the compositor or on the main thread and received finish event, |
| 942 // animation can be marked for deletion. | 943 // animation can be marked for deletion. |
| 943 if (events || animations_[i]->received_finished_event()) { | 944 if (events || animations_[i]->received_finished_event()) { |
| 944 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION, | 945 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION, |
| 945 monotonic_time); | 946 monotonic_time); |
| 946 marked_animations_for_deletions = true; | 947 marked_animations_for_deletions = true; |
| 947 } | 948 } |
| 948 continue; | 949 continue; |
| 949 } | 950 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 AnimationEvent finished_event( | 1000 AnimationEvent finished_event( |
| 1000 AnimationEvent::FINISHED, id_, | 1001 AnimationEvent::FINISHED, id_, |
| 1001 animations_[animation_index]->group(), | 1002 animations_[animation_index]->group(), |
| 1002 animations_[animation_index]->target_property(), | 1003 animations_[animation_index]->target_property(), |
| 1003 monotonic_time); | 1004 monotonic_time); |
| 1004 finished_event.is_impl_only = | 1005 finished_event.is_impl_only = |
| 1005 animations_[animation_index]->is_impl_only(); | 1006 animations_[animation_index]->is_impl_only(); |
| 1006 if (finished_event.is_impl_only) | 1007 if (finished_event.is_impl_only) |
| 1007 NotifyAnimationFinished(finished_event); | 1008 NotifyAnimationFinished(finished_event); |
| 1008 else | 1009 else |
| 1009 events->push_back(finished_event); | 1010 events->events_.push_back(finished_event); |
| 1010 } | 1011 } |
| 1011 animations_[animation_index]->SetRunState( | 1012 animations_[animation_index]->SetRunState( |
| 1012 Animation::WAITING_FOR_DELETION, monotonic_time); | 1013 Animation::WAITING_FOR_DELETION, monotonic_time); |
| 1013 } | 1014 } |
| 1014 marked_animations_for_deletions = true; | 1015 marked_animations_for_deletions = true; |
| 1015 } | 1016 } |
| 1016 } | 1017 } |
| 1017 if (marked_animations_for_deletions) | 1018 if (marked_animations_for_deletions) |
| 1018 NotifyObserversAnimationWaitingForDeletion(); | 1019 NotifyObserversAnimationWaitingForDeletion(); |
| 1019 } | 1020 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 &value_observers_); | 1248 &value_observers_); |
| 1248 LayerAnimationValueObserver* obs; | 1249 LayerAnimationValueObserver* obs; |
| 1249 while ((obs = it.GetNext()) != nullptr) | 1250 while ((obs = it.GetNext()) != nullptr) |
| 1250 if (obs->IsActive()) | 1251 if (obs->IsActive()) |
| 1251 return true; | 1252 return true; |
| 1252 } | 1253 } |
| 1253 return false; | 1254 return false; |
| 1254 } | 1255 } |
| 1255 | 1256 |
| 1256 } // namespace cc | 1257 } // namespace cc |
| OLD | NEW |