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_PLAYER_H_
6 #define CC_ANIMATION_ANIMATION_PLAYER_H_
8 #include "base/containers/linked_list.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h"
11 #include "cc/animation/animation.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/base/scoped_ptr_vector.h"
17 class AnimationDelegate
;
19 class AnimationTimeline
;
20 class ElementAnimations
;
21 class LayerAnimationController
;
22 enum class LayerTreeType
;
24 // An AnimationPlayer owns all animations to be run on particular CC Layer.
25 // Multiple AnimationPlayers can be attached to one layer. In this case,
26 // they share common LayerAnimationController (temp solution) so the
27 // LayerAnimationController-to-Layer relationship stays the same (1:1, LACs
28 // have same IDs as their respective Layers).
29 // For now, the blink logic is responsible for handling of conflicting
30 // same-property animations.
31 // Each AnimationPlayer has its copy on the impl thread.
32 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship).
33 class CC_EXPORT AnimationPlayer
: public base::RefCounted
<AnimationPlayer
>,
34 public base::LinkNode
<AnimationPlayer
> {
36 static scoped_refptr
<AnimationPlayer
> Create(int id
);
37 scoped_refptr
<AnimationPlayer
> CreateImplInstance() const;
39 int id() const { return id_
; }
40 int layer_id() const { return layer_id_
; }
42 // Parent AnimationHost. AnimationPlayer can be detached from
44 AnimationHost
* animation_host() { return animation_host_
; }
45 const AnimationHost
* animation_host() const { return animation_host_
; }
46 void SetAnimationHost(AnimationHost
* animation_host
);
48 // Parent AnimationTimeline.
49 AnimationTimeline
* animation_timeline() { return animation_timeline_
; }
50 const AnimationTimeline
* animation_timeline() const {
51 return animation_timeline_
;
53 void SetAnimationTimeline(AnimationTimeline
* timeline
);
55 // ElementAnimations object where this player is listed.
56 // ElementAnimations has a reference to shared LayerAnimationController.
57 ElementAnimations
* element_animations() const { return element_animations_
; }
59 void set_layer_animation_delegate(AnimationDelegate
* delegate
) {
60 layer_animation_delegate_
= delegate
;
63 void AttachLayer(int layer_id
);
66 void AddAnimation(scoped_ptr
<Animation
> animation
);
67 void PauseAnimation(int animation_id
, double time_offset
);
68 void RemoveAnimation(int animation_id
);
70 void PushPropertiesTo(AnimationPlayer
* player_impl
);
72 // AnimationDelegate routing.
73 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
74 Animation::TargetProperty target_property
,
76 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
77 Animation::TargetProperty target_property
,
81 friend class base::RefCounted
<AnimationPlayer
>;
83 explicit AnimationPlayer(int id
);
86 void SetNeedsCommit();
88 void RegisterPlayer();
89 void UnregisterPlayer();
91 void BindElementAnimations();
92 void UnbindElementAnimations();
94 // We accumulate added animations in animations_ container
95 // if element_animations_ is a nullptr. It allows us to add/remove animations
96 // to non-attached AnimationPlayers.
97 typedef ScopedPtrVector
<Animation
> AnimationList
;
98 AnimationList animations_
;
100 AnimationHost
* animation_host_
;
101 AnimationTimeline
* animation_timeline_
;
102 // element_animations isn't null if player attached to an element (layer).
103 ElementAnimations
* element_animations_
;
104 AnimationDelegate
* layer_animation_delegate_
;
109 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer
);
114 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_