RetroArch/frontend/drivers/platform_android.h

174 lines
5.0 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01:00
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
2012-11-03 07:17:55 +01:00
*
* RetroArch 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.
2012-11-03 07:17:55 +01:00
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
2012-11-03 07:17:55 +01:00
*/
#ifndef _PLATFORM_ANDROID_H
#define _PLATFORM_ANDROID_H
2014-06-10 22:15:23 +02:00
#include <jni.h>
#include "android_native_app_glue.h"
#include <android/window.h>
#include <android/sensor.h>
#ifndef MAX_AXIS
#define MAX_AXIS 10
#endif
#ifndef MAX_PADS
#define MAX_PADS 8
#endif
#ifndef MAX_TOUCH
#define MAX_TOUCH 16
#endif
#ifndef AKEYCODE_ASSIST
#define AKEYCODE_ASSIST 219
#endif
#define LAST_KEYCODE AKEYCODE_ASSIST
typedef struct state_device
{
int id;
int port;
char name[256];
} state_device_t;
struct input_pointer
{
int16_t x, y;
int16_t full_x, full_y;
};
2015-05-01 18:11:34 +02:00
typedef struct
{
float x;
float y;
float z;
} sensor_t;
typedef struct android_input_state
{
int16_t analog_state[MAX_PADS][MAX_AXIS];
int8_t hat_state[MAX_PADS][2];
uint8_t pad_state[MAX_PADS][(LAST_KEYCODE + 7) / 8];
unsigned pads_connected;
state_device_t pad_states[MAX_PADS];
struct input_pointer pointer[MAX_TOUCH];
2015-05-01 18:11:34 +02:00
sensor_t accelerometer_state;
unsigned pointer_count;
} android_input_state_t;
2015-05-01 20:21:52 +02:00
struct android_app_userdata
{
unsigned accelerometer_event_rate;
const ASensor* accelerometerSensor;
uint64_t sensor_state_mask;
char current_ime[PATH_MAX_LENGTH];
jmethodID getIntent;
jmethodID getStringExtra;
jmethodID clearPendingIntent;
jmethodID hasPendingIntent;
jmethodID getPendingIntentConfigPath;
jmethodID getPendingIntentLibretroPath;
jmethodID getPendingIntentFullPath;
jmethodID getPendingIntentIME;
android_input_state_t thread_state;
ASensorManager *sensorManager;
ASensorEventQueue *sensorEventQueue;
2012-11-03 07:17:55 +01:00
};
2014-06-10 22:15:23 +02:00
#define JNI_EXCEPTION(env) \
if ((*env)->ExceptionOccurred(env)) \
{ \
(*env)->ExceptionDescribe(env); \
(*env)->ExceptionClear(env); \
}
#define FIND_CLASS(env, var, classname) \
var = (*env)->FindClass(env, classname); \
JNI_EXCEPTION(env)
#define GET_OBJECT_CLASS(env, var, clazz_obj) \
var = (*env)->GetObjectClass(env, clazz_obj); \
JNI_EXCEPTION(env)
#define GET_FIELD_ID(env, var, clazz, fieldName, fieldDescriptor) \
var = (*env)->GetFieldID(env, clazz, fieldName, fieldDescriptor); \
JNI_EXCEPTION(env)
#define GET_METHOD_ID(env, var, clazz, methodName, fieldDescriptor) \
var = (*env)->GetMethodID(env, clazz, methodName, fieldDescriptor); \
JNI_EXCEPTION(env)
#define GET_STATIC_METHOD_ID(env, var, clazz, methodName, fieldDescriptor) \
var = (*env)->GetStaticMethodID(env, clazz, methodName, fieldDescriptor); \
JNI_EXCEPTION(env)
#define CALL_OBJ_METHOD(env, var, clazz_obj, methodId) \
var = (*env)->CallObjectMethod(env, clazz_obj, methodId); \
JNI_EXCEPTION(env)
#define CALL_OBJ_STATIC_METHOD(env, var, clazz, methodId) \
var = (*env)->CallStaticObjectMethod(env, clazz, methodId); \
JNI_EXCEPTION(env)
#define CALL_OBJ_STATIC_METHOD_PARAM(env, var, clazz, methodId, ...) \
var = (*env)->CallStaticObjectMethod(env, clazz, methodId, __VA_ARGS__); \
JNI_EXCEPTION(env)
#define CALL_OBJ_METHOD_PARAM(env, var, clazz_obj, methodId, ...) \
var = (*env)->CallObjectMethod(env, clazz_obj, methodId, __VA_ARGS__); \
JNI_EXCEPTION(env)
#define CALL_VOID_METHOD(env, clazz_obj, methodId) \
(*env)->CallVoidMethod(env, clazz_obj, methodId); \
JNI_EXCEPTION(env)
#define CALL_VOID_METHOD_PARAM(env, clazz_obj, methodId, ...) \
(*env)->CallVoidMethod(env, clazz_obj, methodId, __VA_ARGS__); \
JNI_EXCEPTION(env)
#define CALL_BOOLEAN_METHOD(env, var, clazz_obj, methodId) \
var = (*env)->CallBooleanMethod(env, clazz_obj, methodId); \
JNI_EXCEPTION(env)
#define CALL_DOUBLE_METHOD(env, var, clazz_obj, methodId) \
var = (*env)->CallDoubleMethod(env, clazz_obj, methodId); \
JNI_EXCEPTION(env)
#define CALL_INT_METHOD(env, var, clazz_obj, methodId) \
var = (*env)->CallIntMethod(env, clazz_obj, methodId); \
JNI_EXCEPTION(env)
bool (*engine_lookup_name)(char *buf,
int *vendorId, int *productId, size_t size, int id);
JNIEnv *jni_thread_getenv(void);
void android_app_write_cmd(struct android_app *android_app, int8_t cmd);
2013-01-06 06:10:07 +01:00
extern struct android_app *g_android;
2015-05-01 20:21:52 +02:00
extern struct android_app_userdata *g_android_userdata;
2013-01-06 06:10:07 +01:00
void android_main(struct android_app *android_app);
int android_main_poll(void *data);
#endif /* _PLATFORM_ANDROID_H */