Chromium Code Reviews| 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> | |
| 9 #include <memory> | 8 #include <memory> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
| 17 #include "cc/animation/animation_curve.h" | 16 #include "cc/animation/animation_curve.h" |
| 18 #include "cc/animation/animation_events.h" | 17 #include "cc/animation/animation_events.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // 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 |
| 167 // thread counterpart continues producing scroll deltas until activation. | 166 // thread counterpart continues producing scroll deltas until activation. |
| 168 // 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 |
| 169 // element's scroll offset matches the offset provided by the main thread | 168 // element's scroll offset matches the offset provided by the main thread |
| 170 // 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 |
| 171 // 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 |
| 172 // JS that simultaneously removes an animation and sets the scroll offset. | 171 // JS that simultaneously removes an animation and sets the scroll offset. |
| 173 bool scroll_offset_animation_was_interrupted() const { | 172 bool scroll_offset_animation_was_interrupted() const { |
| 174 return scroll_offset_animation_was_interrupted_; | 173 return scroll_offset_animation_was_interrupted_; |
| 175 } | 174 } |
| 175 void SetScrollOffsetAnimationWasInterrupted(); | |
| 176 | 176 |
| 177 bool needs_to_start_animations_for_testing() { | 177 // TODO(loyso): Erase it, use AnimationPlayer's one. |
| 178 return needs_to_start_animations_; | 178 bool needs_to_start_animations_for_testing() const; |
| 179 } | |
| 180 | 179 |
| 181 void SetNeedsPushProperties(); | 180 void SetNeedsPushProperties(); |
| 182 bool needs_push_properties() const { return needs_push_properties_; } | 181 bool needs_push_properties() const { return needs_push_properties_; } |
| 183 | 182 |
| 184 private: | 183 // TODO(loyso): Rework UpdateClientAnimationState to use bitset. |
|
ajuma
2016/09/13 17:19:16
Agreed. In particular, the version below that take
loyso (OOO)
2016/09/14 00:20:07
Acknowledged.
| |
| 185 friend class base::RefCounted<ElementAnimations>; | 184 void UpdateClientAnimationState(TargetProperty::Type target_property); |
| 185 void UpdateClientAnimationState(bool transform, bool opacity, bool filter); | |
| 186 void SetNeedsUpdateImplClientState(bool transform, bool opacity, bool filter); | |
| 186 | 187 |
| 187 ElementAnimations(); | 188 void UpdateActivationNormal(); |
| 188 ~ElementAnimations(); | |
| 189 | |
| 190 // A set of target properties. TargetProperty must be 0-based enum. | |
| 191 using TargetProperties = | |
| 192 std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; | |
| 193 | |
| 194 void PushNewAnimationsToImplThread( | |
| 195 ElementAnimations* element_animations_impl) const; | |
| 196 void MarkAbortedAnimationsForDeletion( | |
| 197 ElementAnimations* element_animations_impl) const; | |
| 198 void RemoveAnimationsCompletedOnMainThread( | |
| 199 ElementAnimations* element_animations_impl) const; | |
| 200 void PushPropertiesToImplThread(ElementAnimations* element_animations_impl); | |
| 201 | |
| 202 void StartAnimations(base::TimeTicks monotonic_time); | |
| 203 void PromoteStartedAnimations(base::TimeTicks monotonic_time, | |
| 204 AnimationEvents* events); | |
| 205 void MarkFinishedAnimations(base::TimeTicks monotonic_time); | |
| 206 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, | |
| 207 AnimationEvents* events); | |
| 208 void PurgeAnimationsMarkedForDeletion(); | |
| 209 | |
| 210 void TickAnimations(base::TimeTicks monotonic_time); | |
| 211 | |
| 212 enum UpdateActivationType { NORMAL_ACTIVATION, FORCE_ACTIVATION }; | |
| 213 void UpdateActivation(UpdateActivationType type); | |
| 214 | 189 |
| 215 void NotifyClientOpacityAnimated(float opacity, | 190 void NotifyClientOpacityAnimated(float opacity, |
| 216 bool notify_active_elements, | 191 bool notify_active_elements, |
| 217 bool notify_pending_elements); | 192 bool notify_pending_elements); |
| 218 void NotifyClientTransformAnimated(const gfx::Transform& transform, | 193 void NotifyClientTransformAnimated(const gfx::Transform& transform, |
| 219 bool notify_active_elements, | 194 bool notify_active_elements, |
| 220 bool notify_pending_elements); | 195 bool notify_pending_elements); |
| 221 void NotifyClientFilterAnimated(const FilterOperations& filter, | 196 void NotifyClientFilterAnimated(const FilterOperations& filter, |
| 222 bool notify_active_elements, | 197 bool notify_active_elements, |
| 223 bool notify_pending_elements); | 198 bool notify_pending_elements); |
| 224 void NotifyClientScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset, | 199 void NotifyClientScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset, |
| 225 bool notify_active_elements, | 200 bool notify_active_elements, |
| 226 bool notify_pending_elements); | 201 bool notify_pending_elements); |
| 202 gfx::ScrollOffset ScrollOffsetForAnimation() const; | |
| 203 | |
| 204 private: | |
| 205 friend class base::RefCounted<ElementAnimations>; | |
| 206 | |
| 207 ElementAnimations(); | |
| 208 ~ElementAnimations(); | |
| 209 | |
| 210 enum class ActivationType { NORMAL, FORCE }; | |
| 211 void UpdateActivation(ActivationType type); | |
| 212 | |
| 213 void UpdateClientAnimationStateInternal(TargetProperty::Type property); | |
| 214 | |
| 227 void NotifyClientAnimationChanged( | 215 void NotifyClientAnimationChanged( |
| 228 TargetProperty::Type property, | 216 TargetProperty::Type property, |
| 229 ElementListType list_type, | 217 ElementListType list_type, |
| 230 bool notify_elements_about_potential_animation, | 218 bool notify_elements_about_potential_animation, |
| 231 bool notify_elements_about_running_animation); | 219 bool notify_elements_about_running_animation); |
| 232 | 220 |
| 233 void UpdateClientAnimationState(TargetProperty::Type property); | |
| 234 | |
| 235 void OnFilterAnimated(ElementListType list_type, | 221 void OnFilterAnimated(ElementListType list_type, |
| 236 const FilterOperations& filters); | 222 const FilterOperations& filters); |
| 237 void OnOpacityAnimated(ElementListType list_type, float opacity); | 223 void OnOpacityAnimated(ElementListType list_type, float opacity); |
| 238 void OnTransformAnimated(ElementListType list_type, | 224 void OnTransformAnimated(ElementListType list_type, |
| 239 const gfx::Transform& transform); | 225 const gfx::Transform& transform); |
| 240 void OnScrollOffsetAnimated(ElementListType list_type, | 226 void OnScrollOffsetAnimated(ElementListType list_type, |
| 241 const gfx::ScrollOffset& scroll_offset); | 227 const gfx::ScrollOffset& scroll_offset); |
| 242 void IsAnimatingChanged(ElementListType list_type, | 228 void IsAnimatingChanged(ElementListType list_type, |
| 243 TargetProperty::Type property, | 229 TargetProperty::Type property, |
| 244 AnimationChangeType change_type, | 230 AnimationChangeType change_type, |
| 245 bool is_animating); | 231 bool is_animating); |
| 246 gfx::ScrollOffset ScrollOffsetForAnimation() const; | |
| 247 | 232 |
| 248 void NotifyPlayersAnimationStarted(base::TimeTicks monotonic_time, | 233 void ClearNeedsUpdateImplClientState(); |
| 249 TargetProperty::Type target_property, | |
| 250 int group); | |
| 251 void NotifyPlayersAnimationFinished(base::TimeTicks monotonic_time, | |
| 252 TargetProperty::Type target_property, | |
| 253 int group); | |
| 254 void NotifyPlayersAnimationAborted(base::TimeTicks monotonic_time, | |
| 255 TargetProperty::Type target_property, | |
| 256 int group); | |
| 257 void NotifyPlayersAnimationWaitingForDeletion(); | |
| 258 void NotifyPlayersAnimationPropertyUpdate(const AnimationEvent& event); | |
| 259 void NotifyPlayersAnimationTakeover(base::TimeTicks monotonic_time, | |
| 260 TargetProperty::Type target_property, | |
| 261 double animation_start_time, | |
| 262 std::unique_ptr<AnimationCurve> curve); | |
| 263 | 234 |
| 264 std::unique_ptr<PlayersList> players_list_; | 235 std::unique_ptr<PlayersList> players_list_; |
| 265 AnimationHost* animation_host_; | 236 AnimationHost* animation_host_; |
| 266 ElementId element_id_; | 237 ElementId element_id_; |
| 267 std::vector<std::unique_ptr<Animation>> animations_; | |
| 268 | 238 |
| 269 // This is used to ensure that we don't spam the animation host. | 239 // This is used to ensure that we don't spam the animation host. |
| 270 bool is_active_; | 240 bool is_active_; |
| 271 | 241 |
| 272 base::TimeTicks last_tick_time_; | 242 base::TimeTicks last_tick_time_; |
| 273 | 243 |
| 274 bool has_element_in_active_list_; | 244 bool has_element_in_active_list_; |
| 275 bool has_element_in_pending_list_; | 245 bool has_element_in_pending_list_; |
| 276 | 246 |
| 277 // Only try to start animations when new animations are added or when the | |
| 278 // previous attempt at starting animations failed to start all animations. | |
| 279 bool needs_to_start_animations_; | |
| 280 | |
| 281 bool scroll_offset_animation_was_interrupted_; | 247 bool scroll_offset_animation_was_interrupted_; |
| 282 | 248 |
| 283 bool needs_push_properties_; | 249 bool needs_push_properties_; |
| 284 | 250 |
| 285 struct PropertyAnimationState { | 251 struct PropertyAnimationState { |
| 286 bool currently_running_for_active_elements = false; | 252 bool currently_running_for_active_elements = false; |
| 287 bool currently_running_for_pending_elements = false; | 253 bool currently_running_for_pending_elements = false; |
| 288 bool potentially_animating_for_active_elements = false; | 254 bool potentially_animating_for_active_elements = false; |
| 289 bool potentially_animating_for_pending_elements = false; | 255 bool potentially_animating_for_pending_elements = false; |
| 290 void Clear() { | 256 void Clear() { |
| 291 currently_running_for_active_elements = false; | 257 currently_running_for_active_elements = false; |
| 292 currently_running_for_pending_elements = false; | 258 currently_running_for_pending_elements = false; |
| 293 potentially_animating_for_active_elements = false; | 259 potentially_animating_for_active_elements = false; |
| 294 potentially_animating_for_pending_elements = false; | 260 potentially_animating_for_pending_elements = false; |
| 295 } | 261 } |
| 296 }; | 262 }; |
| 297 | 263 |
| 298 struct PropertyAnimationState filter_animation_state_; | 264 struct PropertyAnimationState filter_animation_state_; |
| 299 struct PropertyAnimationState opacity_animation_state_; | 265 struct PropertyAnimationState opacity_animation_state_; |
| 300 struct PropertyAnimationState transform_animation_state_; | 266 struct PropertyAnimationState transform_animation_state_; |
| 301 | 267 |
| 268 bool needs_update_impl_client_state_transform_ : 1; | |
| 269 bool needs_update_impl_client_state_opacity_ : 1; | |
| 270 bool needs_update_impl_client_state_filter_ : 1; | |
|
ajuma
2016/09/13 17:19:16
These need to be initialized.
loyso (OOO)
2016/09/14 00:20:07
It is initialized. See ClearNeedsUpdateImplClientS
| |
| 271 | |
| 302 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); | 272 DISALLOW_COPY_AND_ASSIGN(ElementAnimations); |
| 303 }; | 273 }; |
| 304 | 274 |
| 305 } // namespace cc | 275 } // namespace cc |
| 306 | 276 |
| 307 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ | 277 #endif // CC_ANIMATION_ELEMENT_ANIMATIONS_H_ |
| OLD | NEW |