com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp revision 315c329544d7c593d1072b071cbb92d9afe74021
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include "jni.h"
20#include <nativehelper/JNIHelp.h>
21#include <android_runtime/AndroidRuntime.h>
22
23#include <Interpolator.h>
24
25namespace android {
26
27using namespace uirenderer;
28
29#ifdef USE_OPENGL_RENDERER
30
31static jlong createAccelerateDecelerateInterpolator(JNIEnv* env, jobject clazz) {
32    return reinterpret_cast<jlong>(new AccelerateDecelerateInterpolator());
33}
34
35static jlong createLutInterpolator(JNIEnv* env, jobject clazz, jfloatArray jlut) {
36    jsize len = env->GetArrayLength(jlut);
37    if (len <= 0) {
38        return 0;
39    }
40    float* lut = new float[len];
41    env->GetFloatArrayRegion(jlut, 0, len, lut);
42    return reinterpret_cast<jlong>(new LUTInterpolator(lut, len));
43}
44
45#endif
46
47// ----------------------------------------------------------------------------
48// JNI Glue
49// ----------------------------------------------------------------------------
50
51const char* const kClassPathName = "com/android/internal/view/animation/NativeInterpolatorFactoryHelper";
52
53static JNINativeMethod gMethods[] = {
54#ifdef USE_OPENGL_RENDERER
55    { "createAccelerateDecelerateInterpolator", "()J", (void*) createAccelerateDecelerateInterpolator },
56    { "createLutInterpolator", "([F)J", (void*) createLutInterpolator },
57#endif
58};
59
60int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) {
61    return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
62}
63
64
65} // namespace android
66