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 <bitset> | 8 #include <bitset> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
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/element_animations.h" | 16 #include "cc/animation/element_animations.h" |
17 #include "cc/animation/element_id.h" | 17 #include "cc/animation/element_id.h" |
18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 | 21 |
22 class AnimationDelegate; | 22 class AnimationDelegate; |
23 class AnimationEvents; | 23 class AnimationEvents; |
24 class AnimationHost; | 24 class AnimationHost; |
25 class AnimationTimeline; | 25 class AnimationTimeline; |
| 26 struct PropertyAnimationState; |
26 | 27 |
27 // An AnimationPlayer owns all animations to be run on particular CC Layer. | 28 // An AnimationPlayer owns all animations to be run on particular CC Layer. |
28 // Multiple AnimationPlayers can be attached to one layer. In this case, | 29 // Multiple AnimationPlayers can be attached to one layer. In this case, |
29 // they share common ElementAnimations so the | 30 // they share common ElementAnimations so the |
30 // ElementAnimations-to-Layer relationship is 1:1. | 31 // ElementAnimations-to-Layer relationship is 1:1. |
31 // For now, the blink logic is responsible for handling of conflicting | 32 // For now, the blink logic is responsible for handling of conflicting |
32 // same-property animations. | 33 // same-property animations. |
33 // Each AnimationPlayer has its copy on the impl thread. | 34 // Each AnimationPlayer has its copy on the impl thread. |
34 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). | 35 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). |
35 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> { | 36 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bool HasActiveAnimation() const; | 88 bool HasActiveAnimation() const; |
88 | 89 |
89 // Returns true if there are any animations at all to process. | 90 // Returns true if there are any animations at all to process. |
90 bool has_any_animation() const { return !animations_.empty(); } | 91 bool has_any_animation() const { return !animations_.empty(); } |
91 | 92 |
92 bool needs_push_properties() const { return needs_push_properties_; } | 93 bool needs_push_properties() const { return needs_push_properties_; } |
93 void SetNeedsPushProperties(); | 94 void SetNeedsPushProperties(); |
94 | 95 |
95 bool HasNonDeletedAnimation() const; | 96 bool HasNonDeletedAnimation() const; |
96 | 97 |
97 using Animations = std::vector<std::unique_ptr<Animation>>; | |
98 const Animations& animations() const { return animations_; } | |
99 | |
100 bool needs_to_start_animations() const { return needs_to_start_animations_; } | 98 bool needs_to_start_animations() const { return needs_to_start_animations_; } |
101 | 99 |
102 void StartAnimations(base::TimeTicks monotonic_time); | 100 void StartAnimations(base::TimeTicks monotonic_time); |
103 void PromoteStartedAnimations(base::TimeTicks monotonic_time, | 101 void PromoteStartedAnimations(base::TimeTicks monotonic_time, |
104 AnimationEvents* events); | 102 AnimationEvents* events); |
105 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, | 103 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, |
106 AnimationEvents* events); | 104 AnimationEvents* events); |
107 void TickAnimations(base::TimeTicks monotonic_time); | 105 void TickAnimations(base::TimeTicks monotonic_time); |
108 void MarkFinishedAnimations(base::TimeTicks monotonic_time); | 106 void MarkFinishedAnimations(base::TimeTicks monotonic_time); |
109 | 107 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 bool HasElementInActiveList() const; | 144 bool HasElementInActiveList() const; |
147 gfx::ScrollOffset ScrollOffsetForAnimation() const; | 145 gfx::ScrollOffset ScrollOffsetForAnimation() const; |
148 | 146 |
149 // Returns the active animation animating the given property that is either | 147 // Returns the active animation animating the given property that is either |
150 // running, or is next to run, if such an animation exists. | 148 // running, or is next to run, if such an animation exists. |
151 Animation* GetAnimation(TargetProperty::Type target_property) const; | 149 Animation* GetAnimation(TargetProperty::Type target_property) const; |
152 | 150 |
153 // Returns the active animation for the given unique animation id. | 151 // Returns the active animation for the given unique animation id. |
154 Animation* GetAnimationById(int animation_id) const; | 152 Animation* GetAnimationById(int animation_id) const; |
155 | 153 |
| 154 void GetPropertyAnimationStateFor(TargetProperty::Type property, |
| 155 PropertyAnimationState* state) const; |
| 156 |
156 private: | 157 private: |
157 friend class base::RefCounted<AnimationPlayer>; | 158 friend class base::RefCounted<AnimationPlayer>; |
158 | 159 |
159 explicit AnimationPlayer(int id); | 160 explicit AnimationPlayer(int id); |
160 ~AnimationPlayer(); | 161 ~AnimationPlayer(); |
161 | 162 |
162 // A set of target properties. TargetProperty must be 0-based enum. | 163 // A set of target properties. TargetProperty must be 0-based enum. |
163 using TargetProperties = | 164 using TargetProperties = |
164 std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; | 165 std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; |
165 | 166 |
166 void SetNeedsCommit(); | 167 void SetNeedsCommit(); |
167 | 168 |
168 void RegisterPlayer(); | 169 void RegisterPlayer(); |
169 void UnregisterPlayer(); | 170 void UnregisterPlayer(); |
170 | 171 |
171 void BindElementAnimations(); | 172 void BindElementAnimations(); |
172 void UnbindElementAnimations(); | 173 void UnbindElementAnimations(); |
173 | 174 |
174 void AnimationAddedForProperty(TargetProperty::Type target_property); | 175 void AnimationAddedForProperty(TargetProperty::Type target_property); |
175 | 176 |
176 void MarkAbortedAnimationsForDeletion( | 177 void MarkAbortedAnimationsForDeletion( |
177 AnimationPlayer* animation_player_impl) const; | 178 AnimationPlayer* animation_player_impl) const; |
178 void PurgeAnimationsMarkedForDeletion(); | 179 void PurgeAnimationsMarkedForDeletion(); |
179 void PushNewAnimationsToImplThread( | 180 void PushNewAnimationsToImplThread( |
180 AnimationPlayer* animation_player_impl) const; | 181 AnimationPlayer* animation_player_impl) const; |
181 void RemoveAnimationsCompletedOnMainThread( | 182 void RemoveAnimationsCompletedOnMainThread( |
182 AnimationPlayer* animation_player_impl) const; | 183 AnimationPlayer* animation_player_impl) const; |
183 void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl); | 184 void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl); |
184 | 185 |
| 186 using Animations = std::vector<std::unique_ptr<Animation>>; |
185 Animations animations_; | 187 Animations animations_; |
186 | 188 |
187 AnimationHost* animation_host_; | 189 AnimationHost* animation_host_; |
188 AnimationTimeline* animation_timeline_; | 190 AnimationTimeline* animation_timeline_; |
189 // element_animations isn't null if player attached to an element (layer). | 191 // element_animations isn't null if player attached to an element (layer). |
190 scoped_refptr<ElementAnimations> element_animations_; | 192 scoped_refptr<ElementAnimations> element_animations_; |
191 AnimationDelegate* animation_delegate_; | 193 AnimationDelegate* animation_delegate_; |
192 | 194 |
193 int id_; | 195 int id_; |
194 ElementId element_id_; | 196 ElementId element_id_; |
195 bool needs_push_properties_; | 197 bool needs_push_properties_; |
196 base::TimeTicks last_tick_time_; | 198 base::TimeTicks last_tick_time_; |
197 | 199 |
198 // Only try to start animations when new animations are added or when the | 200 // Only try to start animations when new animations are added or when the |
199 // previous attempt at starting animations failed to start all animations. | 201 // previous attempt at starting animations failed to start all animations. |
200 bool needs_to_start_animations_; | 202 bool needs_to_start_animations_; |
201 | 203 |
202 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); | 204 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); |
203 }; | 205 }; |
204 | 206 |
205 } // namespace cc | 207 } // namespace cc |
206 | 208 |
207 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ | 209 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ |
OLD | NEW |