1 // Copyright 2015 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_TIMELINE_H_
6 #define CC_ANIMATION_ANIMATION_TIMELINE_H_
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "cc/base/cc_export.h"
18 class AnimationPlayer
;
20 typedef std::vector
<scoped_refptr
<AnimationPlayer
>> AnimationPlayerList
;
22 // An AnimationTimeline owns a group of AnimationPlayers.
23 // This is a cc counterpart for blink::AnimationTimeline (in 1:1 relationship).
24 // Each AnimationTimeline and its AnimationPlayers have their copies on
25 // the impl thread. We synchronize main thread and impl thread instances
27 class CC_EXPORT AnimationTimeline
: public base::RefCounted
<AnimationTimeline
> {
29 static scoped_refptr
<AnimationTimeline
> Create(int id
);
30 scoped_refptr
<AnimationTimeline
> CreateImplInstance() const;
32 int id() const { return id_
; }
34 // Parent AnimationHost.
35 AnimationHost
* animation_host() { return animation_host_
; }
36 const AnimationHost
* animation_host() const { return animation_host_
; }
37 void SetAnimationHost(AnimationHost
* animation_host
);
39 void set_is_impl_only(bool is_impl_only
) { is_impl_only_
= is_impl_only
; }
40 bool is_impl_only() const { return is_impl_only_
; }
42 void AttachPlayer(scoped_refptr
<AnimationPlayer
> player
);
43 void DetachPlayer(scoped_refptr
<AnimationPlayer
> player
);
47 void PushPropertiesTo(AnimationTimeline
* timeline_impl
);
49 AnimationPlayer
* GetPlayerById(int player_id
) const;
52 friend class base::RefCounted
<AnimationTimeline
>;
54 explicit AnimationTimeline(int id
);
55 virtual ~AnimationTimeline();
57 void PushAttachedPlayersToImplThread(AnimationTimeline
* timeline
) const;
58 void RemoveDetachedPlayersFromImplThread(AnimationTimeline
* timeline
) const;
59 void PushPropertiesToImplThread(AnimationTimeline
* timeline
);
61 void ErasePlayers(AnimationPlayerList::iterator begin
,
62 AnimationPlayerList::iterator end
);
64 AnimationPlayerList players_
;
66 AnimationHost
* animation_host_
;
68 // Impl-only AnimationTimeline has no main thread instance and lives on
72 DISALLOW_COPY_AND_ASSIGN(AnimationTimeline
);
77 #endif // CC_ANIMATION_ANIMATION_TIMELINE_H_