blob: c71e3085caf50f6b3e8542bfd8fa10b3c0ce873d [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);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040027 SkScalar* scalars = autoValues.ptr();
28 SkScalar* blend = autoBlend.ptr();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
30 interp->setKeyFrame(index, msec, scalars, blend);
31}
32
Ashok Bhata2f90422014-01-13 20:45:30 +000033static void Interpolator_setRepeatMirror(JNIEnv* env, jobject clazz, jlong interpHandle, jfloat repeatCount, jboolean mirror)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034{
Mike Reed74065272021-04-12 09:52:07 -040035 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 if (repeatCount > 32000)
37 repeatCount = 32000;
38
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040039 interp->setRepeatCount(repeatCount);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 interp->setMirror(mirror != 0);
41}
42
Ashok Bhata2f90422014-01-13 20:45:30 +000043static jint Interpolator_timeToValues(JNIEnv* env, jobject clazz, jlong interpHandle, jint msec, jfloatArray valueArray)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044{
Mike Reed74065272021-04-12 09:52:07 -040045 SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle);
46 SkiaInterpolator::Result result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
48 float* values = valueArray ? env->GetFloatArrayElements(valueArray, NULL) : NULL;
49 result = interp->timeToValues(msec, (SkScalar*)values);
Elliott Hughes4cb17532011-04-12 16:10:26 -070050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 if (valueArray) {
52 int n = env->GetArrayLength(valueArray);
53 for (int i = 0; i < n; i++) {
54 values[i] = SkScalarToFloat(*(SkScalar*)&values[i]);
55 }
56 env->ReleaseFloatArrayElements(valueArray, values, 0);
57 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070058
Ashok Bhata2f90422014-01-13 20:45:30 +000059 return static_cast<jint>(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060}
61
62// ----------------------------------------------------------------------------
63
64/*
65 * JNI registration.
66 */
Daniel Micay76f6a862015-09-19 17:31:01 -040067static const JNINativeMethod gInterpolatorMethods[] = {
Ashok Bhata2f90422014-01-13 20:45:30 +000068 { "nativeConstructor", "(II)J", (void*)Interpolator_constructor },
69 { "nativeDestructor", "(J)V", (void*)Interpolator_destructor },
70 { "nativeReset", "(JII)V", (void*)Interpolator_reset },
71 { "nativeSetKeyFrame", "(JII[F[F)V", (void*)Interpolator_setKeyFrame },
72 { "nativeSetRepeatMirror", "(JFZ)V", (void*)Interpolator_setRepeatMirror },
73 { "nativeTimeToValues", "(JI[F)I", (void*)Interpolator_timeToValues }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074};
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076int register_android_graphics_Interpolator(JNIEnv* env)
77{
Andreas Gampeed6b9df2014-11-20 22:02:20 -080078 return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator",
79 gInterpolatorMethods, NELEM(gInterpolatorMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080}