blob: 265944e216e2685785c8111fbc32fd3bd6aaf2a5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#include "GraphicsJNI.h"
Ben Wagner60126ef2015-08-07 12:13:48 -04002#include "Sk1DPathEffect.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003#include "SkCornerPathEffect.h"
4#include "SkDashPathEffect.h"
5#include "SkDiscretePathEffect.h"
Ben Wagner60126ef2015-08-07 12:13:48 -04006#include "SkPathEffect.h"
7#include "core_jni_helpers.h"
8
9#include <jni.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010
11class SkPathEffectGlue {
12public:
13
Ashok Bhat36bef0b2014-01-20 20:08:01 +000014 static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
15 SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
Derek Sollenberger6062c592011-02-22 13:55:04 -050016 SkSafeUnref(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017 }
18
Ashok Bhat36bef0b2014-01-20 20:08:01 +000019 static jlong Compose_constructor(JNIEnv* env, jobject,
20 jlong outerHandle, jlong innerHandle) {
21 SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle);
22 SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle);
Leon Scrogginscc11f152014-03-31 16:52:13 -040023 SkPathEffect* effect = SkComposePathEffect::Create(outer, inner);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000024 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070026
Ashok Bhat36bef0b2014-01-20 20:08:01 +000027 static jlong Sum_constructor(JNIEnv* env, jobject,
28 jlong firstHandle, jlong secondHandle) {
29 SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
30 SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
Leon Scrogginscc11f152014-03-31 16:52:13 -040031 SkPathEffect* effect = SkSumPathEffect::Create(first, second);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000032 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070034
Ashok Bhat36bef0b2014-01-20 20:08:01 +000035 static jlong Dash_constructor(JNIEnv* env, jobject,
36 jfloatArray intervalArray, jfloat phase) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 AutoJavaFloatArray autoInterval(env, intervalArray);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040038 int count = autoInterval.length() & ~1; // even number
39#ifdef SK_SCALAR_IS_FLOAT
40 SkScalar* intervals = autoInterval.ptr();
41#else
42 #error Need to convert float array to SkScalar array before calling the following function.
43#endif
44 SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, phase);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000045 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070047
Ashok Bhat36bef0b2014-01-20 20:08:01 +000048 static jlong OneD_constructor(JNIEnv* env, jobject,
49 jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
50 const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 SkASSERT(shape != NULL);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040052 SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, advance, phase,
53 (SkPath1DPathEffect::Style)style);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000054 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070056
Ashok Bhat36bef0b2014-01-20 20:08:01 +000057 static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040058 SkPathEffect* effect = SkCornerPathEffect::Create(radius);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000059 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070061
Ashok Bhat36bef0b2014-01-20 20:08:01 +000062 static jlong Discrete_constructor(JNIEnv* env, jobject,
63 jfloat length, jfloat deviation) {
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040064 SkPathEffect* effect = SkDiscretePathEffect::Create(length, deviation);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000065 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068};
69
70////////////////////////////////////////////////////////////////////////////////////////////////////////
71
72static JNINativeMethod gPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000073 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074};
75
76static JNINativeMethod gComposePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000077 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078};
79
80static JNINativeMethod gSumPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000081 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082};
83
84static JNINativeMethod gDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000085 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086};
87
88static JNINativeMethod gPathDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000089 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090};
91
92static JNINativeMethod gCornerPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000093 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094};
95
96static JNINativeMethod gDiscretePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000097 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098};
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100int register_android_graphics_PathEffect(JNIEnv* env)
101{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800102 android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
103 NELEM(gPathEffectMethods));
104 android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
105 gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
106 android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
107 NELEM(gSumPathEffectMethods));
108 android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
109 NELEM(gDashPathEffectMethods));
110 android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
111 gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
112 android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
113 gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
114 android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
115 gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
Elliott Hughes4cb17532011-04-12 16:10:26 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 return 0;
118}