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.
5 #ifndef CC_ANIMATION_ANIMATION_REGISTRAR_H_
6 #define CC_ANIMATION_ANIMATION_REGISTRAR_H_
8 #include "base/containers/hash_tables.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/animation/animation_events.h"
12 #include "cc/base/cc_export.h"
16 class LayerAnimationController
;
18 class CC_EXPORT AnimationRegistrar
{
20 typedef base::hash_map
<int, LayerAnimationController
*> AnimationControllerMap
;
22 static scoped_ptr
<AnimationRegistrar
> Create() {
23 return make_scoped_ptr(new AnimationRegistrar());
26 virtual ~AnimationRegistrar();
28 // If an animation has been registered for the given id, return it. Otherwise
29 // creates a new one and returns a scoped_refptr to it.
30 scoped_refptr
<LayerAnimationController
> GetAnimationControllerForId(int id
);
32 // Registers the given animation controller as active. An active animation
33 // controller is one that has a running animation that needs to be ticked.
34 void DidActivateAnimationController(LayerAnimationController
* controller
);
36 // Unregisters the given animation controller. When this happens, the
37 // animation controller will no longer be ticked (since it's not active). It
38 // is not an error to call this function with a deactivated controller.
39 void DidDeactivateAnimationController(LayerAnimationController
* controller
);
41 // Registers the given controller as alive.
42 void RegisterAnimationController(LayerAnimationController
* controller
);
44 // Unregisters the given controller as alive.
45 void UnregisterAnimationController(LayerAnimationController
* controller
);
47 const AnimationControllerMap
& active_animation_controllers_for_testing()
49 return active_animation_controllers_
;
52 const AnimationControllerMap
& all_animation_controllers_for_testing() const {
53 return all_animation_controllers_
;
56 void set_supports_scroll_animations(bool supports_scroll_animations
) {
57 supports_scroll_animations_
= supports_scroll_animations
;
60 bool supports_scroll_animations() { return supports_scroll_animations_
; }
62 bool needs_animate_layers() const {
63 return !active_animation_controllers_
.empty();
66 bool ActivateAnimations();
67 bool AnimateLayers(base::TimeTicks monotonic_time
);
68 bool UpdateAnimationState(bool start_ready_animations
,
69 AnimationEventsVector
* events
);
71 scoped_ptr
<AnimationEventsVector
> CreateEvents() {
72 return make_scoped_ptr(new AnimationEventsVector());
75 void SetAnimationEvents(scoped_ptr
<AnimationEventsVector
> events
);
80 AnimationControllerMap active_animation_controllers_
;
81 AnimationControllerMap all_animation_controllers_
;
83 bool supports_scroll_animations_
;
85 DISALLOW_COPY_AND_ASSIGN(AnimationRegistrar
);
90 #endif // CC_ANIMATION_ANIMATION_REGISTRAR_H_