summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbehara.ms <behara.ms@samsung.com>2014-11-18 08:01:40 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-18 16:02:45 +0000
commit591d77f964eae64a49bd83910bae574e40f20c1a (patch)
tree66282b31c16baa66f4ce07077ad7954f4d9b1c3d
parented1dafa7db5fcd150a757d1237c83a81666ec47f (diff)
downloadchromium_src-591d77f964eae64a49bd83910bae574e40f20c1a.zip
chromium_src-591d77f964eae64a49bd83910bae574e40f20c1a.tar.gz
chromium_src-591d77f964eae64a49bd83910bae574e40f20c1a.tar.bz2
Make Keyframe use TimeTicks/TimeDelta to represent time instead of double.
BUG=178171 Review URL: https://codereview.chromium.org/719453007 Cr-Commit-Position: refs/heads/master@{#304612}
-rw-r--r--cc/animation/animation_curve.h8
-rw-r--r--cc/animation/keyframed_animation_curve.cc87
-rw-r--r--cc/animation/keyframed_animation_curve.h40
-rw-r--r--cc/animation/keyframed_animation_curve_unittest.cc554
-rw-r--r--cc/animation/layer_animation_controller.cc9
-rw-r--r--cc/animation/layer_animation_controller_unittest.cc84
-rw-r--r--cc/animation/scroll_offset_animation_curve.cc15
-rw-r--r--cc/animation/scroll_offset_animation_curve.h2
-rw-r--r--cc/animation/scroll_offset_animation_curve_unittest.cc71
-rw-r--r--cc/base/time_util.h5
-rw-r--r--cc/blink/web_filter_animation_curve_impl.cc6
-rw-r--r--cc/blink/web_float_animation_curve_impl.cc10
-rw-r--r--cc/blink/web_scroll_offset_animation_curve_impl.cc3
-rw-r--r--cc/blink/web_transform_animation_curve_impl.cc6
-rw-r--r--cc/input/top_controls_manager.cc17
-rw-r--r--cc/layers/layer_unittest.cc5
-rw-r--r--cc/test/animation_test_common.cc34
-rw-r--r--cc/test/animation_test_common.h6
-rw-r--r--cc/test/geometry_test_utils.h6
-rw-r--r--cc/test/layer_tree_test.cc6
-rw-r--r--cc/trees/layer_tree_host_unittest_animation.cc7
-rw-r--r--ui/compositor/float_animation_curve_adapter.cc10
-rw-r--r--ui/compositor/float_animation_curve_adapter.h2
-rw-r--r--ui/compositor/transform_animation_curve_adapter.cc18
-rw-r--r--ui/compositor/transform_animation_curve_adapter.h4
-rw-r--r--ui/compositor/transform_animation_curve_adapter_unittest.cc8
26 files changed, 590 insertions, 433 deletions
diff --git a/cc/animation/animation_curve.h b/cc/animation/animation_curve.h
index c03feb8..f4c697c 100644
--- a/cc/animation/animation_curve.h
+++ b/cc/animation/animation_curve.h
@@ -48,7 +48,7 @@ class CC_EXPORT ColorAnimationCurve : public AnimationCurve {
public:
~ColorAnimationCurve() override {}
- virtual SkColor GetValue(double t) const = 0;
+ virtual SkColor GetValue(base::TimeDelta t) const = 0;
// Partial Animation implementation.
CurveType Type() const override;
@@ -58,7 +58,7 @@ class CC_EXPORT FloatAnimationCurve : public AnimationCurve {
public:
~FloatAnimationCurve() override {}
- virtual float GetValue(double t) const = 0;
+ virtual float GetValue(base::TimeDelta t) const = 0;
// Partial Animation implementation.
CurveType Type() const override;
@@ -68,7 +68,7 @@ class CC_EXPORT TransformAnimationCurve : public AnimationCurve {
public:
~TransformAnimationCurve() override {}
- virtual gfx::Transform GetValue(double t) const = 0;
+ virtual gfx::Transform GetValue(base::TimeDelta t) const = 0;
// Sets |bounds| to be the bounding box for the region within which |box|
// will move during this animation. If this region cannot be computed,
@@ -98,7 +98,7 @@ class CC_EXPORT FilterAnimationCurve : public AnimationCurve {
public:
~FilterAnimationCurve() override {}
- virtual FilterOperations GetValue(double t) const = 0;
+ virtual FilterOperations GetValue(base::TimeDelta t) const = 0;
virtual bool HasFilterThatMovesPixels() const = 0;
// Partial Animation implementation.
diff --git a/cc/animation/keyframed_animation_curve.cc b/cc/animation/keyframed_animation_curve.cc
index a6dc8c5..9642329 100644
--- a/cc/animation/keyframed_animation_curve.cc
+++ b/cc/animation/keyframed_animation_curve.cc
@@ -5,6 +5,7 @@
#include <algorithm>
#include "cc/animation/keyframed_animation_curve.h"
+#include "cc/base/time_util.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/box_f.h"
@@ -30,16 +31,18 @@ void InsertKeyframe(scoped_ptr<KeyframeType> keyframe,
}
template <typename KeyframeType>
-double TransformedAnimationTime(
+base::TimeDelta TransformedAnimationTime(
const ScopedPtrVector<KeyframeType>& keyframes,
const scoped_ptr<TimingFunction>& timing_function,
- double time) {
+ base::TimeDelta time) {
if (timing_function) {
- double start_time = keyframes.front()->Time();
- double duration = keyframes.back()->Time() - start_time;
- double progress = (time - start_time) / duration;
+ base::TimeDelta start_time = keyframes.front()->Time();
+ base::TimeDelta duration =
+ keyframes.back()->Time() - keyframes.front()->Time();
+ double progress = TimeUtil::Divide(time - start_time, duration);
- time = timing_function->GetValue(progress) * duration + start_time;
+ time = TimeUtil::Scale(duration, timing_function->GetValue(progress)) +
+ start_time;
}
return time;
@@ -47,7 +50,7 @@ double TransformedAnimationTime(
template <typename KeyframeType>
size_t GetActiveKeyframe(const ScopedPtrVector<KeyframeType>& keyframes,
- double time) {
+ base::TimeDelta time) {
DCHECK_GE(keyframes.size(), 2ul);
size_t i = 0;
for (; i < keyframes.size() - 2; ++i) { // Last keyframe is never active.
@@ -61,10 +64,11 @@ size_t GetActiveKeyframe(const ScopedPtrVector<KeyframeType>& keyframes,
template <typename KeyframeType>
double TransformedKeyframeProgress(
const ScopedPtrVector<KeyframeType>& keyframes,
- double time,
+ base::TimeDelta time,
size_t i) {
- double progress = (time - keyframes[i]->Time()) /
- (keyframes[i + 1]->Time() - keyframes[i]->Time());
+ double progress =
+ TimeUtil::Divide(time - keyframes[i]->Time(),
+ keyframes[i + 1]->Time() - keyframes[i]->Time());
if (keyframes[i]->timing_function()) {
progress = keyframes[i]->timing_function()->GetValue(progress);
@@ -75,29 +79,30 @@ double TransformedKeyframeProgress(
} // namespace
-Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timing_function)
- : time_(time),
- timing_function_(timing_function.Pass()) {}
+Keyframe::Keyframe(base::TimeDelta time,
+ scoped_ptr<TimingFunction> timing_function)
+ : time_(time), timing_function_(timing_function.Pass()) {
+}
Keyframe::~Keyframe() {}
-double Keyframe::Time() const {
+base::TimeDelta Keyframe::Time() const {
return time_;
}
scoped_ptr<ColorKeyframe> ColorKeyframe::Create(
- double time,
+ base::TimeDelta time,
SkColor value,
scoped_ptr<TimingFunction> timing_function) {
return make_scoped_ptr(
new ColorKeyframe(time, value, timing_function.Pass()));
}
-ColorKeyframe::ColorKeyframe(double time,
+ColorKeyframe::ColorKeyframe(base::TimeDelta time,
SkColor value,
scoped_ptr<TimingFunction> timing_function)
- : Keyframe(time, timing_function.Pass()),
- value_(value) {}
+ : Keyframe(time, timing_function.Pass()), value_(value) {
+}
ColorKeyframe::~ColorKeyframe() {}
@@ -111,18 +116,18 @@ scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const {
}
scoped_ptr<FloatKeyframe> FloatKeyframe::Create(
- double time,
+ base::TimeDelta time,
float value,
scoped_ptr<TimingFunction> timing_function) {
return make_scoped_ptr(
new FloatKeyframe(time, value, timing_function.Pass()));
}
-FloatKeyframe::FloatKeyframe(double time,
+FloatKeyframe::FloatKeyframe(base::TimeDelta time,
float value,
scoped_ptr<TimingFunction> timing_function)
- : Keyframe(time, timing_function.Pass()),
- value_(value) {}
+ : Keyframe(time, timing_function.Pass()), value_(value) {
+}
FloatKeyframe::~FloatKeyframe() {}
@@ -138,18 +143,18 @@ scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const {
}
scoped_ptr<TransformKeyframe> TransformKeyframe::Create(
- double time,
+ base::TimeDelta time,
const TransformOperations& value,
scoped_ptr<TimingFunction> timing_function) {
return make_scoped_ptr(
new TransformKeyframe(time, value, timing_function.Pass()));
}
-TransformKeyframe::TransformKeyframe(double time,
+TransformKeyframe::TransformKeyframe(base::TimeDelta time,
const TransformOperations& value,
scoped_ptr<TimingFunction> timing_function)
- : Keyframe(time, timing_function.Pass()),
- value_(value) {}
+ : Keyframe(time, timing_function.Pass()), value_(value) {
+}
TransformKeyframe::~TransformKeyframe() {}
@@ -165,18 +170,18 @@ scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const {
}
scoped_ptr<FilterKeyframe> FilterKeyframe::Create(
- double time,
+ base::TimeDelta time,
const FilterOperations& value,
scoped_ptr<TimingFunction> timing_function) {
return make_scoped_ptr(
new FilterKeyframe(time, value, timing_function.Pass()));
}
-FilterKeyframe::FilterKeyframe(double time,
+FilterKeyframe::FilterKeyframe(base::TimeDelta time,
const FilterOperations& value,
scoped_ptr<TimingFunction> timing_function)
- : Keyframe(time, timing_function.Pass()),
- value_(value) {}
+ : Keyframe(time, timing_function.Pass()), value_(value) {
+}
FilterKeyframe::~FilterKeyframe() {}
@@ -206,8 +211,7 @@ void KeyframedColorAnimationCurve::AddKeyframe(
}
base::TimeDelta KeyframedColorAnimationCurve::Duration() const {
- return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() -
- keyframes_.front()->Time());
+ return keyframes_.back()->Time() - keyframes_.front()->Time();
}
scoped_ptr<AnimationCurve> KeyframedColorAnimationCurve::Clone() const {
@@ -222,7 +226,7 @@ scoped_ptr<AnimationCurve> KeyframedColorAnimationCurve::Clone() const {
return to_return.Pass();
}
-SkColor KeyframedColorAnimationCurve::GetValue(double t) const {
+SkColor KeyframedColorAnimationCurve::GetValue(base::TimeDelta t) const {
if (t <= keyframes_.front()->Time())
return keyframes_.front()->Value();
@@ -254,8 +258,7 @@ void KeyframedFloatAnimationCurve::AddKeyframe(
}
base::TimeDelta KeyframedFloatAnimationCurve::Duration() const {
- return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() -
- keyframes_.front()->Time());
+ return keyframes_.back()->Time() - keyframes_.front()->Time();
}
scoped_ptr<AnimationCurve> KeyframedFloatAnimationCurve::Clone() const {
@@ -270,7 +273,7 @@ scoped_ptr<AnimationCurve> KeyframedFloatAnimationCurve::Clone() const {
return to_return.Pass();
}
-float KeyframedFloatAnimationCurve::GetValue(double t) const {
+float KeyframedFloatAnimationCurve::GetValue(base::TimeDelta t) const {
if (t <= keyframes_.front()->Time())
return keyframes_.front()->Value();
@@ -300,8 +303,7 @@ void KeyframedTransformAnimationCurve::AddKeyframe(
}
base::TimeDelta KeyframedTransformAnimationCurve::Duration() const {
- return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() -
- keyframes_.front()->Time());
+ return keyframes_.back()->Time() - keyframes_.front()->Time();
}
scoped_ptr<AnimationCurve> KeyframedTransformAnimationCurve::Clone() const {
@@ -316,7 +318,8 @@ scoped_ptr<AnimationCurve> KeyframedTransformAnimationCurve::Clone() const {
return to_return.Pass();
}
-gfx::Transform KeyframedTransformAnimationCurve::GetValue(double t) const {
+gfx::Transform KeyframedTransformAnimationCurve::GetValue(
+ base::TimeDelta t) const {
if (t <= keyframes_.front()->Time())
return keyframes_.front()->Value().Apply();
@@ -412,8 +415,7 @@ void KeyframedFilterAnimationCurve::AddKeyframe(
}
base::TimeDelta KeyframedFilterAnimationCurve::Duration() const {
- return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() -
- keyframes_.front()->Time());
+ return keyframes_.back()->Time() - keyframes_.front()->Time();
}
scoped_ptr<AnimationCurve> KeyframedFilterAnimationCurve::Clone() const {
@@ -428,7 +430,8 @@ scoped_ptr<AnimationCurve> KeyframedFilterAnimationCurve::Clone() const {
return to_return.Pass();
}
-FilterOperations KeyframedFilterAnimationCurve::GetValue(double t) const {
+FilterOperations KeyframedFilterAnimationCurve::GetValue(
+ base::TimeDelta t) const {
if (t <= keyframes_.front()->Time())
return keyframes_.front()->Value();
diff --git a/cc/animation/keyframed_animation_curve.h b/cc/animation/keyframed_animation_curve.h
index ff746fe..e68f4f8 100644
--- a/cc/animation/keyframed_animation_curve.h
+++ b/cc/animation/keyframed_animation_curve.h
@@ -16,17 +16,17 @@ namespace cc {
class CC_EXPORT Keyframe {
public:
- double Time() const;
+ base::TimeDelta Time() const;
const TimingFunction* timing_function() const {
return timing_function_.get();
}
protected:
- Keyframe(double time, scoped_ptr<TimingFunction> timing_function);
+ Keyframe(base::TimeDelta time, scoped_ptr<TimingFunction> timing_function);
virtual ~Keyframe();
private:
- double time_;
+ base::TimeDelta time_;
scoped_ptr<TimingFunction> timing_function_;
DISALLOW_COPY_AND_ASSIGN(Keyframe);
@@ -35,7 +35,7 @@ class CC_EXPORT Keyframe {
class CC_EXPORT ColorKeyframe : public Keyframe {
public:
static scoped_ptr<ColorKeyframe> Create(
- double time,
+ base::TimeDelta time,
SkColor value,
scoped_ptr<TimingFunction> timing_function);
~ColorKeyframe() override;
@@ -45,7 +45,7 @@ class CC_EXPORT ColorKeyframe : public Keyframe {
scoped_ptr<ColorKeyframe> Clone() const;
private:
- ColorKeyframe(double time,
+ ColorKeyframe(base::TimeDelta time,
SkColor value,
scoped_ptr<TimingFunction> timing_function);
@@ -55,7 +55,7 @@ class CC_EXPORT ColorKeyframe : public Keyframe {
class CC_EXPORT FloatKeyframe : public Keyframe {
public:
static scoped_ptr<FloatKeyframe> Create(
- double time,
+ base::TimeDelta time,
float value,
scoped_ptr<TimingFunction> timing_function);
~FloatKeyframe() override;
@@ -65,7 +65,7 @@ class CC_EXPORT FloatKeyframe : public Keyframe {
scoped_ptr<FloatKeyframe> Clone() const;
private:
- FloatKeyframe(double time,
+ FloatKeyframe(base::TimeDelta time,
float value,
scoped_ptr<TimingFunction> timing_function);
@@ -75,7 +75,7 @@ class CC_EXPORT FloatKeyframe : public Keyframe {
class CC_EXPORT TransformKeyframe : public Keyframe {
public:
static scoped_ptr<TransformKeyframe> Create(
- double time,
+ base::TimeDelta time,
const TransformOperations& value,
scoped_ptr<TimingFunction> timing_function);
~TransformKeyframe() override;
@@ -85,10 +85,9 @@ class CC_EXPORT TransformKeyframe : public Keyframe {
scoped_ptr<TransformKeyframe> Clone() const;
private:
- TransformKeyframe(
- double time,
- const TransformOperations& value,
- scoped_ptr<TimingFunction> timing_function);
+ TransformKeyframe(base::TimeDelta time,
+ const TransformOperations& value,
+ scoped_ptr<TimingFunction> timing_function);
TransformOperations value_;
};
@@ -96,7 +95,7 @@ class CC_EXPORT TransformKeyframe : public Keyframe {
class CC_EXPORT FilterKeyframe : public Keyframe {
public:
static scoped_ptr<FilterKeyframe> Create(
- double time,
+ base::TimeDelta time,
const FilterOperations& value,
scoped_ptr<TimingFunction> timing_function);
~FilterKeyframe() override;
@@ -106,10 +105,9 @@ class CC_EXPORT FilterKeyframe : public Keyframe {
scoped_ptr<FilterKeyframe> Clone() const;
private:
- FilterKeyframe(
- double time,
- const FilterOperations& value,
- scoped_ptr<TimingFunction> timing_function);
+ FilterKeyframe(base::TimeDelta time,
+ const FilterOperations& value,
+ scoped_ptr<TimingFunction> timing_function);
FilterOperations value_;
};
@@ -131,7 +129,7 @@ class CC_EXPORT KeyframedColorAnimationCurve : public ColorAnimationCurve {
scoped_ptr<AnimationCurve> Clone() const override;
// BackgrounColorAnimationCurve implementation
- SkColor GetValue(double t) const override;
+ SkColor GetValue(base::TimeDelta t) const override;
private:
KeyframedColorAnimationCurve();
@@ -161,7 +159,7 @@ class CC_EXPORT KeyframedFloatAnimationCurve : public FloatAnimationCurve {
scoped_ptr<AnimationCurve> Clone() const override;
// FloatAnimationCurve implementation
- float GetValue(double t) const override;
+ float GetValue(base::TimeDelta t) const override;
private:
KeyframedFloatAnimationCurve();
@@ -192,7 +190,7 @@ class CC_EXPORT KeyframedTransformAnimationCurve
scoped_ptr<AnimationCurve> Clone() const override;
// TransformAnimationCurve implementation
- gfx::Transform GetValue(double t) const override;
+ gfx::Transform GetValue(base::TimeDelta t) const override;
bool AnimatedBoundsForBox(const gfx::BoxF& box,
gfx::BoxF* bounds) const override;
bool AffectsScale() const override;
@@ -229,7 +227,7 @@ class CC_EXPORT KeyframedFilterAnimationCurve
scoped_ptr<AnimationCurve> Clone() const override;
// FilterAnimationCurve implementation
- FilterOperations GetValue(double t) const override;
+ FilterOperations GetValue(base::TimeDelta t) const override;
bool HasFilterThatMovesPixels() const override;
private:
diff --git a/cc/animation/keyframed_animation_curve_unittest.cc b/cc/animation/keyframed_animation_curve_unittest.cc
index 71fd521..314ce9d 100644
--- a/cc/animation/keyframed_animation_curve_unittest.cc
+++ b/cc/animation/keyframed_animation_curve_unittest.cc
@@ -29,13 +29,15 @@ TEST(KeyframedAnimationCurveTest, OneColorKeyFrame) {
SkColor color = SkColorSetARGB(255, 255, 255, 255);
scoped_ptr<KeyframedColorAnimationCurve> curve(
KeyframedColorAnimationCurve::Create());
- curve->AddKeyframe(ColorKeyframe::Create(0.0, color, nullptr));
-
- EXPECT_SKCOLOR_EQ(color, curve->GetValue(-1.f));
- EXPECT_SKCOLOR_EQ(color, curve->GetValue(0.f));
- EXPECT_SKCOLOR_EQ(color, curve->GetValue(0.5f));
- EXPECT_SKCOLOR_EQ(color, curve->GetValue(1.f));
- EXPECT_SKCOLOR_EQ(color, curve->GetValue(2.f));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta(), color, nullptr));
+
+ EXPECT_SKCOLOR_EQ(color,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SKCOLOR_EQ(color,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a color animation with two keyframes works as expected.
@@ -45,14 +47,21 @@ TEST(KeyframedAnimationCurveTest, TwoColorKeyFrame) {
SkColor color_midpoint = gfx::Tween::ColorValueBetween(0.5, color_a, color_b);
scoped_ptr<KeyframedColorAnimationCurve> curve(
KeyframedColorAnimationCurve::Create());
- curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr));
-
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f));
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f));
- EXPECT_SKCOLOR_EQ(color_midpoint, curve->GetValue(0.5f));
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.f));
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(2.f));
+ curve->AddKeyframe(
+ ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ color_b, nullptr));
+
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SKCOLOR_EQ(color_midpoint,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a color animation with three keyframes works as expected.
@@ -66,17 +75,27 @@ TEST(KeyframedAnimationCurveTest, ThreeColorKeyFrame) {
gfx::Tween::ColorValueBetween(0.5, color_b, color_c);
scoped_ptr<KeyframedColorAnimationCurve> curve(
KeyframedColorAnimationCurve::Create());
- curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(2.0, color_c, nullptr));
-
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f));
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f));
- EXPECT_SKCOLOR_EQ(color_midpoint1, curve->GetValue(0.5f));
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.f));
- EXPECT_SKCOLOR_EQ(color_midpoint2, curve->GetValue(1.5f));
- EXPECT_SKCOLOR_EQ(color_c, curve->GetValue(2.f));
- EXPECT_SKCOLOR_EQ(color_c, curve->GetValue(3.f));
+ curve->AddKeyframe(
+ ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ color_b, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
+ color_c, nullptr));
+
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SKCOLOR_EQ(color_midpoint1,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SKCOLOR_EQ(color_midpoint2,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_SKCOLOR_EQ(color_c,
+ curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_SKCOLOR_EQ(color_c,
+ curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a colro animation with multiple keys at a given time works sanely.
@@ -86,87 +105,103 @@ TEST(KeyframedAnimationCurveTest, RepeatedColorKeyFrame) {
scoped_ptr<KeyframedColorAnimationCurve> curve(
KeyframedColorAnimationCurve::Create());
- curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(1.0, color_a, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr));
- curve->AddKeyframe(ColorKeyframe::Create(2.0, color_b, nullptr));
-
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f));
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f));
- EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.5f));
-
- SkColor value = curve->GetValue(1.0f);
+ curve->AddKeyframe(
+ ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ color_a, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ color_b, nullptr));
+ curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
+ color_b, nullptr));
+
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SKCOLOR_EQ(color_a,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+
+ SkColor value = curve->GetValue(base::TimeDelta::FromSecondsD(1.0f));
EXPECT_EQ(255u, SkColorGetA(value));
int red_value = SkColorGetR(value);
EXPECT_LE(64, red_value);
EXPECT_GE(192, red_value);
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.5f));
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(2.f));
- EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(3.f));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_SKCOLOR_EQ(color_b,
+ curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a float animation with one keyframe works as expected.
TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.5f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(2.f));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a float animation with two keyframes works as expected.
TEST(KeyframedAnimationCurveTest, TwoFloatKeyframe) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(2.f));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a float animation with three keyframes works as expected.
TEST(KeyframedAnimationCurveTest, ThreeFloatKeyframe) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(2.0, 8.f, nullptr));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f));
- EXPECT_FLOAT_EQ(8.f, curve->GetValue(2.f));
- EXPECT_FLOAT_EQ(8.f, curve->GetValue(3.f));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 8.f, nullptr));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a float animation with multiple keys at a given time works sanely.
TEST(KeyframedAnimationCurveTest, RepeatedFloatKeyTimes) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 4.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 6.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(2.0, 6.f, nullptr));
-
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(0.5f));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 4.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 6.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 6.f, nullptr));
+
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
// There is a discontinuity at 1. Any value between 4 and 6 is valid.
- float value = curve->GetValue(1.f);
+ float value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
EXPECT_TRUE(value >= 4 && value <= 6);
- EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f));
- EXPECT_FLOAT_EQ(6.f, curve->GetValue(2.f));
- EXPECT_FLOAT_EQ(6.f, curve->GetValue(3.f));
+ EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a transform animation with one keyframe works as expected.
@@ -175,13 +210,14 @@ TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations;
operations.AppendTranslate(2.f, 0.f, 0.f);
- curve->AddKeyframe(TransformKeyframe::Create(0.f, operations, nullptr));
-
- ExpectTranslateX(2.f, curve->GetValue(-1.f));
- ExpectTranslateX(2.f, curve->GetValue(0.f));
- ExpectTranslateX(2.f, curve->GetValue(0.5f));
- ExpectTranslateX(2.f, curve->GetValue(1.f));
- ExpectTranslateX(2.f, curve->GetValue(2.f));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
+
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a transform animation with two keyframes works as expected.
@@ -193,13 +229,15 @@ TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) {
TransformOperations operations2;
operations2.AppendTranslate(4.f, 0.f, 0.f);
- curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr));
- ExpectTranslateX(2.f, curve->GetValue(-1.f));
- ExpectTranslateX(2.f, curve->GetValue(0.f));
- ExpectTranslateX(3.f, curve->GetValue(0.5f));
- ExpectTranslateX(4.f, curve->GetValue(1.f));
- ExpectTranslateX(4.f, curve->GetValue(2.f));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a transform animation with three keyframes works as expected.
@@ -212,16 +250,19 @@ TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) {
operations2.AppendTranslate(4.f, 0.f, 0.f);
TransformOperations operations3;
operations3.AppendTranslate(8.f, 0.f, 0.f);
- curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(2.f, operations3, nullptr));
- ExpectTranslateX(2.f, curve->GetValue(-1.f));
- ExpectTranslateX(2.f, curve->GetValue(0.f));
- ExpectTranslateX(3.f, curve->GetValue(0.5f));
- ExpectTranslateX(4.f, curve->GetValue(1.f));
- ExpectTranslateX(6.f, curve->GetValue(1.5f));
- ExpectTranslateX(8.f, curve->GetValue(2.f));
- ExpectTranslateX(8.f, curve->GetValue(3.f));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(2.0), operations3, nullptr));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a transform animation with multiple keys at a given time works
@@ -238,23 +279,27 @@ TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) {
operations3.AppendTranslate(6.f, 0.f, 0.f);
TransformOperations operations4;
operations4.AppendTranslate(6.f, 0.f, 0.f);
- curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(1.f, operations3, nullptr));
- curve->AddKeyframe(TransformKeyframe::Create(2.f, operations4, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(2.0), operations4, nullptr));
- ExpectTranslateX(4.f, curve->GetValue(-1.f));
- ExpectTranslateX(4.f, curve->GetValue(0.f));
- ExpectTranslateX(4.f, curve->GetValue(0.5f));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
// There is a discontinuity at 1. Any value between 4 and 6 is valid.
- gfx::Transform value = curve->GetValue(1.f);
+ gfx::Transform value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
EXPECT_GE(value.matrix().get(0, 3), 4.f);
EXPECT_LE(value.matrix().get(0, 3), 6.f);
- ExpectTranslateX(6.f, curve->GetValue(1.5f));
- ExpectTranslateX(6.f, curve->GetValue(2.f));
- ExpectTranslateX(6.f, curve->GetValue(3.f));
+ ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a filter animation with one keyframe works as expected.
@@ -263,13 +308,14 @@ TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) {
KeyframedFilterAnimationCurve::Create());
FilterOperations operations;
operations.Append(FilterOperation::CreateBrightnessFilter(2.f));
- curve->AddKeyframe(FilterKeyframe::Create(0.f, operations, nullptr));
-
- ExpectBrightness(2.f, curve->GetValue(-1.f));
- ExpectBrightness(2.f, curve->GetValue(0.f));
- ExpectBrightness(2.f, curve->GetValue(0.5f));
- ExpectBrightness(2.f, curve->GetValue(1.f));
- ExpectBrightness(2.f, curve->GetValue(2.f));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), operations, nullptr));
+
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a filter animation with two keyframes works as expected.
@@ -281,13 +327,15 @@ TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) {
FilterOperations operations2;
operations2.Append(FilterOperation::CreateBrightnessFilter(4.f));
- curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr));
- ExpectBrightness(2.f, curve->GetValue(-1.f));
- ExpectBrightness(2.f, curve->GetValue(0.f));
- ExpectBrightness(3.f, curve->GetValue(0.5f));
- ExpectBrightness(4.f, curve->GetValue(1.f));
- ExpectBrightness(4.f, curve->GetValue(2.f));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
+ operations2, nullptr));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that a filter animation with three keyframes works as expected.
@@ -300,16 +348,19 @@ TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) {
operations2.Append(FilterOperation::CreateBrightnessFilter(4.f));
FilterOperations operations3;
operations3.Append(FilterOperation::CreateBrightnessFilter(8.f));
- curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(2.f, operations3, nullptr));
- ExpectBrightness(2.f, curve->GetValue(-1.f));
- ExpectBrightness(2.f, curve->GetValue(0.f));
- ExpectBrightness(3.f, curve->GetValue(0.5f));
- ExpectBrightness(4.f, curve->GetValue(1.f));
- ExpectBrightness(6.f, curve->GetValue(1.5f));
- ExpectBrightness(8.f, curve->GetValue(2.f));
- ExpectBrightness(8.f, curve->GetValue(3.f));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
+ operations2, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f),
+ operations3, nullptr));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a filter animation with multiple keys at a given time works
@@ -326,41 +377,47 @@ TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) {
operations3.Append(FilterOperation::CreateBrightnessFilter(6.f));
FilterOperations operations4;
operations4.Append(FilterOperation::CreateBrightnessFilter(6.f));
- curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(1.f, operations3, nullptr));
- curve->AddKeyframe(FilterKeyframe::Create(2.f, operations4, nullptr));
-
- ExpectBrightness(4.f, curve->GetValue(-1.f));
- ExpectBrightness(4.f, curve->GetValue(0.f));
- ExpectBrightness(4.f, curve->GetValue(0.5f));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
+ operations2, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
+ operations3, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f),
+ operations4, nullptr));
+
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
// There is a discontinuity at 1. Any value between 4 and 6 is valid.
- FilterOperations value = curve->GetValue(1.f);
+ FilterOperations value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
EXPECT_EQ(1u, value.size());
EXPECT_EQ(FilterOperation::BRIGHTNESS, value.at(0).type());
EXPECT_GE(value.at(0).amount(), 4);
EXPECT_LE(value.at(0).amount(), 6);
- ExpectBrightness(6.f, curve->GetValue(1.5f));
- ExpectBrightness(6.f, curve->GetValue(2.f));
- ExpectBrightness(6.f, curve->GetValue(3.f));
+ ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that the keyframes may be added out of order.
TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(2.0, 8.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f));
- EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f));
- EXPECT_FLOAT_EQ(8.f, curve->GetValue(2.f));
- EXPECT_FLOAT_EQ(8.f, curve->GetValue(3.f));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 8.f, nullptr));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 4.f, nullptr));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
}
// Tests that a cubic bezier timing function works as expected.
@@ -368,16 +425,19 @@ TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
curve->AddKeyframe(FloatKeyframe::Create(
- 0.0, 0.f, CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f)));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr));
-
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
- EXPECT_LT(0.f, curve->GetValue(0.25f));
- EXPECT_GT(0.25f, curve->GetValue(0.25f));
- EXPECT_NEAR(curve->GetValue(0.5f), 0.5f, 0.00015f);
- EXPECT_LT(0.75f, curve->GetValue(0.75f));
- EXPECT_GT(1.f, curve->GetValue(0.75f));
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f));
+ base::TimeDelta(), 0.f,
+ CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f)));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr));
+
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
+ EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
+ EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f,
+ 0.00015f);
+ EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
+ EXPECT_GT(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
}
// Tests that animated bounds are computed as expected.
@@ -386,13 +446,16 @@ TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(2.0, 3.0, -1.0);
- curve->AddKeyframe(TransformKeyframe::Create(0.5, operations1, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr));
TransformOperations operations2;
operations2.AppendTranslate(4.0, 1.0, 2.0);
- curve->AddKeyframe(TransformKeyframe::Create(
- 1.0, operations2, EaseTimingFunction::Create()));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations2,
+ EaseTimingFunction::Create()));
gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f);
gfx::BoxF bounds;
@@ -408,23 +471,27 @@ TEST(KeyframedAnimationCurveTest, AffectsScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(2.0, 3.0, -1.0);
TransformOperations operations2;
operations2.AppendTranslate(4.0, 1.0, 2.0);
- curve->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.f), operations2, nullptr));
EXPECT_FALSE(curve->AffectsScale());
TransformOperations operations3;
operations3.AppendScale(2.f, 2.f, 2.f);
- curve->AddKeyframe(TransformKeyframe::Create(2.0, operations3, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(2.f), operations3, nullptr));
EXPECT_TRUE(curve->AffectsScale());
TransformOperations operations4;
operations3.AppendTranslate(2.f, 2.f, 2.f);
- curve->AddKeyframe(TransformKeyframe::Create(3.0, operations4, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(3.f), operations4, nullptr));
EXPECT_TRUE(curve->AffectsScale());
}
@@ -435,23 +502,27 @@ TEST(KeyframedAnimationCurveTest, IsTranslation) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(2.0, 3.0, -1.0);
TransformOperations operations2;
operations2.AppendTranslate(4.0, 1.0, 2.0);
- curve->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.f), operations2, nullptr));
EXPECT_TRUE(curve->IsTranslation());
TransformOperations operations3;
operations3.AppendScale(2.f, 2.f, 2.f);
- curve->AddKeyframe(TransformKeyframe::Create(2.0, operations3, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(2.f), operations3, nullptr));
EXPECT_FALSE(curve->IsTranslation());
TransformOperations operations4;
operations3.AppendTranslate(2.f, 2.f, 2.f);
- curve->AddKeyframe(TransformKeyframe::Create(3.0, operations4, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(3.f), operations4, nullptr));
EXPECT_FALSE(curve->IsTranslation());
}
@@ -462,10 +533,12 @@ TEST(KeyframedAnimationCurveTest, MaximumTargetScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendScale(2.f, -3.f, 1.f);
- curve->AddKeyframe(TransformKeyframe::Create(
- 1.0, operations1, EaseTimingFunction::Create()));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1,
+ EaseTimingFunction::Create()));
float maximum_scale = 0.f;
EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale));
@@ -473,16 +546,18 @@ TEST(KeyframedAnimationCurveTest, MaximumTargetScale) {
TransformOperations operations2;
operations2.AppendScale(6.f, 3.f, 2.f);
- curve->AddKeyframe(TransformKeyframe::Create(
- 2.0, operations2, EaseTimingFunction::Create()));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), operations2,
+ EaseTimingFunction::Create()));
EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale));
EXPECT_EQ(6.f, maximum_scale);
TransformOperations operations3;
operations3.AppendRotate(1.f, 0.f, 0.f, 90.f);
- curve->AddKeyframe(TransformKeyframe::Create(
- 3.0, operations3, EaseTimingFunction::Create()));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3,
+ EaseTimingFunction::Create()));
EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale));
@@ -492,12 +567,13 @@ TEST(KeyframedAnimationCurveTest, MaximumTargetScale) {
TransformOperations operations4;
operations4.AppendScale(0.4f, 0.2f, 0.6f);
- curve2->AddKeyframe(TransformKeyframe::Create(
- 0.0, operations4, EaseTimingFunction::Create()));
+ curve2->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), operations4,
+ EaseTimingFunction::Create()));
TransformOperations operations5;
operations5.AppendScale(0.5f, 0.3f, -0.8f);
- curve2->AddKeyframe(TransformKeyframe::Create(
- 1.0, operations5, EaseTimingFunction::Create()));
+ curve2->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations5,
+ EaseTimingFunction::Create()));
EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale));
EXPECT_EQ(0.8f, maximum_scale);
@@ -510,17 +586,20 @@ TEST(KeyframedAnimationCurveTest, MaximumTargetScale) {
TEST(KeyframedAnimationCurveTest, CurveTiming) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
curve->SetTimingFunction(
CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f).Pass());
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
- EXPECT_NEAR(0.05f, curve->GetValue(0.25f), 0.005f);
- EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f));
- EXPECT_NEAR(0.95f, curve->GetValue(0.75f), 0.005f);
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_NEAR(0.05f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)),
+ 0.005f);
+ EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_NEAR(0.95f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)),
+ 0.005f);
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that an animation with a curve and keyframe timing function works as
@@ -529,22 +608,26 @@ TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
curve->AddKeyframe(FloatKeyframe::Create(
- 0.0,
- 0.f,
+ base::TimeDelta(), 0.f,
CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f).Pass()));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
// Curve timing function producing 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(-1.f));
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.25f)); // Clamped. c(.25) < 0
- EXPECT_NEAR(0.17f, curve->GetValue(0.42f), 0.005f); // c(.42)=.27, k(.27)=.17
- EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f));
- EXPECT_NEAR(0.83f, curve->GetValue(0.58f), 0.005f); // c(.58)=.73, k(.73)=.83
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(0.75f)); // Clamped. c(.75) > 1
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f));
- EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(
+ 0.25f))); // Clamped. c(.25) < 0
+ EXPECT_NEAR(0.17f, curve->GetValue(base::TimeDelta::FromSecondsD(0.42f)),
+ 0.005f); // c(.42)=.27, k(.27)=.17
+ EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)),
+ 0.005f); // c(.58)=.73, k(.73)=.83
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(
+ 0.75f))); // Clamped. c(.75) > 1
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
}
// Tests that an animation with a curve timing function and multiple keyframes
@@ -552,21 +635,28 @@ TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) {
TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(2.0, 3.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(3.0, 6.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(4.0, 9.f, nullptr));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), 6.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.f), 9.f, nullptr));
curve->SetTimingFunction(
CubicBezierTimingFunction::Create(0.5f, 0.f, 0.5f, 1.f).Pass());
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f));
- EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
- EXPECT_NEAR(0.42f, curve->GetValue(1.f), 0.005f);
- EXPECT_NEAR(1.f, curve->GetValue(1.455f), 0.005f);
- EXPECT_FLOAT_EQ(3.f, curve->GetValue(2.f));
- EXPECT_NEAR(8.72f, curve->GetValue(3.5f), 0.01f);
- EXPECT_FLOAT_EQ(9.f, curve->GetValue(4.f));
- EXPECT_FLOAT_EQ(9.f, curve->GetValue(5.f));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_NEAR(0.42f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)),
+ 0.005f);
+ EXPECT_NEAR(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.455f)),
+ 0.005f);
+ EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_NEAR(8.72f, curve->GetValue(base::TimeDelta::FromSecondsD(3.5f)),
+ 0.01f);
+ EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(4.f)));
+ EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(5.f)));
}
// Tests that an animation with a curve timing function that overshoots works as
@@ -574,16 +664,22 @@ TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) {
TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) {
scoped_ptr<KeyframedFloatAnimationCurve> curve(
KeyframedFloatAnimationCurve::Create());
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(2.0, 3.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(3.0, 6.f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(4.0, 9.f, nullptr));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 3.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.0), 6.f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.0), 9.f, nullptr));
// Curve timing function producing outputs outside of range [0,1].
curve->SetTimingFunction(
CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass());
- EXPECT_LE(curve->GetValue(1.f), 0.f); // c(.25) < 0
- EXPECT_GE(curve->GetValue(3.f), 9.f); // c(.75) > 1
+ EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)),
+ 0.f); // c(.25) < 0
+ EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)),
+ 9.f); // c(.75) > 1
}
} // namespace
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc
index f621ad3..c9d81cf 100644
--- a/cc/animation/layer_animation_controller.cc
+++ b/cc/animation/layer_animation_controller.cc
@@ -148,8 +148,8 @@ void LayerAnimationController::AccumulatePropertyUpdates(
if (!animation->InEffect(monotonic_time))
continue;
- double trimmed =
- animation->TrimTimeToCurrentIteration(monotonic_time).InSecondsF();
+ base::TimeDelta trimmed =
+ animation->TrimTimeToCurrentIteration(monotonic_time);
switch (animation->target_property()) {
case Animation::Opacity: {
AnimationEvent event(AnimationEvent::PropertyUpdate,
@@ -861,9 +861,8 @@ void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) {
if (!animations_[i]->InEffect(monotonic_time))
continue;
- double trimmed = animations_[i]
- ->TrimTimeToCurrentIteration(monotonic_time)
- .InSecondsF();
+ base::TimeDelta trimmed =
+ animations_[i]->TrimTimeToCurrentIteration(monotonic_time);
switch (animations_[i]->target_property()) {
case Animation::Transform: {
diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc
index 4fa3d84..464a973 100644
--- a/cc/animation/layer_animation_controller_unittest.cc
+++ b/cc/animation/layer_animation_controller_unittest.cc
@@ -510,9 +510,11 @@ TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
// Create simple Transform animation.
TransformOperations operations;
- curve->AddKeyframe(TransformKeyframe::Create(0, operations, nullptr));
+ curve->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
operations.AppendTranslate(delta_x, delta_y, 0);
- curve->AddKeyframe(TransformKeyframe::Create(1, operations, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve.Pass(), 1, 0, Animation::Transform));
@@ -559,10 +561,12 @@ TEST(LayerAnimationControllerTest, FilterTransition) {
FilterOperations start_filters;
start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
- curve->AddKeyframe(FilterKeyframe::Create(0, start_filters, nullptr));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
FilterOperations end_filters;
end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
- curve->AddKeyframe(FilterKeyframe::Create(1, end_filters, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ end_filters, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve.Pass(), 1, 0, Animation::Filter));
@@ -606,10 +610,12 @@ TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) {
// Create simple Filter animation.
FilterOperations start_filters;
start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
- curve->AddKeyframe(FilterKeyframe::Create(0, start_filters, nullptr));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
FilterOperations end_filters;
end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
- curve->AddKeyframe(FilterKeyframe::Create(1, end_filters, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ end_filters, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve.Pass(), 1, 0, Animation::Filter));
@@ -1465,9 +1471,11 @@ TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve1->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve1->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(10.0, 15.0, 0.0);
- curve1->AddKeyframe(TransformKeyframe::Create(1.0, operations1, nullptr));
+ curve1->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve1.Pass(), 1, 1, Animation::Transform));
@@ -1477,9 +1485,11 @@ TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations2;
- curve2->AddKeyframe(TransformKeyframe::Create(0.0, operations2, nullptr));
+ curve2->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
operations2.AppendScale(2.0, 3.0, 4.0);
- curve2->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve2->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
@@ -1511,9 +1521,11 @@ TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
TransformOperations operations3;
gfx::Transform transform3;
transform3.Scale3d(1.0, 2.0, 3.0);
- curve3->AddKeyframe(TransformKeyframe::Create(0.0, operations3, nullptr));
+ curve3->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
operations3.AppendMatrix(transform3);
- curve3->AddKeyframe(TransformKeyframe::Create(1.0, operations3, nullptr));
+ curve3->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
@@ -1781,9 +1793,11 @@ TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve1->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve1->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(10.0, 15.0, 0.0);
- curve1->AddKeyframe(TransformKeyframe::Create(1.0, operations1, nullptr));
+ curve1->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve1.Pass(), 2, 2, Animation::Transform));
@@ -1796,9 +1810,11 @@ TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations2;
- curve2->AddKeyframe(TransformKeyframe::Create(0.0, operations2, nullptr));
+ curve2->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
operations2.AppendScale(2.0, 3.0, 4.0);
- curve2->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve2->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
@@ -1831,9 +1847,11 @@ TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve1->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve1->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendTranslate(10.0, 15.0, 0.0);
- curve1->AddKeyframe(TransformKeyframe::Create(1.0, operations1, nullptr));
+ curve1->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve1.Pass(), 2, 2, Animation::Transform));
@@ -1846,9 +1864,11 @@ TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations2;
- curve2->AddKeyframe(TransformKeyframe::Create(0.0, operations2, nullptr));
+ curve2->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
operations2.AppendScale(2.0, 3.0, 4.0);
- curve2->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve2->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
@@ -1876,9 +1896,11 @@ TEST(LayerAnimationControllerTest, MaximumTargetScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
- curve1->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve1->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
operations1.AppendScale(2.0, 3.0, 4.0);
- curve1->AddKeyframe(TransformKeyframe::Create(1.0, operations1, nullptr));
+ curve1->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
scoped_ptr<Animation> animation(
Animation::Create(curve1.Pass(), 1, 1, Animation::Transform));
@@ -1891,9 +1913,11 @@ TEST(LayerAnimationControllerTest, MaximumTargetScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations2;
- curve2->AddKeyframe(TransformKeyframe::Create(0.0, operations2, nullptr));
+ curve2->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
operations2.AppendScale(6.0, 5.0, 4.0);
- curve2->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve2->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
@@ -1905,9 +1929,11 @@ TEST(LayerAnimationControllerTest, MaximumTargetScale) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations3;
- curve3->AddKeyframe(TransformKeyframe::Create(0.0, operations3, nullptr));
+ curve3->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
operations3.AppendPerspective(6.0);
- curve3->AddKeyframe(TransformKeyframe::Create(1.0, operations3, nullptr));
+ curve3->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform);
controller_impl->AddAnimation(animation.Pass());
@@ -1933,10 +1959,12 @@ TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) {
KeyframedTransformAnimationCurve::Create());
TransformOperations operations1;
operations1.AppendScale(1.0, 2.0, 3.0);
- curve1->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr));
+ curve1->AddKeyframe(
+ TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
TransformOperations operations2;
operations2.AppendScale(4.0, 5.0, 6.0);
- curve1->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr));
+ curve1->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
scoped_ptr<Animation> animation_owned(
Animation::Create(curve1.Pass(), 1, 1, Animation::Transform));
diff --git a/cc/animation/scroll_offset_animation_curve.cc b/cc/animation/scroll_offset_animation_curve.cc
index e0b1a3b5..9567263 100644
--- a/cc/animation/scroll_offset_animation_curve.cc
+++ b/cc/animation/scroll_offset_animation_curve.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "cc/animation/timing_function.h"
+#include "cc/base/time_util.h"
#include "ui/gfx/animation/tween.h"
const double kDurationDivisor = 60.0;
@@ -65,17 +66,18 @@ void ScrollOffsetAnimationCurve::SetInitialValue(
target_value_.DeltaFrom(initial_value_));
}
-gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(double t) const {
- double duration = (total_animation_duration_ - last_retarget_).InSecondsF();
- t -= last_retarget_.InSecondsF();
+gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(
+ base::TimeDelta t) const {
+ base::TimeDelta duration = total_animation_duration_ - last_retarget_;
+ t -= last_retarget_;
- if (t <= 0)
+ if (t <= base::TimeDelta())
return initial_value_;
if (t >= duration)
return target_value_;
- double progress = (timing_function_->GetValue(t / duration));
+ double progress = timing_function_->GetValue(TimeUtil::Divide(t, duration));
return gfx::ScrollOffset(
gfx::Tween::FloatValueBetween(
progress, initial_value_.x(), target_value_.x()),
@@ -105,7 +107,8 @@ scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const {
void ScrollOffsetAnimationCurve::UpdateTarget(
double t,
const gfx::ScrollOffset& new_target) {
- gfx::ScrollOffset current_position = GetValue(t);
+ gfx::ScrollOffset current_position =
+ GetValue(base::TimeDelta::FromSecondsD(t));
gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_);
gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position);
diff --git a/cc/animation/scroll_offset_animation_curve.h b/cc/animation/scroll_offset_animation_curve.h
index 50dfb17..c4ae70b 100644
--- a/cc/animation/scroll_offset_animation_curve.h
+++ b/cc/animation/scroll_offset_animation_curve.h
@@ -24,7 +24,7 @@ class CC_EXPORT ScrollOffsetAnimationCurve : public AnimationCurve {
~ScrollOffsetAnimationCurve() override;
void SetInitialValue(const gfx::ScrollOffset& initial_value);
- gfx::ScrollOffset GetValue(double t) const;
+ gfx::ScrollOffset GetValue(base::TimeDelta t) const;
gfx::ScrollOffset target_value() const { return target_value_; }
void UpdateTarget(double t, const gfx::ScrollOffset& new_target);
diff --git a/cc/animation/scroll_offset_animation_curve_unittest.cc b/cc/animation/scroll_offset_animation_curve_unittest.cc
index d57814e..cb3e914 100644
--- a/cc/animation/scroll_offset_animation_curve_unittest.cc
+++ b/cc/animation/scroll_offset_animation_curve_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/animation/scroll_offset_animation_curve.h"
#include "cc/animation/timing_function.h"
+#include "cc/base/time_util.h"
#include "cc/test/geometry_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -63,24 +64,28 @@ TEST(ScrollOffsetAnimationCurveTest, GetValue) {
EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
- double duration_in_seconds = curve->Duration().InSecondsF();
+ base::TimeDelta duration = curve->Duration();
EXPECT_GT(curve->Duration().InSecondsF(), 0);
EXPECT_LT(curve->Duration().InSecondsF(), 0.1);
EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type());
- EXPECT_EQ(duration_in_seconds, curve->Duration().InSecondsF());
+ EXPECT_EQ(duration, curve->Duration());
- EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0));
- EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0));
- EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
- curve->GetValue(duration_in_seconds / 2.0));
- EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds));
- EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds + 1.0));
+ EXPECT_VECTOR2DF_EQ(initial_value,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.0)));
+ EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
+ EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
+ curve->GetValue(TimeUtil::Scale(duration, 0.5f)),
+ 0.00025);
+ EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration));
+ EXPECT_VECTOR2DF_EQ(
+ target_value,
+ curve->GetValue(duration + base::TimeDelta::FromSecondsD(1.0)));
// Verify that GetValue takes the timing function into account.
- gfx::ScrollOffset value = curve->GetValue(duration_in_seconds / 4.0);
- EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
- EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
+ gfx::ScrollOffset value = curve->GetValue(TimeUtil::Scale(duration, 0.25f));
+ EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
+ EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
// Verify that a clone behaves exactly like the original.
@@ -92,32 +97,34 @@ TEST(ScrollOffsetAnimationCurveTest, Clone) {
target_value,
EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
- double duration_in_seconds = curve->Duration().InSecondsF();
+ base::TimeDelta duration = curve->Duration();
scoped_ptr<AnimationCurve> clone(curve->Clone().Pass());
EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type());
- EXPECT_EQ(duration_in_seconds, clone->Duration().InSecondsF());
+ EXPECT_EQ(duration, clone->Duration());
EXPECT_VECTOR2DF_EQ(initial_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(-1.0));
- EXPECT_VECTOR2DF_EQ(initial_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(0.0));
- EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds / 2.0));
+ base::TimeDelta::FromSecondsD(-1.0)));
EXPECT_VECTOR2DF_EQ(
- target_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(duration_in_seconds));
+ initial_value,
+ clone->ToScrollOffsetAnimationCurve()->GetValue(base::TimeDelta()));
+ EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
+ clone->ToScrollOffsetAnimationCurve()->GetValue(
+ TimeUtil::Scale(duration, 0.5f)),
+ 0.00025);
+ EXPECT_VECTOR2DF_EQ(
+ target_value, clone->ToScrollOffsetAnimationCurve()->GetValue(duration));
EXPECT_VECTOR2DF_EQ(target_value,
clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds + 1.0));
+ duration + base::TimeDelta::FromSecondsD(1.f)));
// Verify that the timing function was cloned correctly.
gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds / 4.0);
- EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
- EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
+ TimeUtil::Scale(duration, 0.25f));
+ EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
+ EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
@@ -128,21 +135,23 @@ TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
target_value, EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
EXPECT_EQ(1.0, curve->Duration().InSecondsF());
- EXPECT_EQ(1800.0, curve->GetValue(0.5).y());
- EXPECT_EQ(3600.0, curve->GetValue(1.0).y());
+ EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
+ EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y());
curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0));
EXPECT_EQ(2.0, curve->Duration().InSecondsF());
- EXPECT_EQ(1800.0, curve->GetValue(0.5).y());
- EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
- EXPECT_EQ(9900.0, curve->GetValue(2.0).y());
+ EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
+ EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
+ 0.01);
+ EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(2.0)).y());
curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0));
EXPECT_NEAR(1.674, curve->Duration().InSecondsF(), 0.01);
- EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
- EXPECT_EQ(7200.0, curve->GetValue(1.674).y());
+ EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
+ 0.01);
+ EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.674)).y());
}
} // namespace
diff --git a/cc/base/time_util.h b/cc/base/time_util.h
index dc07e74..06682c2 100644
--- a/cc/base/time_util.h
+++ b/cc/base/time_util.h
@@ -18,6 +18,11 @@ class CC_EXPORT TimeUtil {
static_cast<double>(time_delta.ToInternalValue()) * value));
}
+ static double Divide(base::TimeDelta dividend, base::TimeDelta divisor) {
+ return static_cast<double>(dividend.ToInternalValue()) /
+ static_cast<double>(divisor.ToInternalValue());
+ }
+
static base::TimeDelta Mod(base::TimeDelta dividend,
base::TimeDelta divisor) {
return base::TimeDelta::FromInternalValue(dividend.ToInternalValue() %
diff --git a/cc/blink/web_filter_animation_curve_impl.cc b/cc/blink/web_filter_animation_curve_impl.cc
index 606929e..bdbffe8 100644
--- a/cc/blink/web_filter_animation_curve_impl.cc
+++ b/cc/blink/web_filter_animation_curve_impl.cc
@@ -32,7 +32,8 @@ void WebFilterAnimationCurveImpl::add(const WebFilterKeyframe& keyframe,
static_cast<const WebFilterOperationsImpl&>(keyframe.value())
.AsFilterOperations();
curve_->AddKeyframe(cc::FilterKeyframe::Create(
- keyframe.time(), filter_operations, CreateTimingFunction(type)));
+ base::TimeDelta::FromSecondsD(keyframe.time()), filter_operations,
+ CreateTimingFunction(type)));
}
void WebFilterAnimationCurveImpl::add(const WebFilterKeyframe& keyframe,
@@ -44,8 +45,7 @@ void WebFilterAnimationCurveImpl::add(const WebFilterKeyframe& keyframe,
static_cast<const WebFilterOperationsImpl&>(keyframe.value())
.AsFilterOperations();
curve_->AddKeyframe(cc::FilterKeyframe::Create(
- keyframe.time(),
- filter_operations,
+ base::TimeDelta::FromSecondsD(keyframe.time()), filter_operations,
cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)));
}
diff --git a/cc/blink/web_float_animation_curve_impl.cc b/cc/blink/web_float_animation_curve_impl.cc
index e5eee53..d85f57c 100644
--- a/cc/blink/web_float_animation_curve_impl.cc
+++ b/cc/blink/web_float_animation_curve_impl.cc
@@ -31,8 +31,9 @@ void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe) {
void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe,
TimingFunctionType type) {
- curve_->AddKeyframe(cc::FloatKeyframe::Create(
- keyframe.time, keyframe.value, CreateTimingFunction(type)));
+ curve_->AddKeyframe(
+ cc::FloatKeyframe::Create(base::TimeDelta::FromSecondsD(keyframe.time),
+ keyframe.value, CreateTimingFunction(type)));
}
void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe,
@@ -41,8 +42,7 @@ void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe,
double x2,
double y2) {
curve_->AddKeyframe(cc::FloatKeyframe::Create(
- keyframe.time,
- keyframe.value,
+ base::TimeDelta::FromSecondsD(keyframe.time), keyframe.value,
cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)));
}
@@ -59,7 +59,7 @@ void WebFloatAnimationCurveImpl::setTimingFunction(double x1,
}
float WebFloatAnimationCurveImpl::getValue(double time) const {
- return curve_->GetValue(time);
+ return curve_->GetValue(base::TimeDelta::FromSecondsD(time));
}
scoped_ptr<cc::AnimationCurve>
diff --git a/cc/blink/web_scroll_offset_animation_curve_impl.cc b/cc/blink/web_scroll_offset_animation_curve_impl.cc
index ba55d5b..cef276c0 100644
--- a/cc/blink/web_scroll_offset_animation_curve_impl.cc
+++ b/cc/blink/web_scroll_offset_animation_curve_impl.cc
@@ -34,7 +34,8 @@ void WebScrollOffsetAnimationCurveImpl::setInitialValue(
}
WebFloatPoint WebScrollOffsetAnimationCurveImpl::getValue(double time) const {
- gfx::ScrollOffset value = curve_->GetValue(time);
+ gfx::ScrollOffset value =
+ curve_->GetValue(base::TimeDelta::FromSecondsD(time));
return WebFloatPoint(value.x(), value.y());
}
diff --git a/cc/blink/web_transform_animation_curve_impl.cc b/cc/blink/web_transform_animation_curve_impl.cc
index f91d94b..86f3602 100644
--- a/cc/blink/web_transform_animation_curve_impl.cc
+++ b/cc/blink/web_transform_animation_curve_impl.cc
@@ -36,7 +36,8 @@ void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe,
static_cast<const WebTransformOperationsImpl&>(keyframe.value())
.AsTransformOperations();
curve_->AddKeyframe(cc::TransformKeyframe::Create(
- keyframe.time(), transform_operations, CreateTimingFunction(type)));
+ base::TimeDelta::FromSecondsD(keyframe.time()), transform_operations,
+ CreateTimingFunction(type)));
}
void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe,
@@ -48,8 +49,7 @@ void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe,
static_cast<const WebTransformOperationsImpl&>(keyframe.value())
.AsTransformOperations();
curve_->AddKeyframe(cc::TransformKeyframe::Create(
- keyframe.time(),
- transform_operations,
+ base::TimeDelta::FromSecondsD(keyframe.time()), transform_operations,
cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)));
}
diff --git a/cc/input/top_controls_manager.cc b/cc/input/top_controls_manager.cc
index cd3534c..ddde672 100644
--- a/cc/input/top_controls_manager.cc
+++ b/cc/input/top_controls_manager.cc
@@ -167,7 +167,7 @@ gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) {
if (!top_controls_animation_ || !client_->HaveRootScrollLayer())
return gfx::Vector2dF();
- double time = (monotonic_time - base::TimeTicks()).InMillisecondsF();
+ base::TimeDelta time = monotonic_time - base::TimeTicks();
float old_offset = client_->ControlsTopOffset();
SetControlsTopOffset(top_controls_animation_->GetValue(time));
@@ -199,16 +199,15 @@ void TopControlsManager::SetupAnimation(AnimationDirection direction) {
return;
top_controls_animation_ = KeyframedFloatAnimationCurve::Create();
- double start_time =
- (gfx::FrameTime::Now() - base::TimeTicks()).InMillisecondsF();
+ base::TimeDelta start_time = gfx::FrameTime::Now() - base::TimeTicks();
top_controls_animation_->AddKeyframe(
FloatKeyframe::Create(start_time, client_->ControlsTopOffset(), nullptr));
float max_ending_offset =
(direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_;
- top_controls_animation_->AddKeyframe(
- FloatKeyframe::Create(start_time + kShowHideMaxDurationMs,
- client_->ControlsTopOffset() + max_ending_offset,
- EaseTimingFunction::Create()));
+ top_controls_animation_->AddKeyframe(FloatKeyframe::Create(
+ start_time + base::TimeDelta::FromMilliseconds(kShowHideMaxDurationMs),
+ client_->ControlsTopOffset() + max_ending_offset,
+ EaseTimingFunction::Create()));
animation_direction_ = direction;
client_->DidChangeTopControlsPosition();
}
@@ -241,8 +240,8 @@ bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) {
if (!top_controls_animation_)
return true;
- double time_ms = (time - base::TimeTicks()).InMillisecondsF();
- float new_offset = top_controls_animation_->GetValue(time_ms);
+ base::TimeDelta animation_time = time - base::TimeTicks();
+ float new_offset = top_controls_animation_->GetValue(animation_time);
if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) ||
(animation_direction_ == HIDING_CONTROLS
diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc
index 4dfe86a..460726f 100644
--- a/cc/layers/layer_unittest.cc
+++ b/cc/layers/layer_unittest.cc
@@ -1144,8 +1144,9 @@ TEST(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) {
static bool AddTestAnimation(Layer* layer) {
scoped_ptr<KeyframedFloatAnimationCurve> curve =
KeyframedFloatAnimationCurve::Create();
- curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.3f, nullptr));
- curve->AddKeyframe(FloatKeyframe::Create(1.0, 0.7f, nullptr));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.3f, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.7f, nullptr));
scoped_ptr<Animation> animation =
Animation::Create(curve.Pass(), 0, 0, Animation::Opacity);
diff --git a/cc/test/animation_test_common.cc b/cc/test/animation_test_common.cc
index fba3166..602374f 100644
--- a/cc/test/animation_test_common.cc
+++ b/cc/test/animation_test_common.cc
@@ -8,6 +8,7 @@
#include "cc/animation/keyframed_animation_curve.h"
#include "cc/animation/layer_animation_controller.h"
#include "cc/animation/transform_operations.h"
+#include "cc/base/time_util.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_impl.h"
@@ -35,8 +36,10 @@ int AddOpacityTransition(Target* target,
if (!use_timing_function)
func = EaseTimingFunction::Create();
if (duration > 0.0)
- curve->AddKeyframe(FloatKeyframe::Create(0.0, start_opacity, func.Pass()));
- curve->AddKeyframe(FloatKeyframe::Create(duration, end_opacity, nullptr));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta(), start_opacity, func.Pass()));
+ curve->AddKeyframe(FloatKeyframe::Create(
+ base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr));
int id = AnimationIdProvider::NextAnimationId();
@@ -60,11 +63,12 @@ int AddAnimatedTransform(Target* target,
curve(KeyframedTransformAnimationCurve::Create());
if (duration > 0.0) {
- curve->AddKeyframe(
- TransformKeyframe::Create(0.0, start_operations, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(),
+ start_operations, nullptr));
}
- curve->AddKeyframe(TransformKeyframe::Create(duration, operations, nullptr));
+ curve->AddKeyframe(TransformKeyframe::Create(
+ base::TimeDelta::FromSecondsD(duration), operations, nullptr));
int id = AnimationIdProvider::NextAnimationId();
@@ -106,12 +110,14 @@ int AddAnimatedFilter(Target* target,
FilterOperations start_filters;
start_filters.Append(
FilterOperation::CreateBrightnessFilter(start_brightness));
- curve->AddKeyframe(FilterKeyframe::Create(0.0, start_filters, nullptr));
+ curve->AddKeyframe(
+ FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
}
FilterOperations filters;
filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness));
- curve->AddKeyframe(FilterKeyframe::Create(duration, filters, nullptr));
+ curve->AddKeyframe(FilterKeyframe::Create(
+ base::TimeDelta::FromSecondsD(duration), filters, nullptr));
int id = AnimationIdProvider::NextAnimationId();
@@ -137,7 +143,7 @@ base::TimeDelta FakeFloatAnimationCurve::Duration() const {
return duration_;
}
-float FakeFloatAnimationCurve::GetValue(double now) const {
+float FakeFloatAnimationCurve::GetValue(base::TimeDelta now) const {
return 0.0f;
}
@@ -155,7 +161,7 @@ base::TimeDelta FakeTransformTransition::Duration() const {
return duration_;
}
-gfx::Transform FakeTransformTransition::GetValue(double time) const {
+gfx::Transform FakeTransformTransition::GetValue(base::TimeDelta time) const {
return gfx::Transform();
}
@@ -188,11 +194,11 @@ base::TimeDelta FakeFloatTransition::Duration() const {
return duration_;
}
-float FakeFloatTransition::GetValue(double time) const {
- time /= duration_.InSecondsF();
- if (time >= 1.0)
- time = 1.0;
- return (1.0 - time) * from_ + time * to_;
+float FakeFloatTransition::GetValue(base::TimeDelta time) const {
+ double progress = TimeUtil::Divide(time, duration_);
+ if (progress >= 1.0)
+ progress = 1.0;
+ return (1.0 - progress) * from_ + progress * to_;
}
FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver()
diff --git a/cc/test/animation_test_common.h b/cc/test/animation_test_common.h
index a69f0c9..2c41518 100644
--- a/cc/test/animation_test_common.h
+++ b/cc/test/animation_test_common.h
@@ -27,7 +27,7 @@ class FakeFloatAnimationCurve : public FloatAnimationCurve {
~FakeFloatAnimationCurve() override;
base::TimeDelta Duration() const override;
- float GetValue(double now) const override;
+ float GetValue(base::TimeDelta now) const override;
scoped_ptr<AnimationCurve> Clone() const override;
private:
@@ -40,7 +40,7 @@ class FakeTransformTransition : public TransformAnimationCurve {
~FakeTransformTransition() override;
base::TimeDelta Duration() const override;
- gfx::Transform GetValue(double time) const override;
+ gfx::Transform GetValue(base::TimeDelta time) const override;
bool AnimatedBoundsForBox(const gfx::BoxF& box,
gfx::BoxF* bounds) const override;
bool AffectsScale() const override;
@@ -60,7 +60,7 @@ class FakeFloatTransition : public FloatAnimationCurve {
~FakeFloatTransition() override;
base::TimeDelta Duration() const override;
- float GetValue(double time) const override;
+ float GetValue(base::TimeDelta time) const override;
scoped_ptr<AnimationCurve> Clone() const override;
diff --git a/cc/test/geometry_test_utils.h b/cc/test/geometry_test_utils.h
index d8829e0..b743f58 100644
--- a/cc/test/geometry_test_utils.h
+++ b/cc/test/geometry_test_utils.h
@@ -68,6 +68,12 @@ do { \
EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \
} while (false)
+#define EXPECT_VECTOR2DF_NEAR(expected, actual, abs_error) \
+ do { \
+ EXPECT_NEAR((expected).x(), (actual).x(), (abs_error)); \
+ EXPECT_NEAR((expected).y(), (actual).y(), (abs_error)); \
+ } while (false)
+
#define EXPECT_FLOAT_ARRAY_EQ(expected, actual, count) \
do { \
for (int i = 0; i < count; i++) { \
diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc
index 89cc554..c0e0c90 100644
--- a/cc/test/layer_tree_test.cc
+++ b/cc/test/layer_tree_test.cc
@@ -524,10 +524,8 @@ void LayerTreeTest::PostAddAnimationToMainThread(
Layer* layer_to_receive_animation) {
main_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&LayerTreeTest::DispatchAddAnimation,
- main_thread_weak_ptr_,
- base::Unretained(layer_to_receive_animation),
- 0.000001));
+ base::Bind(&LayerTreeTest::DispatchAddAnimation, main_thread_weak_ptr_,
+ base::Unretained(layer_to_receive_animation), 0.000004));
}
void LayerTreeTest::PostAddInstantAnimationToMainThread(
diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation.cc
index 9c346e2..8318192 100644
--- a/cc/trees/layer_tree_host_unittest_animation.cc
+++ b/cc/trees/layer_tree_host_unittest_animation.cc
@@ -8,6 +8,7 @@
#include "cc/animation/layer_animation_controller.h"
#include "cc/animation/scroll_offset_animation_curve.h"
#include "cc/animation/timing_function.h"
+#include "cc/base/time_util.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_impl.h"
#include "cc/test/animation_test_common.h"
@@ -503,11 +504,11 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction
const FloatAnimationCurve* curve =
animation->curve()->ToFloatAnimationCurve();
- float start_opacity = curve->GetValue(0.0);
- float end_opacity = curve->GetValue(curve->Duration().InSecondsF());
+ float start_opacity = curve->GetValue(base::TimeDelta());
+ float end_opacity = curve->GetValue(curve->Duration());
float linearly_interpolated_opacity =
0.25f * end_opacity + 0.75f * start_opacity;
- double time = curve->Duration().InSecondsF() * 0.25;
+ base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f);
// If the linear timing function associated with this animation was not
// picked up, then the linearly interpolated opacity would be different
// because of the default ease timing function.
diff --git a/ui/compositor/float_animation_curve_adapter.cc b/ui/compositor/float_animation_curve_adapter.cc
index 3b5e155..d40d701 100644
--- a/ui/compositor/float_animation_curve_adapter.cc
+++ b/ui/compositor/float_animation_curve_adapter.cc
@@ -4,6 +4,8 @@
#include "ui/compositor/float_animation_curve_adapter.h"
+#include "cc/base/time_util.h"
+
namespace ui {
FloatAnimationCurveAdapter::FloatAnimationCurveAdapter(
@@ -26,12 +28,12 @@ scoped_ptr<cc::AnimationCurve> FloatAnimationCurveAdapter::Clone() const {
tween_type_, initial_value_, target_value_, duration_));
}
-float FloatAnimationCurveAdapter::GetValue(double t) const {
- if (t >= duration_.InSecondsF())
+float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const {
+ if (t >= duration_)
return target_value_;
- if (t <= 0.0)
+ if (t <= base::TimeDelta())
return initial_value_;
- double progress = t / duration_.InSecondsF();
+ double progress = cc::TimeUtil::Divide(t, duration_);
return gfx::Tween::FloatValueBetween(
gfx::Tween::CalculateValue(tween_type_, progress),
initial_value_,
diff --git a/ui/compositor/float_animation_curve_adapter.h b/ui/compositor/float_animation_curve_adapter.h
index 88d5870..dc665d4 100644
--- a/ui/compositor/float_animation_curve_adapter.h
+++ b/ui/compositor/float_animation_curve_adapter.h
@@ -23,7 +23,7 @@ class FloatAnimationCurveAdapter : public cc::FloatAnimationCurve {
// FloatAnimationCurve implementation.
base::TimeDelta Duration() const override;
scoped_ptr<cc::AnimationCurve> Clone() const override;
- float GetValue(double t) const override;
+ float GetValue(base::TimeDelta t) const override;
private:
gfx::Tween::Type tween_type_;
diff --git a/ui/compositor/transform_animation_curve_adapter.cc b/ui/compositor/transform_animation_curve_adapter.cc
index 2c11488..1b67ca2 100644
--- a/ui/compositor/transform_animation_curve_adapter.cc
+++ b/ui/compositor/transform_animation_curve_adapter.cc
@@ -4,6 +4,8 @@
#include "ui/compositor/transform_animation_curve_adapter.h"
+#include "cc/base/time_util.h"
+
namespace ui {
TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
@@ -32,12 +34,12 @@ scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
}
gfx::Transform TransformAnimationCurveAdapter::GetValue(
- double t) const {
- if (t >= duration_.InSecondsF())
+ base::TimeDelta t) const {
+ if (t >= duration_)
return target_value_;
- if (t <= 0.0)
+ if (t <= base::TimeDelta())
return initial_value_;
- double progress = t / duration_.InSecondsF();
+ double progress = cc::TimeUtil::Divide(t, duration_);
gfx::DecomposedTransform to_return;
gfx::BlendDecomposedTransforms(&to_return,
@@ -80,7 +82,8 @@ InverseTransformCurveAdapter::InverseTransformCurveAdapter(
: base_curve_(base_curve),
initial_value_(initial_value),
duration_(duration) {
- effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_;
+ effective_initial_value_ =
+ base_curve_.GetValue(base::TimeDelta()) * initial_value_;
}
InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
@@ -95,9 +98,8 @@ scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
}
-gfx::Transform InverseTransformCurveAdapter::GetValue(
- double t) const {
- if (t <= 0.0)
+gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const {
+ if (t <= base::TimeDelta())
return initial_value_;
gfx::Transform base_transform = base_curve_.GetValue(t);
diff --git a/ui/compositor/transform_animation_curve_adapter.h b/ui/compositor/transform_animation_curve_adapter.h
index c08024d..5bbe6a3 100644
--- a/ui/compositor/transform_animation_curve_adapter.h
+++ b/ui/compositor/transform_animation_curve_adapter.h
@@ -27,7 +27,7 @@ class COMPOSITOR_EXPORT TransformAnimationCurveAdapter
// TransformAnimationCurve implementation.
base::TimeDelta Duration() const override;
scoped_ptr<AnimationCurve> Clone() const override;
- gfx::Transform GetValue(double t) const override;
+ gfx::Transform GetValue(base::TimeDelta t) const override;
bool AnimatedBoundsForBox(const gfx::BoxF& box,
gfx::BoxF* bounds) const override;
bool AffectsScale() const override;
@@ -57,7 +57,7 @@ class COMPOSITOR_EXPORT InverseTransformCurveAdapter
base::TimeDelta Duration() const override;
scoped_ptr<AnimationCurve> Clone() const override;
- gfx::Transform GetValue(double t) const override;
+ gfx::Transform GetValue(base::TimeDelta t) const override;
bool AnimatedBoundsForBox(const gfx::BoxF& box,
gfx::BoxF* bounds) const override;
bool AffectsScale() const override;
diff --git a/ui/compositor/transform_animation_curve_adapter_unittest.cc b/ui/compositor/transform_animation_curve_adapter_unittest.cc
index b68e862..10ee668 100644
--- a/ui/compositor/transform_animation_curve_adapter_unittest.cc
+++ b/ui/compositor/transform_animation_curve_adapter_unittest.cc
@@ -7,6 +7,7 @@
#include <sstream>
#include "base/time/time.h"
+#include "cc/base/time_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/test/test_utils.h"
@@ -41,13 +42,12 @@ TEST(InverseTransformCurveAdapterTest, InversesTransform) {
static const int kSteps = 1000;
double step = 1.0 / kSteps;
for (int i = 0; i <= kSteps ; ++i) {
+ base::TimeDelta time_step = cc::TimeUtil::Scale(duration, i * step);
std::ostringstream message;
message << "Step " << i << " of " << kSteps;
SCOPED_TRACE(message.str());
- gfx::Transform progress_parent_transform =
- parent_curve.GetValue(i*step);
- gfx::Transform progress_child_transform =
- child_curve.GetValue(i*step);
+ gfx::Transform progress_parent_transform = parent_curve.GetValue(time_step);
+ gfx::Transform progress_child_transform = child_curve.GetValue(time_step);
CheckApproximatelyEqual(effective_child_transform,
progress_parent_transform *
progress_child_transform);