The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | #include "GraphicsJNI.h" |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 2 | #include "SkiaInterpolator.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 4 | static jlong Interpolator_constructor(JNIEnv* env, jobject clazz, jint valueCount, jint frameCount) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 6 | return reinterpret_cast<jlong>(new SkiaInterpolator(valueCount, frameCount)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | } |
| 8 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 9 | static void Interpolator_destructor(JNIEnv* env, jobject clazz, jlong interpHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 11 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12 | delete interp; |
| 13 | } |
| 14 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 15 | static void Interpolator_reset(JNIEnv* env, jobject clazz, jlong interpHandle, jint valueCount, jint frameCount) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 17 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | interp->reset(valueCount, frameCount); |
| 19 | } |
| 20 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 21 | static void Interpolator_setKeyFrame(JNIEnv* env, jobject clazz, jlong interpHandle, jint index, jint msec, jfloatArray valueArray, jfloatArray blendArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 23 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 25 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | interp->setKeyFrame(index, msec, scalars, blend); |
| 35 | } |
| 36 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 37 | static void Interpolator_setRepeatMirror(JNIEnv* env, jobject clazz, jlong interpHandle, jfloat repeatCount, jboolean mirror) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 39 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | if (repeatCount > 32000) |
| 41 | repeatCount = 32000; |
| 42 | |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 43 | interp->setRepeatCount(repeatCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | interp->setMirror(mirror != 0); |
| 45 | } |
| 46 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 47 | static jint Interpolator_timeToValues(JNIEnv* env, jobject clazz, jlong interpHandle, jint msec, jfloatArray valueArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | { |
Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame^] | 49 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
| 50 | SkiaInterpolator::Result result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
| 52 | float* values = valueArray ? env->GetFloatArrayElements(valueArray, NULL) : NULL; |
| 53 | result = interp->timeToValues(msec, (SkScalar*)values); |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 54 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | 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 Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 62 | |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 63 | return static_cast<jint>(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // ---------------------------------------------------------------------------- |
| 67 | |
| 68 | /* |
| 69 | * JNI registration. |
| 70 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 71 | static const JNINativeMethod gInterpolatorMethods[] = { |
Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 72 | { "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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | int register_android_graphics_Interpolator(JNIEnv* env) |
| 81 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 82 | return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator", |
| 83 | gInterpolatorMethods, NELEM(gInterpolatorMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } |