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
destructor(JNIEnv * env,jobject,jlong effectHandle)11 static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
12 SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
13 SkSafeUnref(effect);
14 }
15
Compose_constructor(JNIEnv * env,jobject,jlong outerHandle,jlong innerHandle)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
Sum_constructor(JNIEnv * env,jobject,jlong firstHandle,jlong secondHandle)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
Dash_constructor(JNIEnv * env,jobject,jfloatArray intervalArray,jfloat phase)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 SkScalar* intervals = autoInterval.ptr();
39 SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release();
40 return reinterpret_cast<jlong>(effect);
41 }
42
OneD_constructor(JNIEnv * env,jobject,jlong shapeHandle,jfloat advance,jfloat phase,jint style)43 static jlong OneD_constructor(JNIEnv* env, jobject,
44 jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
45 const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
46 SkASSERT(shape != NULL);
47 SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase,
48 (SkPath1DPathEffect::Style)style).release();
49 return reinterpret_cast<jlong>(effect);
50 }
51
Corner_constructor(JNIEnv * env,jobject,jfloat radius)52 static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
53 SkPathEffect* effect = SkCornerPathEffect::Make(radius).release();
54 return reinterpret_cast<jlong>(effect);
55 }
56
Discrete_constructor(JNIEnv * env,jobject,jfloat length,jfloat deviation)57 static jlong Discrete_constructor(JNIEnv* env, jobject,
58 jfloat length, jfloat deviation) {
59 SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release();
60 return reinterpret_cast<jlong>(effect);
61 }
62
63 };
64
65 ////////////////////////////////////////////////////////////////////////////////////////////////////////
66
67 static const JNINativeMethod gPathEffectMethods[] = {
68 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
69 };
70
71 static const JNINativeMethod gComposePathEffectMethods[] = {
72 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
73 };
74
75 static const JNINativeMethod gSumPathEffectMethods[] = {
76 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
77 };
78
79 static const JNINativeMethod gDashPathEffectMethods[] = {
80 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
81 };
82
83 static const JNINativeMethod gPathDashPathEffectMethods[] = {
84 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
85 };
86
87 static const JNINativeMethod gCornerPathEffectMethods[] = {
88 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
89 };
90
91 static const JNINativeMethod gDiscretePathEffectMethods[] = {
92 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
93 };
94
register_android_graphics_PathEffect(JNIEnv * env)95 int register_android_graphics_PathEffect(JNIEnv* env)
96 {
97 android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
98 NELEM(gPathEffectMethods));
99 android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
100 gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
101 android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
102 NELEM(gSumPathEffectMethods));
103 android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
104 NELEM(gDashPathEffectMethods));
105 android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
106 gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
107 android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
108 gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
109 android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
110 gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
111
112 return 0;
113 }
114