Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 1 | #include <jni.h> |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame^] | 2 | #include <log/log.h> |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "render_thread.h" |
| 7 | |
| 8 | #define JNI_METHOD(return_type, method_name) \ |
| 9 | JNIEXPORT return_type JNICALL \ |
| 10 | Java_com_google_vr_windowmanager_VrWindowManagerService_##method_name |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | inline jlong jptr(android::dvr::RenderThread* native_vr_window_manager) { |
| 15 | return reinterpret_cast<intptr_t>(native_vr_window_manager); |
| 16 | } |
| 17 | |
| 18 | inline android::dvr::RenderThread* native(jlong ptr) { |
| 19 | return reinterpret_cast<android::dvr::RenderThread*>(ptr); |
| 20 | } |
| 21 | |
| 22 | } // namespace |
| 23 | |
| 24 | extern "C" { |
| 25 | |
| 26 | JNI_METHOD(jlong, nativeCreate)(JNIEnv* env, jclass /*clazz*/, |
| 27 | jobject class_loader, |
| 28 | jobject android_context) { |
| 29 | return jptr(new android::dvr::RenderThread( |
| 30 | env, class_loader, android_context)); |
| 31 | } |
| 32 | |
| 33 | JNI_METHOD(void, nativeDestroy) |
| 34 | (JNIEnv* /*env*/, jclass /*clazz*/, jlong native_render_thread) { |
| 35 | delete native(native_render_thread); |
| 36 | } |
| 37 | |
| 38 | JNI_METHOD(void, nativeEnableDebug) |
| 39 | (JNIEnv* /*env*/, jclass /*clazz*/, jlong native_render_thread) { |
| 40 | native(native_render_thread)->EnableDebug(true); |
| 41 | } |
| 42 | |
| 43 | JNI_METHOD(void, nativeDisableDebug) |
| 44 | (JNIEnv* /*env*/, jclass /*clazz*/, jlong native_render_thread) { |
| 45 | native(native_render_thread)->EnableDebug(false); |
| 46 | } |
| 47 | |
| 48 | JNI_METHOD(void, nativeEnterVrMode) |
| 49 | (JNIEnv* /*env*/, jclass /*clazz*/, jlong native_render_thread) { |
| 50 | native(native_render_thread)->VrMode(true); |
| 51 | } |
| 52 | |
| 53 | JNI_METHOD(void, nativeExitVrMode) |
| 54 | (JNIEnv* /*env*/, jclass /*clazz*/, jlong native_render_thread) { |
| 55 | native(native_render_thread)->VrMode(false); |
| 56 | } |
| 57 | |
| 58 | } // extern "C" |