| 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/output/filter_operations.h" | 17 #include "cc/output/filter_operations.h" |
| 18 #include "ui/gfx/box_f.h" | 18 #include "ui/gfx/box_f.h" |
| 19 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 LayerAnimationController::LayerAnimationController(int id) | 23 LayerAnimationController::LayerAnimationController(int id) |
| 24 : registrar_(0), | 24 : registrar_(0), |
| 25 id_(id), | 25 id_(id), |
| 26 is_active_(false), | 26 is_active_(false), |
| 27 last_tick_time_(0), | 27 last_tick_time_(base::TimeTicks()), |
| 28 value_provider_(NULL), | 28 value_provider_(NULL), |
| 29 layer_animation_delegate_(NULL) {} | 29 layer_animation_delegate_(NULL) {} |
| 30 | 30 |
| 31 LayerAnimationController::~LayerAnimationController() { | 31 LayerAnimationController::~LayerAnimationController() { |
| 32 if (registrar_) | 32 if (registrar_) |
| 33 registrar_->UnregisterAnimationController(this); | 33 registrar_->UnregisterAnimationController(this); |
| 34 } | 34 } |
| 35 | 35 |
| 36 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 36 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( |
| 37 int id) { | 37 int id) { |
| 38 return make_scoped_refptr(new LayerAnimationController(id)); | 38 return make_scoped_refptr(new LayerAnimationController(id)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void LayerAnimationController::PauseAnimation(int animation_id, | 41 void LayerAnimationController::PauseAnimation(int animation_id, |
| 42 double time_offset) { | 42 base::TimeTicks time_offset) { |
| 43 for (size_t i = 0; i < active_animations_.size(); ++i) { | 43 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 44 if (active_animations_[i]->id() == animation_id) { | 44 if (active_animations_[i]->id() == animation_id) { |
| 45 active_animations_[i]->SetRunState( | 45 active_animations_[i]->SetRunState( |
| 46 Animation::Paused, time_offset + active_animations_[i]->start_time()); | 46 Animation::Paused, |
| 47 (time_offset - base::TimeTicks()) + |
| 48 active_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) {} |
| 53 bool operator()(Animation* animation) const { | 55 bool operator()(Animation* animation) const { |
| 54 return animation->id() == id_; | 56 return animation->id() == id_; |
| 55 } | 57 } |
| 56 | 58 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Remove finished impl side animations only after pushing, | 118 // Remove finished impl side animations only after pushing, |
| 117 // and only after the animations are deleted on the main thread | 119 // and only after the animations are deleted on the main thread |
| 118 // this insures we will never push an animation twice. | 120 // this insures we will never push an animation twice. |
| 119 RemoveAnimationsCompletedOnMainThread(controller_impl); | 121 RemoveAnimationsCompletedOnMainThread(controller_impl); |
| 120 | 122 |
| 121 PushPropertiesToImplThread(controller_impl); | 123 PushPropertiesToImplThread(controller_impl); |
| 122 controller_impl->UpdateActivation(NormalActivation); | 124 controller_impl->UpdateActivation(NormalActivation); |
| 123 UpdateActivation(NormalActivation); | 125 UpdateActivation(NormalActivation); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void LayerAnimationController::Animate(double monotonic_time) { | 128 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { |
| 127 DCHECK(monotonic_time); | 129 DCHECK(monotonic_time != base::TimeTicks()); |
| 128 if (!HasValueObserver()) | 130 if (!HasValueObserver()) |
| 129 return; | 131 return; |
| 130 | 132 |
| 131 StartAnimations(monotonic_time); | 133 StartAnimations(monotonic_time); |
| 132 TickAnimations(monotonic_time); | 134 TickAnimations(monotonic_time); |
| 133 last_tick_time_ = monotonic_time; | 135 last_tick_time_ = monotonic_time; |
| 134 } | 136 } |
| 135 | 137 |
| 136 void LayerAnimationController::AccumulatePropertyUpdates( | 138 void LayerAnimationController::AccumulatePropertyUpdates( |
| 137 double monotonic_time, | 139 base::TimeTicks monotonic_time, |
| 138 AnimationEventsVector* events) { | 140 AnimationEventsVector* events) { |
| 139 if (!events) | 141 if (!events) |
| 140 return; | 142 return; |
| 141 | 143 |
| 142 for (size_t i = 0; i < active_animations_.size(); ++i) { | 144 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 143 Animation* animation = active_animations_[i]; | 145 Animation* animation = active_animations_[i]; |
| 144 if (!animation->is_impl_only()) | 146 if (!animation->is_impl_only()) |
| 145 continue; | 147 continue; |
| 146 | 148 |
| 147 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); | 149 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 276 |
| 275 registrar_ = registrar; | 277 registrar_ = registrar; |
| 276 if (registrar_) | 278 if (registrar_) |
| 277 registrar_->RegisterAnimationController(this); | 279 registrar_->RegisterAnimationController(this); |
| 278 | 280 |
| 279 UpdateActivation(ForceActivation); | 281 UpdateActivation(ForceActivation); |
| 280 } | 282 } |
| 281 | 283 |
| 282 void LayerAnimationController::NotifyAnimationStarted( | 284 void LayerAnimationController::NotifyAnimationStarted( |
| 283 const AnimationEvent& event) { | 285 const AnimationEvent& event) { |
| 284 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | 286 base::TimeTicks monotonic_time = event.monotonic_time; |
| 285 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | |
| 286 if (event.is_impl_only) { | 287 if (event.is_impl_only) { |
| 287 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 288 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, |
| 288 OnAnimationStarted(event)); | 289 OnAnimationStarted(event)); |
| 289 if (layer_animation_delegate_) | 290 if (layer_animation_delegate_) |
| 290 layer_animation_delegate_->NotifyAnimationStarted(monotonic_time, | 291 layer_animation_delegate_->NotifyAnimationStarted(monotonic_time, |
| 291 event.target_property); | 292 event.target_property); |
| 292 | 293 |
| 293 return; | 294 return; |
| 294 } | 295 } |
| 295 | 296 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 307 layer_animation_delegate_->NotifyAnimationStarted( | 308 layer_animation_delegate_->NotifyAnimationStarted( |
| 308 monotonic_time, event.target_property); | 309 monotonic_time, event.target_property); |
| 309 | 310 |
| 310 return; | 311 return; |
| 311 } | 312 } |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 | 315 |
| 315 void LayerAnimationController::NotifyAnimationFinished( | 316 void LayerAnimationController::NotifyAnimationFinished( |
| 316 const AnimationEvent& event) { | 317 const AnimationEvent& event) { |
| 317 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | 318 base::TimeTicks monotonic_time = event.monotonic_time; |
| 318 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | |
| 319 if (event.is_impl_only) { | 319 if (event.is_impl_only) { |
| 320 if (layer_animation_delegate_) | 320 if (layer_animation_delegate_) |
| 321 layer_animation_delegate_->NotifyAnimationFinished(monotonic_time, | 321 layer_animation_delegate_->NotifyAnimationFinished(monotonic_time, |
| 322 event.target_property); | 322 event.target_property); |
| 323 return; | 323 return; |
| 324 } | 324 } |
| 325 | 325 |
| 326 for (size_t i = 0; i < active_animations_.size(); ++i) { | 326 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 327 if (active_animations_[i]->group() == event.group_id && | 327 if (active_animations_[i]->group() == event.group_id && |
| 328 active_animations_[i]->target_property() == event.target_property) { | 328 active_animations_[i]->target_property() == event.target_property) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 for (size_t i = 0; i < active_animations_.size(); ++i) { | 568 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 569 Animation* current_impl = | 569 Animation* current_impl = |
| 570 controller_impl->GetAnimation( | 570 controller_impl->GetAnimation( |
| 571 active_animations_[i]->group(), | 571 active_animations_[i]->group(), |
| 572 active_animations_[i]->target_property()); | 572 active_animations_[i]->target_property()); |
| 573 if (current_impl) | 573 if (current_impl) |
| 574 active_animations_[i]->PushPropertiesTo(current_impl); | 574 active_animations_[i]->PushPropertiesTo(current_impl); |
| 575 } | 575 } |
| 576 } | 576 } |
| 577 | 577 |
| 578 void LayerAnimationController::StartAnimations(double monotonic_time) { | 578 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { |
| 579 // First collect running properties. | 579 // First collect running properties. |
| 580 TargetProperties blocked_properties; | 580 TargetProperties blocked_properties; |
| 581 for (size_t i = 0; i < active_animations_.size(); ++i) { | 581 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 582 if (active_animations_[i]->run_state() == Animation::Starting || | 582 if (active_animations_[i]->run_state() == Animation::Starting || |
| 583 active_animations_[i]->run_state() == Animation::Running) | 583 active_animations_[i]->run_state() == Animation::Running) |
| 584 blocked_properties.insert(active_animations_[i]->target_property()); | 584 blocked_properties.insert(active_animations_[i]->target_property()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 for (size_t i = 0; i < active_animations_.size(); ++i) { | 587 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 588 if (active_animations_[i]->run_state() == | 588 if (active_animations_[i]->run_state() == |
| (...skipping 20 matching lines...) Expand all Loading... |
| 609 } | 609 } |
| 610 | 610 |
| 611 // If the intersection is null, then we are free to start the animations | 611 // If the intersection is null, then we are free to start the animations |
| 612 // in the group. | 612 // in the group. |
| 613 if (null_intersection) { | 613 if (null_intersection) { |
| 614 active_animations_[i]->SetRunState( | 614 active_animations_[i]->SetRunState( |
| 615 Animation::Starting, monotonic_time); | 615 Animation::Starting, monotonic_time); |
| 616 for (size_t j = i + 1; j < active_animations_.size(); ++j) { | 616 for (size_t j = i + 1; j < active_animations_.size(); ++j) { |
| 617 if (active_animations_[i]->group() == | 617 if (active_animations_[i]->group() == |
| 618 active_animations_[j]->group()) { | 618 active_animations_[j]->group()) { |
| 619 active_animations_[j]->SetRunState( | 619 active_animations_[j]->SetRunState(Animation::Starting, |
| 620 Animation::Starting, monotonic_time); | 620 monotonic_time); |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 | 627 |
| 628 void LayerAnimationController::PromoteStartedAnimations( | 628 void LayerAnimationController::PromoteStartedAnimations( |
| 629 double monotonic_time, | 629 base::TimeTicks monotonic_time, |
| 630 AnimationEventsVector* events) { | 630 AnimationEventsVector* events) { |
| 631 for (size_t i = 0; i < active_animations_.size(); ++i) { | 631 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 632 if (active_animations_[i]->run_state() == Animation::Starting) { | 632 if (active_animations_[i]->run_state() == Animation::Starting) { |
| 633 active_animations_[i]->SetRunState(Animation::Running, monotonic_time); | 633 active_animations_[i]->SetRunState(Animation::Running, monotonic_time); |
| 634 if (!active_animations_[i]->has_set_start_time() && | 634 if (!active_animations_[i]->has_set_start_time() && |
| 635 !active_animations_[i]->needs_synchronized_start_time()) | 635 !active_animations_[i]->needs_synchronized_start_time()) |
| 636 active_animations_[i]->set_start_time(monotonic_time); | 636 active_animations_[i]->set_start_time(monotonic_time); |
| 637 if (events) { | 637 if (events) { |
| 638 AnimationEvent started_event( | 638 AnimationEvent started_event( |
| 639 AnimationEvent::Started, | 639 AnimationEvent::Started, |
| 640 id_, | 640 id_, |
| 641 active_animations_[i]->group(), | 641 active_animations_[i]->group(), |
| 642 active_animations_[i]->target_property(), | 642 active_animations_[i]->target_property(), |
| 643 monotonic_time); | 643 monotonic_time); |
| 644 started_event.is_impl_only = active_animations_[i]->is_impl_only(); | 644 started_event.is_impl_only = active_animations_[i]->is_impl_only(); |
| 645 events->push_back(started_event); | 645 events->push_back(started_event); |
| 646 } | 646 } |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) { | 651 void LayerAnimationController::MarkFinishedAnimations( |
| 652 base::TimeTicks monotonic_time) { |
| 652 for (size_t i = 0; i < active_animations_.size(); ++i) { | 653 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 653 if (active_animations_[i]->IsFinishedAt(monotonic_time) && | 654 if (active_animations_[i]->IsFinishedAt(monotonic_time) && |
| 654 active_animations_[i]->run_state() != Animation::Aborted && | 655 active_animations_[i]->run_state() != Animation::Aborted && |
| 655 active_animations_[i]->run_state() != Animation::WaitingForDeletion) | 656 active_animations_[i]->run_state() != Animation::WaitingForDeletion) |
| 656 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 657 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); |
| 657 } | 658 } |
| 658 } | 659 } |
| 659 | 660 |
| 660 void LayerAnimationController::MarkAnimationsForDeletion( | 661 void LayerAnimationController::MarkAnimationsForDeletion( |
| 661 double monotonic_time, AnimationEventsVector* events) { | 662 base::TimeTicks monotonic_time, |
| 663 AnimationEventsVector* events) { |
| 662 bool marked_animations_for_deletions = false; | 664 bool marked_animations_for_deletions = false; |
| 663 | 665 |
| 664 // Non-aborted animations are marked for deletion after a corresponding | 666 // Non-aborted animations are marked for deletion after a corresponding |
| 665 // AnimationEvent::Finished event is sent or received. This means that if | 667 // AnimationEvent::Finished event is sent or received. This means that if |
| 666 // we don't have an events vector, we must ensure that non-aborted animations | 668 // we don't have an events vector, we must ensure that non-aborted animations |
| 667 // have received a finished event before marking them for deletion. | 669 // have received a finished event before marking them for deletion. |
| 668 for (size_t i = 0; i < active_animations_.size(); i++) { | 670 for (size_t i = 0; i < active_animations_.size(); i++) { |
| 669 int group_id = active_animations_[i]->group(); | 671 int group_id = active_animations_[i]->group(); |
| 670 if (active_animations_[i]->run_state() == Animation::Aborted) { | 672 if (active_animations_[i]->run_state() == Animation::Aborted) { |
| 671 if (events && !active_animations_[i]->is_impl_only()) { | 673 if (events && !active_animations_[i]->is_impl_only()) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 743 |
| 742 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 744 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { |
| 743 ScopedPtrVector<Animation>& animations = active_animations_; | 745 ScopedPtrVector<Animation>& animations = active_animations_; |
| 744 animations.erase(cc::remove_if(&animations, | 746 animations.erase(cc::remove_if(&animations, |
| 745 animations.begin(), | 747 animations.begin(), |
| 746 animations.end(), | 748 animations.end(), |
| 747 IsWaitingForDeletion), | 749 IsWaitingForDeletion), |
| 748 animations.end()); | 750 animations.end()); |
| 749 } | 751 } |
| 750 | 752 |
| 751 void LayerAnimationController::TickAnimations(double monotonic_time) { | 753 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { |
| 752 for (size_t i = 0; i < active_animations_.size(); ++i) { | 754 for (size_t i = 0; i < active_animations_.size(); ++i) { |
| 753 if (active_animations_[i]->run_state() == Animation::Starting || | 755 if (active_animations_[i]->run_state() == Animation::Starting || |
| 754 active_animations_[i]->run_state() == Animation::Running || | 756 active_animations_[i]->run_state() == Animation::Running || |
| 755 active_animations_[i]->run_state() == Animation::Paused) { | 757 active_animations_[i]->run_state() == Animation::Paused) { |
| 756 double trimmed = | 758 double trimmed = |
| 757 active_animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 759 active_animations_[i]->TrimTimeToCurrentIteration(monotonic_time); |
| 758 | 760 |
| 759 switch (active_animations_[i]->target_property()) { | 761 switch (active_animations_[i]->target_property()) { |
| 760 case Animation::Transform: { | 762 case Animation::Transform: { |
| 761 const TransformAnimationCurve* transform_animation_curve = | 763 const TransformAnimationCurve* transform_animation_curve = |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 value_observers_); | 874 value_observers_); |
| 873 LayerAnimationValueObserver* obs; | 875 LayerAnimationValueObserver* obs; |
| 874 while ((obs = it.GetNext()) != NULL) | 876 while ((obs = it.GetNext()) != NULL) |
| 875 if (obs->IsActive()) | 877 if (obs->IsActive()) |
| 876 return true; | 878 return true; |
| 877 } | 879 } |
| 878 return false; | 880 return false; |
| 879 } | 881 } |
| 880 | 882 |
| 881 } // namespace cc | 883 } // namespace cc |
| OLD | NEW |