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> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 21 | #include "core_jni_helpers.h" |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 22 | |
| 23 | #include <Interpolator.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | using namespace uirenderer; |
| 28 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 29 | static jlong createAccelerateDecelerateInterpolator(JNIEnv* env, jobject clazz) { |
| 30 | return reinterpret_cast<jlong>(new AccelerateDecelerateInterpolator()); |
| 31 | } |
| 32 | |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 33 | static jlong createAccelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) { |
| 34 | return reinterpret_cast<jlong>(new AccelerateInterpolator(factor)); |
| 35 | } |
| 36 | |
| 37 | static jlong createAnticipateInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 38 | return reinterpret_cast<jlong>(new AnticipateInterpolator(tension)); |
| 39 | } |
| 40 | |
| 41 | static jlong createAnticipateOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 42 | return reinterpret_cast<jlong>(new AnticipateOvershootInterpolator(tension)); |
| 43 | } |
| 44 | |
| 45 | static jlong createBounceInterpolator(JNIEnv* env, jobject clazz) { |
| 46 | return reinterpret_cast<jlong>(new BounceInterpolator()); |
| 47 | } |
| 48 | |
| 49 | static jlong createCycleInterpolator(JNIEnv* env, jobject clazz, jfloat cycles) { |
| 50 | return reinterpret_cast<jlong>(new CycleInterpolator(cycles)); |
| 51 | } |
| 52 | |
| 53 | static jlong createDecelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) { |
| 54 | return reinterpret_cast<jlong>(new DecelerateInterpolator(factor)); |
| 55 | } |
| 56 | |
| 57 | static jlong createLinearInterpolator(JNIEnv* env, jobject clazz) { |
| 58 | return reinterpret_cast<jlong>(new LinearInterpolator()); |
| 59 | } |
| 60 | |
| 61 | static jlong createOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 62 | return reinterpret_cast<jlong>(new OvershootInterpolator(tension)); |
| 63 | } |
| 64 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 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 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 75 | // ---------------------------------------------------------------------------- |
| 76 | // JNI Glue |
| 77 | // ---------------------------------------------------------------------------- |
| 78 | |
| 79 | const char* const kClassPathName = "com/android/internal/view/animation/NativeInterpolatorFactoryHelper"; |
| 80 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 81 | static const JNINativeMethod gMethods[] = { |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 82 | { "createAccelerateDecelerateInterpolator", "()J", (void*) createAccelerateDecelerateInterpolator }, |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 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 }, |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 91 | { "createLutInterpolator", "([F)J", (void*) createLutInterpolator }, |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 95 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | } // namespace android |