Skip to content

Commit

Permalink
Make Keyframe use TimeTicks/TimeDelta to represent time instead of do…
Browse files Browse the repository at this point in the history
…uble.

BUG=178171

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

Cr-Commit-Position: refs/heads/master@{#304612}
  • Loading branch information
behara.ms authored and Commit bot committed Nov 18, 2014
1 parent ed1dafa commit 591d77f
Show file tree
Hide file tree
Showing 26 changed files with 590 additions and 433 deletions.
8 changes: 4 additions & 4 deletions cc/animation/animation_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
87 changes: 45 additions & 42 deletions cc/animation/keyframed_animation_curve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -30,24 +31,26 @@ 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;
}

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.
Expand All @@ -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);
Expand All @@ -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() {}

Expand All @@ -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() {}

Expand All @@ -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() {}

Expand All @@ -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() {}

Expand Down Expand Up @@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Expand All @@ -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();

Expand Down
Loading

0 comments on commit 591d77f

Please sign in to comment.