blob: 3dbe1a67f52edf6bf2927bd1a044e9323a8d4f33 [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
Kevin Lubickdd1e5ef2023-02-16 19:50:00 +000038 SkScalar* intervals = autoInterval.ptr();
Mike Reed260ab722016-10-07 15:59:20 -040039 SkPathEffect* effect = SkDashPathEffect::Make(intervals, count, phase).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000040 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070042
Ashok Bhat36bef0b2014-01-20 20:08:01 +000043 static jlong OneD_constructor(JNIEnv* env, jobject,
44 jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
45 const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 SkASSERT(shape != NULL);
Mike Reed260ab722016-10-07 15:59:20 -040047 SkPathEffect* effect = SkPath1DPathEffect::Make(*shape, advance, phase,
48 (SkPath1DPathEffect::Style)style).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000049 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070051
Ashok Bhat36bef0b2014-01-20 20:08:01 +000052 static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
Mike Reed260ab722016-10-07 15:59:20 -040053 SkPathEffect* effect = SkCornerPathEffect::Make(radius).release();
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 Discrete_constructor(JNIEnv* env, jobject,
58 jfloat length, jfloat deviation) {
Mike Reed260ab722016-10-07 15:59:20 -040059 SkPathEffect* effect = SkDiscretePathEffect::Make(length, deviation).release();
Ashok Bhat36bef0b2014-01-20 20:08:01 +000060 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063};
64
65////////////////////////////////////////////////////////////////////////////////////////////////////////
66
Daniel Micay76f6a862015-09-19 17:31:01 -040067static const JNINativeMethod gPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000068 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069};
70
Daniel Micay76f6a862015-09-19 17:31:01 -040071static const JNINativeMethod gComposePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000072 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073};
74
Daniel Micay76f6a862015-09-19 17:31:01 -040075static const JNINativeMethod gSumPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000076 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077};
78
Daniel Micay76f6a862015-09-19 17:31:01 -040079static const JNINativeMethod gDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000080 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081};
82
Daniel Micay76f6a862015-09-19 17:31:01 -040083static const JNINativeMethod gPathDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000084 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085};
86
Daniel Micay76f6a862015-09-19 17:31:01 -040087static const JNINativeMethod gCornerPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000088 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089};
90
Daniel Micay76f6a862015-09-19 17:31:01 -040091static const JNINativeMethod gDiscretePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000092 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093};
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095int register_android_graphics_PathEffect(JNIEnv* env)
96{
Andreas Gampeed6b9df2014-11-20 22:02:20 -080097 android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
98 NELEM(gPathEffectMethods));
99 android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
100 gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
101 android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
102 NELEM(gSumPathEffectMethods));
103 android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
104 NELEM(gDashPathEffectMethods));
105 android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
106 gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
107 android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
108 gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
109 android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
110 gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
Elliott Hughes4cb17532011-04-12 16:10:26 -0700111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 return 0;
113}