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_registrar.h" |
| 6 |
| 7 #include "base/stl_util.h" |
| 8 #include "cc/layer_animation_controller.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 namespace { |
| 13 |
| 14 static AnimationRegistrar::AnimationControllerSet* |
| 15 s_active_main_thread_controllers = 0; |
| 16 static AnimationRegistrar::AnimationControllerSet* |
| 17 s_main_thread_controllers = 0; |
| 18 static AnimationRegistrar::AnimationControllerSet* |
| 19 s_active_compositor_thread_controllers = 0; |
| 20 static AnimationRegistrar::AnimationControllerSet* |
| 21 s_compositor_thread_controllers = 0; |
| 22 |
| 23 AnimationRegistrar::AnimationControllerSet& getControllers( |
| 24 AnimationRegistrar::ThreadName thread_name, bool just_active) { |
| 25 AnimationRegistrar::AnimationControllerSet** controllers = 0; |
| 26 |
| 27 if (just_active) |
| 28 controllers = thread_name == AnimationRegistrar::MainThread |
| 29 ? &s_main_thread_controllers |
| 30 : &s_compositor_thread_controllers; |
| 31 else |
| 32 controllers = thread_name == AnimationRegistrar::MainThread |
| 33 ? &s_active_main_thread_controllers |
| 34 : &s_active_compositor_thread_controllers; |
| 35 |
| 36 if (!*controllers) |
| 37 *controllers = new AnimationRegistrar::AnimationControllerSet; |
| 38 |
| 39 return **controllers; |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 44 // static. |
| 45 void AnimationRegistrar::Activate( |
| 46 LayerAnimationController* controller, |
| 47 AnimationRegistrar::ThreadName thread_name) { |
| 48 getControllers(thread_name, true).insert(controller); |
| 49 } |
| 50 |
| 51 // static. |
| 52 void AnimationRegistrar::Deactivate( |
| 53 LayerAnimationController* controller, |
| 54 AnimationRegistrar::ThreadName thread_name) { |
| 55 AnimationControllerSet& controllers = getControllers(thread_name, true); |
| 56 if (ContainsKey(controllers, controller)) |
| 57 controllers.erase(controller); |
| 58 } |
| 59 |
| 60 // static. |
| 61 const AnimationRegistrar::AnimationControllerSet& |
| 62 AnimationRegistrar::GetActiveControllers( |
| 63 AnimationRegistrar::ThreadName thread_name) { |
| 64 return getControllers(thread_name, true); |
| 65 } |
| 66 |
| 67 // static. |
| 68 void AnimationRegistrar::Register( |
| 69 LayerAnimationController* controller, |
| 70 AnimationRegistrar::ThreadName thread_name) { |
| 71 getControllers(thread_name, false).insert(controller); |
| 72 } |
| 73 |
| 74 // static. |
| 75 void AnimationRegistrar::Unregister( |
| 76 LayerAnimationController* controller, |
| 77 AnimationRegistrar::ThreadName thread_name) { |
| 78 AnimationControllerSet& controllers = getControllers(thread_name, false); |
| 79 if (ContainsKey(controllers, controller)) |
| 80 controllers.erase(controller); |
| 81 |
| 82 // An unregistered controller cannot be active. |
| 83 Deactivate(controller, thread_name); |
| 84 } |
| 85 |
| 86 // static. |
| 87 const AnimationRegistrar::AnimationControllerSet& |
| 88 AnimationRegistrar::GetAllControllers( |
| 89 AnimationRegistrar::ThreadName thread_name) { |
| 90 return getControllers(thread_name, false); |
| 91 } |
| 92 |
| 93 |
| 94 } // namespace cc |
OLD | NEW |