blob: f99bef7b7d58347bf654d23d071b80b4553c69f2 [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"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007
8class SkPathEffectGlue {
9public:
10
Ashok Bhat36bef0b2014-01-20 20:08:01 +000011 static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
12 SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
Derek Sollenberger6062c592011-02-22 13:55:04 -050013 SkSafeUnref(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080014 }
15
Ashok Bhat36bef0b2014-01-20 20:08:01 +000016 static jlong Compose_constructor(JNIEnv* env, jobject,
17 jlong outerHandle, jlong innerHandle) {
18 SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle);
19 SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle);
Mike Reed97fa2292017-03-01 14:08:24 -050020 SkPathEffect* effect = SkPathEffect::MakeCompose(sk_ref_sp(outer),
Mike Reed260ab722016-10-07 15:59:20 -040021 sk_ref_sp(inner)).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000022 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070024
Ashok Bhat36bef0b2014-01-20 20:08:01 +000025 static jlong Sum_constructor(JNIEnv* env, jobject,
26 jlong firstHandle, jlong secondHandle) {
27 SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
28 SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
Mike Reed97fa2292017-03-01 14:08:24 -050029 SkPathEffect* effect = SkPathEffect::MakeSum(sk_ref_sp(first),
Mike Reed260ab722016-10-07 15:59:20 -040030 sk_ref_sp(second)).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000031 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070033
Ashok Bhat36bef0b2014-01-20 20:08:01 +000034 static jlong Dash_constructor(JNIEnv* env, jobject,
35 jfloatArray intervalArray, jfloat phase) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 AutoJavaFloatArray autoInterval(env, intervalArray);
Leon Scroggins III2e0103e2014-04-04 17:05:24 -040037 int count = autoInterval.length() & ~1; // even number
38#ifdef SK_SCALAR_IS_FLOAT
39 SkScalar* intervals = autoInterval.ptr();
40#else
41 #error Need to convert float array to SkScalar array before calling the following function.
42#endif
Mike Reed260ab722016-10-07 15:59:20 -040043 SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000044 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070046
Ashok Bhat36bef0b2014-01-20 20:08:01 +000047 static jlong OneD_constructor(JNIEnv* env, jobject,
48 jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
49 const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 SkASSERT(shape != NULL);
Mike Reed260ab722016-10-07 15:59:20 -040051 SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase,
52 (SkPath1DPathEffect::Style)style).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000053 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070055
Ashok Bhat36bef0b2014-01-20 20:08:01 +000056 static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
Mike Reed260ab722016-10-07 15:59:20 -040057 SkPathEffect* effect = SkCornerPathEffect::Make(radius).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000058 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070060
Ashok Bhat36bef0b2014-01-20 20:08:01 +000061 static jlong Discrete_constructor(JNIEnv* env, jobject,
62 jfloat length, jfloat deviation) {
Mike Reed260ab722016-10-07 15:59:20 -040063 SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000064 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067};
68
69////////////////////////////////////////////////////////////////////////////////////////////////////////
70
Daniel Micay76f6a862015-09-19 17:31:01 -040071static const JNINativeMethod gPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000072 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073};
74
Daniel Micay76f6a862015-09-19 17:31:01 -040075static const JNINativeMethod gComposePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000076 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077};
78
Daniel Micay76f6a862015-09-19 17:31:01 -040079static const JNINativeMethod gSumPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000080 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081};
82
Daniel Micay76f6a862015-09-19 17:31:01 -040083static const JNINativeMethod gDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000084 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085};
86
Daniel Micay76f6a862015-09-19 17:31:01 -040087static const JNINativeMethod gPathDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000088 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089};
90
Daniel Micay76f6a862015-09-19 17:31:01 -040091static const JNINativeMethod gCornerPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000092 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093};
94
Daniel Micay76f6a862015-09-19 17:31:01 -040095static const JNINativeMethod gDiscretePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000096 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097};
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099int register_android_graphics_PathEffect(JNIEnv* env)
100{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800101 android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
102 NELEM(gPathEffectMethods));
103 android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
104 gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
105 android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
106 NELEM(gSumPathEffectMethods));
107 android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
108 NELEM(gDashPathEffectMethods));
109 android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
110 gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
111 android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
112 gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
113 android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
114 gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
Elliott Hughes4cb17532011-04-12 16:10:26 -0700115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 return 0;
117}