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