src/core/android/SDL_android.c
changeset 10672 10fb0ebc4fbf
parent 10358 f46d780b6685
child 10737 3406a0f8b041
     1.1 --- a/src/core/android/SDL_android.c	Fri Dec 02 02:21:35 2016 -0800
     1.2 +++ b/src/core/android/SDL_android.c	Fri Dec 02 02:25:12 2016 -0800
     1.3 @@ -42,12 +42,110 @@
     1.4  #include <pthread.h>
     1.5  #include <sys/types.h>
     1.6  #include <unistd.h>
     1.7 -#define LOG_TAG "SDL_android"
     1.8 +/* #define LOG_TAG "SDL_android" */
     1.9  /* #define LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
    1.10  /* #define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
    1.11  #define LOGI(...) do {} while (0)
    1.12  #define LOGE(...) do {} while (0)
    1.13  
    1.14 +
    1.15 +#define SDL_JAVA_PREFIX                                 org_libsdl_app
    1.16 +#define CONCAT1(prefix, class, function)                CONCAT2(prefix, class, function)
    1.17 +#define CONCAT2(prefix, class, function)                Java_ ## prefix ## _ ## class ## _ ## function
    1.18 +#define SDL_JAVA_INTERFACE(function)                    CONCAT1(SDL_JAVA_PREFIX, SDLActivity, function)
    1.19 +#define SDL_JAVA_INTERFACE_INPUT_CONNECTION(function)   CONCAT1(SDL_JAVA_PREFIX, SDLInputConnection, function)
    1.20 +
    1.21 +
    1.22 +/* Java class SDLActivity */
    1.23 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
    1.24 +        JNIEnv* env, jclass jcls,
    1.25 +        jstring filename);
    1.26 +
    1.27 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
    1.28 +        JNIEnv* env, jclass jcls,
    1.29 +        jint width, jint height, jint format, jfloat rate);
    1.30 +
    1.31 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadDown)(
    1.32 +        JNIEnv* env, jclass jcls,
    1.33 +        jint device_id, jint keycode);
    1.34 +
    1.35 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadUp)(
    1.36 +        JNIEnv* env, jclass jcls,
    1.37 +        jint device_id, jint keycode);
    1.38 +
    1.39 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeJoy)(
    1.40 +        JNIEnv* env, jclass jcls,
    1.41 +        jint device_id, jint axis, jfloat value);
    1.42 +
    1.43 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
    1.44 +        JNIEnv* env, jclass jcls,
    1.45 +        jint device_id, jint hat_id, jint x, jint y);
    1.46 +
    1.47 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
    1.48 +        JNIEnv* env, jclass jcls,
    1.49 +        jint device_id, jstring device_name, jint is_accelerometer, 
    1.50 +        jint nbuttons, jint naxes, jint nhats, jint nballs);
    1.51 +
    1.52 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
    1.53 +        JNIEnv* env, jclass jcls,
    1.54 +        jint device_id);
    1.55 +
    1.56 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(
    1.57 +        JNIEnv* env, jclass jcls);
    1.58 +
    1.59 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(
    1.60 +        JNIEnv* env, jclass jcls);
    1.61 +
    1.62 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
    1.63 +        JNIEnv* env, jclass jcls,
    1.64 +        jint keycode);
    1.65 +
    1.66 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
    1.67 +        JNIEnv* env, jclass jcls,
    1.68 +        jint keycode);
    1.69 +
    1.70 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
    1.71 +        JNIEnv* env, jclass jcls);
    1.72 +
    1.73 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
    1.74 +        JNIEnv* env, jclass jcls,
    1.75 +        jint touch_device_id_in, jint pointer_finger_id_in,
    1.76 +        jint action, jfloat x, jfloat y, jfloat p);
    1.77 +
    1.78 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
    1.79 +        JNIEnv* env, jclass jcls,
    1.80 +        jint button, jint action, jfloat x, jfloat y);
    1.81 +
    1.82 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
    1.83 +        JNIEnv* env, jclass jcls,
    1.84 +        jfloat x, jfloat y, jfloat z);
    1.85 +
    1.86 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
    1.87 +        JNIEnv* env, jclass cls);
    1.88 +
    1.89 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
    1.90 +        JNIEnv* env, jclass cls);
    1.91 +
    1.92 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
    1.93 +        JNIEnv* env, jclass cls);
    1.94 +
    1.95 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
    1.96 +        JNIEnv* env, jclass cls);
    1.97 +
    1.98 +JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
    1.99 +        JNIEnv* env, jclass cls,
   1.100 +        jstring name);
   1.101 +
   1.102 +/* Java class SDLInputConnection */
   1.103 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
   1.104 +        JNIEnv* env, jclass cls,
   1.105 +        jstring text, jint newCursorPosition);
   1.106 +
   1.107 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
   1.108 +        JNIEnv* env, jclass cls,
   1.109 +        jstring text, jint newCursorPosition);
   1.110 +
   1.111 +
   1.112  /* Uncomment this to log messages entering and exiting methods in this file */
   1.113  /* #define DEBUG_JNI */
   1.114  
   1.115 @@ -153,7 +251,7 @@
   1.116  }
   1.117  
   1.118  /* Drop file */
   1.119 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeDropFile(
   1.120 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
   1.121                                      JNIEnv* env, jclass jcls,
   1.122                                      jstring filename)
   1.123  {
   1.124 @@ -164,7 +262,7 @@
   1.125  }
   1.126  
   1.127  /* Resize */
   1.128 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
   1.129 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
   1.130                                      JNIEnv* env, jclass jcls,
   1.131                                      jint width, jint height, jint format, jfloat rate)
   1.132  {
   1.133 @@ -172,7 +270,7 @@
   1.134  }
   1.135  
   1.136  /* Paddown */
   1.137 -JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadDown(
   1.138 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadDown)(
   1.139                                      JNIEnv* env, jclass jcls,
   1.140                                      jint device_id, jint keycode)
   1.141  {
   1.142 @@ -180,15 +278,15 @@
   1.143  }
   1.144  
   1.145  /* Padup */
   1.146 -JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadUp(
   1.147 -                                   JNIEnv* env, jclass jcls,
   1.148 -                                   jint device_id, jint keycode)
   1.149 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadUp)(
   1.150 +                                    JNIEnv* env, jclass jcls,
   1.151 +                                    jint device_id, jint keycode)
   1.152  {
   1.153      return Android_OnPadUp(device_id, keycode);
   1.154  }
   1.155  
   1.156  /* Joy */
   1.157 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeJoy(
   1.158 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeJoy)(
   1.159                                      JNIEnv* env, jclass jcls,
   1.160                                      jint device_id, jint axis, jfloat value)
   1.161  {
   1.162 @@ -196,7 +294,7 @@
   1.163  }
   1.164  
   1.165  /* POV Hat */
   1.166 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeHat(
   1.167 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
   1.168                                      JNIEnv* env, jclass jcls,
   1.169                                      jint device_id, jint hat_id, jint x, jint y)
   1.170  {
   1.171 @@ -204,10 +302,10 @@
   1.172  }
   1.173  
   1.174  
   1.175 -JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeAddJoystick(
   1.176 -    JNIEnv* env, jclass jcls,
   1.177 -    jint device_id, jstring device_name, jint is_accelerometer, 
   1.178 -    jint nbuttons, jint naxes, jint nhats, jint nballs)
   1.179 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
   1.180 +                                    JNIEnv* env, jclass jcls,
   1.181 +                                    jint device_id, jstring device_name, jint is_accelerometer, 
   1.182 +                                    jint nbuttons, jint naxes, jint nhats, jint nballs)
   1.183  {
   1.184      int retval;
   1.185      const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
   1.186 @@ -219,15 +317,16 @@
   1.187      return retval;
   1.188  }
   1.189  
   1.190 -JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeRemoveJoystick(
   1.191 -    JNIEnv* env, jclass jcls, jint device_id)
   1.192 +JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
   1.193 +                                    JNIEnv* env, jclass jcls,
   1.194 +                                    jint device_id)
   1.195  {
   1.196      return Android_RemoveJoystick(device_id);
   1.197  }
   1.198  
   1.199  
   1.200  /* Surface Created */
   1.201 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceChanged(JNIEnv* env, jclass jcls)
   1.202 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, jclass jcls)
   1.203  {
   1.204      SDL_WindowData *data;
   1.205      SDL_VideoDevice *_this;
   1.206 @@ -253,7 +352,7 @@
   1.207  }
   1.208  
   1.209  /* Surface Destroyed */
   1.210 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceDestroyed(JNIEnv* env, jclass jcls)
   1.211 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv* env, jclass jcls)
   1.212  {
   1.213      /* We have to clear the current context and destroy the egl surface here
   1.214       * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
   1.215 @@ -280,21 +379,23 @@
   1.216  }
   1.217  
   1.218  /* Keydown */
   1.219 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
   1.220 -                                    JNIEnv* env, jclass jcls, jint keycode)
   1.221 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
   1.222 +                                    JNIEnv* env, jclass jcls,
   1.223 +                                    jint keycode)
   1.224  {
   1.225      Android_OnKeyDown(keycode);
   1.226  }
   1.227  
   1.228  /* Keyup */
   1.229 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
   1.230 -                                    JNIEnv* env, jclass jcls, jint keycode)
   1.231 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
   1.232 +                                    JNIEnv* env, jclass jcls,
   1.233 +                                    jint keycode)
   1.234  {
   1.235      Android_OnKeyUp(keycode);
   1.236  }
   1.237  
   1.238  /* Keyboard Focus Lost */
   1.239 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost(
   1.240 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
   1.241                                      JNIEnv* env, jclass jcls)
   1.242  {
   1.243      /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
   1.244 @@ -303,7 +404,7 @@
   1.245  
   1.246  
   1.247  /* Touch */
   1.248 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeTouch(
   1.249 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
   1.250                                      JNIEnv* env, jclass jcls,
   1.251                                      jint touch_device_id_in, jint pointer_finger_id_in,
   1.252                                      jint action, jfloat x, jfloat y, jfloat p)
   1.253 @@ -312,7 +413,7 @@
   1.254  }
   1.255  
   1.256  /* Mouse */
   1.257 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeMouse(
   1.258 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
   1.259                                      JNIEnv* env, jclass jcls,
   1.260                                      jint button, jint action, jfloat x, jfloat y)
   1.261  {
   1.262 @@ -320,7 +421,7 @@
   1.263  }
   1.264  
   1.265  /* Accelerometer */
   1.266 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
   1.267 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
   1.268                                      JNIEnv* env, jclass jcls,
   1.269                                      jfloat x, jfloat y, jfloat z)
   1.270  {
   1.271 @@ -331,14 +432,14 @@
   1.272  }
   1.273  
   1.274  /* Low memory */
   1.275 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeLowMemory(
   1.276 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
   1.277                                      JNIEnv* env, jclass cls)
   1.278  {
   1.279      SDL_SendAppEvent(SDL_APP_LOWMEMORY);
   1.280  }
   1.281  
   1.282  /* Quit */
   1.283 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeQuit(
   1.284 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
   1.285                                      JNIEnv* env, jclass cls)
   1.286  {
   1.287      /* Discard previous events. The user should have handled state storage
   1.288 @@ -354,7 +455,7 @@
   1.289  }
   1.290  
   1.291  /* Pause */
   1.292 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativePause(
   1.293 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
   1.294                                      JNIEnv* env, jclass cls)
   1.295  {
   1.296      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
   1.297 @@ -371,7 +472,7 @@
   1.298  }
   1.299  
   1.300  /* Resume */
   1.301 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeResume(
   1.302 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
   1.303                                      JNIEnv* env, jclass cls)
   1.304  {
   1.305      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
   1.306 @@ -389,7 +490,7 @@
   1.307      }
   1.308  }
   1.309  
   1.310 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeCommitText(
   1.311 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
   1.312                                      JNIEnv* env, jclass cls,
   1.313                                      jstring text, jint newCursorPosition)
   1.314  {
   1.315 @@ -400,7 +501,7 @@
   1.316      (*env)->ReleaseStringUTFChars(env, text, utftext);
   1.317  }
   1.318  
   1.319 -JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposingText(
   1.320 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
   1.321                                      JNIEnv* env, jclass cls,
   1.322                                      jstring text, jint newCursorPosition)
   1.323  {
   1.324 @@ -411,7 +512,10 @@
   1.325      (*env)->ReleaseStringUTFChars(env, text, utftext);
   1.326  }
   1.327  
   1.328 -JNIEXPORT jstring JNICALL Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
   1.329 +JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
   1.330 +                                    JNIEnv* env, jclass cls,
   1.331 +                                    jstring name)
   1.332 +{
   1.333      const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
   1.334      const char *hint = SDL_GetHint(utfname);
   1.335