| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/animation/animation_registrar.h" | |
| 6 | |
| 7 #include "base/trace_event/trace_event_argument.h" | |
| 8 #include "cc/animation/layer_animation_controller.h" | |
| 9 | |
| 10 namespace cc { | |
| 11 | |
| 12 AnimationRegistrar::AnimationRegistrar() : supports_scroll_animations_(false) { | |
| 13 } | |
| 14 | |
| 15 AnimationRegistrar::~AnimationRegistrar() { | |
| 16 AnimationControllerMap copy = all_animation_controllers_; | |
| 17 for (AnimationControllerMap::iterator iter = copy.begin(); | |
| 18 iter != copy.end(); | |
| 19 ++iter) | |
| 20 (*iter).second->SetAnimationRegistrar(nullptr); | |
| 21 } | |
| 22 | |
| 23 scoped_refptr<LayerAnimationController> | |
| 24 AnimationRegistrar::GetAnimationControllerForId(int id) { | |
| 25 scoped_refptr<LayerAnimationController> to_return; | |
| 26 if (!ContainsKey(all_animation_controllers_, id)) { | |
| 27 to_return = LayerAnimationController::Create(id); | |
| 28 to_return->SetAnimationRegistrar(this); | |
| 29 all_animation_controllers_[id] = to_return.get(); | |
| 30 } else { | |
| 31 to_return = all_animation_controllers_[id]; | |
| 32 } | |
| 33 return to_return; | |
| 34 } | |
| 35 | |
| 36 void AnimationRegistrar::DidActivateAnimationController( | |
| 37 LayerAnimationController* controller) { | |
| 38 active_animation_controllers_[controller->id()] = controller; | |
| 39 } | |
| 40 | |
| 41 void AnimationRegistrar::DidDeactivateAnimationController( | |
| 42 LayerAnimationController* controller) { | |
| 43 if (ContainsKey(active_animation_controllers_, controller->id())) | |
| 44 active_animation_controllers_.erase(controller->id()); | |
| 45 } | |
| 46 | |
| 47 void AnimationRegistrar::RegisterAnimationController( | |
| 48 LayerAnimationController* controller) { | |
| 49 all_animation_controllers_[controller->id()] = controller; | |
| 50 } | |
| 51 | |
| 52 void AnimationRegistrar::UnregisterAnimationController( | |
| 53 LayerAnimationController* controller) { | |
| 54 if (ContainsKey(all_animation_controllers_, controller->id())) | |
| 55 all_animation_controllers_.erase(controller->id()); | |
| 56 DidDeactivateAnimationController(controller); | |
| 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 | |
| 130 } // namespace cc | |
| OLD | NEW |