| 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_ELEMENT_ANIMATIONS_H_ | 5 #ifndef CC_ANIMATION_ELEMENT_ANIMATIONS_H_ |
| 6 #define CC_ANIMATION_ELEMENT_ANIMATIONS_H_ | 6 #define CC_ANIMATION_ELEMENT_ANIMATIONS_H_ |
| 7 | 7 |
| 8 #include <bitset> | 8 #include <bitset> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 static scoped_refptr<ElementAnimations> Create(); | 44 static scoped_refptr<ElementAnimations> Create(); |
| 45 | 45 |
| 46 int layer_id() const { return layer_id_; } | 46 int layer_id() const { return layer_id_; } |
| 47 void SetLayerId(int layer_id); | 47 void SetLayerId(int layer_id); |
| 48 | 48 |
| 49 // Parent AnimationHost. | 49 // Parent AnimationHost. |
| 50 AnimationHost* animation_host() { return animation_host_; } | 50 AnimationHost* animation_host() { return animation_host_; } |
| 51 const AnimationHost* animation_host() const { return animation_host_; } | 51 const AnimationHost* animation_host() const { return animation_host_; } |
| 52 void SetAnimationHost(AnimationHost* host); | 52 void SetAnimationHost(AnimationHost* host); |
| 53 | 53 |
| 54 void InitValueObservations(); | 54 void InitAffectedElementTypes(); |
| 55 void ClearValueObservations(); | 55 void ClearAffectedElementTypes(); |
| 56 | 56 |
| 57 void LayerRegistered(int layer_id, LayerTreeType tree_type); | 57 void LayerRegistered(int layer_id, LayerTreeType tree_type); |
| 58 void LayerUnregistered(int layer_id, LayerTreeType tree_type); | 58 void LayerUnregistered(int layer_id, LayerTreeType tree_type); |
| 59 | 59 |
| 60 void AddPlayer(AnimationPlayer* player); | 60 void AddPlayer(AnimationPlayer* player); |
| 61 void RemovePlayer(AnimationPlayer* player); | 61 void RemovePlayer(AnimationPlayer* player); |
| 62 bool IsEmpty() const; | 62 bool IsEmpty() const; |
| 63 | 63 |
| 64 typedef base::LinkedList<AnimationPlayer> PlayersList; | 64 typedef base::LinkedList<AnimationPlayer> PlayersList; |
| 65 typedef base::LinkNode<AnimationPlayer> PlayersListNode; | 65 typedef base::LinkNode<AnimationPlayer> PlayersListNode; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 void AbortAnimation(int animation_id); | 77 void AbortAnimation(int animation_id); |
| 78 void AbortAnimations(TargetProperty::Type target_property, | 78 void AbortAnimations(TargetProperty::Type target_property, |
| 79 bool needs_completion = false); | 79 bool needs_completion = false); |
| 80 | 80 |
| 81 void Animate(base::TimeTicks monotonic_time); | 81 void Animate(base::TimeTicks monotonic_time); |
| 82 void AccumulatePropertyUpdates(base::TimeTicks monotonic_time, | 82 void AccumulatePropertyUpdates(base::TimeTicks monotonic_time, |
| 83 AnimationEvents* events); | 83 AnimationEvents* events); |
| 84 | 84 |
| 85 void UpdateState(bool start_ready_animations, AnimationEvents* events); | 85 void UpdateState(bool start_ready_animations, AnimationEvents* events); |
| 86 | 86 |
| 87 // Make animations affect active observers if and only if they affect | 87 // Make animations affect active elements if and only if they affect |
| 88 // pending observers. Any animations that no longer affect any observers | 88 // pending elements. Any animations that no longer affect any elements |
| 89 // are deleted. | 89 // are deleted. |
| 90 void ActivateAnimations(); | 90 void ActivateAnimations(); |
| 91 | 91 |
| 92 // Returns the active animation animating the given property that is either | 92 // Returns the active animation animating the given property that is either |
| 93 // running, or is next to run, if such an animation exists. | 93 // running, or is next to run, if such an animation exists. |
| 94 Animation* GetAnimation(TargetProperty::Type target_property) const; | 94 Animation* GetAnimation(TargetProperty::Type target_property) const; |
| 95 | 95 |
| 96 // Returns the active animation for the given unique animation id. | 96 // Returns the active animation for the given unique animation id. |
| 97 Animation* GetAnimationById(int animation_id) const; | 97 Animation* GetAnimationById(int animation_id) const; |
| 98 | 98 |
| 99 // Returns true if there are any animations that have neither finished nor | 99 // Returns true if there are any animations that have neither finished nor |
| 100 // aborted. | 100 // aborted. |
| 101 bool HasActiveAnimation() const; | 101 bool HasActiveAnimation() const; |
| 102 | 102 |
| 103 // Returns true if there are any animations at all to process. | 103 // Returns true if there are any animations at all to process. |
| 104 bool has_any_animation() const { return !animations_.empty(); } | 104 bool has_any_animation() const { return !animations_.empty(); } |
| 105 | 105 |
| 106 // Returns true if there is an animation that is either currently animating | 106 // Returns true if there is an animation that is either currently animating |
| 107 // the given property or scheduled to animate this property in the future, and | 107 // the given property or scheduled to animate this property in the future, and |
| 108 // that affects the given observer type. | 108 // that affects the given tree type. |
| 109 bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property, | 109 bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property, |
| 110 LayerTreeType observer_type) const; | 110 LayerTreeType tree_type) const; |
| 111 | 111 |
| 112 // Returns true if there is an animation that is currently animating the given | 112 // Returns true if there is an animation that is currently animating the given |
| 113 // property and that affects the given observer type. | 113 // property and that affects the given tree type. |
| 114 bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property, | 114 bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property, |
| 115 LayerTreeType observer_type) const; | 115 LayerTreeType tree_type) const; |
| 116 | 116 |
| 117 void NotifyAnimationStarted(const AnimationEvent& event); | 117 void NotifyAnimationStarted(const AnimationEvent& event); |
| 118 void NotifyAnimationFinished(const AnimationEvent& event); | 118 void NotifyAnimationFinished(const AnimationEvent& event); |
| 119 void NotifyAnimationAborted(const AnimationEvent& event); | 119 void NotifyAnimationAborted(const AnimationEvent& event); |
| 120 void NotifyAnimationPropertyUpdate(const AnimationEvent& event); | 120 void NotifyAnimationPropertyUpdate(const AnimationEvent& event); |
| 121 void NotifyAnimationTakeover(const AnimationEvent& event); | 121 void NotifyAnimationTakeover(const AnimationEvent& event); |
| 122 | 122 |
| 123 bool needs_active_value_observations() const { | 123 bool has_element_in_active_list() const { |
| 124 return needs_active_value_observations_; | 124 return has_element_in_active_list_; |
| 125 } | 125 } |
| 126 bool needs_pending_value_observations() const { | 126 bool has_element_in_pending_list() const { |
| 127 return needs_pending_value_observations_; | 127 return has_element_in_pending_list_; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void set_needs_active_value_observations( | 130 void set_has_element_in_active_list(bool has_element_in_active_list) { |
| 131 bool needs_active_value_observations) { | 131 has_element_in_active_list_ = has_element_in_active_list; |
| 132 needs_active_value_observations_ = needs_active_value_observations; | |
| 133 } | 132 } |
| 134 void set_needs_pending_value_observations( | 133 void set_has_element_in_pending_list(bool has_element_in_pending_list) { |
| 135 bool needs_pending_value_observations) { | 134 has_element_in_pending_list_ = has_element_in_pending_list; |
| 136 needs_pending_value_observations_ = needs_pending_value_observations; | |
| 137 } | 135 } |
| 138 | 136 |
| 139 bool HasFilterAnimationThatInflatesBounds() const; | 137 bool HasFilterAnimationThatInflatesBounds() const; |
| 140 bool HasTransformAnimationThatInflatesBounds() const; | 138 bool HasTransformAnimationThatInflatesBounds() const; |
| 141 bool HasAnimationThatInflatesBounds() const { | 139 bool HasAnimationThatInflatesBounds() const { |
| 142 return HasTransformAnimationThatInflatesBounds() || | 140 return HasTransformAnimationThatInflatesBounds() || |
| 143 HasFilterAnimationThatInflatesBounds(); | 141 HasFilterAnimationThatInflatesBounds(); |
| 144 } | 142 } |
| 145 | 143 |
| 146 bool FilterAnimationBoundsForBox(const gfx::BoxF& box, | 144 bool FilterAnimationBoundsForBox(const gfx::BoxF& box, |
| 147 gfx::BoxF* bounds) const; | 145 gfx::BoxF* bounds) const; |
| 148 bool TransformAnimationBoundsForBox(const gfx::BoxF& box, | 146 bool TransformAnimationBoundsForBox(const gfx::BoxF& box, |
| 149 gfx::BoxF* bounds) const; | 147 gfx::BoxF* bounds) const; |
| 150 | 148 |
| 151 bool HasAnimationThatAffectsScale() const; | 149 bool HasAnimationThatAffectsScale() const; |
| 152 | 150 |
| 153 bool HasOnlyTranslationTransforms(LayerTreeType observer_type) const; | 151 bool HasOnlyTranslationTransforms(LayerTreeType tree_type) const; |
| 154 | 152 |
| 155 bool AnimationsPreserveAxisAlignment() const; | 153 bool AnimationsPreserveAxisAlignment() const; |
| 156 | 154 |
| 157 // Sets |start_scale| to the maximum of starting animation scale along any | 155 // Sets |start_scale| to the maximum of starting animation scale along any |
| 158 // dimension at any destination in active animations. Returns false if the | 156 // dimension at any destination in active animations. Returns false if the |
| 159 // starting scale cannot be computed. | 157 // starting scale cannot be computed. |
| 160 bool AnimationStartScale(LayerTreeType observer_type, | 158 bool AnimationStartScale(LayerTreeType tree_type, float* start_scale) const; |
| 161 float* start_scale) const; | |
| 162 | 159 |
| 163 // Sets |max_scale| to the maximum scale along any dimension at any | 160 // Sets |max_scale| to the maximum scale along any dimension at any |
| 164 // destination in active animations. Returns false if the maximum scale cannot | 161 // destination in active animations. Returns false if the maximum scale cannot |
| 165 // be computed. | 162 // be computed. |
| 166 bool MaximumTargetScale(LayerTreeType observer_type, float* max_scale) const; | 163 bool MaximumTargetScale(LayerTreeType tree_type, float* max_scale) const; |
| 167 | 164 |
| 168 // When a scroll animation is removed on the main thread, its compositor | 165 // When a scroll animation is removed on the main thread, its compositor |
| 169 // thread counterpart continues producing scroll deltas until activation. | 166 // thread counterpart continues producing scroll deltas until activation. |
| 170 // These scroll deltas need to be cleared at activation, so that the active | 167 // These scroll deltas need to be cleared at activation, so that the active |
| 171 // layer's scroll offset matches the offset provided by the main thread | 168 // layer's scroll offset matches the offset provided by the main thread |
| 172 // rather than a combination of this offset and scroll deltas produced by | 169 // rather than a combination of this offset and scroll deltas produced by |
| 173 // the removed animation. This is to provide the illusion of synchronicity to | 170 // the removed animation. This is to provide the illusion of synchronicity to |
| 174 // JS that simultaneously removes an animation and sets the scroll offset. | 171 // JS that simultaneously removes an animation and sets the scroll offset. |
| 175 bool scroll_offset_animation_was_interrupted() const { | 172 bool scroll_offset_animation_was_interrupted() const { |
| 176 return scroll_offset_animation_was_interrupted_; | 173 return scroll_offset_animation_was_interrupted_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 204 void MarkFinishedAnimations(base::TimeTicks monotonic_time); | 201 void MarkFinishedAnimations(base::TimeTicks monotonic_time); |
| 205 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, | 202 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, |
| 206 AnimationEvents* events); | 203 AnimationEvents* events); |
| 207 void PurgeAnimationsMarkedForDeletion(); | 204 void PurgeAnimationsMarkedForDeletion(); |
| 208 | 205 |
| 209 void TickAnimations(base::TimeTicks monotonic_time); | 206 void TickAnimations(base::TimeTicks monotonic_time); |
| 210 | 207 |
| 211 enum UpdateActivationType { NORMAL_ACTIVATION, FORCE_ACTIVATION }; | 208 enum UpdateActivationType { NORMAL_ACTIVATION, FORCE_ACTIVATION }; |
| 212 void UpdateActivation(UpdateActivationType type); | 209 void UpdateActivation(UpdateActivationType type); |
| 213 | 210 |
| 214 void NotifyObserversOpacityAnimated(float opacity, | 211 void NotifyClientOpacityAnimated(float opacity, |
| 215 bool notify_active_observers, | 212 bool notify_active_elements, |
| 216 bool notify_pending_observers); | 213 bool notify_pending_elements); |
| 217 void NotifyObserversTransformAnimated(const gfx::Transform& transform, | 214 void NotifyClientTransformAnimated(const gfx::Transform& transform, |
| 218 bool notify_active_observers, | 215 bool notify_active_elements, |
| 219 bool notify_pending_observers); | 216 bool notify_pending_elements); |
| 220 void NotifyObserversFilterAnimated(const FilterOperations& filter, | 217 void NotifyClientFilterAnimated(const FilterOperations& filter, |
| 221 bool notify_active_observers, | 218 bool notify_active_elements, |
| 222 bool notify_pending_observers); | 219 bool notify_pending_elements); |
| 223 void NotifyObserversScrollOffsetAnimated( | 220 void NotifyClientScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset, |
| 224 const gfx::ScrollOffset& scroll_offset, | 221 bool notify_active_elements, |
| 225 bool notify_active_observers, | 222 bool notify_pending_elements); |
| 226 bool notify_pending_observers); | |
| 227 | 223 |
| 228 void NotifyObserversAnimationWaitingForDeletion(); | 224 void NotifyClientAnimationWaitingForDeletion(); |
| 229 | 225 |
| 230 void NotifyObserversTransformIsPotentiallyAnimatingChanged( | 226 void NotifyClientTransformIsPotentiallyAnimatingChanged( |
| 231 bool notify_active_observers, | 227 bool notify_active_elements, |
| 232 bool notify_pending_observers); | 228 bool notify_pending_elements); |
| 233 | 229 |
| 234 void UpdatePotentiallyAnimatingTransform(); | 230 void UpdatePotentiallyAnimatingTransform(); |
| 235 | 231 |
| 236 void OnFilterAnimated(LayerTreeType tree_type, | 232 void OnFilterAnimated(LayerTreeType tree_type, |
| 237 const FilterOperations& filters); | 233 const FilterOperations& filters); |
| 238 void OnOpacityAnimated(LayerTreeType tree_type, float opacity); | 234 void OnOpacityAnimated(LayerTreeType tree_type, float opacity); |
| 239 void OnTransformAnimated(LayerTreeType tree_type, | 235 void OnTransformAnimated(LayerTreeType tree_type, |
| 240 const gfx::Transform& transform); | 236 const gfx::Transform& transform); |
| 241 void OnScrollOffsetAnimated(LayerTreeType tree_type, | 237 void OnScrollOffsetAnimated(LayerTreeType tree_type, |
| 242 const gfx::ScrollOffset& scroll_offset); | 238 const gfx::ScrollOffset& scroll_offset); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 263 std::unique_ptr<PlayersList> players_list_; | 259 std::unique_ptr<PlayersList> players_list_; |
| 264 AnimationHost* animation_host_; | 260 AnimationHost* animation_host_; |
| 265 int layer_id_; | 261 int layer_id_; |
| 266 std::vector<std::unique_ptr<Animation>> animations_; | 262 std::vector<std::unique_ptr<Animation>> animations_; |
| 267 | 263 |
| 268 // This is used to ensure that we don't spam the animation host. | 264 // This is used to ensure that we don't spam the animation host. |
| 269 bool is_active_; | 265 bool is_active_; |
| 270 | 266 |
| 271 base::TimeTicks last_tick_time_; | 267 base::TimeTicks last_tick_time_; |
| 272 | 268 |
| 273 bool needs_active_value_observations_; | 269 bool has_element_in_active_list_; |
| 274 bool needs_pending_value_observations_; | 270 bool has_element_in_pending_list_; |
| 275 | 271 |
| 276 // Only try to start animations when new animations are added or when the | 272 // Only try to start animations when new animations are added or when the |
| 277 // previous attempt at starting animations failed to start all animations. | 273 // previous attempt at starting animations failed to start all animations. |
| 278 bool needs_to_start_animations_; | 274 bool needs_to_start_animations_; |
| 279 | 275 |
| 280 bool scroll_offset_animation_was_interrupted_; | 276 bool scroll_offset_animation_was_interrupted_; |
| 281 | 277 |
| 282 bool potentially_animating_transform_for_active_observers_; | 278 bool potentially_animating_transform_for_active_elements_; |
| 283 bool potentially_animating_transform_for_pending_observers_; | 279 bool potentially_animating_transform_for_pending_elements_; |
| 284 | 280 |
| 285 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); | 281 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); |
| 286 }; | 282 }; |
| 287 | 283 |
| 288 } // namespace cc | 284 } // namespace cc |
| 289 | 285 |
| 290 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ | 286 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ |
| OLD | NEW |