| 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); |
| Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 27 | SkScalar* scalars = autoValues.ptr(); |
| 28 | SkScalar* blend = autoBlend.ptr(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
| 30 | interp->setKeyFrame(index, msec, scalars, blend); |
| 31 | } |
| 32 | |
| Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 33 | 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] | 34 | { |
| Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame] | 35 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | if (repeatCount > 32000) |
| 37 | repeatCount = 32000; |
| 38 | |
| Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 39 | interp->setRepeatCount(repeatCount); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | interp->setMirror(mirror != 0); |
| 41 | } |
| 42 | |
| Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 43 | 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] | 44 | { |
| Mike Reed | 7406527 | 2021-04-12 09:52:07 -0400 | [diff] [blame] | 45 | SkiaInterpolator* interp = reinterpret_cast<SkiaInterpolator*>(interpHandle); |
| 46 | SkiaInterpolator::Result result; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
| 48 | float* values = valueArray ? env->GetFloatArrayElements(valueArray, NULL) : NULL; |
| 49 | result = interp->timeToValues(msec, (SkScalar*)values); |
| Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 50 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | 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 Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 58 | |
| Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 59 | return static_cast<jint>(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // ---------------------------------------------------------------------------- |
| 63 | |
| 64 | /* |
| 65 | * JNI registration. |
| 66 | */ |
| Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 67 | static const JNINativeMethod gInterpolatorMethods[] = { |
| Ashok Bhat | a2f9042 | 2014-01-13 20:45:30 +0000 | [diff] [blame] | 68 | { "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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | int register_android_graphics_Interpolator(JNIEnv* env) |
| 77 | { |
| Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 78 | return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator", |
| 79 | gInterpolatorMethods, NELEM(gInterpolatorMethods)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |