1 #include <jni.h> 2 #include "GraphicsJNI.h" 3 4 #include "SkPathEffect.h" 5 #include "SkCornerPathEffect.h" 6 #include "SkDashPathEffect.h" 7 #include "SkDiscretePathEffect.h" 8 #include "Sk1DPathEffect.h" 9 #include "SkTemplates.h" 10 11 class SkPathEffectGlue { 12 public: 13 14 static void destructor(JNIEnv* env, jobject, SkPathEffect* effect) { 15 effect->safeUnref(); 16 } 17 18 static SkPathEffect* Compose_constructor(JNIEnv* env, jobject, 19 SkPathEffect* outer, SkPathEffect* inner) { 20 return new SkComposePathEffect(outer, inner); 21 } 22 23 static SkPathEffect* Sum_constructor(JNIEnv* env, jobject, 24 SkPathEffect* first, SkPathEffect* second) { 25 return new SkSumPathEffect(first, second); 26 } 27 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(); 33 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]); 38 } 39 return new SkDashPathEffect(intervals, count, SkFloatToScalar(phase)); 40 } 41 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); 47 } 48 49 static SkPathEffect* Corner_constructor(JNIEnv* env, jobject, float radius){ 50 return new SkCornerPathEffect(SkFloatToScalar(radius)); 51 } 52 53 static SkPathEffect* Discrete_constructor(JNIEnv* env, jobject, 54 float length, float deviation) { 55 return new SkDiscretePathEffect(SkFloatToScalar(length), 56 SkFloatToScalar(deviation)); 57 } 58 59 }; 60 61 //////////////////////////////////////////////////////////////////////////////////////////////////////// 62 63 static JNINativeMethod gPathEffectMethods[] = { 64 { "nativeDestructor", "(I)V", (void*)SkPathEffectGlue::destructor } 65 }; 66 67 static JNINativeMethod gComposePathEffectMethods[] = { 68 { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Compose_constructor } 69 }; 70 71 static JNINativeMethod gSumPathEffectMethods[] = { 72 { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Sum_constructor } 73 }; 74 75 static JNINativeMethod gDashPathEffectMethods[] = { 76 { "nativeCreate", "([FF)I", (void*)SkPathEffectGlue::Dash_constructor } 77 }; 78 79 static JNINativeMethod gPathDashPathEffectMethods[] = { 80 { "nativeCreate", "(IFFI)I", (void*)SkPathEffectGlue::OneD_constructor } 81 }; 82 83 static JNINativeMethod gCornerPathEffectMethods[] = { 84 { "nativeCreate", "(F)I", (void*)SkPathEffectGlue::Corner_constructor } 85 }; 86 87 static JNINativeMethod gDiscretePathEffectMethods[] = { 88 { "nativeCreate", "(FF)I", (void*)SkPathEffectGlue::Discrete_constructor } 89 }; 90 91 #include <android_runtime/AndroidRuntime.h> 92 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 97 98 int register_android_graphics_PathEffect(JNIEnv* env); 99 int register_android_graphics_PathEffect(JNIEnv* env) 100 { 101 int result; 102 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); 110 111 return 0; 112 } 113 114