Cleaner way to get JNI environment from C code
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "SDL_stdinc.h"
|
#include "SDL_stdinc.h"
|
||||||
#include "SDL_video.h"
|
#include "SDL_video.h"
|
||||||
#include "SDL_keysym.h"
|
#include "SDL_keysym.h"
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
/* On-screen keyboard exposed to the application, it's yet available on Android platform only */
|
/* On-screen keyboard exposed to the application, it's yet available on Android platform only */
|
||||||
|
|
||||||
@@ -82,6 +83,10 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBu
|
|||||||
/* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */
|
/* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */
|
||||||
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser();
|
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser();
|
||||||
|
|
||||||
|
/** Exports for Java environment and Video object instance */
|
||||||
|
extern DECLSPEC JNIEnv* SDL_ANDROID_JniEnv();
|
||||||
|
extern DECLSPEC jobject SDL_ANDROID_JniVideoObject();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "SDL_version.h"
|
#include "SDL_version.h"
|
||||||
#include "SDL_thread.h"
|
#include "SDL_thread.h"
|
||||||
#include "SDL_main.h"
|
#include "SDL_main.h"
|
||||||
|
#include "SDL_screenkeyboard.h"
|
||||||
|
|
||||||
/* JNI-C wrapper stuff */
|
/* JNI-C wrapper stuff */
|
||||||
|
|
||||||
@@ -28,12 +29,26 @@
|
|||||||
static int argc = 0;
|
static int argc = 0;
|
||||||
static char ** argv = NULL;
|
static char ** argv = NULL;
|
||||||
|
|
||||||
|
static JNIEnv* static_env = NULL;
|
||||||
|
static jobject static_thiz = NULL;
|
||||||
|
|
||||||
|
JNIEnv* SDL_ANDROID_JniEnv()
|
||||||
|
{
|
||||||
|
return static_env;
|
||||||
|
}
|
||||||
|
jobject SDL_ANDROID_JniVideoObject()
|
||||||
|
{
|
||||||
|
return static_thiz;
|
||||||
|
}
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||||
#else
|
#else
|
||||||
extern void SDL_ANDROID_MultiThreadedVideoLoopInit();
|
extern void SDL_ANDROID_MultiThreadedVideoLoopInit();
|
||||||
extern void SDL_ANDROID_MultiThreadedVideoLoop();
|
extern void SDL_ANDROID_MultiThreadedVideoLoop();
|
||||||
|
|
||||||
static int threadedMain(void * unused)
|
static int threadedMain(void * unused);
|
||||||
|
|
||||||
|
int threadedMain(void * unused)
|
||||||
{
|
{
|
||||||
SDL_main( argc, argv );
|
SDL_main( argc, argv );
|
||||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Application closed, calling exit(0)");
|
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Application closed, calling exit(0)");
|
||||||
@@ -49,6 +64,9 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring
|
|||||||
const jbyte *jstr;
|
const jbyte *jstr;
|
||||||
const char * str = "sdl";
|
const char * str = "sdl";
|
||||||
|
|
||||||
|
static_env = env;
|
||||||
|
static_thiz = thiz;
|
||||||
|
|
||||||
strcpy(curdir, "/sdcard/app-data/");
|
strcpy(curdir, "/sdcard/app-data/");
|
||||||
strcat(curdir, SDL_CURDIR_PATH);
|
strcat(curdir, SDL_CURDIR_PATH);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user