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