diff options
author | loyso <loyso@chromium.org> | 2015-01-08 18:19:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-09 02:20:12 +0000 |
commit | ef8c01ae40ae877c7e7ba27b822ac896e91839b4 (patch) | |
tree | 40722ed1c4685bd0401a0caef64bfe55c33810a4 /cc/animation | |
parent | 24755a4f23ca49f92fdf53078cb8bb528ce33b34 (diff) | |
download | chromium_src-ef8c01ae40ae877c7e7ba27b822ac896e91839b4.zip chromium_src-ef8c01ae40ae877c7e7ba27b822ac896e91839b4.tar.gz chromium_src-ef8c01ae40ae877c7e7ba27b822ac896e91839b4.tar.bz2 |
CC: Allow cubic-bezier timing inputs outside the range [0, 1]
A chromium part. Blink part: https://codereview.chromium.org/787353003
Support this blink change
https://codereview.chromium.org/238573002
but on the compositor side.
BUG=445507
R=dstockwell@chromium.org
R=ajuma@chromium.org
TEST=ManualTests/animation/compositor-animation-steps.html
Review URL: https://codereview.chromium.org/833093002
Cr-Commit-Position: refs/heads/master@{#310671}
Diffstat (limited to 'cc/animation')
-rw-r--r-- | cc/animation/keyframed_animation_curve_unittest.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/cc/animation/keyframed_animation_curve_unittest.cc b/cc/animation/keyframed_animation_curve_unittest.cc index 0fd8da9..dc8537d 100644 --- a/cc/animation/keyframed_animation_curve_unittest.cc +++ b/cc/animation/keyframed_animation_curve_unittest.cc @@ -725,6 +725,68 @@ TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) { EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); } +// Tests that a linear timing function works as expected for inputs outside of +// range [0,1] +TEST(KeyframedAnimationCurveTest, LinearTimingInputsOutsideZeroOneRange) { + scoped_ptr<KeyframedFloatAnimationCurve> curve( + KeyframedFloatAnimationCurve::Create()); + curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); + curve->AddKeyframe( + FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); + // Curve timing function producing timing outputs outside of range [0,1]. + curve->SetTimingFunction( + CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); + + EXPECT_NEAR(-0.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), + 0.001f); + EXPECT_NEAR(2.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), + 0.001f); +} + +// If a curve cubic-bezier timing function produces timing outputs outside +// the range [0, 1] then a keyframe cubic-bezier timing function +// should consume that input properly (using end-point gradients). +TEST(KeyframedAnimationCurveTest, CurveTimingInputsOutsideZeroOneRange) { + scoped_ptr<KeyframedFloatAnimationCurve> curve( + KeyframedFloatAnimationCurve::Create()); + // Keyframe timing function with 0.5 gradients at each end. + curve->AddKeyframe(FloatKeyframe::Create( + base::TimeDelta(), 0.f, + CubicBezierTimingFunction::Create(0.5f, 0.25f, 0.5f, 0.75f).Pass())); + curve->AddKeyframe( + FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); + // Curve timing function producing timing outputs outside of range [0,1]. + curve->SetTimingFunction( + CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); + + EXPECT_NEAR(-0.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), + 0.002f); // c(.25)=-.04, -.04*0.5=-0.02 + EXPECT_NEAR(0.33f, curve->GetValue(base::TimeDelta::FromSecondsD(0.46f)), + 0.002f); // c(.46)=.38, k(.38)=.33 + + EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), + 0.002f); // c(.54)=.62, k(.62)=.67 + EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), + 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 +} + +// Tests that a step timing function works as expected for inputs outside of +// range [0,1] +TEST(KeyframedAnimationCurveTest, StepsTimingInputsOutsideZeroOneRange) { + scoped_ptr<KeyframedFloatAnimationCurve> curve( + KeyframedFloatAnimationCurve::Create()); + curve->AddKeyframe(FloatKeyframe::Create( + base::TimeDelta(), 0.f, StepsTimingFunction::Create(4, 0.5f))); + curve->AddKeyframe( + FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); + // Curve timing function producing timing outputs outside of range [0,1]. + curve->SetTimingFunction( + CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); + + EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); + EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); +} + // Tests that an animation with a curve timing function and multiple keyframes // works as expected. TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |