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> |
Doris Liu | 9e9eeee | 2016-11-29 14:48:25 -0800 | [diff] [blame] | 21 | #include <cutils/log.h> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 22 | #include "core_jni_helpers.h" |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 23 | |
| 24 | #include <Interpolator.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | using namespace uirenderer; |
| 29 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 30 | static jlong createAccelerateDecelerateInterpolator(JNIEnv* env, jobject clazz) { |
| 31 | return reinterpret_cast<jlong>(new AccelerateDecelerateInterpolator()); |
| 32 | } |
| 33 | |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 34 | static jlong createAccelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) { |
| 35 | return reinterpret_cast<jlong>(new AccelerateInterpolator(factor)); |
| 36 | } |
| 37 | |
| 38 | static jlong createAnticipateInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 39 | return reinterpret_cast<jlong>(new AnticipateInterpolator(tension)); |
| 40 | } |
| 41 | |
| 42 | static jlong createAnticipateOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 43 | return reinterpret_cast<jlong>(new AnticipateOvershootInterpolator(tension)); |
| 44 | } |
| 45 | |
| 46 | static jlong createBounceInterpolator(JNIEnv* env, jobject clazz) { |
| 47 | return reinterpret_cast<jlong>(new BounceInterpolator()); |
| 48 | } |
| 49 | |
| 50 | static jlong createCycleInterpolator(JNIEnv* env, jobject clazz, jfloat cycles) { |
| 51 | return reinterpret_cast<jlong>(new CycleInterpolator(cycles)); |
| 52 | } |
| 53 | |
| 54 | static jlong createDecelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) { |
| 55 | return reinterpret_cast<jlong>(new DecelerateInterpolator(factor)); |
| 56 | } |
| 57 | |
| 58 | static jlong createLinearInterpolator(JNIEnv* env, jobject clazz) { |
| 59 | return reinterpret_cast<jlong>(new LinearInterpolator()); |
| 60 | } |
| 61 | |
| 62 | static jlong createOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) { |
| 63 | return reinterpret_cast<jlong>(new OvershootInterpolator(tension)); |
| 64 | } |
| 65 | |
Doris Liu | 9e9eeee | 2016-11-29 14:48:25 -0800 | [diff] [blame] | 66 | static jlong createPathInterpolator(JNIEnv* env, jobject clazz, jfloatArray jX, jfloatArray jY) { |
| 67 | jsize lenX = env->GetArrayLength(jX); |
| 68 | jsize lenY = env->GetArrayLength(jY); |
| 69 | LOG_ALWAYS_FATAL_IF(lenX != lenY || lenX <= 0, "Invalid path interpolator, x size: %d," |
| 70 | " y size: %d", lenX, lenY); |
| 71 | std::vector<float> x(lenX); |
| 72 | std::vector<float> y(lenY); |
| 73 | env->GetFloatArrayRegion(jX, 0, lenX, x.data()); |
| 74 | env->GetFloatArrayRegion(jY, 0, lenX, y.data()); |
| 75 | |
| 76 | return reinterpret_cast<jlong>(new PathInterpolator(std::move(x), std::move(y))); |
| 77 | } |
| 78 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 79 | static jlong createLutInterpolator(JNIEnv* env, jobject clazz, jfloatArray jlut) { |
| 80 | jsize len = env->GetArrayLength(jlut); |
| 81 | if (len <= 0) { |
| 82 | return 0; |
| 83 | } |
| 84 | float* lut = new float[len]; |
| 85 | env->GetFloatArrayRegion(jlut, 0, len, lut); |
| 86 | return reinterpret_cast<jlong>(new LUTInterpolator(lut, len)); |
| 87 | } |
| 88 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 89 | // ---------------------------------------------------------------------------- |
| 90 | // JNI Glue |
| 91 | // ---------------------------------------------------------------------------- |
| 92 | |
| 93 | const char* const kClassPathName = "com/android/internal/view/animation/NativeInterpolatorFactoryHelper"; |
| 94 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 95 | static const JNINativeMethod gMethods[] = { |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 96 | { "createAccelerateDecelerateInterpolator", "()J", (void*) createAccelerateDecelerateInterpolator }, |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 97 | { "createAccelerateInterpolator", "(F)J", (void*) createAccelerateInterpolator }, |
| 98 | { "createAnticipateInterpolator", "(F)J", (void*) createAnticipateInterpolator }, |
| 99 | { "createAnticipateOvershootInterpolator", "(F)J", (void*) createAnticipateOvershootInterpolator }, |
| 100 | { "createBounceInterpolator", "()J", (void*) createBounceInterpolator }, |
| 101 | { "createCycleInterpolator", "(F)J", (void*) createCycleInterpolator }, |
| 102 | { "createDecelerateInterpolator", "(F)J", (void*) createDecelerateInterpolator }, |
| 103 | { "createLinearInterpolator", "()J", (void*) createLinearInterpolator }, |
| 104 | { "createOvershootInterpolator", "(F)J", (void*) createOvershootInterpolator }, |
Doris Liu | 9e9eeee | 2016-11-29 14:48:25 -0800 | [diff] [blame] | 105 | { "createPathInterpolator", "([F[F)J", (void*) createPathInterpolator }, |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 106 | { "createLutInterpolator", "([F)J", (void*) createLutInterpolator }, |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 110 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
| 114 | } // namespace android |