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