summaryrefslogtreecommitdiffstats
path: root/cc/animation
diff options
context:
space:
mode:
authorrafaelw@google.com <rafaelw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 00:57:00 +0000
committerrafaelw@google.com <rafaelw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 00:57:00 +0000
commit5f28eb4ad6cd3c061561e3b84f8e364ff1b487d0 (patch)
tree0d635d7e4430b52fedd50948b90bf45f1f422661 /cc/animation
parent1a0436898a9e983e4b0188c9a7f124c5668a29a7 (diff)
downloadchromium_src-5f28eb4ad6cd3c061561e3b84f8e364ff1b487d0.zip
chromium_src-5f28eb4ad6cd3c061561e3b84f8e364ff1b487d0.tar.gz
chromium_src-5f28eb4ad6cd3c061561e3b84f8e364ff1b487d0.tar.bz2
Revert "Handle direction control in compositor Animations"
Caused compile failures in blink canary builders. TBR=a.renevier@samsung.com BUG=348071 Review URL: https://codereview.chromium.org/220403002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation')
-rw-r--r--cc/animation/animation.cc46
-rw-r--r--cc/animation/animation.h12
-rw-r--r--cc/animation/animation_unittest.cc87
3 files changed, 29 insertions, 116 deletions
diff --git a/cc/animation/animation.cc b/cc/animation/animation.cc
index a84b181..263c347 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),
- direction_(Normal),
+ alternates_direction_(false),
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_;
- // Return 0 if we are before the start of the animation
- if (trimmed < 0)
+ // Zero is always the start of the animation.
+ if (trimmed <= 0)
return 0;
// Always return zero if we have no iterations.
@@ -185,32 +185,26 @@ double Animation::TrimTimeToCurrentIteration(double monotonic_time) const {
if (curve_->Duration() <= 0)
return 0;
- // check if we are past active interval
- bool is_past_total_duration =
- (iterations_ > 0 && trimmed >= curve_->Duration() * iterations_);
+ // If less than an iteration duration, just return trimmed.
+ if (trimmed < curve_->Duration())
+ return trimmed;
- // We need to know the current iteration if we're alternating.
- 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());
+ // 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 running the animation in reverse direction for the current
- // iteration
- bool reverse = (direction_ == Reverse) ||
- (direction_ == Alternate && iteration % 2 == 1) ||
- (direction_ == AlternateReverse && iteration % 2 == 0);
+ // We need to know the current iteration if we're alternating.
+ int 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());
- // if we are running the animation in reverse direction, reverse the result
- if (reverse)
+ // If we're alternating and on an odd iteration, reverse the direction.
+ if (alternates_direction_ && iteration % 2 == 1)
return curve_->Duration() - trimmed;
return trimmed;
@@ -230,7 +224,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->direction_ = direction_;
+ to_return->alternates_direction_ = alternates_direction_;
DCHECK(!to_return->is_controlling_instance_);
to_return->is_controlling_instance_ = true;
return to_return.Pass();
diff --git a/cc/animation/animation.h b/cc/animation/animation.h
index 56f1ff7..f996c38 100644
--- a/cc/animation/animation.h
+++ b/cc/animation/animation.h
@@ -48,8 +48,6 @@ class CC_EXPORT Animation {
TargetPropertyEnumSize
};
- enum Direction { Normal, Reverse, Alternate, AlternateReverse };
-
static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve,
int animation_id,
int group_id,
@@ -80,8 +78,12 @@ class CC_EXPORT Animation {
void Suspend(double monotonic_time);
void Resume(double monotonic_time);
- Direction direction() { return direction_; }
- void set_direction(Direction direction) { direction_ = direction; }
+ // If alternates_direction is true, on odd numbered iterations we reverse the
+ // curve.
+ bool alternates_direction() const { return alternates_direction_; }
+ void set_alternates_direction(bool alternates) {
+ alternates_direction_ = alternates;
+ }
bool IsFinishedAt(double monotonic_time) const;
bool is_finished() const {
@@ -148,7 +150,7 @@ class CC_EXPORT Animation {
RunState run_state_;
int iterations_;
double start_time_;
- Direction direction_;
+ bool alternates_direction_;
// The time offset effectively pushes the start of the animation back in time.
// This is used for resuming paused animations -- an animation is added with a
diff --git a/cc/animation/animation_unittest.cc b/cc/animation/animation_unittest.cc
index 7a9019d..8223cee 100644
--- a/cc/animation/animation_unittest.cc
+++ b/cc/animation/animation_unittest.cc
@@ -49,39 +49,15 @@ TEST(AnimationTest, TrimTimeInfiniteIterations) {
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5));
}
-TEST(AnimationTest, TrimTimeReverse) {
+TEST(AnimationTest, TrimTimeAlternating) {
scoped_ptr<Animation> anim(CreateAnimation(-1));
- anim->set_direction(Animation::Reverse);
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0));
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(1.0));
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
-}
-
-TEST(AnimationTest, TrimTimeAlternate) {
- scoped_ptr<Animation> anim(CreateAnimation(-1));
- anim->set_direction(Animation::Alternate);
+ anim->set_alternates_direction(true);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.25));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.75));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
}
-TEST(AnimationTest, TrimTimeAlternateReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(-1));
- anim->set_direction(Animation::AlternateReverse);
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1.25));
-}
-
TEST(AnimationTest, TrimTimeStartTime) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_start_time(4);
@@ -92,17 +68,6 @@ TEST(AnimationTest, TrimTimeStartTime) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
}
-TEST(AnimationTest, TrimTimeStartTimeReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(1));
- anim->set_start_time(4);
- anim->set_direction(Animation::Reverse);
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(6.0));
-}
-
TEST(AnimationTest, TrimTimeTimeOffset) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_time_offset(4);
@@ -113,17 +78,6 @@ TEST(AnimationTest, TrimTimeTimeOffset) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
}
-TEST(AnimationTest, TrimTimeTimeOffsetReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(1));
- anim->set_time_offset(4);
- anim->set_start_time(4);
- anim->set_direction(Animation::Reverse);
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
-}
-
TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_time_offset(-4);
@@ -134,17 +88,6 @@ TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
}
-TEST(AnimationTest, TrimTimeNegativeTimeOffsetReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(1));
- anim->set_time_offset(-4);
- anim->set_direction(Animation::Reverse);
-
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
-}
-
TEST(AnimationTest, TrimTimePauseResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
@@ -157,19 +100,6 @@ TEST(AnimationTest, TrimTimePauseResume) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
-TEST(AnimationTest, TrimTimePauseResumeReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(1));
- anim->set_direction(Animation::Reverse);
- anim->SetRunState(Animation::Running, 0.0);
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
- anim->SetRunState(Animation::Paused, 0.25);
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
- anim->SetRunState(Animation::Running, 1024.0);
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.75));
-}
-
TEST(AnimationTest, TrimTimeSuspendResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
@@ -182,19 +112,6 @@ TEST(AnimationTest, TrimTimeSuspendResume) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
-TEST(AnimationTest, TrimTimeSuspendResumeReverse) {
- scoped_ptr<Animation> anim(CreateAnimation(1));
- anim->set_direction(Animation::Reverse);
- anim->SetRunState(Animation::Running, 0.0);
- EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
- EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
- anim->Suspend(0.75);
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
- anim->Resume(1024);
- EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
- EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.25));
-}
-
TEST(AnimationTest, TrimTimeZeroDuration) {
scoped_ptr<Animation> anim(CreateAnimation(0, 0));
anim->SetRunState(Animation::Running, 0.0);