Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 direction_(Normal), | 67 direction_(Normal), |
| 68 playback_rate_(1), | 68 playback_rate_(1), |
| 69 fill_mode_(FillModeNone), | |
| 69 needs_synchronized_start_time_(false), | 70 needs_synchronized_start_time_(false), |
| 70 received_finished_event_(false), | 71 received_finished_event_(false), |
| 71 suspended_(false), | 72 suspended_(false), |
| 72 is_controlling_instance_(false), | 73 is_controlling_instance_(false), |
| 73 is_impl_only_(false), | 74 is_impl_only_(false), |
| 74 affects_active_observers_(true), | 75 affects_active_observers_(true), |
| 75 affects_pending_observers_(true) { | 76 affects_pending_observers_(true) { |
| 76 } | 77 } |
| 77 | 78 |
| 78 Animation::~Animation() { | 79 Animation::~Animation() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 152 |
| 152 if (playback_rate_ == 0) | 153 if (playback_rate_ == 0) |
| 153 return false; | 154 return false; |
| 154 | 155 |
| 155 return run_state_ == Running && iterations_ >= 0 && | 156 return run_state_ == Running && iterations_ >= 0 && |
| 156 iterations_ * curve_->Duration() / std::abs(playback_rate_) <= | 157 iterations_ * curve_->Duration() / std::abs(playback_rate_) <= |
| 157 (monotonic_time + time_offset_ - start_time_ - total_paused_time_) | 158 (monotonic_time + time_offset_ - start_time_ - total_paused_time_) |
| 158 .InSecondsF(); | 159 .InSecondsF(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 double Animation::TrimTimeToCurrentIteration( | 162 bool Animation::NoEffectBeforeAnimation(base::TimeTicks monotonic_time) const { |
|
dstockwell
2014/09/18 00:14:29
This method name is a little strange, perhaps just
samli
2014/09/18 00:59:55
Done.
| |
| 162 base::TimeTicks monotonic_time) const { | 163 return ConvertToActiveTime(monotonic_time) < 0 && |
| 164 (fill_mode_ == FillModeNone || fill_mode_ == FillModeForwards); | |
| 165 } | |
| 166 | |
| 167 double Animation::ConvertToActiveTime(base::TimeTicks monotonic_time) const { | |
| 163 base::TimeTicks trimmed = monotonic_time + time_offset_; | 168 base::TimeTicks trimmed = monotonic_time + time_offset_; |
| 164 | 169 |
| 165 // Zero playback rate not supported | |
| 166 DCHECK(playback_rate_); | |
| 167 | |
| 168 // If we're paused, time is 'stuck' at the pause time. | 170 // If we're paused, time is 'stuck' at the pause time. |
| 169 if (run_state_ == Paused) | 171 if (run_state_ == Paused) |
| 170 trimmed = pause_time_; | 172 trimmed = pause_time_; |
| 171 | 173 |
| 172 // Returned time should always be relative to the start time and should | 174 // Returned time should always be relative to the start time and should |
| 173 // subtract all time spent paused. | 175 // subtract all time spent paused. |
| 174 trimmed -= (start_time_ - base::TimeTicks()) + total_paused_time_; | 176 trimmed -= (start_time_ - base::TimeTicks()) + total_paused_time_; |
| 175 | 177 |
| 176 // If we're just starting or we're waiting on receiving a start time, | 178 // If we're just starting or we're waiting on receiving a start time, |
| 177 // time is 'stuck' at the initial state. | 179 // time is 'stuck' at the initial state. |
| 178 if ((run_state_ == Starting && !has_set_start_time()) || | 180 if ((run_state_ == Starting && !has_set_start_time()) || |
| 179 needs_synchronized_start_time()) | 181 needs_synchronized_start_time()) |
| 180 trimmed = base::TimeTicks() + time_offset_; | 182 trimmed = base::TimeTicks() + time_offset_; |
| 181 | 183 |
| 182 double active_time = (trimmed - base::TimeTicks()).InSecondsF(); | 184 return (trimmed - base::TimeTicks()).InSecondsF(); |
| 185 } | |
| 186 | |
| 187 double Animation::TrimTimeToCurrentIteration( | |
| 188 base::TimeTicks monotonic_time) const { | |
| 189 // Zero playback rate not supported | |
| 190 DCHECK(playback_rate_); | |
| 191 | |
| 192 double active_time = ConvertToActiveTime(monotonic_time); | |
| 183 | 193 |
| 184 // Return 0 if we are before the start of the animation | 194 // Return 0 if we are before the start of the animation |
| 185 if (active_time < 0) | 195 if (active_time < 0) |
| 186 return 0; | 196 return 0; |
| 187 | 197 |
| 188 // Always return zero if we have no iterations. | 198 // Always return zero if we have no iterations. |
| 189 if (!iterations_) | 199 if (!iterations_) |
| 190 return 0; | 200 return 0; |
| 191 | 201 |
| 192 // Don't attempt to trim if we have no duration. | 202 // Don't attempt to trim if we have no duration. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 scoped_ptr<Animation> to_return( | 259 scoped_ptr<Animation> to_return( |
| 250 new Animation(curve_->Clone(), id_, group_, target_property_)); | 260 new Animation(curve_->Clone(), id_, group_, target_property_)); |
| 251 to_return->run_state_ = initial_run_state; | 261 to_return->run_state_ = initial_run_state; |
| 252 to_return->iterations_ = iterations_; | 262 to_return->iterations_ = iterations_; |
| 253 to_return->start_time_ = start_time_; | 263 to_return->start_time_ = start_time_; |
| 254 to_return->pause_time_ = pause_time_; | 264 to_return->pause_time_ = pause_time_; |
| 255 to_return->total_paused_time_ = total_paused_time_; | 265 to_return->total_paused_time_ = total_paused_time_; |
| 256 to_return->time_offset_ = time_offset_; | 266 to_return->time_offset_ = time_offset_; |
| 257 to_return->direction_ = direction_; | 267 to_return->direction_ = direction_; |
| 258 to_return->playback_rate_ = playback_rate_; | 268 to_return->playback_rate_ = playback_rate_; |
| 269 to_return->fill_mode_ = fill_mode_; | |
| 259 DCHECK(!to_return->is_controlling_instance_); | 270 DCHECK(!to_return->is_controlling_instance_); |
| 260 to_return->is_controlling_instance_ = true; | 271 to_return->is_controlling_instance_ = true; |
| 261 return to_return.Pass(); | 272 return to_return.Pass(); |
| 262 } | 273 } |
| 263 | 274 |
| 264 void Animation::PushPropertiesTo(Animation* other) const { | 275 void Animation::PushPropertiesTo(Animation* other) const { |
| 265 // Currently, we only push changes due to pausing and resuming animations on | 276 // Currently, we only push changes due to pausing and resuming animations on |
| 266 // the main thread. | 277 // the main thread. |
| 267 if (run_state_ == Animation::Paused || | 278 if (run_state_ == Animation::Paused || |
| 268 other->run_state_ == Animation::Paused) { | 279 other->run_state_ == Animation::Paused) { |
| 269 other->run_state_ = run_state_; | 280 other->run_state_ = run_state_; |
| 270 other->pause_time_ = pause_time_; | 281 other->pause_time_ = pause_time_; |
| 271 other->total_paused_time_ = total_paused_time_; | 282 other->total_paused_time_ = total_paused_time_; |
| 272 } | 283 } |
| 273 } | 284 } |
| 274 | 285 |
| 275 } // namespace cc | 286 } // namespace cc |
| OLD | NEW |