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 "core_jni_helpers.h"
22
23 #include <Interpolator.h>
24
25 namespace android {
26
27 using namespace uirenderer;
28
createAccelerateDecelerateInterpolator(JNIEnv * env,jobject clazz)29 static jlong createAccelerateDecelerateInterpolator(JNIEnv* env, jobject clazz) {
30 return reinterpret_cast<jlong>(new AccelerateDecelerateInterpolator());
31 }
32
createAccelerateInterpolator(JNIEnv * env,jobject clazz,jfloat factor)33 static jlong createAccelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) {
34 return reinterpret_cast<jlong>(new AccelerateInterpolator(factor));
35 }
36
createAnticipateInterpolator(JNIEnv * env,jobject clazz,jfloat tension)37 static jlong createAnticipateInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
38 return reinterpret_cast<jlong>(new AnticipateInterpolator(tension));
39 }
40
createAnticipateOvershootInterpolator(JNIEnv * env,jobject clazz,jfloat tension)41 static jlong createAnticipateOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
42 return reinterpret_cast<jlong>(new AnticipateOvershootInterpolator(tension));
43 }
44
createBounceInterpolator(JNIEnv * env,jobject clazz)45 static jlong createBounceInterpolator(JNIEnv* env, jobject clazz) {
46 return reinterpret_cast<jlong>(new BounceInterpolator());
47 }
48
createCycleInterpolator(JNIEnv * env,jobject clazz,jfloat cycles)49 static jlong createCycleInterpolator(JNIEnv* env, jobject clazz, jfloat cycles) {
50 return reinterpret_cast<jlong>(new CycleInterpolator(cycles));
51 }
52
createDecelerateInterpolator(JNIEnv * env,jobject clazz,jfloat factor)53 static jlong createDecelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) {
54 return reinterpret_cast<jlong>(new DecelerateInterpolator(factor));
55 }
56
createLinearInterpolator(JNIEnv * env,jobject clazz)57 static jlong createLinearInterpolator(JNIEnv* env, jobject clazz) {
58 return reinterpret_cast<jlong>(new LinearInterpolator());
59 }
60
createOvershootInterpolator(JNIEnv * env,jobject clazz,jfloat tension)61 static jlong createOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
62 return reinterpret_cast<jlong>(new OvershootInterpolator(tension));
63 }
64
createLutInterpolator(JNIEnv * env,jobject clazz,jfloatArray jlut)65 static jlong createLutInterpolator(JNIEnv* env, jobject clazz, jfloatArray jlut) {
66 jsize len = env->GetArrayLength(jlut);
67 if (len <= 0) {
68 return 0;
69 }
70 float* lut = new float[len];
71 env->GetFloatArrayRegion(jlut, 0, len, lut);
72 return reinterpret_cast<jlong>(new LUTInterpolator(lut, len));
73 }
74
75 // ----------------------------------------------------------------------------
76 // JNI Glue
77 // ----------------------------------------------------------------------------
78
79 const char* const kClassPathName = "com/android/internal/view/animation/NativeInterpolatorFactoryHelper";
80
81 static JNINativeMethod gMethods[] = {
82 { "createAccelerateDecelerateInterpolator", "()J", (void*) createAccelerateDecelerateInterpolator },
83 { "createAccelerateInterpolator", "(F)J", (void*) createAccelerateInterpolator },
84 { "createAnticipateInterpolator", "(F)J", (void*) createAnticipateInterpolator },
85 { "createAnticipateOvershootInterpolator", "(F)J", (void*) createAnticipateOvershootInterpolator },
86 { "createBounceInterpolator", "()J", (void*) createBounceInterpolator },
87 { "createCycleInterpolator", "(F)J", (void*) createCycleInterpolator },
88 { "createDecelerateInterpolator", "(F)J", (void*) createDecelerateInterpolator },
89 { "createLinearInterpolator", "()J", (void*) createLinearInterpolator },
90 { "createOvershootInterpolator", "(F)J", (void*) createOvershootInterpolator },
91 { "createLutInterpolator", "([F)J", (void*) createLutInterpolator },
92 };
93
register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv * env)94 int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) {
95 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
96 }
97
98
99 } // namespace android
100