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" |
| 15 #include "cc/animation/scroll_offset_animation_curve.h" |
14 #include "cc/base/scoped_ptr_algorithm.h" | 16 #include "cc/base/scoped_ptr_algorithm.h" |
15 #include "cc/output/filter_operations.h" | 17 #include "cc/output/filter_operations.h" |
16 #include "ui/gfx/box_f.h" | 18 #include "ui/gfx/box_f.h" |
17 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
18 | 20 |
19 namespace cc { | 21 namespace cc { |
20 | 22 |
21 LayerAnimationController::LayerAnimationController(int id) | 23 LayerAnimationController::LayerAnimationController(int id) |
22 : registrar_(0), | 24 : registrar_(0), |
23 id_(id), | 25 id_(id), |
24 is_active_(false), | 26 is_active_(false), |
25 last_tick_time_(0), | 27 last_tick_time_(0), |
| 28 value_provider_(NULL), |
26 layer_animation_delegate_(NULL) {} | 29 layer_animation_delegate_(NULL) {} |
27 | 30 |
28 LayerAnimationController::~LayerAnimationController() { | 31 LayerAnimationController::~LayerAnimationController() { |
29 if (registrar_) | 32 if (registrar_) |
30 registrar_->UnregisterAnimationController(this); | 33 registrar_->UnregisterAnimationController(this); |
31 } | 34 } |
32 | 35 |
33 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 36 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( |
34 int id) { | 37 int id) { |
35 return make_scoped_refptr(new LayerAnimationController(id)); | 38 return make_scoped_refptr(new LayerAnimationController(id)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 monotonic_time); | 179 monotonic_time); |
177 event.filters = animation->curve()->ToFilterAnimationCurve()->GetValue( | 180 event.filters = animation->curve()->ToFilterAnimationCurve()->GetValue( |
178 monotonic_time); | 181 monotonic_time); |
179 event.is_impl_only = true; | 182 event.is_impl_only = true; |
180 events->push_back(event); | 183 events->push_back(event); |
181 break; | 184 break; |
182 } | 185 } |
183 | 186 |
184 case Animation::BackgroundColor: { break; } | 187 case Animation::BackgroundColor: { break; } |
185 | 188 |
| 189 case Animation::ScrollOffset: { |
| 190 // Impl-side changes to scroll offset are already sent back to the |
| 191 // main thread (e.g. for user-driven scrolling), so a PropertyUpdate |
| 192 // isn't needed. |
| 193 break; |
| 194 } |
| 195 |
186 case Animation::TargetPropertyEnumSize: | 196 case Animation::TargetPropertyEnumSize: |
187 NOTREACHED(); | 197 NOTREACHED(); |
188 } | 198 } |
189 } | 199 } |
190 } | 200 } |
191 | 201 |
192 void LayerAnimationController::UpdateState(bool start_ready_animations, | 202 void LayerAnimationController::UpdateState(bool start_ready_animations, |
193 AnimationEventsVector* events) { | 203 AnimationEventsVector* events) { |
194 if (!HasActiveValueObserver()) | 204 if (!HasActiveValueObserver()) |
195 return; | 205 return; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 413 |
404 // If the animation is not running on the impl thread, it does not | 414 // If the animation is not running on the impl thread, it does not |
405 // necessarily mean that it needs to be copied over and started; it may | 415 // necessarily mean that it needs to be copied over and started; it may |
406 // have already finished. In this case, the impl thread animation will | 416 // have already finished. In this case, the impl thread animation will |
407 // have already notified that it has started and the main thread animation | 417 // have already notified that it has started and the main thread animation |
408 // will no longer need | 418 // will no longer need |
409 // a synchronized start time. | 419 // a synchronized start time. |
410 if (!active_animations_[i]->needs_synchronized_start_time()) | 420 if (!active_animations_[i]->needs_synchronized_start_time()) |
411 continue; | 421 continue; |
412 | 422 |
| 423 // Scroll animations always start at the current scroll offset. |
| 424 if (active_animations_[i]->target_property() == Animation::ScrollOffset) { |
| 425 gfx::Vector2dF current_scroll_offset; |
| 426 if (controller_impl->value_provider_) { |
| 427 current_scroll_offset = |
| 428 controller_impl->value_provider_->ScrollOffsetForAnimation(); |
| 429 } else { |
| 430 // The owning layer isn't yet in the active tree, so the main thread |
| 431 // scroll offset will be up-to-date. |
| 432 current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); |
| 433 } |
| 434 active_animations_[i]->curve()->ToScrollOffsetAnimationCurve() |
| 435 ->SetInitialValue(current_scroll_offset); |
| 436 } |
| 437 |
413 // The new animation should be set to run as soon as possible. | 438 // The new animation should be set to run as soon as possible. |
414 Animation::RunState initial_run_state = | 439 Animation::RunState initial_run_state = |
415 Animation::WaitingForTargetAvailability; | 440 Animation::WaitingForTargetAvailability; |
416 double start_time = 0; | 441 double start_time = 0; |
417 scoped_ptr<Animation> to_add(active_animations_[i]->CloneAndInitialize( | 442 scoped_ptr<Animation> to_add(active_animations_[i]->CloneAndInitialize( |
418 initial_run_state, start_time)); | 443 initial_run_state, start_time)); |
419 DCHECK(!to_add->needs_synchronized_start_time()); | 444 DCHECK(!to_add->needs_synchronized_start_time()); |
420 controller_impl->AddAnimation(to_add.Pass()); | 445 controller_impl->AddAnimation(to_add.Pass()); |
421 } | 446 } |
422 } | 447 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 filter_animation_curve->GetValue(trimmed); | 695 filter_animation_curve->GetValue(trimmed); |
671 NotifyObserversFilterAnimated(filter); | 696 NotifyObserversFilterAnimated(filter); |
672 break; | 697 break; |
673 } | 698 } |
674 | 699 |
675 case Animation::BackgroundColor: { | 700 case Animation::BackgroundColor: { |
676 // Not yet implemented. | 701 // Not yet implemented. |
677 break; | 702 break; |
678 } | 703 } |
679 | 704 |
| 705 case Animation::ScrollOffset: { |
| 706 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = |
| 707 active_animations_[i]->curve()->ToScrollOffsetAnimationCurve(); |
| 708 const gfx::Vector2dF scroll_offset = |
| 709 scroll_offset_animation_curve->GetValue(trimmed); |
| 710 NotifyObserversScrollOffsetAnimated(scroll_offset); |
| 711 break; |
| 712 } |
| 713 |
680 // Do nothing for sentinel value. | 714 // Do nothing for sentinel value. |
681 case Animation::TargetPropertyEnumSize: | 715 case Animation::TargetPropertyEnumSize: |
682 NOTREACHED(); | 716 NOTREACHED(); |
683 } | 717 } |
684 } | 718 } |
685 } | 719 } |
686 } | 720 } |
687 | 721 |
688 void LayerAnimationController::UpdateActivation(UpdateActivationType type) { | 722 void LayerAnimationController::UpdateActivation(UpdateActivationType type) { |
689 bool force = type == ForceActivation; | 723 bool force = type == ForceActivation; |
(...skipping 27 matching lines...) Expand all Loading... |
717 OnTransformAnimated(transform)); | 751 OnTransformAnimated(transform)); |
718 } | 752 } |
719 | 753 |
720 void LayerAnimationController::NotifyObserversFilterAnimated( | 754 void LayerAnimationController::NotifyObserversFilterAnimated( |
721 const FilterOperations& filters) { | 755 const FilterOperations& filters) { |
722 FOR_EACH_OBSERVER(LayerAnimationValueObserver, | 756 FOR_EACH_OBSERVER(LayerAnimationValueObserver, |
723 value_observers_, | 757 value_observers_, |
724 OnFilterAnimated(filters)); | 758 OnFilterAnimated(filters)); |
725 } | 759 } |
726 | 760 |
| 761 void LayerAnimationController::NotifyObserversScrollOffsetAnimated( |
| 762 gfx::Vector2dF scroll_offset) { |
| 763 FOR_EACH_OBSERVER(LayerAnimationValueObserver, |
| 764 value_observers_, |
| 765 OnScrollOffsetAnimated(scroll_offset)); |
| 766 } |
| 767 |
727 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { | 768 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { |
728 FOR_EACH_OBSERVER(LayerAnimationValueObserver, | 769 FOR_EACH_OBSERVER(LayerAnimationValueObserver, |
729 value_observers_, | 770 value_observers_, |
730 OnAnimationWaitingForDeletion()); | 771 OnAnimationWaitingForDeletion()); |
731 } | 772 } |
732 | 773 |
733 bool LayerAnimationController::HasValueObserver() { | 774 bool LayerAnimationController::HasValueObserver() { |
734 if (value_observers_.might_have_observers()) { | 775 if (value_observers_.might_have_observers()) { |
735 ObserverListBase<LayerAnimationValueObserver>::Iterator it( | 776 ObserverListBase<LayerAnimationValueObserver>::Iterator it( |
736 value_observers_); | 777 value_observers_); |
737 return it.GetNext() != NULL; | 778 return it.GetNext() != NULL; |
738 } | 779 } |
739 return false; | 780 return false; |
740 } | 781 } |
741 | 782 |
742 bool LayerAnimationController::HasActiveValueObserver() { | 783 bool LayerAnimationController::HasActiveValueObserver() { |
743 if (value_observers_.might_have_observers()) { | 784 if (value_observers_.might_have_observers()) { |
744 ObserverListBase<LayerAnimationValueObserver>::Iterator it( | 785 ObserverListBase<LayerAnimationValueObserver>::Iterator it( |
745 value_observers_); | 786 value_observers_); |
746 LayerAnimationValueObserver* obs; | 787 LayerAnimationValueObserver* obs; |
747 while ((obs = it.GetNext()) != NULL) | 788 while ((obs = it.GetNext()) != NULL) |
748 if (obs->IsActive()) | 789 if (obs->IsActive()) |
749 return true; | 790 return true; |
750 } | 791 } |
751 return false; | 792 return false; |
752 } | 793 } |
753 | 794 |
754 } // namespace cc | 795 } // namespace cc |
OLD | NEW |