Chromium Code Reviews| 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 <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" |
| 11 #include "cc/animation/animation_registrar.h" | 11 #include "cc/animation/animation_registrar.h" |
| 12 #include "cc/animation/keyframed_animation_curve.h" | 12 #include "cc/animation/keyframed_animation_curve.h" |
| 13 #include "cc/animation/layer_animation_value_observer.h" | 13 #include "cc/animation/layer_animation_value_observer.h" |
| 14 #include "cc/animation/layer_animation_value_provider.h" | 14 #include "cc/animation/layer_animation_value_provider.h" |
| 15 #include "cc/animation/scroll_offset_animation_curve.h" | 15 #include "cc/animation/scroll_offset_animation_curve.h" |
| 16 #include "cc/base/scoped_ptr_algorithm.h" | 16 #include "cc/base/scoped_ptr_algorithm.h" |
| 17 #include "cc/base/time_util.h" | |
| 17 #include "cc/output/filter_operations.h" | 18 #include "cc/output/filter_operations.h" |
| 18 #include "ui/gfx/box_f.h" | 19 #include "ui/gfx/box_f.h" |
| 19 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 LayerAnimationController::LayerAnimationController(int id) | 24 LayerAnimationController::LayerAnimationController(int id) |
| 24 : registrar_(0), | 25 : registrar_(0), |
| 25 id_(id), | 26 id_(id), |
| 26 is_active_(false), | 27 is_active_(false), |
| 27 last_tick_time_(0), | 28 last_tick_time_(), |
| 28 value_provider_(NULL), | 29 value_provider_(NULL), |
| 29 layer_animation_delegate_(NULL) {} | 30 layer_animation_delegate_(NULL) { |
| 31 } | |
| 30 | 32 |
| 31 LayerAnimationController::~LayerAnimationController() { | 33 LayerAnimationController::~LayerAnimationController() { |
| 32 if (registrar_) | 34 if (registrar_) |
| 33 registrar_->UnregisterAnimationController(this); | 35 registrar_->UnregisterAnimationController(this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 38 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( |
| 37 int id) { | 39 int id) { |
| 38 return make_scoped_refptr(new LayerAnimationController(id)); | 40 return make_scoped_refptr(new LayerAnimationController(id)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void LayerAnimationController::PauseAnimation(int animation_id, | 43 void LayerAnimationController::PauseAnimation(int animation_id, |
| 42 double time_offset) { | 44 base::TimeDelta time_offset) { |
| 43 for (size_t i = 0; i < animations_.size(); ++i) { | 45 for (size_t i = 0; i < animations_.size(); ++i) { |
| 44 if (animations_[i]->id() == animation_id) { | 46 if (animations_[i]->id() == animation_id) { |
| 45 animations_[i]->SetRunState(Animation::Paused, | 47 animations_[i]->SetRunState(Animation::Paused, |
| 46 time_offset + animations_[i]->start_time()); | 48 time_offset + animations_[i]->start_time()); |
| 47 } | 49 } |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 | 52 |
| 51 struct HasAnimationId { | 53 struct HasAnimationId { |
| 52 explicit HasAnimationId(int id) : id_(id) {} | 54 explicit HasAnimationId(int id) : id_(id) {} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // Remove finished impl side animations only after pushing, | 116 // Remove finished impl side animations only after pushing, |
| 115 // and only after the animations are deleted on the main thread | 117 // and only after the animations are deleted on the main thread |
| 116 // this insures we will never push an animation twice. | 118 // this insures we will never push an animation twice. |
| 117 RemoveAnimationsCompletedOnMainThread(controller_impl); | 119 RemoveAnimationsCompletedOnMainThread(controller_impl); |
| 118 | 120 |
| 119 PushPropertiesToImplThread(controller_impl); | 121 PushPropertiesToImplThread(controller_impl); |
| 120 controller_impl->UpdateActivation(NormalActivation); | 122 controller_impl->UpdateActivation(NormalActivation); |
| 121 UpdateActivation(NormalActivation); | 123 UpdateActivation(NormalActivation); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void LayerAnimationController::Animate(double monotonic_time) { | 126 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { |
| 125 DCHECK(monotonic_time); | 127 DCHECK(monotonic_time != base::TimeTicks()); |
| 126 if (!HasValueObserver()) | 128 if (!HasValueObserver()) |
| 127 return; | 129 return; |
| 128 | 130 |
| 129 StartAnimations(monotonic_time); | 131 StartAnimations(monotonic_time); |
| 130 TickAnimations(monotonic_time); | 132 TickAnimations(monotonic_time); |
| 131 last_tick_time_ = monotonic_time; | 133 last_tick_time_ = monotonic_time; |
| 132 } | 134 } |
| 133 | 135 |
| 134 void LayerAnimationController::AccumulatePropertyUpdates( | 136 void LayerAnimationController::AccumulatePropertyUpdates( |
| 135 double monotonic_time, | 137 base::TimeTicks monotonic_time, |
| 136 AnimationEventsVector* events) { | 138 AnimationEventsVector* events) { |
| 137 if (!events) | 139 if (!events) |
| 138 return; | 140 return; |
| 139 | 141 |
| 140 for (size_t i = 0; i < animations_.size(); ++i) { | 142 for (size_t i = 0; i < animations_.size(); ++i) { |
| 141 Animation* animation = animations_[i]; | 143 Animation* animation = animations_[i]; |
| 142 if (!animation->is_impl_only()) | 144 if (!animation->is_impl_only()) |
| 143 continue; | 145 continue; |
| 144 | 146 |
| 145 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); | 147 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 NOTREACHED(); | 198 NOTREACHED(); |
| 197 } | 199 } |
| 198 } | 200 } |
| 199 } | 201 } |
| 200 | 202 |
| 201 void LayerAnimationController::UpdateState(bool start_ready_animations, | 203 void LayerAnimationController::UpdateState(bool start_ready_animations, |
| 202 AnimationEventsVector* events) { | 204 AnimationEventsVector* events) { |
| 203 if (!HasActiveValueObserver()) | 205 if (!HasActiveValueObserver()) |
| 204 return; | 206 return; |
| 205 | 207 |
| 206 DCHECK(last_tick_time_); | 208 DCHECK(TimeUtil::TicksInSecondsF(last_tick_time_)); |
|
ajuma
2014/05/05 15:13:32
DCHECK(last_tick_time != base::TimeTicks())
(This
Sikugu_
2014/05/07 14:49:07
Done.
| |
| 207 if (start_ready_animations) | 209 if (start_ready_animations) |
| 208 PromoteStartedAnimations(last_tick_time_, events); | 210 PromoteStartedAnimations(last_tick_time_, events); |
| 209 | 211 |
| 210 MarkFinishedAnimations(last_tick_time_); | 212 MarkFinishedAnimations(last_tick_time_); |
| 211 MarkAnimationsForDeletion(last_tick_time_, events); | 213 MarkAnimationsForDeletion(last_tick_time_, events); |
| 212 | 214 |
| 213 if (start_ready_animations) { | 215 if (start_ready_animations) { |
| 214 StartAnimations(last_tick_time_); | 216 StartAnimations(last_tick_time_); |
| 215 PromoteStartedAnimations(last_tick_time_, events); | 217 PromoteStartedAnimations(last_tick_time_, events); |
| 216 } | 218 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 295 |
| 294 registrar_ = registrar; | 296 registrar_ = registrar; |
| 295 if (registrar_) | 297 if (registrar_) |
| 296 registrar_->RegisterAnimationController(this); | 298 registrar_->RegisterAnimationController(this); |
| 297 | 299 |
| 298 UpdateActivation(ForceActivation); | 300 UpdateActivation(ForceActivation); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void LayerAnimationController::NotifyAnimationStarted( | 303 void LayerAnimationController::NotifyAnimationStarted( |
| 302 const AnimationEvent& event) { | 304 const AnimationEvent& event) { |
| 303 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | |
| 304 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | |
| 305 if (event.is_impl_only) { | 305 if (event.is_impl_only) { |
| 306 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 306 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, |
| 307 OnAnimationStarted(event)); | 307 OnAnimationStarted(event)); |
| 308 if (layer_animation_delegate_) | 308 if (layer_animation_delegate_) |
| 309 layer_animation_delegate_->NotifyAnimationStarted(monotonic_time, | 309 layer_animation_delegate_->NotifyAnimationStarted(event.monotonic_time, |
| 310 event.target_property); | 310 event.target_property); |
| 311 | |
| 312 return; | 311 return; |
| 313 } | 312 } |
| 314 | 313 |
| 315 for (size_t i = 0; i < animations_.size(); ++i) { | 314 for (size_t i = 0; i < animations_.size(); ++i) { |
| 316 if (animations_[i]->group() == event.group_id && | 315 if (animations_[i]->group() == event.group_id && |
| 317 animations_[i]->target_property() == event.target_property && | 316 animations_[i]->target_property() == event.target_property && |
| 318 animations_[i]->needs_synchronized_start_time()) { | 317 animations_[i]->needs_synchronized_start_time()) { |
| 319 animations_[i]->set_needs_synchronized_start_time(false); | 318 animations_[i]->set_needs_synchronized_start_time(false); |
| 320 if (!animations_[i]->has_set_start_time()) | 319 if (!animations_[i]->has_set_start_time()) |
| 321 animations_[i]->set_start_time(event.monotonic_time); | 320 animations_[i]->set_start_time(event.monotonic_time); |
| 322 | 321 |
| 323 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 322 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, |
| 324 OnAnimationStarted(event)); | 323 OnAnimationStarted(event)); |
| 325 if (layer_animation_delegate_) | 324 if (layer_animation_delegate_) |
| 326 layer_animation_delegate_->NotifyAnimationStarted( | 325 layer_animation_delegate_->NotifyAnimationStarted( |
| 327 monotonic_time, event.target_property); | 326 event.monotonic_time, event.target_property); |
| 328 | 327 |
| 329 return; | 328 return; |
| 330 } | 329 } |
| 331 } | 330 } |
| 332 } | 331 } |
| 333 | 332 |
| 334 void LayerAnimationController::NotifyAnimationFinished( | 333 void LayerAnimationController::NotifyAnimationFinished( |
| 335 const AnimationEvent& event) { | 334 const AnimationEvent& event) { |
| 336 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | |
| 337 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | |
| 338 if (event.is_impl_only) { | 335 if (event.is_impl_only) { |
| 339 if (layer_animation_delegate_) | 336 if (layer_animation_delegate_) |
| 340 layer_animation_delegate_->NotifyAnimationFinished(monotonic_time, | 337 layer_animation_delegate_->NotifyAnimationFinished(event.monotonic_time, |
| 341 event.target_property); | 338 event.target_property); |
| 342 return; | 339 return; |
| 343 } | 340 } |
| 344 | 341 |
| 345 for (size_t i = 0; i < animations_.size(); ++i) { | 342 for (size_t i = 0; i < animations_.size(); ++i) { |
| 346 if (animations_[i]->group() == event.group_id && | 343 if (animations_[i]->group() == event.group_id && |
| 347 animations_[i]->target_property() == event.target_property) { | 344 animations_[i]->target_property() == event.target_property) { |
| 348 animations_[i]->set_received_finished_event(true); | 345 animations_[i]->set_received_finished_event(true); |
| 349 if (layer_animation_delegate_) | 346 if (layer_animation_delegate_) |
| 350 layer_animation_delegate_->NotifyAnimationFinished( | 347 layer_animation_delegate_->NotifyAnimationFinished( |
| 351 monotonic_time, event.target_property); | 348 event.monotonic_time, event.target_property); |
| 352 | 349 |
| 353 return; | 350 return; |
| 354 } | 351 } |
| 355 } | 352 } |
| 356 } | 353 } |
| 357 | 354 |
| 358 void LayerAnimationController::NotifyAnimationAborted( | 355 void LayerAnimationController::NotifyAnimationAborted( |
| 359 const AnimationEvent& event) { | 356 const AnimationEvent& event) { |
| 360 for (size_t i = 0; i < animations_.size(); ++i) { | 357 for (size_t i = 0; i < animations_.size(); ++i) { |
| 361 if (animations_[i]->group() == event.group_id && | 358 if (animations_[i]->group() == event.group_id && |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 void LayerAnimationController::PushPropertiesToImplThread( | 588 void LayerAnimationController::PushPropertiesToImplThread( |
| 592 LayerAnimationController* controller_impl) const { | 589 LayerAnimationController* controller_impl) const { |
| 593 for (size_t i = 0; i < animations_.size(); ++i) { | 590 for (size_t i = 0; i < animations_.size(); ++i) { |
| 594 Animation* current_impl = controller_impl->GetAnimation( | 591 Animation* current_impl = controller_impl->GetAnimation( |
| 595 animations_[i]->group(), animations_[i]->target_property()); | 592 animations_[i]->group(), animations_[i]->target_property()); |
| 596 if (current_impl) | 593 if (current_impl) |
| 597 animations_[i]->PushPropertiesTo(current_impl); | 594 animations_[i]->PushPropertiesTo(current_impl); |
| 598 } | 595 } |
| 599 } | 596 } |
| 600 | 597 |
| 601 void LayerAnimationController::StartAnimations(double monotonic_time) { | 598 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { |
| 602 // First collect running properties affecting each type of observer. | 599 // First collect running properties affecting each type of observer. |
| 603 TargetProperties blocked_properties_for_active_observers; | 600 TargetProperties blocked_properties_for_active_observers; |
| 604 TargetProperties blocked_properties_for_pending_observers; | 601 TargetProperties blocked_properties_for_pending_observers; |
| 605 for (size_t i = 0; i < animations_.size(); ++i) { | 602 for (size_t i = 0; i < animations_.size(); ++i) { |
| 606 if (animations_[i]->run_state() == Animation::Starting || | 603 if (animations_[i]->run_state() == Animation::Starting || |
| 607 animations_[i]->run_state() == Animation::Running) { | 604 animations_[i]->run_state() == Animation::Running) { |
| 608 if (animations_[i]->affects_active_observers()) { | 605 if (animations_[i]->affects_active_observers()) { |
| 609 blocked_properties_for_active_observers.insert( | 606 blocked_properties_for_active_observers.insert( |
| 610 animations_[i]->target_property()); | 607 animations_[i]->target_property()); |
| 611 } | 608 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 if (animations_[i]->group() == animations_[j]->group()) { | 659 if (animations_[i]->group() == animations_[j]->group()) { |
| 663 animations_[j]->SetRunState(Animation::Starting, monotonic_time); | 660 animations_[j]->SetRunState(Animation::Starting, monotonic_time); |
| 664 } | 661 } |
| 665 } | 662 } |
| 666 } | 663 } |
| 667 } | 664 } |
| 668 } | 665 } |
| 669 } | 666 } |
| 670 | 667 |
| 671 void LayerAnimationController::PromoteStartedAnimations( | 668 void LayerAnimationController::PromoteStartedAnimations( |
| 672 double monotonic_time, | 669 base::TimeTicks monotonic_time, |
| 673 AnimationEventsVector* events) { | 670 AnimationEventsVector* events) { |
| 674 for (size_t i = 0; i < animations_.size(); ++i) { | 671 for (size_t i = 0; i < animations_.size(); ++i) { |
| 675 if (animations_[i]->run_state() == Animation::Starting && | 672 if (animations_[i]->run_state() == Animation::Starting && |
| 676 animations_[i]->affects_active_observers()) { | 673 animations_[i]->affects_active_observers()) { |
| 677 animations_[i]->SetRunState(Animation::Running, monotonic_time); | 674 animations_[i]->SetRunState(Animation::Running, monotonic_time); |
| 678 if (!animations_[i]->has_set_start_time() && | 675 if (!animations_[i]->has_set_start_time() && |
| 679 !animations_[i]->needs_synchronized_start_time()) | 676 !animations_[i]->needs_synchronized_start_time()) |
| 680 animations_[i]->set_start_time(monotonic_time); | 677 animations_[i]->set_start_time(monotonic_time); |
| 681 if (events) { | 678 if (events) { |
| 682 AnimationEvent started_event(AnimationEvent::Started, | 679 AnimationEvent started_event(AnimationEvent::Started, |
| 683 id_, | 680 id_, |
| 684 animations_[i]->group(), | 681 animations_[i]->group(), |
| 685 animations_[i]->target_property(), | 682 animations_[i]->target_property(), |
| 686 monotonic_time); | 683 monotonic_time); |
| 687 started_event.is_impl_only = animations_[i]->is_impl_only(); | 684 started_event.is_impl_only = animations_[i]->is_impl_only(); |
| 688 events->push_back(started_event); | 685 events->push_back(started_event); |
| 689 } | 686 } |
| 690 } | 687 } |
| 691 } | 688 } |
| 692 } | 689 } |
| 693 | 690 |
| 694 void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) { | 691 void LayerAnimationController::MarkFinishedAnimations( |
| 692 base::TimeTicks monotonic_time) { | |
| 695 for (size_t i = 0; i < animations_.size(); ++i) { | 693 for (size_t i = 0; i < animations_.size(); ++i) { |
| 696 if (animations_[i]->IsFinishedAt(monotonic_time) && | 694 if (animations_[i]->IsFinishedAt(monotonic_time) && |
| 697 animations_[i]->run_state() != Animation::Aborted && | 695 animations_[i]->run_state() != Animation::Aborted && |
| 698 animations_[i]->run_state() != Animation::WaitingForDeletion) | 696 animations_[i]->run_state() != Animation::WaitingForDeletion) |
| 699 animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 697 animations_[i]->SetRunState(Animation::Finished, monotonic_time); |
| 700 } | 698 } |
| 701 } | 699 } |
| 702 | 700 |
| 703 void LayerAnimationController::MarkAnimationsForDeletion( | 701 void LayerAnimationController::MarkAnimationsForDeletion( |
| 704 double monotonic_time, AnimationEventsVector* events) { | 702 base::TimeTicks monotonic_time, |
| 703 AnimationEventsVector* events) { | |
| 705 bool marked_animations_for_deletions = false; | 704 bool marked_animations_for_deletions = false; |
| 706 | 705 |
| 707 // Non-aborted animations are marked for deletion after a corresponding | 706 // Non-aborted animations are marked for deletion after a corresponding |
| 708 // AnimationEvent::Finished event is sent or received. This means that if | 707 // AnimationEvent::Finished event is sent or received. This means that if |
| 709 // we don't have an events vector, we must ensure that non-aborted animations | 708 // we don't have an events vector, we must ensure that non-aborted animations |
| 710 // have received a finished event before marking them for deletion. | 709 // have received a finished event before marking them for deletion. |
| 711 for (size_t i = 0; i < animations_.size(); i++) { | 710 for (size_t i = 0; i < animations_.size(); i++) { |
| 712 int group_id = animations_[i]->group(); | 711 int group_id = animations_[i]->group(); |
| 713 if (animations_[i]->run_state() == Animation::Aborted) { | 712 if (animations_[i]->run_state() == Animation::Aborted) { |
| 714 if (events && !animations_[i]->is_impl_only()) { | 713 if (events && !animations_[i]->is_impl_only()) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 } | 780 } |
| 782 | 781 |
| 783 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 782 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { |
| 784 animations_.erase(cc::remove_if(&animations_, | 783 animations_.erase(cc::remove_if(&animations_, |
| 785 animations_.begin(), | 784 animations_.begin(), |
| 786 animations_.end(), | 785 animations_.end(), |
| 787 IsWaitingForDeletion), | 786 IsWaitingForDeletion), |
| 788 animations_.end()); | 787 animations_.end()); |
| 789 } | 788 } |
| 790 | 789 |
| 791 void LayerAnimationController::TickAnimations(double monotonic_time) { | 790 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { |
| 792 for (size_t i = 0; i < animations_.size(); ++i) { | 791 for (size_t i = 0; i < animations_.size(); ++i) { |
| 793 if (animations_[i]->run_state() == Animation::Starting || | 792 if (animations_[i]->run_state() == Animation::Starting || |
| 794 animations_[i]->run_state() == Animation::Running || | 793 animations_[i]->run_state() == Animation::Running || |
| 795 animations_[i]->run_state() == Animation::Paused) { | 794 animations_[i]->run_state() == Animation::Paused) { |
| 796 double trimmed = | 795 double trimmed = |
| 797 animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 796 animations_[i]->TrimTimeToCurrentIteration(monotonic_time); |
| 798 | 797 |
| 799 switch (animations_[i]->target_property()) { | 798 switch (animations_[i]->target_property()) { |
| 800 case Animation::Transform: { | 799 case Animation::Transform: { |
| 801 const TransformAnimationCurve* transform_animation_curve = | 800 const TransformAnimationCurve* transform_animation_curve = |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 value_observers_); | 960 value_observers_); |
| 962 LayerAnimationValueObserver* obs; | 961 LayerAnimationValueObserver* obs; |
| 963 while ((obs = it.GetNext()) != NULL) | 962 while ((obs = it.GetNext()) != NULL) |
| 964 if (obs->IsActive()) | 963 if (obs->IsActive()) |
| 965 return true; | 964 return true; |
| 966 } | 965 } |
| 967 return false; | 966 return false; |
| 968 } | 967 } |
| 969 | 968 |
| 970 } // namespace cc | 969 } // namespace cc |
| OLD | NEW |