OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ |
6 #define UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | 6 #define UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Takes ownership of the given element and adds it to the sequence. | 40 // Takes ownership of the given element and adds it to the sequence. |
41 explicit LayerAnimationSequence(LayerAnimationElement* element); | 41 explicit LayerAnimationSequence(LayerAnimationElement* element); |
42 virtual ~LayerAnimationSequence(); | 42 virtual ~LayerAnimationSequence(); |
43 | 43 |
44 // Sets the start time for the animation. This must be called before the | 44 // Sets the start time for the animation. This must be called before the |
45 // first call to {Progress, IsFinished}. Once the animation is finished, this | 45 // first call to {Progress, IsFinished}. Once the animation is finished, this |
46 // must be called again in order to restart the animation. | 46 // must be called again in order to restart the animation. |
47 void set_start_time(base::TimeTicks start_time) { start_time_ = start_time; } | 47 void set_start_time(base::TimeTicks start_time) { start_time_ = start_time; } |
48 base::TimeTicks start_time() const { return start_time_; } | 48 base::TimeTicks start_time() const { return start_time_; } |
49 | 49 |
| 50 // Sets a flag indicating that this sequence will start together with other |
| 51 // sequences, and at least one of the sequences in this group has a threaded |
| 52 // first element. |
| 53 void set_waiting_for_group_start(bool waiting) { |
| 54 waiting_for_group_start_ = waiting; |
| 55 } |
| 56 bool waiting_for_group_start() { return waiting_for_group_start_; } |
| 57 |
| 58 // If starting the animation involves dispatching to another thread, then |
| 59 // proceed with that dispatch; this will ultimately result in the animation |
| 60 // getting an effective start time (the time the animation starts on the other |
| 61 // thread). |
| 62 void ProgressToEffectiveStart(LayerAnimationDelegate* delegate); |
| 63 |
50 // Updates the delegate to the appropriate value for |now|. Requests a | 64 // Updates the delegate to the appropriate value for |now|. Requests a |
51 // redraw if it is required. | 65 // redraw if it is required. |
52 void Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); | 66 void Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); |
53 | 67 |
54 // Returns true if calling Progress now, with the given time, will finish | 68 // Returns true if calling Progress now, with the given time, will finish |
55 // the animation. | 69 // the animation. |
56 bool IsFinished(base::TimeTicks time); | 70 bool IsFinished(base::TimeTicks time); |
57 | 71 |
58 // Updates the delegate to the end of the animation; if this sequence is | 72 // Updates the delegate to the end of the animation; if this sequence is |
59 // cyclic, updates the delegate to the end of one cycle of the sequence. | 73 // cyclic, updates the delegate to the end of one cycle of the sequence. |
60 void ProgressToEnd(LayerAnimationDelegate* delegate); | 74 void ProgressToEnd(LayerAnimationDelegate* delegate); |
61 | 75 |
62 // Sets the target value to the value that would have been set had | 76 // Sets the target value to the value that would have been set had |
63 // the sequence completed. Does nothing if the sequence is cyclic. | 77 // the sequence completed. Does nothing if the sequence is cyclic. |
64 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; | 78 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; |
65 | 79 |
66 // Aborts the given animation. | 80 // Aborts the given animation. |
67 void Abort(); | 81 void Abort(LayerAnimationDelegate* delegate); |
68 | 82 |
69 // All properties modified by the sequence. | 83 // All properties modified by the sequence. |
70 const LayerAnimationElement::AnimatableProperties& properties() const { | 84 const LayerAnimationElement::AnimatableProperties& properties() const { |
71 return properties_; | 85 return properties_; |
72 } | 86 } |
73 | 87 |
74 // Adds an element to the sequence. The sequences takes ownership of this | 88 // Adds an element to the sequence. The sequences takes ownership of this |
75 // element. | 89 // element. |
76 void AddElement(LayerAnimationElement* element); | 90 void AddElement(LayerAnimationElement* element); |
77 | 91 |
78 // Sequences can be looped indefinitely. | 92 // Sequences can be looped indefinitely. |
79 void set_is_cyclic(bool is_cyclic) { is_cyclic_ = is_cyclic; } | 93 void set_is_cyclic(bool is_cyclic) { is_cyclic_ = is_cyclic; } |
80 bool is_cyclic() const { return is_cyclic_; } | 94 bool is_cyclic() const { return is_cyclic_; } |
81 | 95 |
82 // Returns true if this sequence has at least one element affecting a | 96 // Returns true if this sequence has at least one element affecting a |
83 // property in |other|. | 97 // property in |other|. |
84 bool HasCommonProperty( | 98 bool HasCommonProperty( |
85 const LayerAnimationElement::AnimatableProperties& other) const; | 99 const LayerAnimationElement::AnimatableProperties& other) const; |
86 | 100 |
| 101 // Returns true if the first element animates on the compositor thread. |
| 102 bool IsFirstElementThreaded() const; |
| 103 |
| 104 // Used to identify groups of sequences that are supposed to start together. |
| 105 int animation_group_id() const { return animation_group_id_; } |
| 106 void set_animation_group_id(int id) { animation_group_id_ = id; } |
| 107 |
87 // These functions are used for adding or removing observers from the observer | 108 // These functions are used for adding or removing observers from the observer |
88 // list. The observers are notified when animations end. | 109 // list. The observers are notified when animations end. |
89 void AddObserver(LayerAnimationObserver* observer); | 110 void AddObserver(LayerAnimationObserver* observer); |
90 void RemoveObserver(LayerAnimationObserver* observer); | 111 void RemoveObserver(LayerAnimationObserver* observer); |
91 | 112 |
| 113 // Called when a threaded animation is actually started. |
| 114 void OnThreadedAnimationStarted(const cc::AnimationEvent& event); |
| 115 |
92 // Called when the animator schedules this sequence. | 116 // Called when the animator schedules this sequence. |
93 void OnScheduled(); | 117 void OnScheduled(); |
94 | 118 |
95 // Called when the animator is destroyed. | 119 // Called when the animator is destroyed. |
96 void OnAnimatorDestroyed(); | 120 void OnAnimatorDestroyed(); |
97 | 121 |
| 122 // The last_progressed_fraction of the element most recently progressed by |
| 123 // by this sequence. Returns 0.0 if no elements have been progressed. |
| 124 double last_progressed_fraction() const { return last_progressed_fraction_; } |
| 125 |
98 private: | 126 private: |
99 typedef std::vector<linked_ptr<LayerAnimationElement> > Elements; | 127 typedef std::vector<linked_ptr<LayerAnimationElement> > Elements; |
100 | 128 |
101 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, | 129 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, |
102 ObserverReleasedBeforeAnimationSequenceEnds); | 130 ObserverReleasedBeforeAnimationSequenceEnds); |
103 | 131 |
104 // Notifies the observers that this sequence has been scheduled. | 132 // Notifies the observers that this sequence has been scheduled. |
105 void NotifyScheduled(); | 133 void NotifyScheduled(); |
106 | 134 |
107 // Notifies the observers that this sequence has ended. | 135 // Notifies the observers that this sequence has ended. |
(...skipping 11 matching lines...) Expand all Loading... |
119 // True if the sequence should be looped forever. | 147 // True if the sequence should be looped forever. |
120 bool is_cyclic_; | 148 bool is_cyclic_; |
121 | 149 |
122 // These are used when animating to efficiently find the next element. | 150 // These are used when animating to efficiently find the next element. |
123 size_t last_element_; | 151 size_t last_element_; |
124 base::TimeTicks last_start_; | 152 base::TimeTicks last_start_; |
125 | 153 |
126 // The start time of the current run of the sequence. | 154 // The start time of the current run of the sequence. |
127 base::TimeTicks start_time_; | 155 base::TimeTicks start_time_; |
128 | 156 |
| 157 // True if this sequence will start together with other sequences, and at |
| 158 // least one of the sequences in this group has a threaded first element. |
| 159 bool waiting_for_group_start_; |
| 160 |
| 161 // Identifies groups of sequences that are supposed to start together. |
| 162 int animation_group_id_; |
| 163 |
129 // These parties are notified when layer animations end. | 164 // These parties are notified when layer animations end. |
130 ObserverList<LayerAnimationObserver> observers_; | 165 ObserverList<LayerAnimationObserver> observers_; |
131 | 166 |
| 167 // Tracks the last_progressed_fraction() of the most recently progressed |
| 168 // element. |
| 169 double last_progressed_fraction_; |
| 170 |
132 DISALLOW_COPY_AND_ASSIGN(LayerAnimationSequence); | 171 DISALLOW_COPY_AND_ASSIGN(LayerAnimationSequence); |
133 }; | 172 }; |
134 | 173 |
135 } // namespace ui | 174 } // namespace ui |
136 | 175 |
137 #endif // UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | 176 #endif // UI_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ |
OLD | NEW |