| 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 <memory> | 8 #include <memory> |
| 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/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/time/time.h" | |
| 15 #include "cc/animation/animation_export.h" | 14 #include "cc/animation/animation_export.h" |
| 16 #include "cc/trees/element_id.h" | 15 #include "cc/trees/element_id.h" |
| 17 #include "cc/trees/property_animation_state.h" | 16 #include "cc/trees/property_animation_state.h" |
| 18 #include "cc/trees/target_property.h" | 17 #include "cc/trees/target_property.h" |
| 19 #include "ui/gfx/geometry/scroll_offset.h" | 18 #include "ui/gfx/geometry/scroll_offset.h" |
| 20 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 21 | 20 |
| 22 namespace gfx { | 21 namespace gfx { |
| 23 class BoxF; | 22 class BoxF; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 | 26 |
| 28 class AnimationEvents; | |
| 29 class AnimationHost; | 27 class AnimationHost; |
| 30 class AnimationPlayer; | 28 class AnimationPlayer; |
| 31 class FilterOperations; | 29 class FilterOperations; |
| 32 enum class ElementListType; | 30 enum class ElementListType; |
| 33 struct AnimationEvent; | 31 struct AnimationEvent; |
| 34 | 32 |
| 33 enum class ActivationType { NORMAL, FORCE }; |
| 34 |
| 35 // An ElementAnimations owns a list of all AnimationPlayers, attached to | 35 // An ElementAnimations owns a list of all AnimationPlayers, attached to |
| 36 // the element. | 36 // the element. |
| 37 // This is a CC counterpart for blink::ElementAnimations (in 1:1 relationship). | 37 // This is a CC counterpart for blink::ElementAnimations (in 1:1 relationship). |
| 38 // No pointer to/from respective blink::ElementAnimations object for now. | 38 // No pointer to/from respective blink::ElementAnimations object for now. |
| 39 class CC_ANIMATION_EXPORT ElementAnimations | 39 class CC_ANIMATION_EXPORT ElementAnimations |
| 40 : public base::RefCounted<ElementAnimations> { | 40 : public base::RefCounted<ElementAnimations> { |
| 41 public: | 41 public: |
| 42 static scoped_refptr<ElementAnimations> Create(); | 42 static scoped_refptr<ElementAnimations> Create(); |
| 43 | 43 |
| 44 ElementId element_id() const { return element_id_; } | 44 ElementId element_id() const { return element_id_; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 | 61 |
| 62 typedef base::ObserverList<AnimationPlayer> PlayersList; | 62 typedef base::ObserverList<AnimationPlayer> PlayersList; |
| 63 const PlayersList& players_list() const { return players_list_; } | 63 const PlayersList& players_list() const { return players_list_; } |
| 64 | 64 |
| 65 // Ensures that the list of active animations on the main thread and the impl | 65 // Ensures that the list of active animations on the main thread and the impl |
| 66 // thread are kept in sync. This function does not take ownership of the impl | 66 // thread are kept in sync. This function does not take ownership of the impl |
| 67 // thread ElementAnimations. | 67 // thread ElementAnimations. |
| 68 void PushPropertiesTo( | 68 void PushPropertiesTo( |
| 69 scoped_refptr<ElementAnimations> element_animations_impl) const; | 69 scoped_refptr<ElementAnimations> element_animations_impl) const; |
| 70 | 70 |
| 71 void Animate(base::TimeTicks monotonic_time); | |
| 72 | |
| 73 void UpdateState(bool start_ready_animations, AnimationEvents* events); | |
| 74 | |
| 75 // Make animations affect active elements if and only if they affect | |
| 76 // pending elements. Any animations that no longer affect any elements | |
| 77 // are deleted. | |
| 78 void ActivateAnimations(); | |
| 79 | |
| 80 // Returns true if there are any animations that have neither finished nor | 71 // Returns true if there are any animations that have neither finished nor |
| 81 // aborted. | 72 // aborted. |
| 82 bool HasActiveAnimation() const; | 73 bool HasActiveAnimation() const; |
| 83 | 74 |
| 84 // Returns true if there are any animations at all to process. | 75 // Returns true if there are any animations at all to process. |
| 85 bool HasAnyAnimation() const; | 76 bool HasAnyAnimation() const; |
| 86 | 77 |
| 87 bool HasAnyAnimationTargetingProperty(TargetProperty::Type property) const; | 78 bool HasAnyAnimationTargetingProperty(TargetProperty::Type property) const; |
| 88 | 79 |
| 89 // Returns true if there is an animation that is either currently animating | 80 // Returns true if there is an animation that is either currently animating |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // Sets |start_scale| to the maximum of starting animation scale along any | 130 // Sets |start_scale| to the maximum of starting animation scale along any |
| 140 // dimension at any destination in active animations. Returns false if the | 131 // dimension at any destination in active animations. Returns false if the |
| 141 // starting scale cannot be computed. | 132 // starting scale cannot be computed. |
| 142 bool AnimationStartScale(ElementListType list_type, float* start_scale) const; | 133 bool AnimationStartScale(ElementListType list_type, float* start_scale) const; |
| 143 | 134 |
| 144 // Sets |max_scale| to the maximum scale along any dimension at any | 135 // Sets |max_scale| to the maximum scale along any dimension at any |
| 145 // destination in active animations. Returns false if the maximum scale cannot | 136 // destination in active animations. Returns false if the maximum scale cannot |
| 146 // be computed. | 137 // be computed. |
| 147 bool MaximumTargetScale(ElementListType list_type, float* max_scale) const; | 138 bool MaximumTargetScale(ElementListType list_type, float* max_scale) const; |
| 148 | 139 |
| 149 // When a scroll animation is removed on the main thread, its compositor | 140 bool ScrollOffsetAnimationWasInterrupted() const; |
| 150 // thread counterpart continues producing scroll deltas until activation. | |
| 151 // These scroll deltas need to be cleared at activation, so that the active | |
| 152 // element's scroll offset matches the offset provided by the main thread | |
| 153 // rather than a combination of this offset and scroll deltas produced by | |
| 154 // the removed animation. This is to provide the illusion of synchronicity to | |
| 155 // JS that simultaneously removes an animation and sets the scroll offset. | |
| 156 bool scroll_offset_animation_was_interrupted() const { | |
| 157 return scroll_offset_animation_was_interrupted_; | |
| 158 } | |
| 159 void SetScrollOffsetAnimationWasInterrupted(); | |
| 160 | 141 |
| 161 void SetNeedsPushProperties(); | 142 void SetNeedsPushProperties(); |
| 162 bool needs_push_properties() const { return needs_push_properties_; } | 143 bool needs_push_properties() const { return needs_push_properties_; } |
| 163 | 144 |
| 164 void UpdateClientAnimationState(); | 145 void UpdateClientAnimationState(); |
| 165 void SetNeedsUpdateImplClientState(); | 146 void SetNeedsUpdateImplClientState(); |
| 166 | 147 |
| 167 void UpdateActivationNormal(); | |
| 168 | |
| 169 void NotifyClientOpacityAnimated(float opacity, | 148 void NotifyClientOpacityAnimated(float opacity, |
| 170 bool notify_active_elements, | 149 bool notify_active_elements, |
| 171 bool notify_pending_elements); | 150 bool notify_pending_elements); |
| 172 void NotifyClientTransformAnimated(const gfx::Transform& transform, | 151 void NotifyClientTransformAnimated(const gfx::Transform& transform, |
| 173 bool notify_active_elements, | 152 bool notify_active_elements, |
| 174 bool notify_pending_elements); | 153 bool notify_pending_elements); |
| 175 void NotifyClientFilterAnimated(const FilterOperations& filter, | 154 void NotifyClientFilterAnimated(const FilterOperations& filter, |
| 176 bool notify_active_elements, | 155 bool notify_active_elements, |
| 177 bool notify_pending_elements); | 156 bool notify_pending_elements); |
| 178 void NotifyClientScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset, | 157 void NotifyClientScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset, |
| 179 bool notify_active_elements, | 158 bool notify_active_elements, |
| 180 bool notify_pending_elements); | 159 bool notify_pending_elements); |
| 181 gfx::ScrollOffset ScrollOffsetForAnimation() const; | 160 gfx::ScrollOffset ScrollOffsetForAnimation() const; |
| 182 | 161 |
| 183 private: | 162 private: |
| 184 friend class base::RefCounted<ElementAnimations>; | 163 friend class base::RefCounted<ElementAnimations>; |
| 185 | 164 |
| 186 ElementAnimations(); | 165 ElementAnimations(); |
| 187 ~ElementAnimations(); | 166 ~ElementAnimations(); |
| 188 | 167 |
| 189 enum class ActivationType { NORMAL, FORCE }; | |
| 190 void UpdateActivation(ActivationType type); | |
| 191 | |
| 192 void OnFilterAnimated(ElementListType list_type, | 168 void OnFilterAnimated(ElementListType list_type, |
| 193 const FilterOperations& filters); | 169 const FilterOperations& filters); |
| 194 void OnOpacityAnimated(ElementListType list_type, float opacity); | 170 void OnOpacityAnimated(ElementListType list_type, float opacity); |
| 195 void OnTransformAnimated(ElementListType list_type, | 171 void OnTransformAnimated(ElementListType list_type, |
| 196 const gfx::Transform& transform); | 172 const gfx::Transform& transform); |
| 197 void OnScrollOffsetAnimated(ElementListType list_type, | 173 void OnScrollOffsetAnimated(ElementListType list_type, |
| 198 const gfx::ScrollOffset& scroll_offset); | 174 const gfx::ScrollOffset& scroll_offset); |
| 199 | 175 |
| 200 static TargetProperties GetPropertiesMaskForAnimationState(); | 176 static TargetProperties GetPropertiesMaskForAnimationState(); |
| 201 | 177 |
| 178 void UpdateActivation(ActivationType activation_type) const; |
| 179 void Deactivate() const; |
| 180 |
| 202 PlayersList players_list_; | 181 PlayersList players_list_; |
| 203 AnimationHost* animation_host_; | 182 AnimationHost* animation_host_; |
| 204 ElementId element_id_; | 183 ElementId element_id_; |
| 205 | 184 |
| 206 // This is used to ensure that we don't spam the animation host. | |
| 207 bool is_active_; | |
| 208 | |
| 209 base::TimeTicks last_tick_time_; | |
| 210 | |
| 211 bool has_element_in_active_list_; | 185 bool has_element_in_active_list_; |
| 212 bool has_element_in_pending_list_; | 186 bool has_element_in_pending_list_; |
| 213 | 187 |
| 214 mutable bool scroll_offset_animation_was_interrupted_; | |
| 215 | |
| 216 mutable bool needs_push_properties_; | 188 mutable bool needs_push_properties_; |
| 217 | 189 |
| 218 PropertyAnimationState active_state_; | 190 PropertyAnimationState active_state_; |
| 219 PropertyAnimationState pending_state_; | 191 PropertyAnimationState pending_state_; |
| 220 | 192 |
| 221 mutable bool needs_update_impl_client_state_; | 193 mutable bool needs_update_impl_client_state_; |
| 222 | 194 |
| 223 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); | 195 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); |
| 224 }; | 196 }; |
| 225 | 197 |
| 226 } // namespace cc | 198 } // namespace cc |
| 227 | 199 |
| 228 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ | 200 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ |
| OLD | NEW |