OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_ANIMATION_ANIMATION_PLAYER_H_ |
| 6 #define CC_ANIMATION_ANIMATION_PLAYER_H_ |
| 7 |
| 8 #include "base/containers/linked_list.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/time/time.h" |
| 11 #include "cc/animation/animation.h" |
| 12 #include "cc/base/cc_export.h" |
| 13 #include "cc/base/scoped_ptr_vector.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 class AnimationDelegate; |
| 18 class AnimationHost; |
| 19 class AnimationTimeline; |
| 20 class ElementAnimations; |
| 21 class LayerAnimationController; |
| 22 enum class LayerTreeType; |
| 23 |
| 24 // An AnimationPlayer owns all animations to be run on particular CC Layer. |
| 25 // Multiple AnimationPlayers can be attached to one layer. In this case, |
| 26 // they share common LayerAnimationController (temp solution) so the |
| 27 // LayerAnimationController-to-Layer relationship stays the same (1:1, LACs |
| 28 // have same IDs as their respective Layers). |
| 29 // For now, the blink logic is responsible for handling of conflicting |
| 30 // same-property animations. |
| 31 // Each AnimationPlayer has its copy on the impl thread. |
| 32 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). |
| 33 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer>, |
| 34 public base::LinkNode<AnimationPlayer> { |
| 35 public: |
| 36 static scoped_refptr<AnimationPlayer> Create(int id); |
| 37 scoped_refptr<AnimationPlayer> CreateImplInstance() const; |
| 38 |
| 39 int id() const { return id_; } |
| 40 int layer_id() const { return layer_id_; } |
| 41 |
| 42 // Parent AnimationHost. AnimationPlayer can be detached from |
| 43 // AnimationTimeline. |
| 44 AnimationHost* animation_host() { return animation_host_; } |
| 45 const AnimationHost* animation_host() const { return animation_host_; } |
| 46 void SetAnimationHost(AnimationHost* animation_host); |
| 47 |
| 48 // Parent AnimationTimeline. |
| 49 AnimationTimeline* animation_timeline() { return animation_timeline_; } |
| 50 const AnimationTimeline* animation_timeline() const { |
| 51 return animation_timeline_; |
| 52 } |
| 53 void SetAnimationTimeline(AnimationTimeline* timeline); |
| 54 |
| 55 // ElementAnimations object where this player is listed. |
| 56 // ElementAnimations has a reference to shared LayerAnimationController. |
| 57 ElementAnimations* element_animations() const { return element_animations_; } |
| 58 |
| 59 void set_layer_animation_delegate(AnimationDelegate* delegate) { |
| 60 layer_animation_delegate_ = delegate; |
| 61 } |
| 62 |
| 63 void AttachLayer(int layer_id); |
| 64 void DetachLayer(); |
| 65 |
| 66 void AddAnimation(scoped_ptr<Animation> animation); |
| 67 void PauseAnimation(int animation_id, double time_offset); |
| 68 void RemoveAnimation(int animation_id); |
| 69 |
| 70 void PushPropertiesTo(AnimationPlayer* player_impl); |
| 71 |
| 72 // AnimationDelegate routing. |
| 73 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 74 Animation::TargetProperty target_property, |
| 75 int group); |
| 76 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
| 77 Animation::TargetProperty target_property, |
| 78 int group); |
| 79 |
| 80 private: |
| 81 friend class base::RefCounted<AnimationPlayer>; |
| 82 |
| 83 explicit AnimationPlayer(int id); |
| 84 ~AnimationPlayer(); |
| 85 |
| 86 void SetNeedsCommit(); |
| 87 |
| 88 void RegisterPlayer(); |
| 89 void UnregisterPlayer(); |
| 90 |
| 91 void BindElementAnimations(); |
| 92 void UnbindElementAnimations(); |
| 93 |
| 94 // We accumulate added animations in animations_ container |
| 95 // if element_animations_ is a nullptr. It allows us to add/remove animations |
| 96 // to non-attached AnimationPlayers. |
| 97 typedef ScopedPtrVector<Animation> AnimationList; |
| 98 AnimationList animations_; |
| 99 |
| 100 AnimationHost* animation_host_; |
| 101 AnimationTimeline* animation_timeline_; |
| 102 // element_animations isn't null if player attached to an element (layer). |
| 103 ElementAnimations* element_animations_; |
| 104 AnimationDelegate* layer_animation_delegate_; |
| 105 |
| 106 int id_; |
| 107 int layer_id_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); |
| 110 }; |
| 111 |
| 112 } // namespace cc |
| 113 |
| 114 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ |
OLD | NEW |