mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-13 22:08:34 +00:00
(Android) Refactor JNI code
This commit is contained in:
parent
e198dac691
commit
18bf8e2a16
1
AUTHORS
1
AUTHORS
@ -31,6 +31,7 @@ Michael Lelli - <toadking@toadking.com>
|
||||
- Gamecube/Wii libogc port
|
||||
- Raspberry Pi video driver
|
||||
- Linux Raw keyboard input driver
|
||||
- Android port patches
|
||||
|
||||
Darren Alton -
|
||||
- OpenPandora port
|
||||
|
@ -58,7 +58,7 @@ struct jni_out_params_char
|
||||
|
||||
extern struct droid g_android;
|
||||
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params);
|
||||
void jni_get(void *params, void *out_params, unsigned out_type);
|
||||
bool android_run_events(struct android_app* android_app);
|
||||
|
||||
#endif
|
||||
|
@ -298,6 +298,36 @@ static void *android_input_init(void)
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void android_input_get_devicename(int id, struct jni_params *params, struct jni_out_params_char *out_params)
|
||||
{
|
||||
JNIEnv *env;
|
||||
JavaVM *vm = params->java_vm;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
jclass clazz = (*env)->FindClass(env, "org.retroarch.browser.ModuleActivity");
|
||||
|
||||
jmethodID giid = (*env)->GetMethodID(env, clazz, params->method_name, params->method_signature);
|
||||
|
||||
jobject obj = (*env)->CallObjectMethod(env, params->class_obj, giid); //Got our object
|
||||
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
|
||||
jmethodID gseid = (*env)->GetMethodID(env, class_obj, params->obj_method_name, params->obj_method_signature);
|
||||
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj, gseid, (*env)->NewStringUTF(env, out_params->in));
|
||||
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
|
||||
strncpy(out_params->out, test_argv, out_params->out_sizeof);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void android_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
@ -309,6 +339,7 @@ static void android_input_poll(void *data)
|
||||
|
||||
g_extern.lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS));
|
||||
|
||||
|
||||
// Read all pending events.
|
||||
while(AInputQueue_hasEvents(android_app->inputQueue))
|
||||
{
|
||||
@ -322,6 +353,26 @@ static void android_input_poll(void *data)
|
||||
|
||||
int source = AInputEvent_getSource(event);
|
||||
int id = AInputEvent_getDeviceId(event);
|
||||
|
||||
#if 0
|
||||
char devicename[512];
|
||||
|
||||
struct jni_out_params_char out_args;
|
||||
struct jni_params jni_args;
|
||||
|
||||
jni_args.java_vm = g_android.app->activity->vm;
|
||||
snprintf(jni_args.method_name, sizeof(jni_args.method_name), "getDeviceName");
|
||||
snprintf(jni_args.method_signature, sizeof(jni_args.method_signature), "(Ljava/lang/String;)Ljava/lang/String;");
|
||||
|
||||
out_args.out = devicename;
|
||||
out_args.out_sizeof = sizeof(devicename);
|
||||
|
||||
android_input_get_devicename(id, &jni_args, &out_args);
|
||||
|
||||
RARCH_LOG("Device name: %s\n", out_args.out);
|
||||
#endif
|
||||
|
||||
|
||||
int type_event = AInputEvent_getType(event);
|
||||
int state_id = state_device_ids[id];
|
||||
|
||||
|
@ -68,26 +68,49 @@ static void print_cur_config(struct android_app* android_app)
|
||||
AConfiguration_getUiModeNight(android_app->config));
|
||||
}
|
||||
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params)
|
||||
#define JNI_OUT_CHAR 0
|
||||
|
||||
void jni_get(void *params, void *out_params, unsigned out_type)
|
||||
{
|
||||
JNIEnv *env;
|
||||
JavaVM *vm = params->java_vm;
|
||||
struct jni_params *in_params = (struct jni_params*)params;
|
||||
|
||||
JavaVM *vm = in_params->java_vm;
|
||||
jobject obj = NULL;
|
||||
jmethodID gseid = NULL;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
jclass acl = (*env)->GetObjectClass(env, params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, params->method_name, params->method_signature);
|
||||
jobject obj = (*env)->CallObjectMethod(env, params->class_obj, giid); //Got our object
|
||||
if (in_params->class_obj)
|
||||
{
|
||||
jclass acl = (*env)->GetObjectClass(env, in_params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, in_params->method_name, in_params->method_signature);
|
||||
obj = (*env)->CallObjectMethod(env, in_params->class_obj, giid); //Got our object
|
||||
}
|
||||
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
jmethodID gseid = (*env)->GetMethodID(env, class_obj, params->obj_method_name, params->obj_method_signature);
|
||||
if (in_params->obj_method_name && obj)
|
||||
{
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
gseid = (*env)->GetMethodID(env, class_obj, in_params->obj_method_name,
|
||||
in_params->obj_method_signature);
|
||||
}
|
||||
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj, gseid, (*env)->NewStringUTF(env, out_params->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
|
||||
strncpy(out_params->out, test_argv, out_params->out_sizeof);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
switch (out_type)
|
||||
{
|
||||
case JNI_OUT_CHAR:
|
||||
if(gseid != NULL)
|
||||
{
|
||||
struct jni_out_params_char *out_params_char = (struct jni_out_params_char*)out_params;
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj,
|
||||
gseid, (*env)->NewStringUTF(env, out_params_char->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
strncpy(out_params_char->out, test_argv, out_params_char->out_sizeof);
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
||||
@ -342,13 +365,13 @@ static void* android_app_entry(void* param)
|
||||
out_args.out_sizeof = sizeof(rom_path);
|
||||
snprintf(out_args.in, sizeof(out_args.in), "ROM");
|
||||
|
||||
jni_get_char_argv(&jni_args, &out_args);
|
||||
jni_get(&jni_args, &out_args, JNI_OUT_CHAR);
|
||||
|
||||
out_args.out = libretro_path;
|
||||
out_args.out_sizeof = sizeof(libretro_path);
|
||||
snprintf(out_args.in, sizeof(out_args.in), "LIBRETRO");
|
||||
|
||||
jni_get_char_argv(&jni_args, &out_args);
|
||||
jni_get(&jni_args, &out_args, JNI_OUT_CHAR);
|
||||
|
||||
char refreshrate_char[128];
|
||||
float refreshrate;
|
||||
@ -357,7 +380,7 @@ static void* android_app_entry(void* param)
|
||||
out_args.out_sizeof = sizeof(refreshrate_char);
|
||||
snprintf(out_args.in, sizeof(out_args.in), "REFRESHRATE");
|
||||
|
||||
jni_get_char_argv(&jni_args, &out_args);
|
||||
jni_get(&jni_args, &out_args, JNI_OUT_CHAR);
|
||||
|
||||
refreshrate = (float)strtod(refreshrate_char, NULL);
|
||||
|
||||
|
@ -47,6 +47,15 @@ public class ModuleActivity extends Activity implements AdapterView.OnItemClickL
|
||||
private IconAdapter<ModuleWrapper> adapter;
|
||||
static private final int ACTIVITY_LOAD_ROM = 0;
|
||||
static private String libretro_path;
|
||||
|
||||
public String getDeviceName(int id)
|
||||
{
|
||||
final String name = InputDevice.getDevice(7).getName();
|
||||
if(name != null)
|
||||
return name;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
public float getRefreshRate()
|
||||
{
|
||||
@ -107,7 +116,8 @@ public class ModuleActivity extends Activity implements AdapterView.OnItemClickL
|
||||
case ACTIVITY_LOAD_ROM:
|
||||
if(data.getStringExtra("PATH") != null)
|
||||
{
|
||||
Toast.makeText(this, "Loading: ["+ data.getStringExtra("PATH") + "]...", Toast.LENGTH_SHORT).show();
|
||||
//Toast.makeText(this, "Loading: ["+ data.getStringExtra("PATH") + "]...", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, getDeviceName(5), Toast.LENGTH_SHORT).show();
|
||||
myIntent = new Intent(this, NativeActivity.class);
|
||||
myIntent.putExtra("ROM", data.getStringExtra("PATH"));
|
||||
myIntent.putExtra("LIBRETRO", libretro_path);
|
||||
|
Loading…
Reference in New Issue
Block a user