mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 00:40:09 +00:00
(Android) Cut down on g_android usage
This commit is contained in:
parent
413771f14f
commit
fc55e48221
@ -23,7 +23,6 @@
|
|||||||
struct droid
|
struct droid
|
||||||
{
|
{
|
||||||
struct android_app* app;
|
struct android_app* app;
|
||||||
char current_ime[PATH_MAX];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct droid g_android;
|
extern struct droid g_android;
|
||||||
|
@ -49,6 +49,7 @@ struct android_app
|
|||||||
int running;
|
int running;
|
||||||
AInputQueue* pendingInputQueue;
|
AInputQueue* pendingInputQueue;
|
||||||
ANativeWindow* pendingWindow;
|
ANativeWindow* pendingWindow;
|
||||||
|
char current_ime[PATH_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -153,9 +154,8 @@ enum {
|
|||||||
APP_CMD_DEAD,
|
APP_CMD_DEAD,
|
||||||
};
|
};
|
||||||
|
|
||||||
int8_t android_app_read_cmd(struct android_app* android_app);
|
int8_t android_app_read_cmd (void *data);
|
||||||
|
extern void engine_app_read_cmd (void *data);
|
||||||
extern void engine_app_read_cmd(struct android_app *app);
|
extern void engine_handle_cmd (void *data, int32_t cmd);
|
||||||
extern void engine_handle_cmd(struct android_app* android_app, int32_t cmd);
|
|
||||||
|
|
||||||
#endif /* _ANDROID_NATIVE_APP_GLUE_H */
|
#endif /* _ANDROID_NATIVE_APP_GLUE_H */
|
||||||
|
@ -116,7 +116,7 @@ static void android_input_poll(void *data)
|
|||||||
state_id = pads_connected;
|
state_id = pads_connected;
|
||||||
state_device_ids[pads_connected++] = id;
|
state_device_ids[pads_connected++] = id;
|
||||||
|
|
||||||
input_autodetect_setup(state_id, id, source);
|
input_autodetect_setup(android_app, state_id, id, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = 0;
|
int action = 0;
|
||||||
|
@ -21,11 +21,12 @@ uint64_t keycode_lut[LAST_KEYCODE];
|
|||||||
|
|
||||||
bool volume_enable;
|
bool volume_enable;
|
||||||
|
|
||||||
static void input_autodetect_get_device_name(char *buf, size_t size, int id)
|
static void input_autodetect_get_device_name(void *data, char *buf, size_t size, int id)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
JavaVM *vm = g_android.app->activity->vm;
|
JavaVM *vm = android_app->activity->vm;
|
||||||
JNIEnv *env = NULL;
|
JNIEnv *env = NULL;
|
||||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||||
|
|
||||||
@ -77,8 +78,9 @@ void input_autodetect_init (void)
|
|||||||
volume_enable = true;
|
volume_enable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_autodetect_setup(unsigned port, unsigned id, int source)
|
void input_autodetect_setup (void *data, unsigned port, unsigned id, int source)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
// Hack - we have to add '1' to the bit mask here because
|
// Hack - we have to add '1' to the bit mask here because
|
||||||
// RETRO_DEVICE_ID_JOYPAD_B is 0
|
// RETRO_DEVICE_ID_JOYPAD_B is 0
|
||||||
|
|
||||||
@ -99,11 +101,11 @@ void input_autodetect_setup(unsigned port, unsigned id, int source)
|
|||||||
|
|
||||||
g_settings.input.dpad_emulation[port] = DPAD_EMULATION_LSTICK;
|
g_settings.input.dpad_emulation[port] = DPAD_EMULATION_LSTICK;
|
||||||
|
|
||||||
char *current_ime = g_android.current_ime;
|
char *current_ime = android_app->current_ime;
|
||||||
|
|
||||||
if (g_settings.input.autodetect_enable)
|
if (g_settings.input.autodetect_enable)
|
||||||
{
|
{
|
||||||
input_autodetect_get_device_name(name_buf, sizeof(name_buf), id);
|
input_autodetect_get_device_name(android_app, name_buf, sizeof(name_buf), id);
|
||||||
if (*name_buf)
|
if (*name_buf)
|
||||||
{
|
{
|
||||||
if (strstr(name_buf, "Logitech"))
|
if (strstr(name_buf, "Logitech"))
|
||||||
|
@ -64,6 +64,6 @@ extern uint64_t keycode_lut[LAST_KEYCODE];
|
|||||||
extern bool volume_enable;
|
extern bool volume_enable;
|
||||||
|
|
||||||
void input_autodetect_init (void);
|
void input_autodetect_init (void);
|
||||||
void input_autodetect_setup(unsigned port, unsigned id, int source);
|
void input_autodetect_setup (void *data, unsigned port, unsigned id, int source);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,8 +28,9 @@
|
|||||||
|
|
||||||
#include "../../../config.def.h"
|
#include "../../../config.def.h"
|
||||||
|
|
||||||
static void print_cur_config(struct android_app* android_app)
|
static void print_cur_config (void *data)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
char lang[2], country[2];
|
char lang[2], country[2];
|
||||||
AConfiguration_getLanguage(android_app->config, lang);
|
AConfiguration_getLanguage(android_app->config, lang);
|
||||||
AConfiguration_getCountry(android_app->config, country);
|
AConfiguration_getCountry(android_app->config, country);
|
||||||
@ -57,8 +58,10 @@ static void print_cur_config(struct android_app* android_app)
|
|||||||
/**
|
/**
|
||||||
* Process the next main command.
|
* Process the next main command.
|
||||||
*/
|
*/
|
||||||
void engine_handle_cmd(struct android_app* android_app, int32_t cmd)
|
void engine_handle_cmd (void *data, int32_t cmd)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case APP_CMD_INPUT_CHANGED:
|
case APP_CMD_INPUT_CHANGED:
|
||||||
@ -175,8 +178,9 @@ void engine_handle_cmd(struct android_app* android_app, int32_t cmd)
|
|||||||
|
|
||||||
#define MAX_ARGS 32
|
#define MAX_ARGS 32
|
||||||
|
|
||||||
static bool android_run_events(struct android_app* android_app)
|
static bool android_run_events (void *data)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
int id = ALooper_pollOnce(-1, NULL, NULL, NULL);
|
int id = ALooper_pollOnce(-1, NULL, NULL, NULL);
|
||||||
|
|
||||||
if (id == LOOPER_ID_MAIN)
|
if (id == LOOPER_ID_MAIN)
|
||||||
@ -236,8 +240,9 @@ static void jni_get(struct jni_params *in_params, struct jni_out_params_char *ou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int android_app_set_argv(char** argv)
|
static int android_app_set_argv (void *data, char** argv)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
char rom_path[PATH_MAX];
|
char rom_path[PATH_MAX];
|
||||||
char libretro_path[PATH_MAX];
|
char libretro_path[PATH_MAX];
|
||||||
char config_file[PATH_MAX];
|
char config_file[PATH_MAX];
|
||||||
@ -245,10 +250,10 @@ static int android_app_set_argv(char** argv)
|
|||||||
struct jni_params in_params;
|
struct jni_params in_params;
|
||||||
struct jni_out_params_char out_args;
|
struct jni_out_params_char out_args;
|
||||||
|
|
||||||
JNI_OnLoad(g_android.app->activity->vm, NULL);
|
JNI_OnLoad(android_app->activity->vm, NULL);
|
||||||
|
|
||||||
in_params.java_vm = g_android.app->activity->vm;
|
in_params.java_vm = android_app->activity->vm;
|
||||||
in_params.class_obj = g_android.app->activity->clazz;
|
in_params.class_obj = android_app->activity->clazz;
|
||||||
|
|
||||||
strlcpy(in_params.method_name, "getIntent", sizeof(in_params.method_name));
|
strlcpy(in_params.method_name, "getIntent", sizeof(in_params.method_name));
|
||||||
strlcpy(in_params.method_signature, "()Landroid/content/Intent;", sizeof(in_params.method_signature));
|
strlcpy(in_params.method_signature, "()Landroid/content/Intent;", sizeof(in_params.method_signature));
|
||||||
@ -274,8 +279,8 @@ static int android_app_set_argv(char** argv)
|
|||||||
jni_get(&in_params, &out_args);
|
jni_get(&in_params, &out_args);
|
||||||
|
|
||||||
// Current IME
|
// Current IME
|
||||||
out_args.out = g_android.current_ime;
|
out_args.out = android_app->current_ime;
|
||||||
out_args.out_sizeof = sizeof(g_android.current_ime);
|
out_args.out_sizeof = sizeof(android_app->current_ime);
|
||||||
strlcpy(out_args.in, "IME", sizeof(out_args.in));
|
strlcpy(out_args.in, "IME", sizeof(out_args.in));
|
||||||
jni_get(&in_params, &out_args);
|
jni_get(&in_params, &out_args);
|
||||||
|
|
||||||
@ -286,7 +291,7 @@ static int android_app_set_argv(char** argv)
|
|||||||
RARCH_LOG("ROM Filename: [%s].\n", rom_path);
|
RARCH_LOG("ROM Filename: [%s].\n", rom_path);
|
||||||
RARCH_LOG("Libretro path: [%s].\n", libretro_path);
|
RARCH_LOG("Libretro path: [%s].\n", libretro_path);
|
||||||
RARCH_LOG("Config file: [%s].\n", config_file);
|
RARCH_LOG("Config file: [%s].\n", config_file);
|
||||||
RARCH_LOG("Current IME: [%s].\n", g_android.current_ime);
|
RARCH_LOG("Current IME: [%s].\n", android_app->current_ime);
|
||||||
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
|
||||||
@ -304,9 +309,9 @@ static int android_app_set_argv(char** argv)
|
|||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* android_app_entry(void* param)
|
static void* android_app_entry(void *data)
|
||||||
{
|
{
|
||||||
struct android_app* android_app = (struct android_app*)param;
|
struct android_app* android_app = (struct android_app*)data;
|
||||||
int init_ret = -1;
|
int init_ret = -1;
|
||||||
|
|
||||||
android_app->config = AConfiguration_new();
|
android_app->config = AConfiguration_new();
|
||||||
@ -327,7 +332,7 @@ static void* android_app_entry(void* param)
|
|||||||
g_android.app = android_app;
|
g_android.app = android_app;
|
||||||
|
|
||||||
char *argv[MAX_ARGS] = {NULL};
|
char *argv[MAX_ARGS] = {NULL};
|
||||||
int argc = android_app_set_argv(argv);
|
int argc = android_app_set_argv(android_app, argv);
|
||||||
|
|
||||||
RARCH_LOG("Native Activity started.\n");
|
RARCH_LOG("Native Activity started.\n");
|
||||||
rarch_main_clear_state();
|
rarch_main_clear_state();
|
||||||
@ -352,14 +357,14 @@ static void* android_app_entry(void* param)
|
|||||||
rarch_init_msg_queue();
|
rarch_init_msg_queue();
|
||||||
|
|
||||||
while ((input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ?
|
while ((input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ?
|
||||||
android_run_events(g_android.app) :
|
android_run_events(android_app) :
|
||||||
rarch_main_iterate());
|
rarch_main_iterate());
|
||||||
|
|
||||||
RARCH_LOG("RetroArch stopped.\n");
|
RARCH_LOG("RetroArch stopped.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
g_android.app->activityState = APP_CMD_DEAD;
|
android_app->activityState = APP_CMD_DEAD;
|
||||||
RARCH_LOG("Deinitializing RetroArch...\n");
|
RARCH_LOG("Deinitializing RetroArch...\n");
|
||||||
|
|
||||||
if (init_ret == 0)
|
if (init_ret == 0)
|
||||||
@ -382,14 +387,16 @@ exit:
|
|||||||
exit(init_ret);
|
exit(init_ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void android_app_write_cmd(struct android_app* android_app, int8_t cmd)
|
static inline void android_app_write_cmd (void *data, int8_t cmd)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd))
|
if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd))
|
||||||
RARCH_ERR("Failure writing android_app cmd: %s\n", strerror(errno));
|
RARCH_ERR("Failure writing android_app cmd: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue)
|
static void android_app_set_input (void *data, AInputQueue* inputQueue)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
pthread_mutex_lock(&android_app->mutex);
|
||||||
android_app->pendingInputQueue = inputQueue;
|
android_app->pendingInputQueue = inputQueue;
|
||||||
android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED);
|
android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED);
|
||||||
@ -398,8 +405,9 @@ static void android_app_set_input(struct android_app* android_app, AInputQueue*
|
|||||||
pthread_mutex_unlock(&android_app->mutex);
|
pthread_mutex_unlock(&android_app->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_app_set_window(struct android_app* android_app, ANativeWindow* window)
|
static void android_app_set_window (void *data, ANativeWindow* window)
|
||||||
{
|
{
|
||||||
|
struct android_app *android_app = (struct android_app*)data;
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
pthread_mutex_lock(&android_app->mutex);
|
||||||
if (android_app->pendingWindow != NULL)
|
if (android_app->pendingWindow != NULL)
|
||||||
android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
|
android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
|
||||||
|
@ -80,7 +80,7 @@ static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
|
|||||||
|
|
||||||
static bool gfx_ctx_init(void)
|
static bool gfx_ctx_init(void)
|
||||||
{
|
{
|
||||||
RARCH_LOG("gfx_ctx_init().\n");
|
struct android_app *android_app = (struct android_app*)g_android.app;
|
||||||
const EGLint attribs[] = {
|
const EGLint attribs[] = {
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||||
@ -128,9 +128,9 @@ static bool gfx_ctx_init(void)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ANativeWindow_setBuffersGeometry(g_android.app->window, 0, 0, format);
|
ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format);
|
||||||
|
|
||||||
if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, g_android.app->window, 0)))
|
if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, android_app->window, 0)))
|
||||||
{
|
{
|
||||||
RARCH_ERR("eglCreateWindowSurface failed.\n");
|
RARCH_ERR("eglCreateWindowSurface failed.\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user