1315c329544d7c593d1072b071cbb92d9afe74021John Reck/*
2315c329544d7c593d1072b071cbb92d9afe74021John Reck * Copyright (C) 2014 The Android Open Source Project
3315c329544d7c593d1072b071cbb92d9afe74021John Reck *
4315c329544d7c593d1072b071cbb92d9afe74021John Reck * Licensed under the Apache License, Version 2.0 (the "License");
5315c329544d7c593d1072b071cbb92d9afe74021John Reck * you may not use this file except in compliance with the License.
6315c329544d7c593d1072b071cbb92d9afe74021John Reck * You may obtain a copy of the License at
7315c329544d7c593d1072b071cbb92d9afe74021John Reck *
8315c329544d7c593d1072b071cbb92d9afe74021John Reck *      http://www.apache.org/licenses/LICENSE-2.0
9315c329544d7c593d1072b071cbb92d9afe74021John Reck *
10315c329544d7c593d1072b071cbb92d9afe74021John Reck * Unless required by applicable law or agreed to in writing, software
11315c329544d7c593d1072b071cbb92d9afe74021John Reck * distributed under the License is distributed on an "AS IS" BASIS,
12315c329544d7c593d1072b071cbb92d9afe74021John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13315c329544d7c593d1072b071cbb92d9afe74021John Reck * See the License for the specific language governing permissions and
14315c329544d7c593d1072b071cbb92d9afe74021John Reck * limitations under the License.
15315c329544d7c593d1072b071cbb92d9afe74021John Reck */
16315c329544d7c593d1072b071cbb92d9afe74021John Reck
17315c329544d7c593d1072b071cbb92d9afe74021John Reck#define LOG_TAG "OpenGLRenderer"
18315c329544d7c593d1072b071cbb92d9afe74021John Reck
19315c329544d7c593d1072b071cbb92d9afe74021John Reck#include "jni.h"
20315c329544d7c593d1072b071cbb92d9afe74021John Reck#include <nativehelper/JNIHelp.h>
21ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#include "core_jni_helpers.h"
22315c329544d7c593d1072b071cbb92d9afe74021John Reck
23315c329544d7c593d1072b071cbb92d9afe74021John Reck#include <Interpolator.h>
24315c329544d7c593d1072b071cbb92d9afe74021John Reck
25315c329544d7c593d1072b071cbb92d9afe74021John Recknamespace android {
26315c329544d7c593d1072b071cbb92d9afe74021John Reck
27315c329544d7c593d1072b071cbb92d9afe74021John Reckusing namespace uirenderer;
28315c329544d7c593d1072b071cbb92d9afe74021John Reck
29315c329544d7c593d1072b071cbb92d9afe74021John Reckstatic jlong createAccelerateDecelerateInterpolator(JNIEnv* env, jobject clazz) {
30315c329544d7c593d1072b071cbb92d9afe74021John Reck    return reinterpret_cast<jlong>(new AccelerateDecelerateInterpolator());
31315c329544d7c593d1072b071cbb92d9afe74021John Reck}
32315c329544d7c593d1072b071cbb92d9afe74021John Reck
33c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createAccelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) {
34c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new AccelerateInterpolator(factor));
35c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
36c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
37c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createAnticipateInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
38c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new AnticipateInterpolator(tension));
39c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
40c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
41c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createAnticipateOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
42c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new AnticipateOvershootInterpolator(tension));
43c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
44c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
45c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createBounceInterpolator(JNIEnv* env, jobject clazz) {
46c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new BounceInterpolator());
47c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
48c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
49c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createCycleInterpolator(JNIEnv* env, jobject clazz, jfloat cycles) {
50c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new CycleInterpolator(cycles));
51c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
52c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
53c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createDecelerateInterpolator(JNIEnv* env, jobject clazz, jfloat factor) {
54c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new DecelerateInterpolator(factor));
55c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
56c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
57c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createLinearInterpolator(JNIEnv* env, jobject clazz) {
58c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new LinearInterpolator());
59c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
60c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
61c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reckstatic jlong createOvershootInterpolator(JNIEnv* env, jobject clazz, jfloat tension) {
62c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    return reinterpret_cast<jlong>(new OvershootInterpolator(tension));
63c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck}
64c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck
65315c329544d7c593d1072b071cbb92d9afe74021John Reckstatic jlong createLutInterpolator(JNIEnv* env, jobject clazz, jfloatArray jlut) {
66315c329544d7c593d1072b071cbb92d9afe74021John Reck    jsize len = env->GetArrayLength(jlut);
67315c329544d7c593d1072b071cbb92d9afe74021John Reck    if (len <= 0) {
68315c329544d7c593d1072b071cbb92d9afe74021John Reck        return 0;
69315c329544d7c593d1072b071cbb92d9afe74021John Reck    }
70315c329544d7c593d1072b071cbb92d9afe74021John Reck    float* lut = new float[len];
71315c329544d7c593d1072b071cbb92d9afe74021John Reck    env->GetFloatArrayRegion(jlut, 0, len, lut);
72315c329544d7c593d1072b071cbb92d9afe74021John Reck    return reinterpret_cast<jlong>(new LUTInterpolator(lut, len));
73315c329544d7c593d1072b071cbb92d9afe74021John Reck}
74315c329544d7c593d1072b071cbb92d9afe74021John Reck
75315c329544d7c593d1072b071cbb92d9afe74021John Reck// ----------------------------------------------------------------------------
76315c329544d7c593d1072b071cbb92d9afe74021John Reck// JNI Glue
77315c329544d7c593d1072b071cbb92d9afe74021John Reck// ----------------------------------------------------------------------------
78315c329544d7c593d1072b071cbb92d9afe74021John Reck
79315c329544d7c593d1072b071cbb92d9afe74021John Reckconst char* const kClassPathName = "com/android/internal/view/animation/NativeInterpolatorFactoryHelper";
80315c329544d7c593d1072b071cbb92d9afe74021John Reck
8176f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gMethods[] = {
82315c329544d7c593d1072b071cbb92d9afe74021John Reck    { "createAccelerateDecelerateInterpolator", "()J", (void*) createAccelerateDecelerateInterpolator },
83c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createAccelerateInterpolator", "(F)J", (void*) createAccelerateInterpolator },
84c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createAnticipateInterpolator", "(F)J", (void*) createAnticipateInterpolator },
85c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createAnticipateOvershootInterpolator", "(F)J", (void*) createAnticipateOvershootInterpolator },
86c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createBounceInterpolator", "()J", (void*) createBounceInterpolator },
87c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createCycleInterpolator", "(F)J", (void*) createCycleInterpolator },
88c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createDecelerateInterpolator", "(F)J", (void*) createDecelerateInterpolator },
89c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createLinearInterpolator", "()J", (void*) createLinearInterpolator },
90c8ac775659fd252ce2cc9a61837c170ff70f0a1aJohn Reck    { "createOvershootInterpolator", "(F)J", (void*) createOvershootInterpolator },
91315c329544d7c593d1072b071cbb92d9afe74021John Reck    { "createLutInterpolator", "([F)J", (void*) createLutInterpolator },
92315c329544d7c593d1072b071cbb92d9afe74021John Reck};
93315c329544d7c593d1072b071cbb92d9afe74021John Reck
94315c329544d7c593d1072b071cbb92d9afe74021John Reckint register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) {
95ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe    return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
96315c329544d7c593d1072b071cbb92d9afe74021John Reck}
97315c329544d7c593d1072b071cbb92d9afe74021John Reck
98315c329544d7c593d1072b071cbb92d9afe74021John Reck
99315c329544d7c593d1072b071cbb92d9afe74021John Reck} // namespace android
100