summaryrefslogtreecommitdiffstats
path: root/cc/animation/animation_registrar.h
blob: 45e49ef0e8552996db48f542ad03a3000478ad9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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.

#ifndef CC_ANIMATION_ANIMATION_REGISTRAR_H_
#define CC_ANIMATION_ANIMATION_REGISTRAR_H_

#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "cc/base/cc_export.h"

namespace cc {

class AnimationEvents;
class LayerAnimationController;

class CC_EXPORT AnimationRegistrar {
 public:
  typedef base::hash_map<int, LayerAnimationController*> AnimationControllerMap;

  static scoped_ptr<AnimationRegistrar> Create() {
    return make_scoped_ptr(new AnimationRegistrar());
  }

  virtual ~AnimationRegistrar();

  // If an animation has been registered for the given id, return it. Otherwise
  // creates a new one and returns a scoped_refptr to it.
  scoped_refptr<LayerAnimationController> GetAnimationControllerForId(int id);

  // Registers the given animation controller as active. An active animation
  // controller is one that has a running animation that needs to be ticked.
  void DidActivateAnimationController(LayerAnimationController* controller);

  // Unregisters the given animation controller. When this happens, the
  // animation controller will no longer be ticked (since it's not active). It
  // is not an error to call this function with a deactivated controller.
  void DidDeactivateAnimationController(LayerAnimationController* controller);

  // Registers the given controller as alive.
  void RegisterAnimationController(LayerAnimationController* controller);

  // Unregisters the given controller as alive.
  void UnregisterAnimationController(LayerAnimationController* controller);

  const AnimationControllerMap& active_animation_controllers_for_testing()
      const {
    return active_animation_controllers_;
  }

  const AnimationControllerMap& all_animation_controllers_for_testing() const {
    return all_animation_controllers_;
  }

  void set_supports_scroll_animations(bool supports_scroll_animations) {
    supports_scroll_animations_ = supports_scroll_animations;
  }

  bool supports_scroll_animations() { return supports_scroll_animations_; }

  bool needs_animate_layers() const {
    return !active_animation_controllers_.empty();
  }

  bool ActivateAnimations();
  bool AnimateLayers(base::TimeTicks monotonic_time);
  bool UpdateAnimationState(bool start_ready_animations,
                            AnimationEvents* events);

  scoped_ptr<AnimationEvents> CreateEvents();
  void SetAnimationEvents(scoped_ptr<AnimationEvents> events);

 private:
  AnimationRegistrar();

  AnimationControllerMap active_animation_controllers_;
  AnimationControllerMap all_animation_controllers_;

  bool supports_scroll_animations_;

  DISALLOW_COPY_AND_ASSIGN(AnimationRegistrar);
};

}  // namespace cc

#endif  // CC_ANIMATION_ANIMATION_REGISTRAR_H_