Skip to content

Commit

Permalink
CC: Clamp opacity values during an animation
Browse files Browse the repository at this point in the history
Opacity values should be clipped between [0,1] in a composited animation.

BUG=400869

Review URL: https://codereview.chromium.org/474803002

Cr-Commit-Position: refs/heads/master@{#289746}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289746 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
samli@chromium.org committed Aug 15, 2014
1 parent c9535ba commit bbe1def
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cc/animation/layer_animation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) {
case Animation::Opacity: {
const FloatAnimationCurve* float_animation_curve =
animations_[i]->curve()->ToFloatAnimationCurve();
const float opacity = float_animation_curve->GetValue(trimmed);
const float opacity = std::max(
std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f);
NotifyObserversOpacityAnimated(
opacity,
animations_[i]->affects_active_observers(),
Expand Down
32 changes: 32 additions & 0 deletions cc/animation/layer_animation_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,38 @@ TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) {
EXPECT_EQ(0.75f, dummy_impl.opacity());
}

TEST(LayerAnimationControllerTest, ClippedOpacityValues) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
controller->AddValueObserver(&dummy);

AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true);

controller->Animate(kInitialTickTime);
EXPECT_EQ(1.f, dummy.opacity());

// Opacity values are clipped [0,1]
controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
EXPECT_EQ(1.f, dummy.opacity());
}

TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) {
FakeLayerAnimationValueObserver dummy;
scoped_refptr<LayerAnimationController> controller(
LayerAnimationController::Create(0));
controller->AddValueObserver(&dummy);

AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true);

controller->Animate(kInitialTickTime);
EXPECT_EQ(0.f, dummy.opacity());

// Opacity values are clipped [0,1]
controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
EXPECT_EQ(0.f, dummy.opacity());
}

TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) {
scoped_ptr<AnimationEventsVector> events(
make_scoped_ptr(new AnimationEventsVector));
Expand Down

0 comments on commit bbe1def

Please sign in to comment.