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