diff options
author | dhewg | 2011-02-23 22:44:33 +0100 |
---|---|---|
committer | dhewg | 2011-02-24 23:18:32 +0100 |
commit | f80d993860257a8e74936bc74eb99bda2fbfcaa4 (patch) | |
tree | 8a2e1226757706fe8e4bec23b9b135c46f42f68d /backends | |
parent | c4706733d45de09803b7cd40c3536a4e04b4f767 (diff) | |
download | scummvm-rg350-f80d993860257a8e74936bc74eb99bda2fbfcaa4.tar.gz scummvm-rg350-f80d993860257a8e74936bc74eb99bda2fbfcaa4.tar.bz2 scummvm-rg350-f80d993860257a8e74936bc74eb99bda2fbfcaa4.zip |
ANDROID: Wrap JNI code in a class
Diffstat (limited to 'backends')
-rw-r--r-- | backends/platform/android/android.cpp | 25 | ||||
-rw-r--r-- | backends/platform/android/android.h | 8 | ||||
-rw-r--r-- | backends/platform/android/asset-archive.cpp | 21 | ||||
-rw-r--r-- | backends/platform/android/gfx.cpp | 6 | ||||
-rw-r--r-- | backends/platform/android/jni.cpp | 301 | ||||
-rw-r--r-- | backends/platform/android/jni.h | 87 |
6 files changed, 265 insertions, 183 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f2c9a7407d..9437bf540c 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -98,8 +98,6 @@ static inline T scalef(T in, float numerator, float denominator) { return static_cast<float>(in) * numerator / denominator; } -OSystem_Android *g_sys = 0; - OSystem_Android::OSystem_Android(jobject am) : _screen_changeid(0), _force_redraw(false), @@ -166,7 +164,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); - JNU_AttachThread(); + JNI::attachThread(); struct timespec tv; tv.tv_sec = 0; @@ -177,7 +175,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { nanosleep(&tv, 0); } - JNU_DetachThread(); + JNI::detachThread(); return 0; } @@ -185,7 +183,7 @@ void *OSystem_Android::timerThreadFunc(void *arg) { void OSystem_Android::initBackend() { ENTER(); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); ConfMan.setInt("autosave_period", 0); ConfMan.setInt("FM_medium_quality", true); @@ -235,10 +233,10 @@ void OSystem_Android::initBackend() { void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { ENTER(); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); jobjectArray array = (jobjectArray)env->CallObjectMethod(back_ptr, MID_getPluginDirectories); + if (env->ExceptionCheck()) { warning("Error finding plugin directories"); @@ -477,7 +475,7 @@ void OSystem_Android::quit() { void OSystem_Android::setWindowCaption(const char *caption) { ENTER("%s", caption); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring java_caption = env->NewStringUTF(caption); env->CallVoidMethod(back_ptr, MID_setWindowCaption, java_caption); @@ -494,9 +492,8 @@ void OSystem_Android::setWindowCaption(const char *caption) { void OSystem_Android::displayMessageOnOSD(const char *msg) { ENTER("%s", msg); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring java_msg = env->NewStringUTF(msg); - env->CallVoidMethod(back_ptr, MID_displayMessageOnOSD, java_msg); if (env->ExceptionCheck()) { @@ -512,8 +509,7 @@ void OSystem_Android::displayMessageOnOSD(const char *msg) { void OSystem_Android::showVirtualKeyboard(bool enable) { ENTER("%d", enable); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); env->CallVoidMethod(back_ptr, MID_showVirtualKeyboard, enable); if (env->ExceptionCheck()) { @@ -560,8 +556,7 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { s.add("ASSET", _asset_archive, priority, false); - JNIEnv *env = JNU_GetEnv(); - + JNIEnv *env = JNI::getEnv(); jobjectArray array = (jobjectArray)env->CallObjectMethod(back_ptr, MID_getSysArchives); @@ -606,7 +601,7 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) #ifdef DYNAMIC_MODULES void AndroidPluginProvider::addCustomDirectories(Common::FSList &dirs) const { - g_sys->addPluginDirectories(dirs); + ((OSystem_Android *)g_system)->addPluginDirectories(dirs); } #endif diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index da487c5ceb..0ccf57e7c1 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -36,6 +36,7 @@ #include "backends/plugins/posix/posix-provider.h" #include "backends/fs/posix/posix-fs-factory.h" +#include "backends/platform/android/jni.h" #include "backends/platform/android/texture.h" #include <pthread.h> @@ -81,13 +82,6 @@ extern void checkGlError(const char *expr, const char *file, int line); // back pointer to (java) peer instance extern jobject back_ptr; -extern JNIEnv *JNU_GetEnv(); -extern void JNU_AttachThread(); -extern void JNU_DetachThread(); - -class OSystem_Android; -extern OSystem_Android *g_sys; - #ifdef DYNAMIC_MODULES class AndroidPluginProvider : public POSIXPluginProvider { protected: diff --git a/backends/platform/android/asset-archive.cpp b/backends/platform/android/asset-archive.cpp index 71ce25aa72..eb2530823d 100644 --- a/backends/platform/android/asset-archive.cpp +++ b/backends/platform/android/asset-archive.cpp @@ -36,10 +36,9 @@ #include "common/archive.h" #include "common/debug.h" +#include "backends/platform/android/jni.h" #include "backends/platform/android/asset-archive.h" -extern JNIEnv *JNU_GetEnv(); - // Must match android.content.res.AssetManager.ACCESS_* const jint ACCESS_UNKNOWN = 0; const jint ACCESS_RANDOM = 1; @@ -124,7 +123,7 @@ JavaInputStream::JavaInputStream(JNIEnv *env, jobject is) : } JavaInputStream::~JavaInputStream() { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); close(env); env->DeleteGlobalRef(_buf); @@ -139,7 +138,7 @@ void JavaInputStream::close(JNIEnv *env) { } uint32 JavaInputStream::read(void *dataPtr, uint32 dataSize) { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); if (_buflen < jint(dataSize)) { _buflen = dataSize; @@ -171,7 +170,7 @@ uint32 JavaInputStream::read(void *dataPtr, uint32 dataSize) { } bool JavaInputStream::seek(int32 offset, int whence) { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); uint32 newpos; switch (whence) { @@ -318,7 +317,7 @@ AssetFdReadStream::AssetFdReadStream(JNIEnv *env, jobject assetfd) : } AssetFdReadStream::~AssetFdReadStream() { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); env->CallVoidMethod(_assetfd, MID_close); if (env->ExceptionCheck()) @@ -369,7 +368,7 @@ bool AssetFdReadStream::seek(int32 offset, int whence) { } AndroidAssetArchive::AndroidAssetArchive(jobject am) { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); _am = env->NewGlobalRef(am); jclass cls = env->GetObjectClass(_am); @@ -387,12 +386,12 @@ AndroidAssetArchive::AndroidAssetArchive(jobject am) { } AndroidAssetArchive::~AndroidAssetArchive() { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); env->DeleteGlobalRef(_am); } bool AndroidAssetArchive::hasFile(const Common::String &name) { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring path = env->NewStringUTF(name.c_str()); jobject result = env->CallObjectMethod(_am, MID_open, path, ACCESS_UNKNOWN); if (env->ExceptionCheck()) { @@ -412,7 +411,7 @@ bool AndroidAssetArchive::hasFile(const Common::String &name) { } int AndroidAssetArchive::listMembers(Common::ArchiveMemberList &member_list) { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); Common::List<Common::String> dirlist; dirlist.push_back(""); @@ -469,7 +468,7 @@ Common::ArchiveMemberPtr AndroidAssetArchive::getMember(const Common::String &na } Common::SeekableReadStream *AndroidAssetArchive::createReadStreamForMember(const Common::String &path) const { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); jstring jpath = env->NewStringUTF(path.c_str()); // Try openFd() first ... diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp index 2b730385e6..2370958d30 100644 --- a/backends/platform/android/gfx.cpp +++ b/backends/platform/android/gfx.cpp @@ -62,7 +62,7 @@ int OSystem_Android::getGraphicsMode() const { void OSystem_Android::setupScummVMSurface() { ENTER(); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); env->CallVoidMethod(back_ptr, MID_setupScummVMSurface); if (env->ExceptionCheck()) @@ -116,7 +116,7 @@ void OSystem_Android::setupScummVMSurface() { } void OSystem_Android::destroyScummVMSurface() { - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); env->CallVoidMethod(back_ptr, MID_destroyScummVMSurface); // Can't use OpenGLES functions after this } @@ -261,7 +261,7 @@ void OSystem_Android::updateScreen() { GLCALL(glPopMatrix()); - JNIEnv *env = JNU_GetEnv(); + JNIEnv *env = JNI::getEnv(); if (!env->CallBooleanMethod(back_ptr, MID_swapBuffers)) { // Context lost -> need to reinit GL destroyScummVMSurface(); diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index b81587b3ba..4fa08ef7ab 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -30,28 +30,116 @@ #include "backends/platform/android/android.h" -// Fix JNIEXPORT declaration to actually do something useful -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) - jobject back_ptr; -static JavaVM *cached_jvm; +__attribute__ ((visibility("default"))) +jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { + return JNI::onLoad(vm); +} + +JavaVM *JNI::_vm = 0; +jobject JNI::_jobj = 0; +OSystem_Android *JNI::_system = 0; + +jfieldID JNI::_FID_Event_type = 0; +jfieldID JNI::_FID_Event_synthetic = 0; +jfieldID JNI::_FID_Event_kbd_keycode = 0; +jfieldID JNI::_FID_Event_kbd_ascii = 0; +jfieldID JNI::_FID_Event_kbd_flags = 0; +jfieldID JNI::_FID_Event_mouse_x = 0; +jfieldID JNI::_FID_Event_mouse_y = 0; +jfieldID JNI::_FID_Event_mouse_relative = 0; +jfieldID JNI::_FID_ScummVM_nativeScummVM = 0; + +const JNINativeMethod JNI::_natives[] = { + { "create", "(Landroid/content/res/AssetManager;)V", + (void *)JNI::create }, + { "nativeDestroy", "()V", + (void *)JNI::destroy }, + { "scummVMMain", "([Ljava/lang/String;)I", + (void *)JNI::main }, + { "pushEvent", "(Lorg/inodes/gus/scummvm/Event;)V", + (void *)JNI::pushEvent }, + { "audioMixCallback", "([B)V", + (void *)JNI::audioMixCallback }, + { "setConfMan", "(Ljava/lang/String;I)V", + (void *)JNI::setConfManInt }, + { "setConfMan", "(Ljava/lang/String;Ljava/lang/String;)V", + (void *)JNI::setConfManString }, + { "enableZoning", "(Z)V", + (void *)JNI::enableZoning }, + { "setSurfaceSize", "(II)V", + (void *)JNI::setSurfaceSize }, +}; + +JNI::JNI() { +} + +JNI::~JNI() { +} + +jint JNI::onLoad(JavaVM *vm) { + _vm = vm; + + JNIEnv *env; + + if (_vm->GetEnv((void **)&env, JNI_VERSION_1_2)) + return JNI_ERR; + + jclass cls = env->FindClass("org/inodes/gus/scummvm/ScummVM"); + if (cls == 0) + return JNI_ERR; + + if (env->RegisterNatives(cls, _natives, ARRAYSIZE(_natives)) < 0) + return JNI_ERR; + + _FID_ScummVM_nativeScummVM = env->GetFieldID(cls, "nativeScummVM", "J"); + if (_FID_ScummVM_nativeScummVM == 0) + return JNI_ERR; + + jclass event = env->FindClass("org/inodes/gus/scummvm/Event"); + if (event == 0) + return JNI_ERR; + + _FID_Event_type = env->GetFieldID(event, "type", "I"); + if (_FID_Event_type == 0) + return JNI_ERR; + + _FID_Event_synthetic = env->GetFieldID(event, "synthetic", "Z"); + if (_FID_Event_synthetic == 0) + return JNI_ERR; + + _FID_Event_kbd_keycode = env->GetFieldID(event, "kbd_keycode", "I"); + if (_FID_Event_kbd_keycode == 0) + return JNI_ERR; + + _FID_Event_kbd_ascii = env->GetFieldID(event, "kbd_ascii", "I"); + if (_FID_Event_kbd_ascii == 0) + return JNI_ERR; + + _FID_Event_kbd_flags = env->GetFieldID(event, "kbd_flags", "I"); + if (_FID_Event_kbd_flags == 0) + return JNI_ERR; + + _FID_Event_mouse_x = env->GetFieldID(event, "mouse_x", "I"); + if (_FID_Event_mouse_x == 0) + return JNI_ERR; + + _FID_Event_mouse_y = env->GetFieldID(event, "mouse_y", "I"); + if (_FID_Event_mouse_y == 0) + return JNI_ERR; + + _FID_Event_mouse_relative = env->GetFieldID(event, "mouse_relative", "Z"); + if (_FID_Event_mouse_relative == 0) + return JNI_ERR; -static jfieldID FID_Event_type; -static jfieldID FID_Event_synthetic; -static jfieldID FID_Event_kbd_keycode; -static jfieldID FID_Event_kbd_ascii; -static jfieldID FID_Event_kbd_flags; -static jfieldID FID_Event_mouse_x; -static jfieldID FID_Event_mouse_y; -static jfieldID FID_Event_mouse_relative; -static jfieldID FID_ScummVM_nativeScummVM; + return JNI_VERSION_1_2; +} -JNIEnv *JNU_GetEnv() { +JNIEnv *JNI::getEnv() { JNIEnv *env = 0; - jint res = cached_jvm->GetEnv((void **)&env, JNI_VERSION_1_2); + jint res = _vm->GetEnv((void **)&env, JNI_VERSION_1_2); if (res != JNI_OK) { LOGE("GetEnv() failed: %d", res); @@ -61,9 +149,10 @@ JNIEnv *JNU_GetEnv() { return env; } -void JNU_AttachThread() { +void JNI::attachThread() { JNIEnv *env = 0; - jint res = cached_jvm->AttachCurrentThread(&env, 0); + + jint res = _vm->AttachCurrentThread(&env, 0); if (res != JNI_OK) { LOGE("AttachCurrentThread() failed: %d", res); @@ -71,8 +160,8 @@ void JNU_AttachThread() { } } -void JNU_DetachThread() { - jint res = cached_jvm->DetachCurrentThread(); +void JNI::detachThread() { + jint res = _vm->DetachCurrentThread(); if (res != JNI_OK) { LOGE("DetachCurrentThread() failed: %d", res); @@ -80,7 +169,7 @@ void JNU_DetachThread() { } } -static void JNU_ThrowByName(JNIEnv *env, const char *name, const char *msg) { +void JNI::throwByName(JNIEnv *env, const char *name, const char *msg) { jclass cls = env->FindClass(name); // if cls is 0, an exception has already been thrown @@ -90,49 +179,50 @@ static void JNU_ThrowByName(JNIEnv *env, const char *name, const char *msg) { env->DeleteLocalRef(cls); } -static void ScummVM_create(JNIEnv *env, jobject self, jobject am) { - assert(!g_system); +void JNI::create(JNIEnv *env, jobject self, jobject am) { + assert(!_system); - g_sys = new OSystem_Android(am); - assert(g_sys); + _system = new OSystem_Android(am); + assert(_system); // weak global ref to allow class to be unloaded // ... except dalvik implements NewWeakGlobalRef only on froyo - //back_ptr = env->NewWeakGlobalRef(self); - back_ptr = env->NewGlobalRef(self); + //_jobj = env->NewWeakGlobalRef(self); + _jobj = env->NewGlobalRef(self); + back_ptr = _jobj; // Exception already thrown by initJavaHooks? - if (!g_sys->initJavaHooks(env)) + if (!_system->initJavaHooks(env)) return; - env->SetLongField(self, FID_ScummVM_nativeScummVM, (jlong)g_sys); + env->SetLongField(self, _FID_ScummVM_nativeScummVM, (jlong)_system); - g_system = g_sys; + g_system = _system; } -static void ScummVM_nativeDestroy(JNIEnv *env, jobject self) { - assert(g_sys); +void JNI::destroy(JNIEnv *env, jobject self) { + assert(_system); - OSystem_Android *tmp = g_sys; + OSystem_Android *tmp = _system; g_system = 0; - g_sys = 0; + _system = 0; delete tmp; // see above - //JNU_GetEnv()->DeleteWeakGlobalRef(back_ptr); - JNU_GetEnv()->DeleteGlobalRef(back_ptr); + //JNI::getEnv()->DeleteWeakGlobalRef(_jobj); + JNI::getEnv()->DeleteGlobalRef(_jobj); } -static jint ScummVM_scummVMMain(JNIEnv *env, jobject self, jobjectArray args) { - assert(g_sys); +jint JNI::main(JNIEnv *env, jobject self, jobjectArray args) { + assert(_system); const int MAX_NARGS = 32; int res = -1; int argc = env->GetArrayLength(args); if (argc > MAX_NARGS) { - JNU_ThrowByName(env, "java/lang/IllegalArgumentException", - "too many arguments"); + throwByName(env, "java/lang/IllegalArgumentException", + "too many arguments"); return 0; } @@ -169,7 +259,7 @@ static jint ScummVM_scummVMMain(JNIEnv *env, jobject self, jobjectArray args) { LOGI("Exiting scummvm_main"); - g_sys->quit(); + _system->quit(); cleanup: nargs--; @@ -191,25 +281,25 @@ cleanup: return res; } -static void ScummVM_pushEvent(JNIEnv *env, jobject self, jobject java_event) { - assert(g_sys); +void JNI::pushEvent(JNIEnv *env, jobject self, jobject java_event) { + assert(_system); Common::Event event; event.type = (Common::EventType)env->GetIntField(java_event, - FID_Event_type); + _FID_Event_type); event.synthetic = - env->GetBooleanField(java_event, FID_Event_synthetic); + env->GetBooleanField(java_event, _FID_Event_synthetic); switch (event.type) { case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: event.kbd.keycode = (Common::KeyCode)env->GetIntField( - java_event, FID_Event_kbd_keycode); + java_event, _FID_Event_kbd_keycode); event.kbd.ascii = static_cast<int>(env->GetIntField( - java_event, FID_Event_kbd_ascii)); + java_event, _FID_Event_kbd_ascii)); event.kbd.flags = static_cast<int>(env->GetIntField( - java_event, FID_Event_kbd_flags)); + java_event, _FID_Event_kbd_flags)); break; case Common::EVENT_MOUSEMOVE: case Common::EVENT_LBUTTONDOWN: @@ -221,25 +311,24 @@ static void ScummVM_pushEvent(JNIEnv *env, jobject self, jobject java_event) { case Common::EVENT_MBUTTONDOWN: case Common::EVENT_MBUTTONUP: event.mouse.x = - env->GetIntField(java_event, FID_Event_mouse_x); + env->GetIntField(java_event, _FID_Event_mouse_x); event.mouse.y = - env->GetIntField(java_event, FID_Event_mouse_y); + env->GetIntField(java_event, _FID_Event_mouse_y); // This is a terrible hack. We stash "relativeness" // in the kbd.flags field until pollEvent() can work // it out. event.kbd.flags = env->GetBooleanField( - java_event, FID_Event_mouse_relative) ? 1 : 0; + java_event, _FID_Event_mouse_relative) ? 1 : 0; break; default: break; } - g_sys->pushEvent(event); + _system->pushEvent(event); } -static void ScummVM_audioMixCallback(JNIEnv *env, jobject self, - jbyteArray jbuf) { - assert(g_sys); +void JNI::audioMixCallback(JNIEnv *env, jobject self, jbyteArray jbuf) { + assert(_system); jsize len = env->GetArrayLength(jbuf); jbyte *buf = env->GetByteArrayElements(jbuf, 0); @@ -250,15 +339,14 @@ static void ScummVM_audioMixCallback(JNIEnv *env, jobject self, } Audio::MixerImpl *mixer = - static_cast<Audio::MixerImpl *>(g_sys->getMixer()); + static_cast<Audio::MixerImpl *>(_system->getMixer()); assert(mixer); mixer->mixCallback(reinterpret_cast<byte *>(buf), len); env->ReleaseByteArrayElements(jbuf, buf, 0); } -static void ScummVM_setConfManInt(JNIEnv *env, jclass cls, - jstring key_obj, jint value) { +void JNI::setConfManInt(JNIEnv *env, jclass cls, jstring key_obj, jint value) { ENTER("%p, %d", key_obj, (int)value); const char *key = env->GetStringUTFChars(key_obj, 0); @@ -271,8 +359,8 @@ static void ScummVM_setConfManInt(JNIEnv *env, jclass cls, env->ReleaseStringUTFChars(key_obj, key); } -static void ScummVM_setConfManString(JNIEnv *env, jclass cls, jstring key_obj, - jstring value_obj) { +void JNI::setConfManString(JNIEnv *env, jclass cls, jstring key_obj, + jstring value_obj) { ENTER("%p, %p", key_obj, value_obj); const char *key = env->GetStringUTFChars(key_obj, 0); @@ -293,97 +381,16 @@ static void ScummVM_setConfManString(JNIEnv *env, jclass cls, jstring key_obj, env->ReleaseStringUTFChars(key_obj, key); } -static void ScummVM_enableZoning(JNIEnv *env, jobject self, jboolean enable) { - assert(g_sys); +void JNI::enableZoning(JNIEnv *env, jobject self, jboolean enable) { + assert(_system); - g_sys->enableZoning(enable); + _system->enableZoning(enable); } -static void ScummVM_setSurfaceSize(JNIEnv *env, jobject self, - jint width, jint height) { - assert(g_sys); - - g_sys->setSurfaceSize(width, height); -} - -const static JNINativeMethod gMethods[] = { - { "create", "(Landroid/content/res/AssetManager;)V", - (void *)ScummVM_create }, - { "nativeDestroy", "()V", - (void *)ScummVM_nativeDestroy }, - { "scummVMMain", "([Ljava/lang/String;)I", - (void *)ScummVM_scummVMMain }, - { "pushEvent", "(Lorg/inodes/gus/scummvm/Event;)V", - (void *)ScummVM_pushEvent }, - { "audioMixCallback", "([B)V", - (void *)ScummVM_audioMixCallback }, - { "setConfMan", "(Ljava/lang/String;I)V", - (void *)ScummVM_setConfManInt }, - { "setConfMan", "(Ljava/lang/String;Ljava/lang/String;)V", - (void *)ScummVM_setConfManString }, - { "enableZoning", "(Z)V", - (void *)ScummVM_enableZoning }, - { "setSurfaceSize", "(II)V", - (void *)ScummVM_setSurfaceSize }, -}; - -JNIEXPORT jint JNICALL -JNI_OnLoad(JavaVM *jvm, void *reserved) { - cached_jvm = jvm; - - JNIEnv *env; - - if (jvm->GetEnv((void **)&env, JNI_VERSION_1_2)) - return JNI_ERR; - - jclass cls = env->FindClass("org/inodes/gus/scummvm/ScummVM"); - if (cls == 0) - return JNI_ERR; - - if (env->RegisterNatives(cls, gMethods, ARRAYSIZE(gMethods)) < 0) - return JNI_ERR; - - FID_ScummVM_nativeScummVM = env->GetFieldID(cls, "nativeScummVM", "J"); - if (FID_ScummVM_nativeScummVM == 0) - return JNI_ERR; +void JNI::setSurfaceSize(JNIEnv *env, jobject self, jint width, jint height) { + assert(_system); - jclass event = env->FindClass("org/inodes/gus/scummvm/Event"); - if (event == 0) - return JNI_ERR; - - FID_Event_type = env->GetFieldID(event, "type", "I"); - if (FID_Event_type == 0) - return JNI_ERR; - - FID_Event_synthetic = env->GetFieldID(event, "synthetic", "Z"); - if (FID_Event_synthetic == 0) - return JNI_ERR; - - FID_Event_kbd_keycode = env->GetFieldID(event, "kbd_keycode", "I"); - if (FID_Event_kbd_keycode == 0) - return JNI_ERR; - - FID_Event_kbd_ascii = env->GetFieldID(event, "kbd_ascii", "I"); - if (FID_Event_kbd_ascii == 0) - return JNI_ERR; - - FID_Event_kbd_flags = env->GetFieldID(event, "kbd_flags", "I"); - if (FID_Event_kbd_flags == 0) - return JNI_ERR; - - FID_Event_mouse_x = env->GetFieldID(event, "mouse_x", "I"); - if (FID_Event_mouse_x == 0) - return JNI_ERR; - - FID_Event_mouse_y = env->GetFieldID(event, "mouse_y", "I"); - if (FID_Event_mouse_y == 0) - return JNI_ERR; - - FID_Event_mouse_relative = env->GetFieldID(event, "mouse_relative", "Z"); - if (FID_Event_mouse_relative == 0) - return JNI_ERR; - - return JNI_VERSION_1_2; + _system->setSurfaceSize(width, height); } #endif diff --git a/backends/platform/android/jni.h b/backends/platform/android/jni.h new file mode 100644 index 0000000000..39276b9388 --- /dev/null +++ b/backends/platform/android/jni.h @@ -0,0 +1,87 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef _ANDROID_JNI_H_ +#define _ANDROID_JNI_H_ + +#if defined(__ANDROID__) + +#include <jni.h> + +extern jobject back_ptr; + +class OSystem_Android; + +class JNI { +public: + static jint onLoad(JavaVM *vm); + + static JNIEnv *getEnv(); + + static void attachThread(); + static void detachThread(); + +private: + JNI(); + virtual ~JNI(); + +private: + static JavaVM *_vm; + // back pointer to (java) peer instance + static jobject _jobj; + static OSystem_Android *_system; + + static jfieldID _FID_Event_type; + static jfieldID _FID_Event_synthetic; + static jfieldID _FID_Event_kbd_keycode; + static jfieldID _FID_Event_kbd_ascii; + static jfieldID _FID_Event_kbd_flags; + static jfieldID _FID_Event_mouse_x; + static jfieldID _FID_Event_mouse_y; + static jfieldID _FID_Event_mouse_relative; + static jfieldID _FID_ScummVM_nativeScummVM; + + static const JNINativeMethod _natives[]; + + static void throwByName(JNIEnv *env, const char *name, const char *msg); + + // natives for the dark side + static void create(JNIEnv *env, jobject self, jobject am); + static void destroy(JNIEnv *env, jobject self); + static jint main(JNIEnv *env, jobject self, jobjectArray args); + static void pushEvent(JNIEnv *env, jobject self, jobject java_event); + static void audioMixCallback(JNIEnv *env, jobject self, jbyteArray jbuf); + static void setConfManInt(JNIEnv *env, jclass cls, jstring key_obj, + jint value); + static void setConfManString(JNIEnv *env, jclass cls, jstring key_obj, + jstring value_obj); + static void enableZoning(JNIEnv *env, jobject self, jboolean enable); + static void setSurfaceSize(JNIEnv *env, jobject self, jint width, + jint height); +}; + +#endif +#endif + |