summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/Animator.h1
-rw-r--r--libs/hwui/Interpolator.cpp93
-rw-r--r--libs/hwui/Interpolator.h78
-rw-r--r--libs/hwui/utils/MathUtils.h8
4 files changed, 176 insertions, 4 deletions
diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h
index 86fc7c3..52a1807 100644
--- a/libs/hwui/Animator.h
+++ b/libs/hwui/Animator.h
@@ -45,6 +45,7 @@ public:
ANDROID_API void setInterpolator(Interpolator* interpolator);
ANDROID_API void setDuration(nsecs_t durationInMs);
+ ANDROID_API nsecs_t duration() { return mDuration; }
ANDROID_API void setListener(AnimationListener* listener) {
mListener = listener;
}
diff --git a/libs/hwui/Interpolator.cpp b/libs/hwui/Interpolator.cpp
index 004ddf5..1f84b86 100644
--- a/libs/hwui/Interpolator.cpp
+++ b/libs/hwui/Interpolator.cpp
@@ -13,9 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#define LOG_TAG "Interpolator"
+
#include "Interpolator.h"
-#include <math.h>
+#include <cmath>
+#include <cutils/log.h>
+
+#include "utils/MathUtils.h"
namespace android {
namespace uirenderer {
@@ -28,5 +34,90 @@ 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;
+}
+
+LUTInterpolator::~LUTInterpolator() {
+ delete mValues;
+ mValues = 0;
+}
+
+float LUTInterpolator::interpolate(float input) {
+ float lutpos = input * mSize;
+ if (lutpos >= (mSize - 1)) {
+ return mValues[mSize - 1];
+ }
+
+ float ipart, weight;
+ weight = modff(lutpos, &ipart);
+
+ int i1 = (int) ipart;
+ int i2 = MathUtils::min(i1 + 1, mSize - 1);
+
+ float v1 = mValues[i1];
+ float v2 = mValues[i2];
+
+ return MathUtils::lerp(v1, v2, weight);
+}
+
+
} /* namespace uirenderer */
} /* namespace android */
diff --git a/libs/hwui/Interpolator.h b/libs/hwui/Interpolator.h
index 2cfb60c..dfa0a85 100644
--- a/libs/hwui/Interpolator.h
+++ b/libs/hwui/Interpolator.h
@@ -16,6 +16,10 @@
#ifndef INTERPOLATOR_H
#define INTERPOLATOR_H
+#include <stddef.h>
+
+#include <cutils/compiler.h>
+
namespace android {
namespace uirenderer {
@@ -31,12 +35,80 @@ protected:
Interpolator() {}
};
-class AccelerateDecelerateInterpolator : public Interpolator {
+class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
+public:
+ 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:
- AccelerateDecelerateInterpolator() {}
- virtual ~AccelerateDecelerateInterpolator() {}
+ 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 {
+public:
+ LUTInterpolator(float* values, size_t size);
+ ~LUTInterpolator();
+
+ virtual float interpolate(float input);
+
+private:
+ float* mValues;
+ size_t mSize;
};
} /* namespace uirenderer */
diff --git a/libs/hwui/utils/MathUtils.h b/libs/hwui/utils/MathUtils.h
index 8ba44dc..1a7082b 100644
--- a/libs/hwui/utils/MathUtils.h
+++ b/libs/hwui/utils/MathUtils.h
@@ -33,6 +33,14 @@ public:
inline static bool isPositive(float value) {
return value >= gNonZeroEpsilon;
}
+
+ inline static int min(int a, int b) {
+ return a < b ? a : b;
+ }
+
+ inline static float lerp(float v1, float v2, float t) {
+ return v1 + ((v2 - v1) * t);
+ }
}; // class MathUtils
} /* namespace uirenderer */