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 <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "cc/animation/animation.h" | 14 #include "cc/animation/animation.h" |
14 #include "cc/animation/animation_curve.h" | 15 #include "cc/animation/animation_curve.h" |
15 #include "cc/animation/element_animations.h" | 16 #include "cc/animation/element_animations.h" |
| 17 #include "cc/animation/element_id.h" |
16 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
17 | 19 |
18 namespace cc { | 20 namespace cc { |
19 | 21 |
20 class AnimationDelegate; | 22 class AnimationDelegate; |
| 23 class AnimationEvents; |
21 class AnimationHost; | 24 class AnimationHost; |
22 class AnimationTimeline; | 25 class AnimationTimeline; |
23 class ElementAnimations; | |
24 | 26 |
25 // 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. |
26 // Multiple AnimationPlayers can be attached to one layer. In this case, | 28 // Multiple AnimationPlayers can be attached to one layer. In this case, |
27 // they share common ElementAnimations so the | 29 // they share common ElementAnimations so the |
28 // ElementAnimations-to-Layer relationship is 1:1. | 30 // ElementAnimations-to-Layer relationship is 1:1. |
29 // For now, the blink logic is responsible for handling of conflicting | 31 // For now, the blink logic is responsible for handling of conflicting |
30 // same-property animations. | 32 // same-property animations. |
31 // Each AnimationPlayer has its copy on the impl thread. | 33 // Each AnimationPlayer has its copy on the impl thread. |
32 // 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). |
33 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> { | 35 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void AddAnimation(std::unique_ptr<Animation> animation); | 68 void AddAnimation(std::unique_ptr<Animation> animation); |
67 void PauseAnimation(int animation_id, double time_offset); | 69 void PauseAnimation(int animation_id, double time_offset); |
68 void RemoveAnimation(int animation_id); | 70 void RemoveAnimation(int animation_id); |
69 void AbortAnimation(int animation_id); | 71 void AbortAnimation(int animation_id); |
70 void AbortAnimations(TargetProperty::Type target_property, | 72 void AbortAnimations(TargetProperty::Type target_property, |
71 bool needs_completion); | 73 bool needs_completion); |
72 | 74 |
73 void PushPropertiesTo(AnimationPlayer* player_impl); | 75 void PushPropertiesTo(AnimationPlayer* player_impl); |
74 | 76 |
75 // AnimationDelegate routing. | 77 // AnimationDelegate routing. |
76 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 78 bool NotifyAnimationStarted(const AnimationEvent& event); |
77 TargetProperty::Type target_property, | 79 bool NotifyAnimationFinished(const AnimationEvent& event); |
78 int group); | 80 bool NotifyAnimationAborted(const AnimationEvent& event); |
79 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 81 void NotifyAnimationTakeover(const AnimationEvent& event); |
80 TargetProperty::Type target_property, | 82 bool NotifyAnimationFinishedForTesting(TargetProperty::Type target_property, |
81 int group); | 83 int group_id); |
82 void NotifyAnimationAborted(base::TimeTicks monotonic_time, | 84 |
83 TargetProperty::Type target_property, | 85 // Returns true if there are any animations that have neither finished nor |
84 int group); | 86 // aborted. |
85 void NotifyAnimationWaitingForDeletion(); | 87 bool HasActiveAnimation() const; |
86 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | |
87 TargetProperty::Type target_property, | |
88 double animation_start_time, | |
89 std::unique_ptr<AnimationCurve> curve); | |
90 | 88 |
91 // Returns true if there are any animations at all to process. | 89 // Returns true if there are any animations at all to process. |
92 bool has_any_animation() const { return !animations_.empty(); } | 90 bool has_any_animation() const { return !animations_.empty(); } |
93 | 91 |
94 bool needs_push_properties() const { return needs_push_properties_; } | 92 bool needs_push_properties() const { return needs_push_properties_; } |
95 void SetNeedsPushProperties(); | 93 void SetNeedsPushProperties(); |
96 | 94 |
| 95 bool HasNonDeletedAnimation() const; |
| 96 |
| 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_; } |
| 101 |
| 102 void StartAnimations(base::TimeTicks monotonic_time); |
| 103 void PromoteStartedAnimations(base::TimeTicks monotonic_time, |
| 104 AnimationEvents* events); |
| 105 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, |
| 106 AnimationEvents* events); |
| 107 void TickAnimations(base::TimeTicks monotonic_time); |
| 108 void MarkFinishedAnimations(base::TimeTicks monotonic_time); |
| 109 |
| 110 // Make animations affect active elements if and only if they affect |
| 111 // pending elements. Any animations that no longer affect any elements |
| 112 // are deleted. |
| 113 void ActivateAnimations(bool* changed_transform_animation, |
| 114 bool* changed_opacity_animation, |
| 115 bool* changed_filter_animation); |
| 116 |
| 117 bool HasFilterAnimationThatInflatesBounds() const; |
| 118 bool HasTransformAnimationThatInflatesBounds() const; |
| 119 |
| 120 bool TransformAnimationBoundsForBox(const gfx::BoxF& box, |
| 121 gfx::BoxF* bounds) const; |
| 122 bool HasAnimationThatAffectsScale() const; |
| 123 bool HasOnlyTranslationTransforms(ElementListType list_type) const; |
| 124 bool AnimationsPreserveAxisAlignment() const; |
| 125 |
| 126 // Sets |start_scale| to the maximum of starting animation scale along any |
| 127 // dimension at any destination in active animations. Returns false if the |
| 128 // starting scale cannot be computed. |
| 129 bool AnimationStartScale(ElementListType list_type, float* start_scale) const; |
| 130 |
| 131 // Sets |max_scale| to the maximum scale along any dimension at any |
| 132 // destination in active animations. Returns false if the maximum scale cannot |
| 133 // be computed. |
| 134 bool MaximumTargetScale(ElementListType list_type, float* max_scale) const; |
| 135 |
| 136 // Returns true if there is an animation that is either currently animating |
| 137 // the given property or scheduled to animate this property in the future, and |
| 138 // that affects the given tree type. |
| 139 bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property, |
| 140 ElementListType list_type) const; |
| 141 |
| 142 // Returns true if there is an animation that is currently animating the given |
| 143 // property and that affects the given tree type. |
| 144 bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property, |
| 145 ElementListType list_type) const; |
| 146 |
| 147 bool HasElementInActiveList() const; |
| 148 gfx::ScrollOffset ScrollOffsetForAnimation() const; |
| 149 |
| 150 // Returns the active animation animating the given property that is either |
| 151 // running, or is next to run, if such an animation exists. |
| 152 Animation* GetAnimation(TargetProperty::Type target_property) const; |
| 153 |
| 154 // Returns the active animation for the given unique animation id. |
| 155 Animation* GetAnimationById(int animation_id) const; |
| 156 |
97 private: | 157 private: |
98 friend class base::RefCounted<AnimationPlayer>; | 158 friend class base::RefCounted<AnimationPlayer>; |
99 | 159 |
100 explicit AnimationPlayer(int id); | 160 explicit AnimationPlayer(int id); |
101 ~AnimationPlayer(); | 161 ~AnimationPlayer(); |
102 | 162 |
| 163 // A set of target properties. TargetProperty must be 0-based enum. |
| 164 using TargetProperties = |
| 165 std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; |
| 166 |
103 void SetNeedsCommit(); | 167 void SetNeedsCommit(); |
104 | 168 |
105 void RegisterPlayer(); | 169 void RegisterPlayer(); |
106 void UnregisterPlayer(); | 170 void UnregisterPlayer(); |
107 | 171 |
108 void BindElementAnimations(); | 172 void BindElementAnimations(); |
109 void UnbindElementAnimations(); | 173 void UnbindElementAnimations(); |
110 | 174 |
111 // We accumulate added animations in animations_ container | 175 void AnimationAddedForProperty(TargetProperty::Type target_property); |
112 // if element_animations_ is a nullptr. It allows us to add/remove animations | 176 |
113 // to non-attached AnimationPlayers. | 177 void MarkAbortedAnimationsForDeletion( |
114 std::vector<std::unique_ptr<Animation>> animations_; | 178 AnimationPlayer* animation_player_impl) const; |
| 179 void PurgeAnimationsMarkedForDeletion(); |
| 180 void PushNewAnimationsToImplThread( |
| 181 AnimationPlayer* animation_player_impl) const; |
| 182 void RemoveAnimationsCompletedOnMainThread( |
| 183 AnimationPlayer* animation_player_impl) const; |
| 184 void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl); |
| 185 |
| 186 Animations animations_; |
115 | 187 |
116 AnimationHost* animation_host_; | 188 AnimationHost* animation_host_; |
117 AnimationTimeline* animation_timeline_; | 189 AnimationTimeline* animation_timeline_; |
118 // element_animations isn't null if player attached to an element (layer). | 190 // element_animations isn't null if player attached to an element (layer). |
119 scoped_refptr<ElementAnimations> element_animations_; | 191 scoped_refptr<ElementAnimations> element_animations_; |
120 AnimationDelegate* animation_delegate_; | 192 AnimationDelegate* animation_delegate_; |
121 | 193 |
122 int id_; | 194 int id_; |
123 ElementId element_id_; | 195 ElementId element_id_; |
124 bool needs_push_properties_; | 196 bool needs_push_properties_; |
| 197 base::TimeTicks last_tick_time_; |
| 198 |
| 199 // Only try to start animations when new animations are added or when the |
| 200 // previous attempt at starting animations failed to start all animations. |
| 201 bool needs_to_start_animations_; |
125 | 202 |
126 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); | 203 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); |
127 }; | 204 }; |
128 | 205 |
129 } // namespace cc | 206 } // namespace cc |
130 | 207 |
131 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ | 208 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ |
OLD | NEW |