diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 10:00:36 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 10:00:36 +0000 |
commit | befd0f518ccc7d4e627e8748dcd7f4ff8089591b (patch) | |
tree | 4bf751be8490cfa2af31bda2b37de86775987d09 /cc/animation/timing_function.cc | |
parent | f1f1c77bb31371ef7c7ede442364a369ee6e4664 (diff) | |
download | chromium_src-befd0f518ccc7d4e627e8748dcd7f4ff8089591b.zip chromium_src-befd0f518ccc7d4e627e8748dcd7f4ff8089591b.tar.gz chromium_src-befd0f518ccc7d4e627e8748dcd7f4ff8089591b.tar.bz2 |
cc: Chromify TimingFunction
R=danakj@chromium.org
BUG=none
Review URL: https://chromiumcodereview.appspot.com/12991003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation/timing_function.cc')
-rw-r--r-- | cc/animation/timing_function.cc | 151 |
1 files changed, 77 insertions, 74 deletions
diff --git a/cc/animation/timing_function.cc b/cc/animation/timing_function.cc index c0af3c2..769e9f0 100644 --- a/cc/animation/timing_function.cc +++ b/cc/animation/timing_function.cc @@ -13,96 +13,99 @@ namespace { // Dot14 has 14 bits for decimal places, and the remainder for whole numbers. typedef int Dot14; -#define DOT14_ONE (1 << 14) -#define DOT14_HALF (1 << 13) - -#define Dot14ToFloat(x) ((x) / 16384.f) +#define DOT14_ONE (1 << 14) +#define DOT14_HALF (1 << 13) static inline Dot14 Dot14Mul(Dot14 a, Dot14 b) { - return (a * b + DOT14_HALF) >> 14; + return (a * b + DOT14_HALF) >> 14; } static inline Dot14 EvalCubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C) { - return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t); + return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t); } static inline Dot14 PinAndConvert(SkScalar x) { - if (x <= 0) - return 0; - if (x >= SK_Scalar1) - return DOT14_ONE; - return SkScalarToFixed(x) >> 2; + if (x <= 0) + return 0; + if (x >= SK_Scalar1) + return DOT14_ONE; + return SkScalarToFixed(x) >> 2; } -SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by, - SkScalar cx, SkScalar cy, +SkScalar SkUnitCubicInterp(SkScalar bx, + SkScalar by, + SkScalar cx, + SkScalar cy, SkScalar value) { - Dot14 x = PinAndConvert(value); - - if (x == 0) return 0; - if (x == DOT14_ONE) return SK_Scalar1; - - Dot14 b = PinAndConvert(bx); - Dot14 c = PinAndConvert(cx); - - // Now compute our coefficients from the control points. - // t -> 3b - // t^2 -> 3c - 6b - // t^3 -> 3b - 3c + 1 - Dot14 A = 3 * b; - Dot14 B = 3 * (c - 2 * b); - Dot14 C = 3 * (b - c) + DOT14_ONE; - - // Now search for a t value given x. - Dot14 t = DOT14_HALF; - Dot14 dt = DOT14_HALF; - for (int i = 0; i < 13; i++) { - dt >>= 1; - Dot14 guess = EvalCubic(t, A, B, C); - if (x < guess) - t -= dt; - else - t += dt; - } - - // Now we have t, so compute the coefficient for Y and evaluate. - b = PinAndConvert(by); - c = PinAndConvert(cy); - A = 3 * b; - B = 3 * (c - 2 * b); - C = 3 * (b - c) + DOT14_ONE; - return SkFixedToScalar(EvalCubic(t, A, B, C) << 2); + Dot14 x = PinAndConvert(value); + + if (x == 0) + return 0; + if (x == DOT14_ONE) + return SK_Scalar1; + + Dot14 b = PinAndConvert(bx); + Dot14 c = PinAndConvert(cx); + + // Now compute our coefficients from the control points. + // t -> 3b + // t^2 -> 3c - 6b + // t^3 -> 3b - 3c + 1 + Dot14 A = 3 * b; + Dot14 B = 3 * (c - 2 * b); + Dot14 C = 3 * (b - c) + DOT14_ONE; + + // Now search for a t value given x. + Dot14 t = DOT14_HALF; + Dot14 dt = DOT14_HALF; + for (int i = 0; i < 13; i++) { + dt >>= 1; + Dot14 guess = EvalCubic(t, A, B, C); + if (x < guess) + t -= dt; + else + t += dt; + } + + // Now we have t, so compute the coefficient for Y and evaluate. + b = PinAndConvert(by); + c = PinAndConvert(cy); + A = 3 * b; + B = 3 * (c - 2 * b); + C = 3 * (b - c) + DOT14_ONE; + return SkFixedToScalar(EvalCubic(t, A, B, C) << 2); } } // namespace namespace cc { -TimingFunction::TimingFunction() { -} +TimingFunction::TimingFunction() {} -TimingFunction::~TimingFunction() { -} +TimingFunction::~TimingFunction() {} double TimingFunction::Duration() const { - return 1.0; + return 1.0; } -scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::create( - double x1, double y1, double x2, double y2) { - return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, 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) +CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, + double y1, + double x2, + double y2) : x1_(SkDoubleToScalar(x1)), y1_(SkDoubleToScalar(y1)), x2_(SkDoubleToScalar(x2)), - y2_(SkDoubleToScalar(y2)) { -} + y2_(SkDoubleToScalar(y2)) {} -CubicBezierTimingFunction::~CubicBezierTimingFunction() { -} +CubicBezierTimingFunction::~CubicBezierTimingFunction() {} float CubicBezierTimingFunction::GetValue(double x) const { SkScalar value = SkUnitCubicInterp(x1_, y1_, x2_, y2_, x); @@ -116,24 +119,24 @@ scoped_ptr<AnimationCurve> CubicBezierTimingFunction::Clone() const { // 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.0).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.0, 1.0, 1.0).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.0, 0.58, 1.0).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, 0.58, 1).PassAs<TimingFunction>(); } } // namespace cc |