blob: fc3d70b87f5a591b57996d1e21101add1065e087 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#include "GraphicsJNI.h"
Mike Reed74065272021-04-12 09:52:07 -04002#include "SkiaInterpolator.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003
Ashok Bhata2f90422014-01-13 20:45:30 +00004static jlong Interpolator_constructor(JNIEnv* env, jobject clazz, jint valueCount, jint frameCount)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005{
Mike Reed74065272021-04-12 09:52:07 -04006 return reinterpret_cast<jlong>(new SkiaInterpolator(valueCount, frameCount));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007}
8
Ashok Bhata2f90422014-01-13 20:45:30 +00009static void Interpolator_destructor(JNIEnv* env, jobject clazz, jlong interpHandle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010{
Mike Reed74065272021-04-12 09:52:07 -040011 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012 delete interp;
13}
14
Ashok Bhata2f90422014-01-13 20:45:30 +000015static void Interpolator_reset(JNIEnv* env, jobject clazz, jlong interpHandle, jint valueCount, jint frameCount)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080016{
Mike Reed74065272021-04-12 09:52:07 -040017 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018 interp->reset(valueCount, frameCount);
19}
20
Ashok Bhata2f90422014-01-13 20:45:30 +000021static void Interpolator_setKeyFrame(JNIEnv* env, jobject clazz, jlong interpHandle, jint index, jint msec, jfloatArray valueArray, jfloatArray blendArray)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022{
Mike Reed74065272021-04-12 09:52:07 -040023 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040025 AutoJavaFloatArray autoValues(env, valueArray);
26 AutoJavaFloatArray autoBlend(env, blendArray, 4);
27#ifdef SK_SCALAR_IS_FLOAT
28 SkScalar* scalars = autoValues.ptr();
29 SkScalar* blend = autoBlend.ptr();
30#else
31 #error Need to convert float array to SkScalar array before calling the following function.
32#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34 interp->setKeyFrame(index, msec, scalars, blend);
35}
36
Ashok Bhata2f90422014-01-13 20:45:30 +000037static void Interpolator_setRepeatMirror(JNIEnv* env, jobject clazz, jlong interpHandle, jfloat repeatCount, jboolean mirror)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038{
Mike Reed74065272021-04-12 09:52:07 -040039 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 if (repeatCount > 32000)
41 repeatCount = 32000;
42
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040043 interp->setRepeatCount(repeatCount);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 interp->setMirror(mirror != 0);
45}
46
Ashok Bhata2f90422014-01-13 20:45:30 +000047static jint Interpolator_timeToValues(JNIEnv* env, jobject clazz, jlong interpHandle, jint msec, jfloatArray valueArray)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048{
Mike Reed74065272021-04-12 09:52:07 -040049 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
50 SkiaInterpolator::Result result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52 float* values = valueArray ? env->GetFloatArrayElements(valueArray, NULL) : NULL;
53 result = interp->timeToValues(msec, (SkScalar*)values);
Elliott Hughes4cb17532011-04-12 16:10:26 -070054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 if (valueArray) {
56 int n = env->GetArrayLength(valueArray);
57 for (int i = 0; i < n; i++) {
58 values[i] = SkScalarToFloat(*(SkScalar*)&values[i]);
59 }
60 env->ReleaseFloatArrayElements(valueArray, values, 0);
61 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070062
Ashok Bhata2f90422014-01-13 20:45:30 +000063 return static_cast<jint>(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064}
65
66// ----------------------------------------------------------------------------
67
68/*
69 * JNI registration.
70 */
Daniel Micay76f6a862015-09-19 17:31:01 -040071static const JNINativeMethod gInterpolatorMethods[] = {
Ashok Bhata2f90422014-01-13 20:45:30 +000072 { "nativeConstructor", "(II)J", (void*)Interpolator_constructor },
73 { "nativeDestructor", "(J)V", (void*)Interpolator_destructor },
74 { "nativeReset", "(JII)V", (void*)Interpolator_reset },
75 { "nativeSetKeyFrame", "(JII[F[F)V", (void*)Interpolator_setKeyFrame },
76 { "nativeSetRepeatMirror", "(JFZ)V", (void*)Interpolator_setRepeatMirror },
77 { "nativeTimeToValues", "(JI[F)I", (void*)Interpolator_timeToValues }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078};
79
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080int register_android_graphics_Interpolator(JNIEnv* env)
81{
Andreas Gampeed6b9df2014-11-20 22:02:20 -080082 return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator",
83 gInterpolatorMethods, NELEM(gInterpolatorMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084}