summaryrefslogtreecommitdiff
path: root/libs/hwui/Interpolator.cpp
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2016-11-29 14:48:25 -0800
committerDoris Liu <tianliu@google.com>2016-11-30 16:03:23 -0800
commit9e9eeeeb78d94804cda00c2b36e56fdaca5552d6 (patch)
treeb1aa34736ba2f6683ebc8c995f1034d93342667b /libs/hwui/Interpolator.cpp
parentca67fa44ffc8a39701bfa0ca155cfa087d8806ce (diff)
Introduce PathInterpolator to native animators
For interpolators defined with a path, PathInterpolator is more accurate and likely less costly for longer animations than what are currently using as a substiute - LUTInterpolator. Test: manual test and added a unit test BUG: 32830741 Change-Id: I867c7a28e4261392cce9c45a2992ab4fd120c496
Diffstat (limited to 'libs/hwui/Interpolator.cpp')
-rw-r--r--libs/hwui/Interpolator.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/hwui/Interpolator.cpp b/libs/hwui/Interpolator.cpp
index cc47f0052b73..ae9ee6ea2593 100644
--- a/libs/hwui/Interpolator.cpp
+++ b/libs/hwui/Interpolator.cpp
@@ -88,6 +88,39 @@ float OvershootInterpolator::interpolate(float t) {
return t * t * ((mTension + 1) * t + mTension) + 1.0f;
}
+float PathInterpolator::interpolate(float t) {
+ if (t <= 0) {
+ return 0;
+ } else if (t >= 1) {
+ return 1;
+ }
+ // Do a binary search for the correct x to interpolate between.
+ size_t startIndex = 0;
+ size_t endIndex = mX.size() - 1;
+
+ while (endIndex > startIndex + 1) {
+ int midIndex = (startIndex + endIndex) / 2;
+ if (t < mX[midIndex]) {
+ endIndex = midIndex;
+ } else {
+ startIndex = midIndex;
+ }
+ }
+
+ float xRange = mX[endIndex] - mX[startIndex];
+ if (xRange == 0) {
+ return mY[startIndex];
+ }
+
+ float tInRange = t - mX[startIndex];
+ float fraction = tInRange / xRange;
+
+ float startY = mY[startIndex];
+ float endY = mY[endIndex];
+ return startY + (fraction * (endY - startY));
+
+}
+
LUTInterpolator::LUTInterpolator(float* values, size_t size)
: mValues(values)
, mSize(size) {