OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "cc/animation/animation.h" | 5 #include "cc/animation/animation.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 Animation::Animation(scoped_ptr<AnimationCurve> curve, | 57 Animation::Animation(scoped_ptr<AnimationCurve> curve, |
58 int animation_id, | 58 int animation_id, |
59 int group_id, | 59 int group_id, |
60 TargetProperty target_property) | 60 TargetProperty target_property) |
61 : curve_(curve.Pass()), | 61 : curve_(curve.Pass()), |
62 id_(animation_id), | 62 id_(animation_id), |
63 group_(group_id), | 63 group_(group_id), |
64 target_property_(target_property), | 64 target_property_(target_property), |
65 run_state_(WaitingForTargetAvailability), | 65 run_state_(WaitingForTargetAvailability), |
66 iterations_(1), | 66 iterations_(1), |
67 start_time_(0), | 67 start_time_(base::TimeTicks()), |
68 alternates_direction_(false), | 68 alternates_direction_(false), |
69 time_offset_(0), | 69 time_offset_(base::TimeDelta()), |
70 needs_synchronized_start_time_(false), | 70 needs_synchronized_start_time_(false), |
71 received_finished_event_(false), | 71 received_finished_event_(false), |
72 suspended_(false), | 72 suspended_(false), |
73 pause_time_(0), | 73 pause_time_(base::TimeTicks()), |
74 total_paused_time_(0), | 74 total_paused_time_(base::TimeTicks()), |
75 is_controlling_instance_(false), | 75 is_controlling_instance_(false), |
76 is_impl_only_(false) {} | 76 is_impl_only_(false) {} |
77 | 77 |
78 Animation::~Animation() { | 78 Animation::~Animation() { |
79 if (run_state_ == Running || run_state_ == Paused) | 79 if (run_state_ == Running || run_state_ == Paused) |
80 SetRunState(Aborted, 0); | 80 SetRunState(Aborted, base::TimeTicks()); |
81 } | 81 } |
82 | 82 |
83 void Animation::SetRunState(RunState run_state, double monotonic_time) { | 83 void Animation::SetRunState(RunState run_state, |
| 84 base::TimeTicks monotonic_time) { |
84 if (suspended_) | 85 if (suspended_) |
85 return; | 86 return; |
86 | 87 |
87 char name_buffer[256]; | 88 char name_buffer[256]; |
88 base::snprintf(name_buffer, | 89 base::snprintf(name_buffer, |
89 sizeof(name_buffer), | 90 sizeof(name_buffer), |
90 "%s-%d%s", | 91 "%s-%d%s", |
91 s_targetPropertyNames[target_property_], | 92 s_targetPropertyNames[target_property_], |
92 group_, | 93 group_, |
93 is_controlling_instance_ ? "(impl)" : ""); | 94 is_controlling_instance_ ? "(impl)" : ""); |
94 | 95 |
95 bool is_waiting_to_start = run_state_ == WaitingForTargetAvailability || | 96 bool is_waiting_to_start = run_state_ == WaitingForTargetAvailability || |
96 run_state_ == Starting; | 97 run_state_ == Starting; |
97 | |
98 if (is_waiting_to_start && run_state == Running) { | 98 if (is_waiting_to_start && run_state == Running) { |
99 TRACE_EVENT_ASYNC_BEGIN1( | 99 TRACE_EVENT_ASYNC_BEGIN1( |
100 "cc", "Animation", this, "Name", TRACE_STR_COPY(name_buffer)); | 100 "cc", "Animation", this, "Name", TRACE_STR_COPY(name_buffer)); |
101 } | 101 } |
102 | 102 |
103 bool was_finished = is_finished(); | 103 bool was_finished = is_finished(); |
104 | 104 |
105 const char* old_run_state_name = s_runStateNames[run_state_]; | 105 const char* old_run_state_name = s_runStateNames[run_state_]; |
106 | 106 |
107 if (run_state == Running && run_state_ == Paused) | 107 if (run_state == Running && run_state_ == Paused) |
(...skipping 16 matching lines...) Expand all Loading... |
124 | 124 |
125 TRACE_EVENT_INSTANT2("cc", | 125 TRACE_EVENT_INSTANT2("cc", |
126 "LayerAnimationController::SetRunState", | 126 "LayerAnimationController::SetRunState", |
127 TRACE_EVENT_SCOPE_THREAD, | 127 TRACE_EVENT_SCOPE_THREAD, |
128 "Name", | 128 "Name", |
129 TRACE_STR_COPY(name_buffer), | 129 TRACE_STR_COPY(name_buffer), |
130 "State", | 130 "State", |
131 TRACE_STR_COPY(state_buffer)); | 131 TRACE_STR_COPY(state_buffer)); |
132 } | 132 } |
133 | 133 |
134 void Animation::Suspend(double monotonic_time) { | 134 void Animation::Suspend(base::TimeTicks monotonic_time) { |
135 SetRunState(Paused, monotonic_time); | 135 SetRunState(Paused, monotonic_time); |
136 suspended_ = true; | 136 suspended_ = true; |
137 } | 137 } |
138 | 138 |
139 void Animation::Resume(double monotonic_time) { | 139 void Animation::Resume(base::TimeTicks monotonic_time) { |
140 suspended_ = false; | 140 suspended_ = false; |
141 SetRunState(Running, monotonic_time); | 141 SetRunState(Running, monotonic_time); |
142 } | 142 } |
143 | 143 |
144 bool Animation::IsFinishedAt(double monotonic_time) const { | 144 bool Animation::IsFinishedAt(base::TimeTicks monotonic_time) const { |
145 if (is_finished()) | 145 if (is_finished()) |
146 return true; | 146 return true; |
147 | |
148 if (needs_synchronized_start_time_) | 147 if (needs_synchronized_start_time_) |
149 return false; | 148 return false; |
150 | 149 return run_state_ == Running && iterations_ >= 0 && |
151 return run_state_ == Running && | 150 iterations_ * curve_->Duration() <= |
152 iterations_ >= 0 && | 151 ticks_inseconds((monotonic_time + time_offset_) - |
153 iterations_ * curve_->Duration() <= (monotonic_time - | 152 (start_time_ - total_paused_time_)); |
154 start_time() - | |
155 total_paused_time_ + | |
156 time_offset_); | |
157 } | 153 } |
158 | 154 |
159 double Animation::TrimTimeToCurrentIteration(double monotonic_time) const { | 155 double Animation::TrimTimeToCurrentIteration( |
160 double trimmed = monotonic_time + time_offset_; | 156 base::TimeTicks monotonic_time) const { |
| 157 |
| 158 double trimmed = ticks_inseconds(monotonic_time + time_offset_); |
161 | 159 |
162 // If we're paused, time is 'stuck' at the pause time. | 160 // If we're paused, time is 'stuck' at the pause time. |
163 if (run_state_ == Paused) | 161 if (run_state_ == Paused) |
164 trimmed = pause_time_; | 162 trimmed = ticks_inseconds(pause_time_); |
165 | 163 |
166 // Returned time should always be relative to the start time and should | 164 // Returned time should always be relative to the start time and should |
167 // subtract all time spent paused. | 165 // subtract all time spent paused. |
168 trimmed -= start_time_ + total_paused_time_; | 166 trimmed -= ticks_inseconds(start_time_) + ticks_inseconds(total_paused_time_); |
169 | 167 |
170 // If we're just starting or we're waiting on receiving a start time, | 168 // If we're just starting or we're waiting on receiving a start time, |
171 // time is 'stuck' at the initial state. | 169 // time is 'stuck' at the initial state. |
172 if ((run_state_ == Starting && !has_set_start_time()) || | 170 if ((run_state_ == Starting && !has_set_start_time()) || |
173 needs_synchronized_start_time()) | 171 needs_synchronized_start_time()) |
174 trimmed = time_offset_; | 172 trimmed = delta_inseconds(time_offset_); |
175 | 173 |
176 // Zero is always the start of the animation. | 174 // Zero is always the start of the animation. |
177 if (trimmed <= 0) | 175 if (trimmed <= 0) |
178 return 0; | 176 return 0; |
179 | 177 |
180 // Always return zero if we have no iterations. | 178 // Always return zero if we have no iterations. |
181 if (!iterations_) | 179 if (!iterations_) |
182 return 0; | 180 return 0; |
183 | 181 |
184 // Don't attempt to trim if we have no duration. | 182 // Don't attempt to trim if we have no duration. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // the main thread. | 229 // the main thread. |
232 if (run_state_ == Animation::Paused || | 230 if (run_state_ == Animation::Paused || |
233 other->run_state_ == Animation::Paused) { | 231 other->run_state_ == Animation::Paused) { |
234 other->run_state_ = run_state_; | 232 other->run_state_ = run_state_; |
235 other->pause_time_ = pause_time_; | 233 other->pause_time_ = pause_time_; |
236 other->total_paused_time_ = total_paused_time_; | 234 other->total_paused_time_ = total_paused_time_; |
237 } | 235 } |
238 } | 236 } |
239 | 237 |
240 } // namespace cc | 238 } // namespace cc |
OLD | NEW |