The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | #include <jni.h> |
| 2 | #include "GraphicsJNI.h" |
| 3 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 4 | #include "core_jni_helpers.h" |
| 5 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6 | #include "SkPathEffect.h" |
| 7 | #include "SkCornerPathEffect.h" |
| 8 | #include "SkDashPathEffect.h" |
| 9 | #include "SkDiscretePathEffect.h" |
| 10 | #include "Sk1DPathEffect.h" |
| 11 | #include "SkTemplates.h" |
| 12 | |
| 13 | class SkPathEffectGlue { |
| 14 | public: |
| 15 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 16 | static void destructor(JNIEnv* env, jobject, jlong effectHandle) { |
| 17 | SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle); |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 18 | SkSafeUnref(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | } |
| 20 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 21 | static jlong Compose_constructor(JNIEnv* env, jobject, |
| 22 | jlong outerHandle, jlong innerHandle) { |
| 23 | SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle); |
| 24 | SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle); |
Leon Scroggins | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame] | 25 | SkPathEffect* effect = SkComposePathEffect::Create(outer, inner); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 26 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 28 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 29 | static jlong Sum_constructor(JNIEnv* env, jobject, |
| 30 | jlong firstHandle, jlong secondHandle) { |
| 31 | SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle); |
| 32 | SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle); |
Leon Scroggins | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame] | 33 | SkPathEffect* effect = SkSumPathEffect::Create(first, second); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 34 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 36 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 37 | static jlong Dash_constructor(JNIEnv* env, jobject, |
| 38 | jfloatArray intervalArray, jfloat phase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | AutoJavaFloatArray autoInterval(env, intervalArray); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 40 | int count = autoInterval.length() & ~1; // even number |
| 41 | #ifdef SK_SCALAR_IS_FLOAT |
| 42 | SkScalar* intervals = autoInterval.ptr(); |
| 43 | #else |
| 44 | #error Need to convert float array to SkScalar array before calling the following function. |
| 45 | #endif |
| 46 | SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, phase); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 47 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 49 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 50 | static jlong OneD_constructor(JNIEnv* env, jobject, |
| 51 | jlong shapeHandle, jfloat advance, jfloat phase, jint style) { |
| 52 | const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | SkASSERT(shape != NULL); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 54 | SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, advance, phase, |
| 55 | (SkPath1DPathEffect::Style)style); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 56 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 58 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 59 | static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){ |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 60 | SkPathEffect* effect = SkCornerPathEffect::Create(radius); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 61 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 63 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 64 | static jlong Discrete_constructor(JNIEnv* env, jobject, |
| 65 | jfloat length, jfloat deviation) { |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 66 | SkPathEffect* effect = SkDiscretePathEffect::Create(length, deviation); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 67 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | static JNINativeMethod gPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 75 | { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | static JNINativeMethod gComposePathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 79 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static JNINativeMethod gSumPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 83 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static JNINativeMethod gDashPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 87 | { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static JNINativeMethod gPathDashPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 91 | { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static JNINativeMethod gCornerPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 95 | { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static JNINativeMethod gDiscretePathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 99 | { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | int register_android_graphics_PathEffect(JNIEnv* env) |
| 103 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 104 | android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods, |
| 105 | NELEM(gPathEffectMethods)); |
| 106 | android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect", |
| 107 | gComposePathEffectMethods, NELEM(gComposePathEffectMethods)); |
| 108 | android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods, |
| 109 | NELEM(gSumPathEffectMethods)); |
| 110 | android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods, |
| 111 | NELEM(gDashPathEffectMethods)); |
| 112 | android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect", |
| 113 | gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods)); |
| 114 | android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect", |
| 115 | gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods)); |
| 116 | android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect", |
| 117 | gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods)); |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | return 0; |
| 120 | } |