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

Unified Diff: cc/animation/animation.cc

Issue 180153010: Handle direction control in compositor Animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add myself to src/AUTHORS Created 6 years, 9 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
« no previous file with comments | « cc/animation/animation.h ('k') | cc/animation/animation_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation/animation.cc
diff --git a/cc/animation/animation.cc b/cc/animation/animation.cc
index 263c34743dcf8d19ee4a9b958beb88e6323abb08..a84b181edc37d917022a14a5c01bd83193365abf 100644
--- a/cc/animation/animation.cc
+++ b/cc/animation/animation.cc
@@ -65,7 +65,7 @@ Animation::Animation(scoped_ptr<AnimationCurve> curve,
run_state_(WaitingForTargetAvailability),
iterations_(1),
start_time_(0),
- alternates_direction_(false),
+ direction_(Normal),
time_offset_(0),
needs_synchronized_start_time_(false),
received_finished_event_(false),
@@ -173,8 +173,8 @@ double Animation::TrimTimeToCurrentIteration(double monotonic_time) const {
needs_synchronized_start_time())
trimmed = time_offset_;
- // Zero is always the start of the animation.
- if (trimmed <= 0)
+ // Return 0 if we are before the start of the animation
+ if (trimmed < 0)
return 0;
// Always return zero if we have no iterations.
@@ -185,26 +185,32 @@ double Animation::TrimTimeToCurrentIteration(double monotonic_time) const {
if (curve_->Duration() <= 0)
return 0;
- // If less than an iteration duration, just return trimmed.
- if (trimmed < curve_->Duration())
- return trimmed;
-
- // If greater than or equal to the total duration, return iteration duration.
- if (iterations_ >= 0 && trimmed >= curve_->Duration() * iterations_) {
- if (alternates_direction_ && !(iterations_ % 2))
- return 0;
- return curve_->Duration();
- }
+ // check if we are past active interval
+ bool is_past_total_duration =
+ (iterations_ > 0 && trimmed >= curve_->Duration() * iterations_);
// We need to know the current iteration if we're alternating.
- int iteration = static_cast<int>(trimmed / curve_->Duration());
+ int iteration = 0;
+
+ // If we are past the active interval, return iteration duration.
+ if (is_past_total_duration) {
+ iteration = iterations_;
+ trimmed = curve_->Duration();
+ } else {
+ iteration = static_cast<int>(trimmed / curve_->Duration());
+ // Calculate x where trimmed = x + n * curve_->Duration() for some positive
+ // integer n.
+ trimmed = fmod(trimmed, curve_->Duration());
+ }
- // Calculate x where trimmed = x + n * curve_->Duration() for some positive
- // integer n.
- trimmed = fmod(trimmed, curve_->Duration());
+ // check if we are running the animation in reverse direction for the current
+ // iteration
+ bool reverse = (direction_ == Reverse) ||
+ (direction_ == Alternate && iteration % 2 == 1) ||
+ (direction_ == AlternateReverse && iteration % 2 == 0);
- // If we're alternating and on an odd iteration, reverse the direction.
- if (alternates_direction_ && iteration % 2 == 1)
+ // if we are running the animation in reverse direction, reverse the result
+ if (reverse)
return curve_->Duration() - trimmed;
return trimmed;
@@ -224,7 +230,7 @@ scoped_ptr<Animation> Animation::CloneAndInitialize(RunState initial_run_state,
to_return->pause_time_ = pause_time_;
to_return->total_paused_time_ = total_paused_time_;
to_return->time_offset_ = time_offset_;
- to_return->alternates_direction_ = alternates_direction_;
+ to_return->direction_ = direction_;
DCHECK(!to_return->is_controlling_instance_);
to_return->is_controlling_instance_ = true;
return to_return.Pass();
« no previous file with comments | « cc/animation/animation.h ('k') | cc/animation/animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698