1 #include "jni.h" 2 #include <android_runtime/AndroidRuntime.h> 3 4 #include "SkCamera.h" 5 6 static jfieldID gNativeInstanceFieldID; 7 8 static void Camera_constructor(JNIEnv* env, jobject obj) { 9 Sk3DView* view = new Sk3DView; 10 env->SetIntField(obj, gNativeInstanceFieldID, (int)view); 11 } 12 13 static void Camera_destructor(JNIEnv* env, jobject obj) { 14 delete (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 15 } 16 17 static void Camera_save(JNIEnv* env, jobject obj) { 18 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 19 v->save(); 20 } 21 22 static void Camera_restore(JNIEnv* env, jobject obj) { 23 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 24 v->restore(); 25 } 26 27 static void Camera_translate(JNIEnv* env, jobject obj, 28 float dx, float dy, float dz) { 29 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 30 v->translate(SkFloatToScalar(dx), SkFloatToScalar(dy), SkFloatToScalar(dz)); 31 } 32 33 static void Camera_rotateX(JNIEnv* env, jobject obj, float degrees) { 34 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 35 v->rotateX(SkFloatToScalar(degrees)); 36 } 37 38 static void Camera_rotateY(JNIEnv* env, jobject obj, float degrees) { 39 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 40 v->rotateY(SkFloatToScalar(degrees)); 41 } 42 43 static void Camera_rotateZ(JNIEnv* env, jobject obj, float degrees) { 44 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 45 v->rotateZ(SkFloatToScalar(degrees)); 46 } 47 48 static void Camera_getMatrix(JNIEnv* env, jobject obj, int native_matrix) { 49 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 50 v->getMatrix((SkMatrix*)native_matrix); 51 } 52 53 static void Camera_applyToCanvas(JNIEnv* env, jobject obj, int native_canvas) { 54 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 55 v->applyToCanvas((SkCanvas*)native_canvas); 56 } 57 58 static float Camera_dotWithNormal(JNIEnv* env, jobject obj, 59 float x, float y, float z) { 60 Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID); 61 SkScalar dot = v->dotWithNormal(SkFloatToScalar(x), SkFloatToScalar(y), 62 SkFloatToScalar(z)); 63 return SkScalarToFloat(dot); 64 } 65 66 // ---------------------------------------------------------------------------- 67 68 /* 69 * JNI registration. 70 */ 71 static JNINativeMethod gCameraMethods[] = { 72 /* name, signature, funcPtr */ 73 74 { "nativeConstructor", "()V", (void*)Camera_constructor }, 75 { "nativeDestructor", "()V", (void*)Camera_destructor }, 76 { "save", "()V", (void*)Camera_save }, 77 { "restore", "()V", (void*)Camera_restore }, 78 { "translate", "(FFF)V", (void*)Camera_translate }, 79 { "rotateX", "(F)V", (void*)Camera_rotateX }, 80 { "rotateY", "(F)V", (void*)Camera_rotateY }, 81 { "rotateZ", "(F)V", (void*)Camera_rotateZ }, 82 { "nativeGetMatrix", "(I)V", (void*)Camera_getMatrix }, 83 { "nativeApplyToCanvas", "(I)V", (void*)Camera_applyToCanvas }, 84 { "dotWithNormal", "(FFF)F", (void*)Camera_dotWithNormal } 85 }; 86 87 int register_android_graphics_Camera(JNIEnv* env); 88 int register_android_graphics_Camera(JNIEnv* env) { 89 jclass clazz = env->FindClass("android/graphics/Camera"); 90 if (clazz == 0) { 91 return -1; 92 } 93 gNativeInstanceFieldID = env->GetFieldID(clazz, "native_instance", "I"); 94 if (gNativeInstanceFieldID == 0) { 95 return -1; 96 } 97 return android::AndroidRuntime::registerNativeMethods(env, 98 "android/graphics/Camera", 99 gCameraMethods, 100 SK_ARRAY_COUNT(gCameraMethods)); 101 } 102 103