cc: Switch time_source.h and timing_function* to Chrome coding style.
BUG=144576,144577 TEST=cc_unittests R=jamesr@chromium.org Review URL: https://codereview.chromium.org/11411024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168302 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -11,6 +11,8 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Thread;
|
||||
|
||||
// This timer implements a time source that achieves the specified interval
|
||||
// in face of millisecond-precision delayed callbacks and random queueing delays.
|
||||
class CC_EXPORT DelayBasedTimeSource : public TimeSource {
|
||||
|
@ -11,14 +11,12 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Thread;
|
||||
|
||||
class TimeSourceClient {
|
||||
public:
|
||||
virtual void onTimerTick() = 0;
|
||||
public:
|
||||
virtual void onTimerTick() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~TimeSourceClient() { }
|
||||
protected:
|
||||
virtual ~TimeSourceClient() {}
|
||||
};
|
||||
|
||||
// An generic interface for getting a reliably-ticking timesource of
|
||||
@ -27,20 +25,22 @@ protected:
|
||||
// Be sure to call setActive(false) before releasing your reference to the
|
||||
// timer, or it will keep on ticking!
|
||||
class CC_EXPORT TimeSource : public base::RefCounted<TimeSource> {
|
||||
public:
|
||||
virtual void setClient(TimeSourceClient*) = 0;
|
||||
virtual void setActive(bool) = 0;
|
||||
virtual bool active() const = 0;
|
||||
virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval) = 0;
|
||||
virtual base::TimeTicks lastTickTime() = 0;
|
||||
virtual base::TimeTicks nextTickTime() = 0;
|
||||
public:
|
||||
virtual void setClient(TimeSourceClient*) = 0;
|
||||
virtual void setActive(bool) = 0;
|
||||
virtual bool active() const = 0;
|
||||
virtual void setTimebaseAndInterval(base::TimeTicks timebase,
|
||||
base::TimeDelta interval) = 0;
|
||||
virtual base::TimeTicks lastTickTime() = 0;
|
||||
virtual base::TimeTicks nextTickTime() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~TimeSource() { }
|
||||
protected:
|
||||
virtual ~TimeSource() {}
|
||||
|
||||
private:
|
||||
friend class base::RefCounted<TimeSource>;
|
||||
private:
|
||||
friend class base::RefCounted<TimeSource>;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_TIME_SOURCE_H_
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cc/timing_function.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkMath.h"
|
||||
|
||||
// TODO(danakj) These methods come from SkInterpolator.cpp. When such a method
|
||||
@ -17,18 +18,15 @@ typedef int Dot14;
|
||||
|
||||
#define Dot14ToFloat(x) ((x) / 16384.f)
|
||||
|
||||
static inline Dot14 Dot14Mul(Dot14 a, Dot14 b)
|
||||
{
|
||||
static inline Dot14 Dot14Mul(Dot14 a, Dot14 b) {
|
||||
return (a * b + DOT14_HALF) >> 14;
|
||||
}
|
||||
|
||||
static inline Dot14 EvalCubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C)
|
||||
{
|
||||
static inline Dot14 EvalCubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C) {
|
||||
return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t);
|
||||
}
|
||||
|
||||
static inline Dot14 PinAndConvert(SkScalar x)
|
||||
{
|
||||
static inline Dot14 PinAndConvert(SkScalar x) {
|
||||
if (x <= 0)
|
||||
return 0;
|
||||
if (x >= SK_Scalar1)
|
||||
@ -36,8 +34,9 @@ static inline Dot14 PinAndConvert(SkScalar x)
|
||||
return SkScalarToFixed(x) >> 2;
|
||||
}
|
||||
|
||||
SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by, SkScalar cx, SkScalar cy, SkScalar value)
|
||||
{
|
||||
SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by,
|
||||
SkScalar cx, SkScalar cy,
|
||||
SkScalar value) {
|
||||
Dot14 x = PinAndConvert(value);
|
||||
|
||||
if (x == 0) return 0;
|
||||
@ -75,70 +74,65 @@ SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by, SkScalar cx, SkScalar cy, S
|
||||
return SkFixedToScalar(EvalCubic(t, A, B, C) << 2);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
|
||||
TimingFunction::TimingFunction()
|
||||
{
|
||||
TimingFunction::TimingFunction() {
|
||||
}
|
||||
|
||||
TimingFunction::~TimingFunction()
|
||||
{
|
||||
TimingFunction::~TimingFunction() {
|
||||
}
|
||||
|
||||
double TimingFunction::duration() const
|
||||
{
|
||||
double TimingFunction::duration() const {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::create(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::create(
|
||||
double x1, double y1, double x2, double y2) {
|
||||
return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, double y1, double x2, double y2)
|
||||
: m_x1(SkDoubleToScalar(x1))
|
||||
, m_y1(SkDoubleToScalar(y1))
|
||||
, m_x2(SkDoubleToScalar(x2))
|
||||
, m_y2(SkDoubleToScalar(y2))
|
||||
{
|
||||
CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, double y1,
|
||||
double x2, double y2)
|
||||
: x1_(SkDoubleToScalar(x1)),
|
||||
y1_(SkDoubleToScalar(y1)),
|
||||
x2_(SkDoubleToScalar(x2)),
|
||||
y2_(SkDoubleToScalar(y2)) {
|
||||
}
|
||||
|
||||
CubicBezierTimingFunction::~CubicBezierTimingFunction()
|
||||
{
|
||||
CubicBezierTimingFunction::~CubicBezierTimingFunction() {
|
||||
}
|
||||
|
||||
float CubicBezierTimingFunction::getValue(double x) const
|
||||
{
|
||||
SkScalar value = SkUnitCubicInterp(m_x1, m_y1, m_x2, m_y2, x);
|
||||
return SkScalarToFloat(value);
|
||||
float CubicBezierTimingFunction::getValue(double x) const {
|
||||
SkScalar value = SkUnitCubicInterp(x1_, y1_, x2_, y2_, x);
|
||||
return SkScalarToFloat(value);
|
||||
}
|
||||
|
||||
scoped_ptr<AnimationCurve> CubicBezierTimingFunction::clone() const
|
||||
{
|
||||
return make_scoped_ptr(new CubicBezierTimingFunction(*this)).PassAs<AnimationCurve>();
|
||||
scoped_ptr<AnimationCurve> CubicBezierTimingFunction::clone() const {
|
||||
return make_scoped_ptr(
|
||||
new CubicBezierTimingFunction(*this)).PassAs<AnimationCurve>();
|
||||
}
|
||||
|
||||
// These numbers come from http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
|
||||
scoped_ptr<TimingFunction> EaseTimingFunction::create()
|
||||
{
|
||||
return CubicBezierTimingFunction::create(0.25, 0.1, 0.25, 1).PassAs<TimingFunction>();
|
||||
scoped_ptr<TimingFunction> EaseTimingFunction::create() {
|
||||
return CubicBezierTimingFunction::create(
|
||||
0.25, 0.1, 0.25, 1).PassAs<TimingFunction>();
|
||||
}
|
||||
|
||||
scoped_ptr<TimingFunction> EaseInTimingFunction::create()
|
||||
{
|
||||
return CubicBezierTimingFunction::create(0.42, 0, 1.0, 1).PassAs<TimingFunction>();
|
||||
scoped_ptr<TimingFunction> EaseInTimingFunction::create() {
|
||||
return CubicBezierTimingFunction::create(
|
||||
0.42, 0, 1.0, 1).PassAs<TimingFunction>();
|
||||
}
|
||||
|
||||
scoped_ptr<TimingFunction> EaseOutTimingFunction::create()
|
||||
{
|
||||
return CubicBezierTimingFunction::create(0, 0, 0.58, 1).PassAs<TimingFunction>();
|
||||
scoped_ptr<TimingFunction> EaseOutTimingFunction::create() {
|
||||
return CubicBezierTimingFunction::create(
|
||||
0, 0, 0.58, 1).PassAs<TimingFunction>();
|
||||
}
|
||||
|
||||
scoped_ptr<TimingFunction> EaseInOutTimingFunction::create()
|
||||
{
|
||||
return CubicBezierTimingFunction::create(0.42, 0, 0.58, 1).PassAs<TimingFunction>();
|
||||
scoped_ptr<TimingFunction> EaseInOutTimingFunction::create() {
|
||||
return CubicBezierTimingFunction::create(
|
||||
0.42, 0, 0.58, 1).PassAs<TimingFunction>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
@ -13,54 +13,55 @@ namespace cc {
|
||||
|
||||
// See http://www.w3.org/TR/css3-transitions/.
|
||||
class CC_EXPORT TimingFunction : public FloatAnimationCurve {
|
||||
public:
|
||||
virtual ~TimingFunction();
|
||||
public:
|
||||
virtual ~TimingFunction();
|
||||
|
||||
// Partial implementation of FloatAnimationCurve.
|
||||
virtual double duration() const OVERRIDE;
|
||||
// Partial implementation of FloatAnimationCurve.
|
||||
virtual double duration() const OVERRIDE;
|
||||
|
||||
protected:
|
||||
TimingFunction();
|
||||
protected:
|
||||
TimingFunction();
|
||||
};
|
||||
|
||||
class CC_EXPORT CubicBezierTimingFunction : public TimingFunction {
|
||||
public:
|
||||
static scoped_ptr<CubicBezierTimingFunction> create(double x1, double y1, double x2, double y2);
|
||||
virtual ~CubicBezierTimingFunction();
|
||||
public:
|
||||
static scoped_ptr<CubicBezierTimingFunction> create(double x1, double y1,
|
||||
double x2, double y2);
|
||||
virtual ~CubicBezierTimingFunction();
|
||||
|
||||
// Partial implementation of FloatAnimationCurve.
|
||||
virtual float getValue(double time) const OVERRIDE;
|
||||
virtual scoped_ptr<AnimationCurve> clone() const OVERRIDE;
|
||||
// Partial implementation of FloatAnimationCurve.
|
||||
virtual float getValue(double time) const OVERRIDE;
|
||||
virtual scoped_ptr<AnimationCurve> clone() const OVERRIDE;
|
||||
|
||||
protected:
|
||||
CubicBezierTimingFunction(double x1, double y1, double x2, double y2);
|
||||
protected:
|
||||
CubicBezierTimingFunction(double x1, double y1, double x2, double y2);
|
||||
|
||||
SkScalar m_x1;
|
||||
SkScalar m_y1;
|
||||
SkScalar m_x2;
|
||||
SkScalar m_y2;
|
||||
SkScalar x1_;
|
||||
SkScalar y1_;
|
||||
SkScalar x2_;
|
||||
SkScalar y2_;
|
||||
};
|
||||
|
||||
class CC_EXPORT EaseTimingFunction {
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
};
|
||||
|
||||
class CC_EXPORT EaseInTimingFunction {
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
};
|
||||
|
||||
class CC_EXPORT EaseOutTimingFunction {
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
};
|
||||
|
||||
class CC_EXPORT EaseInOutTimingFunction {
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
public:
|
||||
static scoped_ptr<TimingFunction> create();
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_TIMING_FUNCTION_H_
|
||||
|
@ -3,13 +3,15 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cc/timing_function.h"
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace cc {
|
||||
namespace {
|
||||
|
||||
TEST(TimingFunctionTest, CubicBezierTimingFunction) {
|
||||
scoped_ptr<CubicBezierTimingFunction> function = CubicBezierTimingFunction::create(0.25, 0, 0.75, 1);
|
||||
scoped_ptr<CubicBezierTimingFunction> function =
|
||||
CubicBezierTimingFunction::create(0.25, 0, 0.75, 1);
|
||||
|
||||
double epsilon = 0.00015;
|
||||
|
||||
|
Reference in New Issue
Block a user