summaryrefslogtreecommitdiffstats
path: root/cc/animation/animation_timeline.h
blob: ca618ca36d726be76cbfa8889f1b4f63fb257251 (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
// Copyright 2015 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_TIMELINE_H_
#define CC_ANIMATION_ANIMATION_TIMELINE_H_

#include <unordered_map>

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

namespace cc {

class AnimationHost;
class AnimationPlayer;

// An AnimationTimeline owns a group of AnimationPlayers.
// This is a cc counterpart for blink::AnimationTimeline (in 1:1 relationship).
// Each AnimationTimeline and its AnimationPlayers have their copies on
// the impl thread. We synchronize main thread and impl thread instances
// using integer IDs.
class CC_EXPORT AnimationTimeline : public base::RefCounted<AnimationTimeline> {
 public:
  static scoped_refptr<AnimationTimeline> Create(int id);
  scoped_refptr<AnimationTimeline> CreateImplInstance() const;

  int id() const { return id_; }

  // Parent AnimationHost.
  AnimationHost* animation_host() { return animation_host_; }
  const AnimationHost* animation_host() const { return animation_host_; }
  void SetAnimationHost(AnimationHost* animation_host);

  void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; }
  bool is_impl_only() const { return is_impl_only_; }

  void AttachPlayer(scoped_refptr<AnimationPlayer> player);
  void DetachPlayer(scoped_refptr<AnimationPlayer> player);

  void ClearPlayers();

  void PushPropertiesTo(AnimationTimeline* timeline_impl);

  AnimationPlayer* GetPlayerById(int player_id) const;

 private:
  friend class base::RefCounted<AnimationTimeline>;

  explicit AnimationTimeline(int id);
  virtual ~AnimationTimeline();

  void PushAttachedPlayersToImplThread(AnimationTimeline* timeline) const;
  void RemoveDetachedPlayersFromImplThread(AnimationTimeline* timeline) const;
  void PushPropertiesToImplThread(AnimationTimeline* timeline);

  void ErasePlayer(scoped_refptr<AnimationPlayer> player);

  // A list of all players which this timeline owns.
  using IdToPlayerMap = std::unordered_map<int, scoped_refptr<AnimationPlayer>>;
  IdToPlayerMap id_to_player_map_;

  int id_;
  AnimationHost* animation_host_;

  // Impl-only AnimationTimeline has no main thread instance and lives on
  // it's own.
  bool is_impl_only_;

  DISALLOW_COPY_AND_ASSIGN(AnimationTimeline);
};

}  // namespace cc

#endif  // CC_ANIMATION_ANIMATION_TIMELINE_H_