1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#include "jni.h"
#include "core_jni_helpers.h"
#include "SkCamera.h"
#include "Canvas.h"
#include "GraphicsJNI.h"
static jfieldID gNativeInstanceFieldID;
static void Camera_constructor(JNIEnv* env, jobject obj) {
Sk3DView* view = new Sk3DView;
env->SetLongField(obj, gNativeInstanceFieldID, reinterpret_cast<jlong>(view));
}
static void Camera_destructor(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* view = reinterpret_cast<Sk3DView*>(viewHandle);
delete view;
}
static void Camera_save(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->save();
}
static void Camera_restore(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->restore();
}
static void Camera_translate(JNIEnv* env, jobject obj,
jfloat dx, jfloat dy, jfloat dz) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->translate(dx, dy, dz);
}
static void Camera_rotateX(JNIEnv* env, jobject obj, jfloat degrees) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->rotateX(degrees);
}
static void Camera_rotateY(JNIEnv* env, jobject obj, jfloat degrees) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->rotateY(degrees);
}
static void Camera_rotateZ(JNIEnv* env, jobject obj, jfloat degrees) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->rotateZ(degrees);
}
static void Camera_rotate(JNIEnv* env, jobject obj, jfloat x, jfloat y, jfloat z) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->rotateX(x);
v->rotateY(y);
v->rotateZ(z);
}
static void Camera_setLocation(JNIEnv* env, jobject obj, jfloat x, jfloat y, jfloat z) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->setCameraLocation(x, y, z);
}
static jfloat Camera_getLocationX(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
return SkScalarToFloat(v->getCameraLocationX());
}
static jfloat Camera_getLocationY(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
return SkScalarToFloat(v->getCameraLocationY());
}
static jfloat Camera_getLocationZ(JNIEnv* env, jobject obj) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
return SkScalarToFloat(v->getCameraLocationZ());
}
static void Camera_getMatrix(JNIEnv* env, jobject obj, jlong matrixHandle) {
SkMatrix* native_matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->getMatrix(native_matrix);
}
static void Camera_applyToCanvas(JNIEnv* env, jobject obj, jlong canvasHandle) {
SkCanvas* canvas = reinterpret_cast<android::Canvas*>(canvasHandle)->asSkCanvas();
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
v->applyToCanvas(canvas);
}
static jfloat Camera_dotWithNormal(JNIEnv* env, jobject obj,
jfloat x, jfloat y, jfloat z) {
jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
SkScalar dot = v->dotWithNormal(x, y, z);
return SkScalarToFloat(dot);
}
// ----------------------------------------------------------------------------
/*
* JNI registration.
*/
static JNINativeMethod gCameraMethods[] = {
/* name, signature, funcPtr */
{ "nativeConstructor", "()V", (void*)Camera_constructor },
{ "nativeDestructor", "()V", (void*)Camera_destructor },
{ "save", "()V", (void*)Camera_save },
{ "restore", "()V", (void*)Camera_restore },
{ "translate", "(FFF)V", (void*)Camera_translate },
{ "rotateX", "(F)V", (void*)Camera_rotateX },
{ "rotateY", "(F)V", (void*)Camera_rotateY },
{ "rotateZ", "(F)V", (void*)Camera_rotateZ },
{ "rotate", "(FFF)V", (void*)Camera_rotate },
{ "setLocation", "(FFF)V", (void*)Camera_setLocation },
{ "getLocationX", "()F", (void*)Camera_getLocationX },
{ "getLocationY", "()F", (void*)Camera_getLocationY },
{ "getLocationZ", "()F", (void*)Camera_getLocationZ },
{ "nativeGetMatrix", "(J)V", (void*)Camera_getMatrix },
{ "nativeApplyToCanvas", "(J)V", (void*)Camera_applyToCanvas },
{ "dotWithNormal", "(FFF)F", (void*)Camera_dotWithNormal }
};
int register_android_graphics_Camera(JNIEnv* env) {
jclass clazz = android::FindClassOrDie(env, "android/graphics/Camera");
gNativeInstanceFieldID = android::GetFieldIDOrDie(env, clazz, "native_instance", "J");
return android::RegisterMethodsOrDie(env, "android/graphics/Camera", gCameraMethods,
NELEM(gCameraMethods));
}
|