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::TimeDelta 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 // TODO(sikugu): http://crbug.com/178171 - Remove double |
| 46 // and use base::TimeTicks/TimeDelta instead all over the file. |
| 47 // Remove usage of TimeTicksToDoubleTime. |
45 active_animations_[i]->SetRunState( | 48 active_animations_[i]->SetRunState( |
46 Animation::Paused, time_offset + active_animations_[i]->start_time()); | 49 Animation::Paused, time_offset + active_animations_[i]->start_time()); |
47 } | 50 } |
48 } | 51 } |
49 } | 52 } |
50 | 53 |
51 struct HasAnimationId { | 54 struct HasAnimationId { |
52 explicit HasAnimationId(int id) : id_(id) {} | 55 explicit HasAnimationId(int id) : id_(id) {} |
53 bool operator()(Animation* animation) const { | 56 bool operator()(Animation* animation) const { |
54 return animation->id() == id_; | 57 return animation->id() == id_; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Remove finished impl side animations only after pushing, | 119 // Remove finished impl side animations only after pushing, |
117 // and only after the animations are deleted on the main thread | 120 // and only after the animations are deleted on the main thread |
118 // this insures we will never push an animation twice. | 121 // this insures we will never push an animation twice. |
119 RemoveAnimationsCompletedOnMainThread(controller_impl); | 122 RemoveAnimationsCompletedOnMainThread(controller_impl); |
120 | 123 |
121 PushPropertiesToImplThread(controller_impl); | 124 PushPropertiesToImplThread(controller_impl); |
122 controller_impl->UpdateActivation(NormalActivation); | 125 controller_impl->UpdateActivation(NormalActivation); |
123 UpdateActivation(NormalActivation); | 126 UpdateActivation(NormalActivation); |
124 } | 127 } |
125 | 128 |
126 void LayerAnimationController::Animate(double monotonic_time) { | 129 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { |
127 DCHECK(monotonic_time); | 130 DCHECK(monotonic_time != base::TimeTicks()); |
128 if (!HasValueObserver()) | 131 if (!HasValueObserver()) |
129 return; | 132 return; |
130 | 133 |
131 StartAnimations(monotonic_time); | 134 StartAnimations(monotonic_time); |
132 TickAnimations(monotonic_time); | 135 TickAnimations(monotonic_time); |
133 last_tick_time_ = monotonic_time; | 136 last_tick_time_ = monotonic_time; |
134 } | 137 } |
135 | 138 |
136 void LayerAnimationController::AccumulatePropertyUpdates( | 139 void LayerAnimationController::AccumulatePropertyUpdates( |
137 double monotonic_time, | 140 base::TimeTicks monotonic_time, |
138 AnimationEventsVector* events) { | 141 AnimationEventsVector* events) { |
139 if (!events) | 142 if (!events) |
140 return; | 143 return; |
141 | 144 |
142 for (size_t i = 0; i < active_animations_.size(); ++i) { | 145 for (size_t i = 0; i < active_animations_.size(); ++i) { |
143 Animation* animation = active_animations_[i]; | 146 Animation* animation = active_animations_[i]; |
144 if (!animation->is_impl_only()) | 147 if (!animation->is_impl_only()) |
145 continue; | 148 continue; |
146 | 149 |
147 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); | 150 double trimmed = animation->TrimTimeToCurrentIteration(monotonic_time); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 277 |
275 registrar_ = registrar; | 278 registrar_ = registrar; |
276 if (registrar_) | 279 if (registrar_) |
277 registrar_->RegisterAnimationController(this); | 280 registrar_->RegisterAnimationController(this); |
278 | 281 |
279 UpdateActivation(ForceActivation); | 282 UpdateActivation(ForceActivation); |
280 } | 283 } |
281 | 284 |
282 void LayerAnimationController::NotifyAnimationStarted( | 285 void LayerAnimationController::NotifyAnimationStarted( |
283 const AnimationEvent& event) { | 286 const AnimationEvent& event) { |
284 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | |
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(event.monotonic_time, |
291 event.target_property); | 292 event.target_property); |
292 | |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 for (size_t i = 0; i < active_animations_.size(); ++i) { | 296 for (size_t i = 0; i < active_animations_.size(); ++i) { |
297 if (active_animations_[i]->group() == event.group_id && | 297 if (active_animations_[i]->group() == event.group_id && |
298 active_animations_[i]->target_property() == event.target_property && | 298 active_animations_[i]->target_property() == event.target_property && |
299 active_animations_[i]->needs_synchronized_start_time()) { | 299 active_animations_[i]->needs_synchronized_start_time()) { |
300 active_animations_[i]->set_needs_synchronized_start_time(false); | 300 active_animations_[i]->set_needs_synchronized_start_time(false); |
301 if (!active_animations_[i]->has_set_start_time()) | 301 if (!active_animations_[i]->has_set_start_time()) |
302 active_animations_[i]->set_start_time(event.monotonic_time); | 302 active_animations_[i]->set_start_time(event.monotonic_time); |
303 | 303 |
304 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, | 304 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, |
305 OnAnimationStarted(event)); | 305 OnAnimationStarted(event)); |
306 if (layer_animation_delegate_) | 306 if (layer_animation_delegate_) |
307 layer_animation_delegate_->NotifyAnimationStarted( | 307 layer_animation_delegate_->NotifyAnimationStarted( |
308 monotonic_time, event.target_property); | 308 event.monotonic_time, event.target_property); |
309 | 309 |
310 return; | 310 return; |
311 } | 311 } |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 void LayerAnimationController::NotifyAnimationFinished( | 315 void LayerAnimationController::NotifyAnimationFinished( |
316 const AnimationEvent& event) { | 316 const AnimationEvent& event) { |
317 base::TimeTicks monotonic_time = base::TimeTicks::FromInternalValue( | |
318 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | |
319 if (event.is_impl_only) { | 317 if (event.is_impl_only) { |
320 if (layer_animation_delegate_) | 318 if (layer_animation_delegate_) |
321 layer_animation_delegate_->NotifyAnimationFinished(monotonic_time, | 319 layer_animation_delegate_->NotifyAnimationFinished(event.monotonic_time, |
322 event.target_property); | 320 event.target_property); |
323 return; | 321 return; |
324 } | 322 } |
325 | 323 |
326 for (size_t i = 0; i < active_animations_.size(); ++i) { | 324 for (size_t i = 0; i < active_animations_.size(); ++i) { |
327 if (active_animations_[i]->group() == event.group_id && | 325 if (active_animations_[i]->group() == event.group_id && |
328 active_animations_[i]->target_property() == event.target_property) { | 326 active_animations_[i]->target_property() == event.target_property) { |
329 active_animations_[i]->set_received_finished_event(true); | 327 active_animations_[i]->set_received_finished_event(true); |
330 if (layer_animation_delegate_) | 328 if (layer_animation_delegate_) |
331 layer_animation_delegate_->NotifyAnimationFinished( | 329 layer_animation_delegate_->NotifyAnimationFinished( |
332 monotonic_time, event.target_property); | 330 event.monotonic_time, event.target_property); |
333 | 331 |
334 return; | 332 return; |
335 } | 333 } |
336 } | 334 } |
337 } | 335 } |
338 | 336 |
339 void LayerAnimationController::NotifyAnimationAborted( | 337 void LayerAnimationController::NotifyAnimationAborted( |
340 const AnimationEvent& event) { | 338 const AnimationEvent& event) { |
341 for (size_t i = 0; i < active_animations_.size(); ++i) { | 339 for (size_t i = 0; i < active_animations_.size(); ++i) { |
342 if (active_animations_[i]->group() == event.group_id && | 340 if (active_animations_[i]->group() == event.group_id && |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 for (size_t i = 0; i < active_animations_.size(); ++i) { | 566 for (size_t i = 0; i < active_animations_.size(); ++i) { |
569 Animation* current_impl = | 567 Animation* current_impl = |
570 controller_impl->GetAnimation( | 568 controller_impl->GetAnimation( |
571 active_animations_[i]->group(), | 569 active_animations_[i]->group(), |
572 active_animations_[i]->target_property()); | 570 active_animations_[i]->target_property()); |
573 if (current_impl) | 571 if (current_impl) |
574 active_animations_[i]->PushPropertiesTo(current_impl); | 572 active_animations_[i]->PushPropertiesTo(current_impl); |
575 } | 573 } |
576 } | 574 } |
577 | 575 |
578 void LayerAnimationController::StartAnimations(double monotonic_time) { | 576 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { |
579 // First collect running properties. | 577 // First collect running properties. |
580 TargetProperties blocked_properties; | 578 TargetProperties blocked_properties; |
581 for (size_t i = 0; i < active_animations_.size(); ++i) { | 579 for (size_t i = 0; i < active_animations_.size(); ++i) { |
582 if (active_animations_[i]->run_state() == Animation::Starting || | 580 if (active_animations_[i]->run_state() == Animation::Starting || |
583 active_animations_[i]->run_state() == Animation::Running) | 581 active_animations_[i]->run_state() == Animation::Running) |
584 blocked_properties.insert(active_animations_[i]->target_property()); | 582 blocked_properties.insert(active_animations_[i]->target_property()); |
585 } | 583 } |
586 | 584 |
587 for (size_t i = 0; i < active_animations_.size(); ++i) { | 585 for (size_t i = 0; i < active_animations_.size(); ++i) { |
588 if (active_animations_[i]->run_state() == | 586 if (active_animations_[i]->run_state() == |
(...skipping 30 matching lines...) Expand all Loading... |
619 active_animations_[j]->SetRunState( | 617 active_animations_[j]->SetRunState( |
620 Animation::Starting, monotonic_time); | 618 Animation::Starting, monotonic_time); |
621 } | 619 } |
622 } | 620 } |
623 } | 621 } |
624 } | 622 } |
625 } | 623 } |
626 } | 624 } |
627 | 625 |
628 void LayerAnimationController::PromoteStartedAnimations( | 626 void LayerAnimationController::PromoteStartedAnimations( |
629 double monotonic_time, | 627 base::TimeTicks monotonic_time, |
630 AnimationEventsVector* events) { | 628 AnimationEventsVector* events) { |
631 for (size_t i = 0; i < active_animations_.size(); ++i) { | 629 for (size_t i = 0; i < active_animations_.size(); ++i) { |
632 if (active_animations_[i]->run_state() == Animation::Starting) { | 630 if (active_animations_[i]->run_state() == Animation::Starting) { |
633 active_animations_[i]->SetRunState(Animation::Running, monotonic_time); | 631 active_animations_[i]->SetRunState(Animation::Running, monotonic_time); |
634 if (!active_animations_[i]->has_set_start_time() && | 632 if (!active_animations_[i]->has_set_start_time() && |
635 !active_animations_[i]->needs_synchronized_start_time()) | 633 !active_animations_[i]->needs_synchronized_start_time()) |
636 active_animations_[i]->set_start_time(monotonic_time); | 634 active_animations_[i]->set_start_time(monotonic_time); |
637 if (events) { | 635 if (events) { |
638 AnimationEvent started_event( | 636 AnimationEvent started_event( |
639 AnimationEvent::Started, | 637 AnimationEvent::Started, |
640 id_, | 638 id_, |
641 active_animations_[i]->group(), | 639 active_animations_[i]->group(), |
642 active_animations_[i]->target_property(), | 640 active_animations_[i]->target_property(), |
643 monotonic_time); | 641 monotonic_time); |
644 started_event.is_impl_only = active_animations_[i]->is_impl_only(); | 642 started_event.is_impl_only = active_animations_[i]->is_impl_only(); |
645 events->push_back(started_event); | 643 events->push_back(started_event); |
646 } | 644 } |
647 } | 645 } |
648 } | 646 } |
649 } | 647 } |
650 | 648 |
651 void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) { | 649 void LayerAnimationController::MarkFinishedAnimations( |
| 650 base::TimeTicks monotonic_time) { |
652 for (size_t i = 0; i < active_animations_.size(); ++i) { | 651 for (size_t i = 0; i < active_animations_.size(); ++i) { |
653 if (active_animations_[i]->IsFinishedAt(monotonic_time) && | 652 if (active_animations_[i]->IsFinishedAt(monotonic_time) && |
654 active_animations_[i]->run_state() != Animation::Aborted && | 653 active_animations_[i]->run_state() != Animation::Aborted && |
655 active_animations_[i]->run_state() != Animation::WaitingForDeletion) | 654 active_animations_[i]->run_state() != Animation::WaitingForDeletion) |
656 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); | 655 active_animations_[i]->SetRunState(Animation::Finished, monotonic_time); |
657 } | 656 } |
658 } | 657 } |
659 | 658 |
660 void LayerAnimationController::MarkAnimationsForDeletion( | 659 void LayerAnimationController::MarkAnimationsForDeletion( |
661 double monotonic_time, AnimationEventsVector* events) { | 660 base::TimeTicks monotonic_time, |
| 661 AnimationEventsVector* events) { |
662 bool marked_animations_for_deletions = false; | 662 bool marked_animations_for_deletions = false; |
663 | 663 |
664 // Non-aborted animations are marked for deletion after a corresponding | 664 // Non-aborted animations are marked for deletion after a corresponding |
665 // AnimationEvent::Finished event is sent or received. This means that if | 665 // 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 | 666 // 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. | 667 // have received a finished event before marking them for deletion. |
668 for (size_t i = 0; i < active_animations_.size(); i++) { | 668 for (size_t i = 0; i < active_animations_.size(); i++) { |
669 int group_id = active_animations_[i]->group(); | 669 int group_id = active_animations_[i]->group(); |
670 if (active_animations_[i]->run_state() == Animation::Aborted) { | 670 if (active_animations_[i]->run_state() == Animation::Aborted) { |
671 if (events && !active_animations_[i]->is_impl_only()) { | 671 if (events && !active_animations_[i]->is_impl_only()) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 | 741 |
742 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 742 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { |
743 ScopedPtrVector<Animation>& animations = active_animations_; | 743 ScopedPtrVector<Animation>& animations = active_animations_; |
744 animations.erase(cc::remove_if(&animations, | 744 animations.erase(cc::remove_if(&animations, |
745 animations.begin(), | 745 animations.begin(), |
746 animations.end(), | 746 animations.end(), |
747 IsWaitingForDeletion), | 747 IsWaitingForDeletion), |
748 animations.end()); | 748 animations.end()); |
749 } | 749 } |
750 | 750 |
751 void LayerAnimationController::TickAnimations(double monotonic_time) { | 751 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { |
752 for (size_t i = 0; i < active_animations_.size(); ++i) { | 752 for (size_t i = 0; i < active_animations_.size(); ++i) { |
753 if (active_animations_[i]->run_state() == Animation::Starting || | 753 if (active_animations_[i]->run_state() == Animation::Starting || |
754 active_animations_[i]->run_state() == Animation::Running || | 754 active_animations_[i]->run_state() == Animation::Running || |
755 active_animations_[i]->run_state() == Animation::Paused) { | 755 active_animations_[i]->run_state() == Animation::Paused) { |
756 double trimmed = | 756 double trimmed = |
757 active_animations_[i]->TrimTimeToCurrentIteration(monotonic_time); | 757 active_animations_[i]->TrimTimeToCurrentIteration(monotonic_time); |
758 | 758 |
759 switch (active_animations_[i]->target_property()) { | 759 switch (active_animations_[i]->target_property()) { |
760 case Animation::Transform: { | 760 case Animation::Transform: { |
761 const TransformAnimationCurve* transform_animation_curve = | 761 const TransformAnimationCurve* transform_animation_curve = |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 value_observers_); | 872 value_observers_); |
873 LayerAnimationValueObserver* obs; | 873 LayerAnimationValueObserver* obs; |
874 while ((obs = it.GetNext()) != NULL) | 874 while ((obs = it.GetNext()) != NULL) |
875 if (obs->IsActive()) | 875 if (obs->IsActive()) |
876 return true; | 876 return true; |
877 } | 877 } |
878 return false; | 878 return false; |
879 } | 879 } |
880 | 880 |
881 } // namespace cc | 881 } // namespace cc |
OLD | NEW |