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