Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2297)

Unified Diff: cc/animation/animation.cc

Issue 231133002: CC::Animations should use TimeTicks & TimeDelta to represent time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review changes. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/animation/animation.cc
diff --git a/cc/animation/animation.cc b/cc/animation/animation.cc
index be0e29116ee50f77e74b21d2814cde48ca407c47..1154884e32ce984274fc49fd7e358c008d7b4e2d 100644
--- a/cc/animation/animation.cc
+++ b/cc/animation/animation.cc
@@ -9,6 +9,7 @@
#include "base/debug/trace_event.h"
#include "base/strings/string_util.h"
#include "cc/animation/animation_curve.h"
+#include "cc/base/time_util.h"
namespace {
@@ -64,14 +65,14 @@ Animation::Animation(scoped_ptr<AnimationCurve> curve,
target_property_(target_property),
run_state_(WaitingForTargetAvailability),
iterations_(1),
- start_time_(0),
+ start_time_(),
direction_(Normal),
- time_offset_(0),
+ time_offset_(),
needs_synchronized_start_time_(false),
received_finished_event_(false),
suspended_(false),
- pause_time_(0),
- total_paused_time_(0),
+ pause_time_(),
+ total_paused_time_(),
is_controlling_instance_(false),
is_impl_only_(false),
affects_active_observers_(true),
@@ -80,10 +81,11 @@ Animation::Animation(scoped_ptr<AnimationCurve> curve,
Animation::~Animation() {
if (run_state_ == Running || run_state_ == Paused)
- SetRunState(Aborted, 0);
+ SetRunState(Aborted, base::TimeTicks());
}
-void Animation::SetRunState(RunState run_state, double monotonic_time) {
+void Animation::SetRunState(RunState run_state,
+ base::TimeTicks monotonic_time) {
if (suspended_)
return;
@@ -108,7 +110,7 @@ void Animation::SetRunState(RunState run_state, double monotonic_time) {
const char* old_run_state_name = s_runStateNames[run_state_];
if (run_state == Running && run_state_ == Paused)
- total_paused_time_ += monotonic_time - pause_time_;
+ total_paused_time_ += (monotonic_time - pause_time_);
else if (run_state == Paused)
pause_time_ = monotonic_time;
run_state_ = run_state;
@@ -134,47 +136,50 @@ void Animation::SetRunState(RunState run_state, double monotonic_time) {
TRACE_STR_COPY(state_buffer));
}
-void Animation::Suspend(double monotonic_time) {
+void Animation::Suspend(base::TimeTicks monotonic_time) {
SetRunState(Paused, monotonic_time);
suspended_ = true;
}
-void Animation::Resume(double monotonic_time) {
+void Animation::Resume(base::TimeTicks monotonic_time) {
suspended_ = false;
SetRunState(Running, monotonic_time);
}
-bool Animation::IsFinishedAt(double monotonic_time) const {
+bool Animation::IsFinishedAt(base::TimeTicks monotonic_time) const {
if (is_finished())
return true;
if (needs_synchronized_start_time_)
return false;
- return run_state_ == Running &&
- iterations_ >= 0 &&
- iterations_ * curve_->Duration() <= (monotonic_time -
- start_time() -
- total_paused_time_ +
- time_offset_);
+ return run_state_ == Running && iterations_ >= 0 &&
+ iterations_ * curve_->Duration() <=
+ (TimeUtil::TicksInSecondsF(monotonic_time) +
+ time_offset_.InSecondsF() -
+ TimeUtil::TicksInSecondsF(start_time_) -
+ total_paused_time_.InSecondsF());
}
-double Animation::TrimTimeToCurrentIteration(double monotonic_time) const {
- double trimmed = monotonic_time + time_offset_;
+double Animation::TrimTimeToCurrentIteration(
+ base::TimeTicks monotonic_time) const {
+ double trimmed =
+ TimeUtil::TicksInSecondsF(monotonic_time) + time_offset_.InSecondsF();
// If we're paused, time is 'stuck' at the pause time.
if (run_state_ == Paused)
- trimmed = pause_time_;
+ trimmed = TimeUtil::TicksInSecondsF(pause_time_);
// Returned time should always be relative to the start time and should
// subtract all time spent paused.
- trimmed -= start_time_ + total_paused_time_;
+ trimmed -=
+ TimeUtil::TicksInSecondsF(start_time_) + total_paused_time_.InSecondsF();
// If we're just starting or we're waiting on receiving a start time,
// time is 'stuck' at the initial state.
if ((run_state_ == Starting && !has_set_start_time()) ||
needs_synchronized_start_time())
- trimmed = time_offset_;
+ trimmed = time_offset_.InSecondsF();
// Return 0 if we are before the start of the animation
if (trimmed < 0)

Powered by Google App Engine
This is Rietveld 408576698