Skip to content

Commit

Permalink
Revert "Handle direction control in compositor Animations"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rafaelw@google.com committed Apr 1, 2014
1 parent 1a04368 commit 5f28eb4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 159 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Andrew Brampton <me@bramp.net>
Andrew Tulloch <andrew@tullo.ch>
Anish Patankar <anish.p@samsung.com>
Antonio Gomes <a1.gomes@sisa.samsung.com>
Arnaud Renevier <a.renevier@samsung.com>
Arthur Lussos <developer0420@gmail.com>
Arun Mankuzhi <arun.m@samsung.com>
Arunprasad Rajkumar <ararunprasad@gmail.com>
Expand Down
46 changes: 20 additions & 26 deletions cc/animation/animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions cc/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
87 changes: 2 additions & 85 deletions cc/animation/animation_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
39 changes: 2 additions & 37 deletions webkit/renderer/compositor_bindings/web_animation_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,48 +95,13 @@ void WebAnimationImpl::setTimeOffset(double monotonic_time) {
animation_->set_time_offset(monotonic_time);
}

#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION
blink::WebAnimation::Direction WebAnimationImpl::direction() const {
switch (animation_->direction()) {
case cc::Animation::Normal:
return DirectionNormal;
case cc::Animation::Reverse:
return DirectionReverse;
case cc::Animation::Alternate:
return DirectionAlternate;
case cc::Animation::AlternateReverse:
return DirectionAlternateReverse;
default:
NOTREACHED();
}
return DirectionNormal;
}

void WebAnimationImpl::setDirection(Direction direction) {
switch (direction) {
case DirectionNormal:
animation_->set_direction(cc::Animation::Normal);
break;
case DirectionReverse:
animation_->set_direction(cc::Animation::Reverse);
break;
case DirectionAlternate:
animation_->set_direction(cc::Animation::Alternate);
break;
case DirectionAlternateReverse:
animation_->set_direction(cc::Animation::AlternateReverse);
break;
}
}
#else
bool WebAnimationImpl::alternatesDirection() const {
return animation_->direction() == cc::Animation::Alternate;
return animation_->alternates_direction();
}

void WebAnimationImpl::setAlternatesDirection(bool alternates) {
return animation_->set_direction(cc::Animation::Alternate);
animation_->set_alternates_direction(alternates);
}
#endif

scoped_ptr<cc::Animation> WebAnimationImpl::PassAnimation() {
animation_->set_needs_synchronized_start_time(true);
Expand Down
5 changes: 0 additions & 5 deletions webkit/renderer/compositor_bindings/web_animation_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ class WebAnimationImpl : public blink::WebAnimation {
virtual void setStartTime(double monotonic_time);
virtual double timeOffset() const;
virtual void setTimeOffset(double monotonic_time);
#if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION
virtual Direction direction() const;
virtual void setDirection(Direction);
#else
virtual bool alternatesDirection() const;
virtual void setAlternatesDirection(bool alternates);
#endif

scoped_ptr<cc::Animation> PassAnimation();

Expand Down

0 comments on commit 5f28eb4

Please sign in to comment.