Chromium Code Reviews| Index: cc/animation_registrar.cc |
| diff --git a/cc/animation_registrar.cc b/cc/animation_registrar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22cee3c397fcdbe2c6e3f49d618100c2fd2638d2 |
| --- /dev/null |
| +++ b/cc/animation_registrar.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/animation_registrar.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "cc/layer_animation_controller.h" |
| + |
| +#if defined(COMPILER_GCC) |
| +namespace BASE_HASH_NAMESPACE { |
| +template<> |
| +struct hash<cc::AnimationRegistrar::ThreadName> { |
| + size_t operator()(cc::AnimationRegistrar::ThreadName thread_name) const { |
| + return hash<size_t>()(static_cast<size_t>(thread_name)); |
| + } |
| +}; |
| +} // namespace BASE_HASH_NAMESPACE |
| +#endif // COMPILER |
| + |
| +namespace cc { |
| + |
| +namespace { |
| + |
| +typedef base::hash_map<AnimationRegistrar::ThreadName, |
| + AnimationRegistrar::AnimationControllerSet*> |
| + AnimationRegistrarMap; |
| + |
| +static AnimationRegistrarMap* s_registrar_map = 0; |
|
jamesr
2012/12/05 02:25:49
in some situations we'll need to have multiple com
|
| + |
| +AnimationRegistrar::AnimationControllerSet& getAnimationControllerSet( |
| + AnimationRegistrar::ThreadName thread_name) { |
| + if (!s_registrar_map) |
| + s_registrar_map = new AnimationRegistrarMap; |
| + |
| + if (!ContainsKey(*s_registrar_map, thread_name)) |
| + (*s_registrar_map)[thread_name] = |
| + new AnimationRegistrar::AnimationControllerSet; |
| + return *(*s_registrar_map)[thread_name]; |
| +} |
| + |
| + |
| +} // namespace |
| + |
| +// static. |
| +void AnimationRegistrar::ActivateAnimationController( |
| + LayerAnimationController* controller, |
| + AnimationRegistrar::ThreadName thread_name) { |
| + getAnimationControllerSet(thread_name).insert(controller); |
| +} |
| + |
| +// static. |
| +void AnimationRegistrar::DeactivateAnimationController( |
| + LayerAnimationController* controller, |
| + AnimationRegistrar::ThreadName thread_name) { |
| + AnimationControllerSet& controllers = getAnimationControllerSet(thread_name); |
| + if (ContainsKey(controllers, controller)) |
| + controllers.erase(controller); |
| +} |
| + |
| +// static. |
| +const AnimationRegistrar::AnimationControllerSet& |
| +AnimationRegistrar::GetActiveControllers( |
| + AnimationRegistrar::ThreadName thread_name) { |
| + return getAnimationControllerSet(thread_name); |
| +} |
| + |
| +} // namespace cc |