diff options
author | John Reck <jreck@google.com> | 2014-05-13 16:17:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-13 16:17:03 +0000 |
commit | 515396a6b5ee3eab57fed87ee0f4aa63783e2e61 (patch) | |
tree | 5cbed05ec1c78e725fb7bb1bd01c44721028e0c9 /libs | |
parent | b657deaf47347e9b198eeebacebae28753638378 (diff) | |
parent | c8ac775659fd252ce2cc9a61837c170ff70f0a1a (diff) | |
download | frameworks_base-515396a6b5ee3eab57fed87ee0f4aa63783e2e61.zip frameworks_base-515396a6b5ee3eab57fed87ee0f4aa63783e2e61.tar.gz frameworks_base-515396a6b5ee3eab57fed87ee0f4aa63783e2e61.tar.bz2 |
Merge "More native interpolators"
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/Interpolator.cpp | 58 | ||||
-rw-r--r-- | libs/hwui/Interpolator.h | 60 |
2 files changed, 115 insertions, 3 deletions
diff --git a/libs/hwui/Interpolator.cpp b/libs/hwui/Interpolator.cpp index b56648e..1f84b86 100644 --- a/libs/hwui/Interpolator.cpp +++ b/libs/hwui/Interpolator.cpp @@ -18,7 +18,7 @@ #include "Interpolator.h" -#include <math.h> +#include <cmath> #include <cutils/log.h> #include "utils/MathUtils.h" @@ -34,6 +34,62 @@ float AccelerateDecelerateInterpolator::interpolate(float input) { return (float)(cosf((input + 1) * M_PI) / 2.0f) + 0.5f; } +float AccelerateInterpolator::interpolate(float input) { + if (mFactor == 1.0f) { + return input * input; + } else { + return pow(input, mDoubleFactor); + } +} + +float AnticipateInterpolator::interpolate(float t) { + return t * t * ((mTension + 1) * t - mTension); +} + +static float a(float t, float s) { + return t * t * ((s + 1) * t - s); +} + +static float o(float t, float s) { + return t * t * ((s + 1) * t + s); +} + +float AnticipateOvershootInterpolator::interpolate(float t) { + if (t < 0.5f) return 0.5f * a(t * 2.0f, mTension); + else return 0.5f * (o(t * 2.0f - 2.0f, mTension) + 2.0f); +} + +static float bounce(float t) { + return t * t * 8.0f; +} + +float BounceInterpolator::interpolate(float t) { + t *= 1.1226f; + if (t < 0.3535f) return bounce(t); + else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f; + else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f; + else return bounce(t - 1.0435f) + 0.95f; +} + +float CycleInterpolator::interpolate(float input) { + return sinf(2 * mCycles * M_PI * input); +} + +float DecelerateInterpolator::interpolate(float input) { + float result; + if (mFactor == 1.0f) { + result = 1.0f - (1.0f - input) * (1.0f - input); + } else { + result = 1.0f - pow((1.0f - input), 2 * mFactor); + } + return result; +} + +float OvershootInterpolator::interpolate(float t) { + t -= 1.0f; + return t * t * ((mTension + 1) * t + mTension) + 1.0f; +} + LUTInterpolator::LUTInterpolator(float* values, size_t size) { mValues = values; mSize = size; diff --git a/libs/hwui/Interpolator.h b/libs/hwui/Interpolator.h index 44fb37c..dfa0a85 100644 --- a/libs/hwui/Interpolator.h +++ b/libs/hwui/Interpolator.h @@ -37,10 +37,66 @@ protected: class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator { public: - AccelerateDecelerateInterpolator() {} - virtual ~AccelerateDecelerateInterpolator() {} + virtual float interpolate(float input); +}; + +class ANDROID_API AccelerateInterpolator : public Interpolator { +public: + AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {} + virtual float interpolate(float input); +private: + const float mFactor; + const float mDoubleFactor; +}; + +class ANDROID_API AnticipateInterpolator : public Interpolator { +public: + AnticipateInterpolator(float tension) : mTension(tension) {} + virtual float interpolate(float input); +private: + const float mTension; +}; + +class ANDROID_API AnticipateOvershootInterpolator : public Interpolator { +public: + AnticipateOvershootInterpolator(float tension) : mTension(tension) {} + virtual float interpolate(float input); +private: + const float mTension; +}; + +class ANDROID_API BounceInterpolator : public Interpolator { +public: + virtual float interpolate(float input); +}; + +class ANDROID_API CycleInterpolator : public Interpolator { +public: + CycleInterpolator(float cycles) : mCycles(cycles) {} + virtual float interpolate(float input); +private: + const float mCycles; +}; + +class ANDROID_API DecelerateInterpolator : public Interpolator { +public: + DecelerateInterpolator(float factor) : mFactor(factor) {} + virtual float interpolate(float input); +private: + const float mFactor; +}; +class ANDROID_API LinearInterpolator : public Interpolator { +public: + virtual float interpolate(float input) { return input; } +}; + +class ANDROID_API OvershootInterpolator : public Interpolator { +public: + OvershootInterpolator(float tension) : mTension(tension) {} virtual float interpolate(float input); +private: + const float mTension; }; class ANDROID_API LUTInterpolator : public Interpolator { |