| 1 | #include "GraphicsJNI.h" |
| 2 | #include "Sk1DPathEffect.h" |
| 3 | #include "SkCornerPathEffect.h" |
| 4 | #include "SkDashPathEffect.h" |
| 5 | #include "SkDiscretePathEffect.h" |
| 6 | #include "SkPathEffect.h" |
| 7 | |
| 8 | class SkPathEffectGlue { |
| 9 | public: |
| 10 | |
| 11 | static void destructor(JNIEnv* env, jobject, jlong effectHandle) { |
| 12 | SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle); |
| 13 | SkSafeUnref(effect); |
| 14 | } |
| 15 | |
| 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); |
| 20 | SkPathEffect* effect = SkPathEffect::MakeCompose(sk_ref_sp(outer), |
| 21 | sk_ref_sp(inner)).release(); |
| 22 | return reinterpret_cast<jlong>(effect); |
| 23 | } |
| 24 | |
| 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); |
| 29 | SkPathEffect* effect = SkPathEffect::MakeSum(sk_ref_sp(first), |
| 30 | sk_ref_sp(second)).release(); |
| 31 | return reinterpret_cast<jlong>(effect); |
| 32 | } |
| 33 | |
| 34 | static jlong Dash_constructor(JNIEnv* env, jobject, |
| 35 | jfloatArray intervalArray, jfloat phase) { |
| 36 | AutoJavaFloatArray autoInterval(env, intervalArray); |
| 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 |
| 43 | SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release(); |
| 44 | return reinterpret_cast<jlong>(effect); |
| 45 | } |
| 46 | |
| 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); |
| 50 | SkASSERT(shape != NULL); |
| 51 | SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase, |
| 52 | (SkPath1DPathEffect::Style)style).release(); |
| 53 | return reinterpret_cast<jlong>(effect); |
| 54 | } |
| 55 | |
| 56 | static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){ |
| 57 | SkPathEffect* effect = SkCornerPathEffect::Make(radius).release(); |
| 58 | return reinterpret_cast<jlong>(effect); |
| 59 | } |
| 60 | |
| 61 | static jlong Discrete_constructor(JNIEnv* env, jobject, |
| 62 | jfloat length, jfloat deviation) { |
| 63 | SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release(); |
| 64 | return reinterpret_cast<jlong>(effect); |
| 65 | } |
| 66 | |
| 67 | }; |
| 68 | |
| 69 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 70 | |
| 71 | static const JNINativeMethod gPathEffectMethods[] = { |
| 72 | { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor } |
| 73 | }; |
| 74 | |
| 75 | static const JNINativeMethod gComposePathEffectMethods[] = { |
| 76 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor } |
| 77 | }; |
| 78 | |
| 79 | static const JNINativeMethod gSumPathEffectMethods[] = { |
| 80 | { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor } |
| 81 | }; |
| 82 | |
| 83 | static const JNINativeMethod gDashPathEffectMethods[] = { |
| 84 | { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor } |
| 85 | }; |
| 86 | |
| 87 | static const JNINativeMethod gPathDashPathEffectMethods[] = { |
| 88 | { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor } |
| 89 | }; |
| 90 | |
| 91 | static const JNINativeMethod gCornerPathEffectMethods[] = { |
| 92 | { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor } |
| 93 | }; |
| 94 | |
| 95 | static const JNINativeMethod gDiscretePathEffectMethods[] = { |
| 96 | { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor } |
| 97 | }; |
| 98 | |
| 99 | int register_android_graphics_PathEffect(JNIEnv* env) |
| 100 | { |
| 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)); |
| 115 | |
| 116 | return 0; |
| 117 | } |