2 #include "GraphicsJNI.h"
4 #include "SkPathEffect.h"
5 #include "SkCornerPathEffect.h"
6 #include "SkDashPathEffect.h"
7 #include "SkDiscretePathEffect.h"
8 #include "Sk1DPathEffect.h"
9 #include "SkTemplates.h"
11 class SkPathEffectGlue {
14 static void destructor(JNIEnv* env, jobject, SkPathEffect* effect) {
18 static SkPathEffect* Compose_constructor(JNIEnv* env, jobject,
19 SkPathEffect* outer, SkPathEffect* inner) {
20 return new SkComposePathEffect(outer, inner);
23 static SkPathEffect* Sum_constructor(JNIEnv* env, jobject,
24 SkPathEffect* first, SkPathEffect* second) {
25 return new SkSumPathEffect(first, second);
28 static SkPathEffect* Dash_constructor(JNIEnv* env, jobject,
29 jfloatArray intervalArray, float phase) {
30 AutoJavaFloatArray autoInterval(env, intervalArray);
31 int count = autoInterval.length() & ~1; // even number
32 float* values = autoInterval.ptr();
34 SkAutoSTMalloc<32, SkScalar> storage(count);
35 SkScalar* intervals = storage.get();
36 for (int i = 0; i < count; i++) {
37 intervals[i] = SkFloatToScalar(values[i]);
39 return new SkDashPathEffect(intervals, count, SkFloatToScalar(phase));
42 static SkPathEffect* OneD_constructor(JNIEnv* env, jobject,
43 const SkPath* shape, float advance, float phase, int style) {
44 SkASSERT(shape != NULL);
45 return new SkPath1DPathEffect(*shape, SkFloatToScalar(advance),
46 SkFloatToScalar(phase), (SkPath1DPathEffect::Style)style);
49 static SkPathEffect* Corner_constructor(JNIEnv* env, jobject, float radius){
50 return new SkCornerPathEffect(SkFloatToScalar(radius));
53 static SkPathEffect* Discrete_constructor(JNIEnv* env, jobject,
54 float length, float deviation) {
55 return new SkDiscretePathEffect(SkFloatToScalar(length),
56 SkFloatToScalar(deviation));
61 ////////////////////////////////////////////////////////////////////////////////////////////////////////
63 static JNINativeMethod gPathEffectMethods[] = {
64 { "nativeDestructor", "(I)V", (void*)SkPathEffectGlue::destructor }
67 static JNINativeMethod gComposePathEffectMethods[] = {
68 { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Compose_constructor }
71 static JNINativeMethod gSumPathEffectMethods[] = {
72 { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Sum_constructor }
75 static JNINativeMethod gDashPathEffectMethods[] = {
76 { "nativeCreate", "([FF)I", (void*)SkPathEffectGlue::Dash_constructor }
79 static JNINativeMethod gPathDashPathEffectMethods[] = {
80 { "nativeCreate", "(IFFI)I", (void*)SkPathEffectGlue::OneD_constructor }
83 static JNINativeMethod gCornerPathEffectMethods[] = {
84 { "nativeCreate", "(F)I", (void*)SkPathEffectGlue::Corner_constructor }
87 static JNINativeMethod gDiscretePathEffectMethods[] = {
88 { "nativeCreate", "(FF)I", (void*)SkPathEffectGlue::Discrete_constructor }
91 #include <android_runtime/AndroidRuntime.h>
93 #define REG(env, name, array) \
94 result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
95 SK_ARRAY_COUNT(array)); \
96 if (result < 0) return result
98 int register_android_graphics_PathEffect(JNIEnv* env);
99 int register_android_graphics_PathEffect(JNIEnv* env)
103 REG(env, "android/graphics/PathEffect", gPathEffectMethods);
104 REG(env, "android/graphics/ComposePathEffect", gComposePathEffectMethods);
105 REG(env, "android/graphics/SumPathEffect", gSumPathEffectMethods);
106 REG(env, "android/graphics/DashPathEffect", gDashPathEffectMethods);
107 REG(env, "android/graphics/PathDashPathEffect", gPathDashPathEffectMethods);
108 REG(env, "android/graphics/CornerPathEffect", gCornerPathEffectMethods);
109 REG(env, "android/graphics/DiscretePathEffect", gDiscretePathEffectMethods);