summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/Animator.cpp7
-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/renderthread/CanvasContext.cpp38
-rw-r--r--libs/hwui/renderthread/CanvasContext.h3
-rw-r--r--libs/hwui/utils/MathUtils.h8
7 files changed, 220 insertions, 8 deletions
diff --git a/libs/hwui/Animator.cpp b/libs/hwui/Animator.cpp
index 6a3003e..a033f86 100644
--- a/libs/hwui/Animator.cpp
+++ b/libs/hwui/Animator.cpp
@@ -199,13 +199,18 @@ float CanvasPropertyPaintAnimator::getValue() const {
return -1;
}
+static uint8_t to_uint8(float value) {
+ int c = (int) (value + .5f);
+ return static_cast<uint8_t>( c < 0 ? 0 : c > 255 ? 255 : c );
+}
+
void CanvasPropertyPaintAnimator::setValue(float value) {
switch (mField) {
case STROKE_WIDTH:
mProperty->value.setStrokeWidth(value);
return;
case ALPHA:
- mProperty->value.setAlpha(value);
+ mProperty->value.setAlpha(to_uint8(value));
return;
}
LOG_ALWAYS_FATAL("Unknown field %d", (int) mField);
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/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 5a23158..5754536 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -98,6 +98,8 @@ public:
bool enableDirtyRegions(EGLSurface surface);
+ void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
+
private:
GlobalContext();
// GlobalContext is never destroyed, method is purposely not implemented
@@ -118,6 +120,10 @@ private:
bool mCanSetDirtyRegions;
EGLSurface mCurrentSurface;
+
+ sp<GraphicBuffer> mAtlasBuffer;
+ int64_t* mAtlasMap;
+ size_t mAtlasMapSize;
};
GlobalContext* GlobalContext::sContext = 0;
@@ -135,7 +141,9 @@ GlobalContext::GlobalContext()
, mEglContext(EGL_NO_CONTEXT)
, mPBufferSurface(EGL_NO_SURFACE)
, mRequestDirtyRegions(load_dirty_regions_property())
- , mCurrentSurface(EGL_NO_SURFACE) {
+ , mCurrentSurface(EGL_NO_SURFACE)
+ , mAtlasMap(NULL)
+ , mAtlasMapSize(0) {
mCanSetDirtyRegions = mRequestDirtyRegions;
ALOGD("Render dirty regions requested: %s", mRequestDirtyRegions ? "true" : "false");
}
@@ -201,9 +209,28 @@ void GlobalContext::createContext() {
"Failed to create context, error = %s", egl_error_str());
}
+void GlobalContext::setTextureAtlas(const sp<GraphicBuffer>& buffer,
+ int64_t* map, size_t mapSize) {
+
+ // Already initialized
+ if (mAtlasBuffer.get()) {
+ ALOGW("Multiple calls to setTextureAtlas!");
+ delete map;
+ return;
+ }
+
+ mAtlasBuffer = buffer;
+ mAtlasMap = map;
+ mAtlasMapSize = mapSize;
+
+ if (hasContext()) {
+ usePBufferSurface();
+ initAtlas();
+ }
+}
+
void GlobalContext::initAtlas() {
- // TODO implement
- // For now just run without an atlas
+ Caches::getInstance().assetAtlas.init(mAtlasBuffer, mAtlasMap, mAtlasMapSize);
}
void GlobalContext::usePBufferSurface() {
@@ -533,6 +560,11 @@ void CanvasContext::requireGlContext() {
}
}
+void CanvasContext::setTextureAtlas(const sp<GraphicBuffer>& buffer,
+ int64_t* map, size_t mapSize) {
+ GlobalContext::get()->setTextureAtlas(buffer, map, mapSize);
+}
+
} /* namespace renderthread */
} /* namespace uirenderer */
} /* namespace android */
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index dcb9858..a793d42 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -70,6 +70,9 @@ public:
Layer* createRenderLayer(int width, int height);
Layer* createTextureLayer();
+ ANDROID_API static void setTextureAtlas(const sp<GraphicBuffer>& buffer,
+ int64_t* map, size_t mapSize);
+
private:
void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info);
void prepareTree(TreeInfo& info);
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 */