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 "cc/animation/layer_animation_controller.h" |
| 11 #include "cc/animation/layer_animation_value_observer.h" |
| 12 #include "cc/animation/layer_animation_value_provider.h" |
| 13 #include "cc/base/cc_export.h" |
| 14 |
| 15 namespace gfx { |
| 16 class ScrollOffset; |
| 17 class Transform; |
| 18 } |
| 19 |
| 20 namespace cc { |
| 21 |
| 22 class AnimationHost; |
| 23 class AnimationTimeline; |
| 24 class FilterOperations; |
| 25 class Layer; |
| 26 enum class LayerTreeType; |
| 27 |
| 28 // An AnimationPlayer owns all animations to be run on particular CC Layer. |
| 29 // Multiple AnimationPlayers can be attached to one layer. In this case, |
| 30 // they share common LayerAnimationController (temp solution) so the |
| 31 // LayerAnimationController-to-Layer relationship stays the same (1:1, LACs |
| 32 // have same IDs as their correspondent Layers). |
| 33 // For now, the blink logic is responsible for handling conflicting |
| 34 // same-property animations. |
| 35 // Each AnimationPlayer has its copy on the impl thread. |
| 36 // This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship). |
| 37 class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer>, |
| 38 public base::LinkNode<AnimationPlayer>, |
| 39 public LayerAnimationValueProvider { |
| 40 public: |
| 41 static scoped_refptr<AnimationPlayer> Create(int id); |
| 42 scoped_refptr<AnimationPlayer> CreateImplInstance() const; |
| 43 |
| 44 int id() const { return id_; } |
| 45 int layer_id() const { return layer_id_; } |
| 46 |
| 47 // Parent AnimationHost. AnimationPlayer can be detached from |
| 48 // AnimationTimeline. |
| 49 AnimationHost* animation_host() { return animation_host_; } |
| 50 const AnimationHost* animation_host() const { return animation_host_; } |
| 51 void SetAnimationHost(AnimationHost* animation_host); |
| 52 |
| 53 // Parent AnimationTimeline. |
| 54 AnimationTimeline* animation_timeline() { return animation_timeline_; } |
| 55 const AnimationTimeline* animation_timeline() const { |
| 56 return animation_timeline_; |
| 57 } |
| 58 void SetAnimationTimeline(AnimationTimeline* timeline); |
| 59 |
| 60 LayerAnimationController* layer_animation_controller() const { |
| 61 return layer_animation_controller_.get(); |
| 62 } |
| 63 |
| 64 void set_layer_animation_delegate(AnimationDelegate* delegate); |
| 65 |
| 66 void AttachLayer(int layer_id); |
| 67 void DetachLayer(); |
| 68 |
| 69 void LayerRegistered(int layer_id, LayerTreeType tree_type); |
| 70 void LayerUnregistered(int layer_id, LayerTreeType tree_type); |
| 71 |
| 72 void AddAnimation(scoped_ptr<Animation> animation); |
| 73 void PauseAnimation(int animation_id, double time_offset); |
| 74 void RemoveAnimation(int animation_id); |
| 75 |
| 76 void PushPropertiesTo(AnimationPlayer* player_impl); |
| 77 |
| 78 bool has_active_value_observer_for_testing() const { |
| 79 return active_value_observer_; |
| 80 } |
| 81 bool has_pending_value_observer_for_testing() const { |
| 82 return pending_value_observer_; |
| 83 } |
| 84 |
| 85 // TODO(loyso): Do not share LAC between AnimationPlayers so we don't need |
| 86 // this method. |
| 87 void RefreshObservers(); |
| 88 |
| 89 private: |
| 90 friend class base::RefCounted<AnimationPlayer>; |
| 91 |
| 92 explicit AnimationPlayer(int id); |
| 93 ~AnimationPlayer() override; |
| 94 |
| 95 void SetNeedsCommit(); |
| 96 |
| 97 void SetFilterMutated(LayerTreeType tree_type, |
| 98 const FilterOperations& filters); |
| 99 void SetOpacityMutated(LayerTreeType tree_type, float opacity); |
| 100 void SetTransformMutated(LayerTreeType tree_type, |
| 101 const gfx::Transform& transform); |
| 102 void SetScrollOffsetMutated(LayerTreeType tree_type, |
| 103 const gfx::ScrollOffset& scroll_offset); |
| 104 |
| 105 void AddControllerToTimeline(); |
| 106 void RemoveControllerFromTimeline(); |
| 107 |
| 108 void CreateActiveValueObserver(); |
| 109 void DestroyActiveValueObserver(); |
| 110 |
| 111 void CreatePendingValueObserver(); |
| 112 void DestroyPendingValueObserver(); |
| 113 |
| 114 // LayerAnimationValueProvider implementation. |
| 115 gfx::ScrollOffset ScrollOffsetForAnimation() const override; |
| 116 |
| 117 class ValueObserver; |
| 118 scoped_ptr<ValueObserver> active_value_observer_; |
| 119 scoped_ptr<ValueObserver> pending_value_observer_; |
| 120 |
| 121 scoped_refptr<LayerAnimationController> layer_animation_controller_; |
| 122 AnimationHost* animation_host_; |
| 123 AnimationTimeline* animation_timeline_; |
| 124 AnimationDelegate* layer_animation_delegate_; |
| 125 |
| 126 int id_; |
| 127 int layer_id_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(AnimationPlayer); |
| 130 }; |
| 131 |
| 132 } // namespace cc |
| 133 |
| 134 #endif // CC_ANIMATION_ANIMATION_PLAYER_H_ |
OLD | NEW |