Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2841)

Unified Diff: cc/animation_registrar.cc

Issue 11443004: Maintain global lists of animation controllers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« cc/animation_registrar.h ('K') | « cc/animation_registrar.h ('k') | cc/cc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698