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); |
Mike Reed | 97fa229 | 2017-03-01 14:08:24 -0500 | [diff] [blame] | 23 | SkPathEffect* effect = SkPathEffect::MakeCompose(sk_ref_sp(outer), |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 24 | sk_ref_sp(inner)).release(); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 25 | return reinterpret_cast<jlong>(effect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | } |
Elliott Hughes | 4cb1753 | 2011-04-12 16:10:26 -0700 | [diff] [blame] | 27 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 28 | static jlong Sum_constructor(JNIEnv* env, jobject, |
| 29 | jlong firstHandle, jlong secondHandle) { |
| 30 | SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle); |
| 31 | SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle); |
Mike Reed | 97fa229 | 2017-03-01 14:08:24 -0500 | [diff] [blame] | 32 | SkPathEffect* effect = SkPathEffect::MakeSum(sk_ref_sp(first), |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 33 | sk_ref_sp(second)).release(); |
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 |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 46 | SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release(); |
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); |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 54 | SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase, |
| 55 | (SkPath1DPathEffect::Style)style).release(); |
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){ |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 60 | SkPathEffect* effect = SkCornerPathEffect::Make(radius).release(); |
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) { |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 66 | SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release(); |
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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 74 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 78 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 82 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 86 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 90 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 94 | static const 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 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 98 | static const 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 | } |