| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return 0; | 187 return 0; |
| 188 | 188 |
| 189 // check if we are past active interval | 189 // check if we are past active interval |
| 190 bool is_past_total_duration = | 190 bool is_past_total_duration = |
| 191 (iterations_ > 0 && | 191 (iterations_ > 0 && |
| 192 trimmed_in_seconds >= curve_->Duration() * iterations_); | 192 trimmed_in_seconds >= curve_->Duration() * iterations_); |
| 193 | 193 |
| 194 // We need to know the current iteration if we're alternating. | 194 // We need to know the current iteration if we're alternating. |
| 195 int iteration = 0; | 195 int iteration = 0; |
| 196 | 196 |
| 197 // If we are past the active interval, return iteration duration. | 197 // If we are past the active interval, return iteration duration of last |
| 198 // iteration |
| 198 if (is_past_total_duration) { | 199 if (is_past_total_duration) { |
| 199 iteration = iterations_ - 1; | 200 iteration = iterations_ - 1; |
| 200 trimmed_in_seconds = curve_->Duration(); | 201 double frac = fmod(curve_->Duration() * iterations_, curve_->Duration()); |
| 202 trimmed_in_seconds = frac == 0 ? curve_->Duration() : frac; |
| 201 } else { | 203 } else { |
| 202 iteration = static_cast<int>(trimmed_in_seconds / curve_->Duration()); | 204 iteration = static_cast<int>(trimmed_in_seconds / curve_->Duration()); |
| 203 // Calculate x where trimmed = x + n * curve_->Duration() for some positive | 205 // Calculate x where trimmed = x + n * curve_->Duration() for some positive |
| 204 // integer n. | 206 // integer n. |
| 205 trimmed_in_seconds = fmod(trimmed_in_seconds, curve_->Duration()); | 207 trimmed_in_seconds = fmod(trimmed_in_seconds, curve_->Duration()); |
| 206 } | 208 } |
| 207 | 209 |
| 208 // check if we are running the animation in reverse direction for the current | 210 // check if we are running the animation in reverse direction for the current |
| 209 // iteration | 211 // iteration |
| 210 bool reverse = (direction_ == Reverse) || | 212 bool reverse = (direction_ == Reverse) || |
| (...skipping 28 matching lines...) Expand all Loading... |
| 239 // the main thread. | 241 // the main thread. |
| 240 if (run_state_ == Animation::Paused || | 242 if (run_state_ == Animation::Paused || |
| 241 other->run_state_ == Animation::Paused) { | 243 other->run_state_ == Animation::Paused) { |
| 242 other->run_state_ = run_state_; | 244 other->run_state_ = run_state_; |
| 243 other->pause_time_ = pause_time_; | 245 other->pause_time_ = pause_time_; |
| 244 other->total_paused_time_ = total_paused_time_; | 246 other->total_paused_time_ = total_paused_time_; |
| 245 } | 247 } |
| 246 } | 248 } |
| 247 | 249 |
| 248 } // namespace cc | 250 } // namespace cc |
| OLD | NEW |