blob: 81b46ce2beb277bf2b47ca7e1b7b9e58034f453f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#include <jni.h>
2#include "GraphicsJNI.h"
3
4#include "SkPathEffect.h"
5#include "SkCornerPathEffect.h"
6#include "SkDashPathEffect.h"
7#include "SkDiscretePathEffect.h"
8#include "Sk1DPathEffect.h"
9#include "SkTemplates.h"
10
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);
38 int count = autoInterval.length() & ~1; // even number
39 float* values = autoInterval.ptr();
40
41 SkAutoSTMalloc<32, SkScalar> storage(count);
Elliott Hughes4cb17532011-04-12 16:10:26 -070042 SkScalar* intervals = storage.get();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 for (int i = 0; i < count; i++) {
44 intervals[i] = SkFloatToScalar(values[i]);
45 }
Leon Scrogginscc11f152014-03-31 16:52:13 -040046 SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, SkFloatToScalar(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 Scrogginscc11f152014-03-31 16:52:13 -040054 SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, SkFloatToScalar(advance),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 SkFloatToScalar(phase), (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 Scrogginscc11f152014-03-31 16:52:13 -040060 SkPathEffect* effect = SkCornerPathEffect::Create(SkFloatToScalar(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 Scrogginscc11f152014-03-31 16:52:13 -040066 SkPathEffect* effect = SkDiscretePathEffect::Create(SkFloatToScalar(length),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 SkFloatToScalar(deviation));
Ashok Bhat36bef0b2014-01-20 20:08:01 +000068 return reinterpret_cast<jlong>(effect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 }
Elliott Hughes4cb17532011-04-12 16:10:26 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071};
72
73////////////////////////////////////////////////////////////////////////////////////////////////////////
74
75static JNINativeMethod gPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000076 { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077};
78
79static JNINativeMethod gComposePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000080 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081};
82
83static JNINativeMethod gSumPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000084 { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085};
86
87static JNINativeMethod gDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000088 { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089};
90
91static JNINativeMethod gPathDashPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000092 { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093};
94
95static JNINativeMethod gCornerPathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000096 { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097};
98
99static JNINativeMethod gDiscretePathEffectMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000100 { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101};
102
103#include <android_runtime/AndroidRuntime.h>
104
105#define REG(env, name, array) \
106 result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
107 SK_ARRAY_COUNT(array)); \
108 if (result < 0) return result
109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110int register_android_graphics_PathEffect(JNIEnv* env)
111{
112 int result;
Elliott Hughes4cb17532011-04-12 16:10:26 -0700113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 REG(env, "android/graphics/PathEffect", gPathEffectMethods);
115 REG(env, "android/graphics/ComposePathEffect", gComposePathEffectMethods);
116 REG(env, "android/graphics/SumPathEffect", gSumPathEffectMethods);
117 REG(env, "android/graphics/DashPathEffect", gDashPathEffectMethods);
118 REG(env, "android/graphics/PathDashPathEffect", gPathDashPathEffectMethods);
119 REG(env, "android/graphics/CornerPathEffect", gCornerPathEffectMethods);
120 REG(env, "android/graphics/DiscretePathEffect", gDiscretePathEffectMethods);
Elliott Hughes4cb17532011-04-12 16:10:26 -0700121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 return 0;
123}