blob: 9d0f0ad687556cbb2e202ac20d5946beae698ec7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#include <jni.h>
2#include "GraphicsJNI.h"
3
Andreas Gampeed6b9df2014-11-20 22:02:20 -08004#include "core_jni_helpers.h"
5
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006#include "SkPathEffect.h"
7#include "SkCornerPathEffect.h"
8#include "SkDashPathEffect.h"
9#include "SkDiscretePathEffect.h"
10#include "Sk1DPathEffect.h"
11#include "SkTemplates.h"
12
13class SkPathEffectGlue {
14public:
15
Ashok Bhat36bef0b2014-01-20 20:08:01 +000016 static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
17 SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
Derek Sollenberger6062c592011-02-22 13:55:04 -050018 SkSafeUnref(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019 }
20
Ashok Bhat36bef0b2014-01-20 20:08:01 +000021 static jlong Compose_constructor(JNIEnv* env, jobject,
22 jlong outerHandle, jlong innerHandle) {
23 SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle);
24 SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle);
Leon Scrogginscc11f152014-03-31 16:52:13 -040025 SkPathEffect* effect = SkComposePathEffect::Create(outer, inner);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000026 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070028
Ashok Bhat36bef0b2014-01-20 20:08:01 +000029 static jlong Sum_constructor(JNIEnv* env, jobject,
30 jlong firstHandle, jlong secondHandle) {
31 SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
32 SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
Leon Scrogginscc11f152014-03-31 16:52:13 -040033 SkPathEffect* effect = SkSumPathEffect::Create(first, second);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000034 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070036
Ashok Bhat36bef0b2014-01-20 20:08:01 +000037 static jlong Dash_constructor(JNIEnv* env, jobject,
38 jfloatArray intervalArray, jfloat phase) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 AutoJavaFloatArray autoInterval(env, intervalArray);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040040 int count = autoInterval.length() & ~1; // even number
41#ifdef SK_SCALAR_IS_FLOAT
42 SkScalar* intervals = autoInterval.ptr();
43#else
44 #error Need to convert float array to SkScalar array before calling the following function.
45#endif
46 SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, phase);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000047 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070049
Ashok Bhat36bef0b2014-01-20 20:08:01 +000050 static jlong OneD_constructor(JNIEnv* env, jobject,
51 jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
52 const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 SkASSERT(shape != NULL);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040054 SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, advance, phase,
55 (SkPath1DPathEffect::Style)style);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000056 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070058
Ashok Bhat36bef0b2014-01-20 20:08:01 +000059 static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040060 SkPathEffect* effect = SkCornerPathEffect::Create(radius);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000061 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070063
Ashok Bhat36bef0b2014-01-20 20:08:01 +000064 static jlong Discrete_constructor(JNIEnv* env, jobject,
65 jfloat length, jfloat deviation) {
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040066 SkPathEffect* effect = SkDiscretePathEffect::Create(length, deviation);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000067 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070};
71
72////////////////////////////////////////////////////////////////////////////////////////////////////////
73
74static JNINativeMethod gPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000075 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076};
77
78static JNINativeMethod gComposePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000079 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080};
81
82static JNINativeMethod gSumPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000083 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084};
85
86static JNINativeMethod gDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000087 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088};
89
90static JNINativeMethod gPathDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000091 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092};
93
94static JNINativeMethod gCornerPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000095 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096};
97
98static JNINativeMethod gDiscretePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000099 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100};
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102int register_android_graphics_PathEffect(JNIEnv* env)
103{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800104 android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
105 NELEM(gPathEffectMethods));
106 android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
107 gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
108 android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
109 NELEM(gSumPathEffectMethods));
110 android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
111 NELEM(gDashPathEffectMethods));
112 android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
113 gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
114 android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
115 gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
116 android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
117 gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
Elliott Hughes4cb17532011-04-12 16:10:26 -0700118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 return 0;
120}