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/animation_registrar.h" | 5 #include "cc/animation/animation_registrar.h" |
6 | 6 |
| 7 #include "base/trace_event/trace_event_argument.h" |
7 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
8 | 9 |
9 namespace cc { | 10 namespace cc { |
10 | 11 |
11 AnimationRegistrar::AnimationRegistrar() : supports_scroll_animations_(false) { | 12 AnimationRegistrar::AnimationRegistrar() : supports_scroll_animations_(false) { |
12 } | 13 } |
13 | 14 |
14 AnimationRegistrar::~AnimationRegistrar() { | 15 AnimationRegistrar::~AnimationRegistrar() { |
15 AnimationControllerMap copy = all_animation_controllers_; | 16 AnimationControllerMap copy = all_animation_controllers_; |
16 for (AnimationControllerMap::iterator iter = copy.begin(); | 17 for (AnimationControllerMap::iterator iter = copy.begin(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 all_animation_controllers_[controller->id()] = controller; | 49 all_animation_controllers_[controller->id()] = controller; |
49 } | 50 } |
50 | 51 |
51 void AnimationRegistrar::UnregisterAnimationController( | 52 void AnimationRegistrar::UnregisterAnimationController( |
52 LayerAnimationController* controller) { | 53 LayerAnimationController* controller) { |
53 if (ContainsKey(all_animation_controllers_, controller->id())) | 54 if (ContainsKey(all_animation_controllers_, controller->id())) |
54 all_animation_controllers_.erase(controller->id()); | 55 all_animation_controllers_.erase(controller->id()); |
55 DidDeactivateAnimationController(controller); | 56 DidDeactivateAnimationController(controller); |
56 } | 57 } |
57 | 58 |
| 59 bool AnimationRegistrar::ActivateAnimations() { |
| 60 if (!needs_animate_layers()) |
| 61 return false; |
| 62 |
| 63 TRACE_EVENT0("cc", "AnimationRegistrar::ActivateAnimations"); |
| 64 AnimationControllerMap active_controllers_copy = |
| 65 active_animation_controllers_; |
| 66 for (auto& it : active_controllers_copy) |
| 67 it.second->ActivateAnimations(); |
| 68 |
| 69 return true; |
| 70 } |
| 71 |
| 72 bool AnimationRegistrar::AnimateLayers(base::TimeTicks monotonic_time) { |
| 73 if (!needs_animate_layers()) |
| 74 return false; |
| 75 |
| 76 TRACE_EVENT0("cc", "AnimationRegistrar::AnimateLayers"); |
| 77 AnimationControllerMap controllers_copy = active_animation_controllers_; |
| 78 for (auto& it : controllers_copy) |
| 79 it.second->Animate(monotonic_time); |
| 80 |
| 81 return true; |
| 82 } |
| 83 |
| 84 bool AnimationRegistrar::UpdateAnimationState(bool start_ready_animations, |
| 85 AnimationEventsVector* events) { |
| 86 if (!needs_animate_layers()) |
| 87 return false; |
| 88 |
| 89 TRACE_EVENT0("cc", "AnimationRegistrar::UpdateAnimationState"); |
| 90 AnimationControllerMap active_controllers_copy = |
| 91 active_animation_controllers_; |
| 92 for (auto& it : active_controllers_copy) |
| 93 it.second->UpdateState(start_ready_animations, events); |
| 94 |
| 95 return true; |
| 96 } |
| 97 |
| 98 void AnimationRegistrar::SetAnimationEvents( |
| 99 scoped_ptr<AnimationEventsVector> events) { |
| 100 for (size_t event_index = 0; event_index < events->size(); ++event_index) { |
| 101 int event_layer_id = (*events)[event_index].layer_id; |
| 102 |
| 103 // Use the map of all controllers, not just active ones, since non-active |
| 104 // controllers may still receive events for impl-only animations. |
| 105 const AnimationRegistrar::AnimationControllerMap& animation_controllers = |
| 106 all_animation_controllers_; |
| 107 auto iter = animation_controllers.find(event_layer_id); |
| 108 if (iter != animation_controllers.end()) { |
| 109 switch ((*events)[event_index].type) { |
| 110 case AnimationEvent::STARTED: |
| 111 (*iter).second->NotifyAnimationStarted((*events)[event_index]); |
| 112 break; |
| 113 |
| 114 case AnimationEvent::FINISHED: |
| 115 (*iter).second->NotifyAnimationFinished((*events)[event_index]); |
| 116 break; |
| 117 |
| 118 case AnimationEvent::ABORTED: |
| 119 (*iter).second->NotifyAnimationAborted((*events)[event_index]); |
| 120 break; |
| 121 |
| 122 case AnimationEvent::PROPERTY_UPDATE: |
| 123 (*iter).second->NotifyAnimationPropertyUpdate((*events)[event_index]); |
| 124 break; |
| 125 } |
| 126 } |
| 127 } |
| 128 } |
| 129 |
58 } // namespace cc | 130 } // namespace cc |
OLD | NEW |