blob: a4992de72ff63c9fb7a8294740282dc85724b218 [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);
Mike Reed97fa2292017-03-01 14:08:24 -050023 SkPathEffect* effect = SkPathEffect::MakeCompose(sk_ref_sp(outer),
Mike Reed260ab722016-10-07 15:59:20 -040024 sk_ref_sp(inner)).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000025 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070027
Ashok Bhat36bef0b2014-01-20 20:08:01 +000028 static jlong Sum_constructor(JNIEnv* env, jobject,
29 jlong firstHandle, jlong secondHandle) {
30 SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
31 SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
Mike Reed97fa2292017-03-01 14:08:24 -050032 SkPathEffect* effect = SkPathEffect::MakeSum(sk_ref_sp(first),
Mike Reed260ab722016-10-07 15:59:20 -040033 sk_ref_sp(second)).release();
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
Mike Reed260ab722016-10-07 15:59:20 -040046 SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release();
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);
Mike Reed260ab722016-10-07 15:59:20 -040054 SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase,
55 (SkPath1DPathEffect::Style)style).release();
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){
Mike Reed260ab722016-10-07 15:59:20 -040060 SkPathEffect* effect = SkCornerPathEffect::Make(radius).release();
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) {
Mike Reed260ab722016-10-07 15:59:20 -040066 SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release();
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
Daniel Micay76f6a862015-09-19 17:31:01 -040074static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040078static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040082static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040086static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040090static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040094static const 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
Daniel Micay76f6a862015-09-19 17:31:01 -040098static const 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}