Index: cc/animation_registrar.cc |
diff --git a/cc/animation_registrar.cc b/cc/animation_registrar.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..477ce2e1f8bff5f9a3a4f48dd4ab65d272dbf028 |
--- /dev/null |
+++ b/cc/animation_registrar.cc |
@@ -0,0 +1,94 @@ |
+// 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" |
+ |
+namespace cc { |
+ |
+namespace { |
+ |
+static AnimationRegistrar::AnimationControllerSet* |
+ s_active_main_thread_controllers = 0; |
+static AnimationRegistrar::AnimationControllerSet* |
+ s_main_thread_controllers = 0; |
+static AnimationRegistrar::AnimationControllerSet* |
+ s_active_compositor_thread_controllers = 0; |
+static AnimationRegistrar::AnimationControllerSet* |
+ s_compositor_thread_controllers = 0; |
+ |
+AnimationRegistrar::AnimationControllerSet& getControllers( |
+ AnimationRegistrar::ThreadName thread_name, bool just_active) { |
+ AnimationRegistrar::AnimationControllerSet** controllers = 0; |
+ |
+ if (just_active) |
+ controllers = thread_name == AnimationRegistrar::MainThread |
+ ? &s_main_thread_controllers |
+ : &s_compositor_thread_controllers; |
+ else |
+ controllers = thread_name == AnimationRegistrar::MainThread |
+ ? &s_active_main_thread_controllers |
+ : &s_active_compositor_thread_controllers; |
+ |
+ if (!*controllers) |
+ *controllers = new AnimationRegistrar::AnimationControllerSet; |
+ |
+ return **controllers; |
+} |
+ |
+} // namespace |
+ |
+// static. |
+void AnimationRegistrar::Activate( |
+ LayerAnimationController* controller, |
+ AnimationRegistrar::ThreadName thread_name) { |
+ getControllers(thread_name, true).insert(controller); |
+} |
+ |
+// static. |
+void AnimationRegistrar::Deactivate( |
+ LayerAnimationController* controller, |
+ AnimationRegistrar::ThreadName thread_name) { |
+ AnimationControllerSet& controllers = getControllers(thread_name, true); |
+ if (ContainsKey(controllers, controller)) |
+ controllers.erase(controller); |
+} |
+ |
+// static. |
+const AnimationRegistrar::AnimationControllerSet& |
+AnimationRegistrar::GetActiveControllers( |
+ AnimationRegistrar::ThreadName thread_name) { |
+ return getControllers(thread_name, true); |
+} |
+ |
+// static. |
+void AnimationRegistrar::Register( |
+ LayerAnimationController* controller, |
+ AnimationRegistrar::ThreadName thread_name) { |
+ getControllers(thread_name, false).insert(controller); |
+} |
+ |
+// static. |
+void AnimationRegistrar::Unregister( |
+ LayerAnimationController* controller, |
+ AnimationRegistrar::ThreadName thread_name) { |
+ AnimationControllerSet& controllers = getControllers(thread_name, false); |
+ if (ContainsKey(controllers, controller)) |
+ controllers.erase(controller); |
+ |
+ // An unregistered controller cannot be active. |
+ Deactivate(controller, thread_name); |
+} |
+ |
+// static. |
+const AnimationRegistrar::AnimationControllerSet& |
+AnimationRegistrar::GetAllControllers( |
+ AnimationRegistrar::ThreadName thread_name) { |
+ return getControllers(thread_name, false); |
+} |
+ |
+ |
+} // namespace cc |