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