OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_ANIMATION_ANIMATION_PLAYER_H_ | 5 #ifndef CC_ANIMATION_ANIMATION_PLAYER_H_ |
6 #define CC_ANIMATION_ANIMATION_PLAYER_H_ | 6 #define CC_ANIMATION_ANIMATION_PLAYER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/containers/linked_list.h" | 10 #include "base/containers/linked_list.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "cc/animation/animation.h" | 14 #include "cc/animation/animation.h" |
15 #include "cc/animation/animation_curve.h" | 15 #include "cc/animation/animation_curve.h" |
| 16 #include "cc/animation/animation_player_observer.h" |
16 #include "cc/animation/element_animations.h" | 17 #include "cc/animation/element_animations.h" |
17 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 | 21 |
21 class AnimationDelegate; | 22 class AnimationDelegate; |
22 class AnimationHost; | 23 class AnimationHost; |
23 class AnimationTimeline; | 24 class AnimationTimeline; |
24 class ElementAnimations; | 25 class ElementAnimations; |
25 | 26 |
26 // An AnimationPlayer owns all animations to be run on particular CC Layer. | 27 // An AnimationPlayer owns all animations to be run on particular CC Layer. |
27 // Multiple AnimationPlayers can be attached to one layer. In this case, | 28 // Multiple AnimationPlayers can be attached to one layer. In this case, |
28 // they share common ElementAnimations so the | 29 // they share common ElementAnimations so the |
29 // ElementAnimations-to-Layer relationship is 1:1. | 30 // ElementAnimations-to-Layer relationship is 1:1. |
30 // For now, the blink logic is responsible for handling of conflicting | 31 // For now, the blink logic is responsible for handling of conflicting |
31 // same-property animations. | 32 // same-property animations. |
32 // Each AnimationPlayer has its copy on the impl thread. | 33 // Each AnimationPlayer has its copy on the impl thread. |
33 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). | 34 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). |
34 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer>, | 35 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> { |
35 public base::LinkNode<AnimationPlayer> { | |
36 public: | 36 public: |
37 static scoped_refptr<AnimationPlayer> Create(int id); | 37 static scoped_refptr<AnimationPlayer> Create(int id); |
38 scoped_refptr<AnimationPlayer> CreateImplInstance() const; | 38 scoped_refptr<AnimationPlayer> CreateImplInstance() const; |
39 | 39 |
40 int id() const { return id_; } | 40 int id() const { return id_; } |
41 ElementId element_id() const { return element_id_; } | 41 ElementId element_id() const { return element_id_; } |
42 | 42 |
43 // Parent AnimationHost. AnimationPlayer can be detached from | 43 // Parent AnimationHost. AnimationPlayer can be detached from |
44 // AnimationTimeline. | 44 // AnimationTimeline. |
45 AnimationHost* animation_host() { return animation_host_; } | 45 AnimationHost* animation_host() { return animation_host_; } |
(...skipping 22 matching lines...) Expand all Loading... |
68 void AddAnimation(std::unique_ptr<Animation> animation); | 68 void AddAnimation(std::unique_ptr<Animation> animation); |
69 void PauseAnimation(int animation_id, double time_offset); | 69 void PauseAnimation(int animation_id, double time_offset); |
70 void RemoveAnimation(int animation_id); | 70 void RemoveAnimation(int animation_id); |
71 void AbortAnimation(int animation_id); | 71 void AbortAnimation(int animation_id); |
72 void AbortAnimations(TargetProperty::Type target_property, | 72 void AbortAnimations(TargetProperty::Type target_property, |
73 bool needs_completion); | 73 bool needs_completion); |
74 | 74 |
75 void PushPropertiesTo(AnimationPlayer* player_impl); | 75 void PushPropertiesTo(AnimationPlayer* player_impl); |
76 | 76 |
77 // AnimationDelegate routing. | 77 // AnimationDelegate routing. |
78 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 78 virtual void OnAnimationStarted(base::TimeTicks monotonic_time, |
79 TargetProperty::Type target_property, | 79 TargetProperty::Type target_property, |
80 int group); | 80 int group); |
81 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 81 virtual void OnAnimationFinished(base::TimeTicks monotonic_time, |
82 TargetProperty::Type target_property, | 82 TargetProperty::Type target_property, |
83 int group); | 83 int group); |
84 void NotifyAnimationAborted(base::TimeTicks monotonic_time, | 84 virtual void OnAnimationAborted(base::TimeTicks monotonic_time, |
85 TargetProperty::Type target_property, | 85 TargetProperty::Type target_property, |
86 int group); | 86 int group); |
87 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | 87 virtual void OnAnimationTakeover(base::TimeTicks monotonic_time, |
88 TargetProperty::Type target_property, | 88 TargetProperty::Type target_property, |
89 double animation_start_time, | 89 double animation_start_time, |
90 std::unique_ptr<AnimationCurve> curve); | 90 std::unique_ptr<AnimationCurve> curve); |
91 | 91 |
92 // Whether this player has animations waiting to get sent to ElementAnimations | 92 // Whether this player has animations waiting to get sent to ElementAnimations |
93 bool has_pending_animations_for_testing() const { | 93 bool has_pending_animations_for_testing() const { |
94 return !animations_.empty(); | 94 return !animations_.empty(); |
95 } | 95 } |
96 | 96 |
| 97 protected: |
| 98 explicit AnimationPlayer(int id); |
| 99 virtual ~AnimationPlayer(); |
| 100 |
97 private: | 101 private: |
98 friend class base::RefCounted<AnimationPlayer>; | 102 friend class base::RefCounted<AnimationPlayer>; |
99 | 103 |
100 explicit AnimationPlayer(int id); | |
101 ~AnimationPlayer(); | |
102 | |
103 void SetNeedsCommit(); | 104 void SetNeedsCommit(); |
104 | 105 |
105 void RegisterPlayer(); | 106 void RegisterPlayer(); |
106 void UnregisterPlayer(); | 107 void UnregisterPlayer(); |
107 | 108 |
108 void BindElementAnimations(); | 109 void BindElementAnimations(); |
109 void UnbindElementAnimations(); | 110 void UnbindElementAnimations(); |
110 | 111 |
111 // We accumulate added animations in animations_ container | 112 // We accumulate added animations in animations_ container |
112 // if element_animations_ is a nullptr. It allows us to add/remove animations | 113 // if element_animations_ is a nullptr. It allows us to add/remove animations |
113 // to non-attached AnimationPlayers. | 114 // to non-attached AnimationPlayers. |
114 std::vector<std::unique_ptr<Animation>> animations_; | 115 std::vector<std::unique_ptr<Animation>> animations_; |
115 | 116 |
116 AnimationHost* animation_host_; | 117 AnimationHost* animation_host_; |
117 AnimationTimeline* animation_timeline_; | 118 AnimationTimeline* animation_timeline_; |
118 // element_animations isn't null if player attached to an element (layer). | 119 // element_animations isn't null if player attached to an element (layer). |
119 scoped_refptr<ElementAnimations> element_animations_; | 120 scoped_refptr<ElementAnimations> element_animations_; |
120 AnimationDelegate* animation_delegate_; | 121 AnimationDelegate* animation_delegate_; |
121 | 122 |
122 int id_; | 123 int id_; |
123 ElementId element_id_; | 124 ElementId element_id_; |
124 | 125 |
125 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); | 126 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); |
126 }; | 127 }; |
127 | 128 |
128 } // namespace cc | 129 } // namespace cc |
129 | 130 |
130 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ | 131 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ |
OLD | NEW |