The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | #include <jni.h> |
| 2 | #include "GraphicsJNI.h" |
| 3 | |
| 4 | #include "SkPathEffect.h" |
| 5 | #include "SkCornerPathEffect.h" |
| 6 | #include "SkDashPathEffect.h" |
| 7 | #include "SkDiscretePathEffect.h" |
| 8 | #include "Sk1DPathEffect.h" |
| 9 | #include "SkTemplates.h" |
| 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); |
| 38 | int count = autoInterval.length() & ~1; // even number |
| 39 | float* values = autoInterval.ptr(); |
| 40 | |
| 41 | SkAutoSTMalloc<32, SkScalar> storage(count); |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 42 | SkScalar* intervals = storage.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | for (int i = 0; i < count; i++) { |
| 44 | intervals[i] = SkFloatToScalar(values[i]); |
| 45 | } |
Leon Scroggins | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame^] | 46 | SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, SkFloatToScalar(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 | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame^] | 54 | SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, SkFloatToScalar(advance), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | SkFloatToScalar(phase), (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 | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame^] | 60 | SkPathEffect* effect = SkCornerPathEffect::Create(SkFloatToScalar(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 | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame^] | 66 | SkPathEffect* effect = SkDiscretePathEffect::Create(SkFloatToScalar(length), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | SkFloatToScalar(deviation)); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 68 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 74 | |
| 75 | static JNINativeMethod gPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 76 | { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static JNINativeMethod gComposePathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 80 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static JNINativeMethod gSumPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 84 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | static JNINativeMethod gDashPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 88 | { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | static JNINativeMethod gPathDashPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 92 | { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static JNINativeMethod gCornerPathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 96 | { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static JNINativeMethod gDiscretePathEffectMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 100 | { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #include <android_runtime/AndroidRuntime.h> |
| 104 | |
| 105 | #define REG(env, name, array) \ |
| 106 | result = android::AndroidRuntime::registerNativeMethods(env, name, array, \ |
| 107 | SK_ARRAY_COUNT(array)); \ |
| 108 | if (result < 0) return result |
| 109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | int register_android_graphics_PathEffect(JNIEnv* env) |
| 111 | { |
| 112 | int result; |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | REG(env, "android/graphics/PathEffect", gPathEffectMethods); |
| 115 | REG(env, "android/graphics/ComposePathEffect", gComposePathEffectMethods); |
| 116 | REG(env, "android/graphics/SumPathEffect", gSumPathEffectMethods); |
| 117 | REG(env, "android/graphics/DashPathEffect", gDashPathEffectMethods); |
| 118 | REG(env, "android/graphics/PathDashPathEffect", gPathDashPathEffectMethods); |
| 119 | REG(env, "android/graphics/CornerPathEffect", gCornerPathEffectMethods); |
| 120 | REG(env, "android/graphics/DiscretePathEffect", gDiscretePathEffectMethods); |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | return 0; |
| 123 | } |