Android: preparation bug 4142, reduce usage of global variable Android_Window
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 03 Jan 2019 13:14:16 +0100
changeset 124946053ab61996a
parent 12493 82f9397db3e7
child 12495 219a154f54cb
Android: preparation bug 4142, reduce usage of global variable Android_Window
src/core/android/SDL_android.c
src/video/android/SDL_androidevents.c
src/video/android/SDL_androidmouse.c
src/video/android/SDL_androidmouse.h
src/video/android/SDL_androidtouch.c
src/video/android/SDL_androidtouch.h
src/video/android/SDL_androidvideo.c
src/video/android/SDL_androidvideo.h
src/video/android/SDL_androidwindow.c
src/video/android/SDL_androidwindow.h
     1.1 --- a/src/core/android/SDL_android.c	Wed Jan 02 18:06:33 2019 +0100
     1.2 +++ b/src/core/android/SDL_android.c	Thu Jan 03 13:14:16 2019 +0100
     1.3 @@ -68,92 +68,92 @@
     1.4  
     1.5  /* Java class SDLActivity */
     1.6  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(
     1.7 -        JNIEnv* mEnv, jclass cls);
     1.8 +        JNIEnv *mEnv, jclass cls);
     1.9  
    1.10  JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(
    1.11 -        JNIEnv* env, jclass cls,
    1.12 +        JNIEnv *env, jclass cls,
    1.13          jstring library, jstring function, jobject array);
    1.14  
    1.15  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
    1.16 -        JNIEnv* env, jclass jcls,
    1.17 +        JNIEnv *env, jclass jcls,
    1.18          jstring filename);
    1.19  
    1.20  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
    1.21 -        JNIEnv* env, jclass jcls,
    1.22 +        JNIEnv *env, jclass jcls,
    1.23          jint surfaceWidth, jint surfaceHeight,
    1.24          jint deviceWidth, jint deviceHeight, jint format, jfloat rate);
    1.25  
    1.26  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(
    1.27 -        JNIEnv* env, jclass jcls);
    1.28 +        JNIEnv *env, jclass jcls);
    1.29  
    1.30  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(
    1.31 -        JNIEnv* env, jclass jcls);
    1.32 +        JNIEnv *env, jclass jcls);
    1.33  
    1.34  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
    1.35 -        JNIEnv* env, jclass jcls,
    1.36 +        JNIEnv *env, jclass jcls,
    1.37          jint keycode);
    1.38  
    1.39  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
    1.40 -        JNIEnv* env, jclass jcls,
    1.41 +        JNIEnv *env, jclass jcls,
    1.42          jint keycode);
    1.43  
    1.44  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
    1.45 -        JNIEnv* env, jclass jcls);
    1.46 +        JNIEnv *env, jclass jcls);
    1.47  
    1.48  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
    1.49 -        JNIEnv* env, jclass jcls,
    1.50 +        JNIEnv *env, jclass jcls,
    1.51          jint touch_device_id_in, jint pointer_finger_id_in,
    1.52          jint action, jfloat x, jfloat y, jfloat p);
    1.53  
    1.54  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
    1.55 -        JNIEnv* env, jclass jcls,
    1.56 +        JNIEnv *env, jclass jcls,
    1.57          jint button, jint action, jfloat x, jfloat y, jboolean relative);
    1.58  
    1.59  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
    1.60 -        JNIEnv* env, jclass jcls,
    1.61 +        JNIEnv *env, jclass jcls,
    1.62          jfloat x, jfloat y, jfloat z);
    1.63  
    1.64  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
    1.65 -        JNIEnv* env, jclass jcls);
    1.66 +        JNIEnv *env, jclass jcls);
    1.67  
    1.68  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
    1.69 -        JNIEnv* env, jclass cls);
    1.70 +        JNIEnv *env, jclass cls);
    1.71  
    1.72  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
    1.73 -        JNIEnv* env, jclass cls);
    1.74 +        JNIEnv *env, jclass cls);
    1.75  
    1.76  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
    1.77 -        JNIEnv* env, jclass cls);
    1.78 +        JNIEnv *env, jclass cls);
    1.79  
    1.80  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
    1.81 -        JNIEnv* env, jclass cls);
    1.82 +        JNIEnv *env, jclass cls);
    1.83  
    1.84  JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
    1.85 -        JNIEnv* env, jclass cls,
    1.86 +        JNIEnv *env, jclass cls,
    1.87          jstring name);
    1.88  
    1.89  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
    1.90 -        JNIEnv* env, jclass cls,
    1.91 +        JNIEnv *env, jclass cls,
    1.92          jstring name, jstring value);
    1.93  
    1.94  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeEnvironmentVariablesSet)(
    1.95 -        JNIEnv* env, jclass cls);
    1.96 +        JNIEnv *env, jclass cls);
    1.97  
    1.98  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
    1.99 -        JNIEnv* env, jclass cls,
   1.100 +        JNIEnv *env, jclass cls,
   1.101          jint orientation);
   1.102  
   1.103  /* Java class SDLInputConnection */
   1.104  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
   1.105 -        JNIEnv* env, jclass cls,
   1.106 +        JNIEnv *env, jclass cls,
   1.107          jstring text, jint newCursorPosition);
   1.108  
   1.109  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar)(
   1.110 -        JNIEnv* env, jclass cls,
   1.111 +        JNIEnv *env, jclass cls,
   1.112          jchar chUnicode);
   1.113  
   1.114  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
   1.115 -        JNIEnv* env, jclass cls,
   1.116 +        JNIEnv *env, jclass cls,
   1.117          jstring text, jint newCursorPosition);
   1.118  
   1.119  /* Java class SDLAudioManager */
   1.120 @@ -165,36 +165,36 @@
   1.121          JNIEnv *env, jclass jcls);
   1.122  
   1.123  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
   1.124 -        JNIEnv* env, jclass jcls,
   1.125 +        JNIEnv *env, jclass jcls,
   1.126          jint device_id, jint keycode);
   1.127  
   1.128  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
   1.129 -        JNIEnv* env, jclass jcls,
   1.130 +        JNIEnv *env, jclass jcls,
   1.131          jint device_id, jint keycode);
   1.132  
   1.133  JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)(
   1.134 -        JNIEnv* env, jclass jcls,
   1.135 +        JNIEnv *env, jclass jcls,
   1.136          jint device_id, jint axis, jfloat value);
   1.137  
   1.138  JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
   1.139 -        JNIEnv* env, jclass jcls,
   1.140 +        JNIEnv *env, jclass jcls,
   1.141          jint device_id, jint hat_id, jint x, jint y);
   1.142  
   1.143  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
   1.144 -        JNIEnv* env, jclass jcls,
   1.145 +        JNIEnv *env, jclass jcls,
   1.146          jint device_id, jstring device_name, jstring device_desc, jint vendor_id, jint product_id,
   1.147          jboolean is_accelerometer, jint button_mask, jint naxes, jint nhats, jint nballs);
   1.148  
   1.149  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
   1.150 -        JNIEnv* env, jclass jcls,
   1.151 +        JNIEnv *env, jclass jcls,
   1.152          jint device_id);
   1.153  
   1.154  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
   1.155 -        JNIEnv* env, jclass jcls,
   1.156 +        JNIEnv *env, jclass jcls,
   1.157          jint device_id, jstring device_name);
   1.158  
   1.159  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)(
   1.160 -        JNIEnv* env, jclass jcls,
   1.161 +        JNIEnv *env, jclass jcls,
   1.162          jint device_id);
   1.163  
   1.164  
   1.165 @@ -202,7 +202,7 @@
   1.166  /* Uncomment this to log messages entering and exiting methods in this file */
   1.167  /* #define DEBUG_JNI */
   1.168  
   1.169 -static void Android_JNI_ThreadDestroyed(void*);
   1.170 +static void Android_JNI_ThreadDestroyed(void *);
   1.171  static void checkJNIReady(void);
   1.172  
   1.173  /*******************************************************************************
   1.174 @@ -215,7 +215,7 @@
   1.175                                 Globals
   1.176  *******************************************************************************/
   1.177  static pthread_key_t mThreadKey;
   1.178 -static JavaVM* mJavaVM;
   1.179 +static JavaVM *mJavaVM;
   1.180  
   1.181  /* Main activity */
   1.182  static jclass mActivityClass;
   1.183 @@ -286,12 +286,12 @@
   1.184  *******************************************************************************/
   1.185  
   1.186  /* Library init */
   1.187 -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
   1.188 +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
   1.189  {
   1.190      JNIEnv *env;
   1.191      mJavaVM = vm;
   1.192      LOGI("JNI_OnLoad called");
   1.193 -    if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
   1.194 +    if ((*mJavaVM)->GetEnv(mJavaVM, (void **) &env, JNI_VERSION_1_4) != JNI_OK) {
   1.195          LOGE("Failed to get the environment using GetEnv()");
   1.196          return -1;
   1.197      }
   1.198 @@ -318,7 +318,7 @@
   1.199  }
   1.200  
   1.201  /* Activity initialization -- called before SDL_main() to initialize JNI bindings */
   1.202 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
   1.203 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls)
   1.204  {
   1.205      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetupJNI()");
   1.206  
   1.207 @@ -397,7 +397,7 @@
   1.208  }
   1.209  
   1.210  /* Audio initialization -- called before SDL_main() to initialize JNI bindings */
   1.211 -JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
   1.212 +JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls)
   1.213  {
   1.214      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "AUDIO nativeSetupJNI()");
   1.215  
   1.216 @@ -435,7 +435,7 @@
   1.217  }
   1.218  
   1.219  /* Controller initialization -- called before SDL_main() to initialize JNI bindings */
   1.220 -JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
   1.221 +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls)
   1.222  {
   1.223      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "CONTROLLER nativeSetupJNI()");
   1.224  
   1.225 @@ -463,7 +463,7 @@
   1.226  typedef int (*SDL_main_func)(int argc, char *argv[]);
   1.227  
   1.228  /* Start up the SDL app */
   1.229 -JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv* env, jclass cls, jstring library, jstring function, jobject array)
   1.230 +JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, jstring library, jstring function, jobject array)
   1.231  {
   1.232      int status = -1;
   1.233      const char *library_file;
   1.234 @@ -488,15 +488,15 @@
   1.235  
   1.236              /* Prepare the arguments. */
   1.237              len = (*env)->GetArrayLength(env, array);
   1.238 -            argv = SDL_small_alloc(char*, 1 + len + 1, &isstack);  /* !!! FIXME: check for NULL */
   1.239 +            argv = SDL_small_alloc(char *, 1 + len + 1, &isstack);  /* !!! FIXME: check for NULL */
   1.240              argc = 0;
   1.241              /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
   1.242                 https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
   1.243               */
   1.244              argv[argc++] = SDL_strdup("app_process");
   1.245              for (i = 0; i < len; ++i) {
   1.246 -                const char* utf;
   1.247 -                char* arg = NULL;
   1.248 +                const char *utf;
   1.249 +                char *arg = NULL;
   1.250                  jstring string = (*env)->GetObjectArrayElement(env, array, i);
   1.251                  if (string) {
   1.252                      utf = (*env)->GetStringUTFChars(env, string, 0);
   1.253 @@ -543,7 +543,7 @@
   1.254  
   1.255  /* Drop file */
   1.256  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
   1.257 -                                    JNIEnv* env, jclass jcls,
   1.258 +                                    JNIEnv *env, jclass jcls,
   1.259                                      jstring filename)
   1.260  {
   1.261      const char *path = (*env)->GetStringUTFChars(env, filename, NULL);
   1.262 @@ -554,11 +554,11 @@
   1.263  
   1.264  /* Resize */
   1.265  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
   1.266 -                                    JNIEnv* env, jclass jcls,
   1.267 +                                    JNIEnv *env, jclass jcls,
   1.268                                      jint surfaceWidth, jint surfaceHeight,
   1.269                                      jint deviceWidth, jint deviceHeight, jint format, jfloat rate)
   1.270  {
   1.271 -    Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
   1.272 +    Android_SetScreenResolution(Android_Window, surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
   1.273  }
   1.274  
   1.275  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
   1.276 @@ -571,7 +571,7 @@
   1.277  
   1.278  /* Paddown */
   1.279  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
   1.280 -                                    JNIEnv* env, jclass jcls,
   1.281 +                                    JNIEnv *env, jclass jcls,
   1.282                                      jint device_id, jint keycode)
   1.283  {
   1.284      return Android_OnPadDown(device_id, keycode);
   1.285 @@ -579,7 +579,7 @@
   1.286  
   1.287  /* Padup */
   1.288  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
   1.289 -                                    JNIEnv* env, jclass jcls,
   1.290 +                                    JNIEnv *env, jclass jcls,
   1.291                                      jint device_id, jint keycode)
   1.292  {
   1.293      return Android_OnPadUp(device_id, keycode);
   1.294 @@ -587,7 +587,7 @@
   1.295  
   1.296  /* Joy */
   1.297  JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)(
   1.298 -                                    JNIEnv* env, jclass jcls,
   1.299 +                                    JNIEnv *env, jclass jcls,
   1.300                                      jint device_id, jint axis, jfloat value)
   1.301  {
   1.302      Android_OnJoy(device_id, axis, value);
   1.303 @@ -595,7 +595,7 @@
   1.304  
   1.305  /* POV Hat */
   1.306  JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
   1.307 -                                    JNIEnv* env, jclass jcls,
   1.308 +                                    JNIEnv *env, jclass jcls,
   1.309                                      jint device_id, jint hat_id, jint x, jint y)
   1.310  {
   1.311      Android_OnHat(device_id, hat_id, x, y);
   1.312 @@ -603,7 +603,7 @@
   1.313  
   1.314  
   1.315  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
   1.316 -                                    JNIEnv* env, jclass jcls,
   1.317 +                                    JNIEnv *env, jclass jcls,
   1.318                                      jint device_id, jstring device_name, jstring device_desc,
   1.319                                      jint vendor_id, jint product_id, jboolean is_accelerometer,
   1.320                                      jint button_mask, jint naxes, jint nhats, jint nballs)
   1.321 @@ -621,14 +621,14 @@
   1.322  }
   1.323  
   1.324  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
   1.325 -                                    JNIEnv* env, jclass jcls,
   1.326 +                                    JNIEnv *env, jclass jcls,
   1.327                                      jint device_id)
   1.328  {
   1.329      return Android_RemoveJoystick(device_id);
   1.330  }
   1.331  
   1.332  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
   1.333 -    JNIEnv* env, jclass jcls, jint device_id, jstring device_name)
   1.334 +    JNIEnv *env, jclass jcls, jint device_id, jstring device_name)
   1.335  {
   1.336      int retval;
   1.337      const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
   1.338 @@ -641,68 +641,59 @@
   1.339  }
   1.340  
   1.341  JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)(
   1.342 -    JNIEnv* env, jclass jcls, jint device_id)
   1.343 +    JNIEnv *env, jclass jcls, jint device_id)
   1.344  {
   1.345      return Android_RemoveHaptic(device_id);
   1.346  }
   1.347  
   1.348  
   1.349  /* Surface Created */
   1.350 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, jclass jcls)
   1.351 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, jclass jcls)
   1.352  {
   1.353 -    SDL_WindowData *data;
   1.354 -    SDL_VideoDevice *_this;
   1.355 +    if (Android_Window && Android_Window->driverdata)
   1.356 +    {
   1.357 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.358 +        SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
   1.359  
   1.360 -    if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
   1.361 -        return;
   1.362 +        /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
   1.363 +        if (data->egl_surface == EGL_NO_SURFACE) {
   1.364 +            if (data->native_window) {
   1.365 +                ANativeWindow_release(data->native_window);
   1.366 +            }
   1.367 +            data->native_window = Android_JNI_GetNativeWindow();
   1.368 +            data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
   1.369 +        }
   1.370 +
   1.371 +        /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.372      }
   1.373 -
   1.374 -    _this =  SDL_GetVideoDevice();
   1.375 -    data =  (SDL_WindowData *) Android_Window->driverdata;
   1.376 -
   1.377 -    /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
   1.378 -    if (data->egl_surface == EGL_NO_SURFACE) {
   1.379 -        if(data->native_window) {
   1.380 -            ANativeWindow_release(data->native_window);
   1.381 -        }
   1.382 -        data->native_window = Android_JNI_GetNativeWindow();
   1.383 -        data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
   1.384 -    }
   1.385 -
   1.386 -    /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.387 -
   1.388  }
   1.389  
   1.390  /* Surface Destroyed */
   1.391 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv* env, jclass jcls)
   1.392 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv *env, jclass jcls)
   1.393  {
   1.394 -    /* We have to clear the current context and destroy the egl surface here
   1.395 -     * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
   1.396 -     * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d
   1.397 -     */
   1.398 -    SDL_WindowData *data;
   1.399 -    SDL_VideoDevice *_this;
   1.400 +    if (Android_Window && Android_Window->driverdata)
   1.401 +    {
   1.402 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.403 +        SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
   1.404  
   1.405 -    if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
   1.406 -        return;
   1.407 +        /* We have to clear the current context and destroy the egl surface here
   1.408 +         * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
   1.409 +         * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d
   1.410 +         */
   1.411 +
   1.412 +        if (data->egl_surface != EGL_NO_SURFACE) {
   1.413 +            SDL_EGL_MakeCurrent(_this, NULL, NULL);
   1.414 +            SDL_EGL_DestroySurface(_this, data->egl_surface);
   1.415 +            data->egl_surface = EGL_NO_SURFACE;
   1.416 +        }
   1.417 +
   1.418 +        /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.419      }
   1.420 -
   1.421 -    _this =  SDL_GetVideoDevice();
   1.422 -    data = (SDL_WindowData *) Android_Window->driverdata;
   1.423 -
   1.424 -    if (data->egl_surface != EGL_NO_SURFACE) {
   1.425 -        SDL_EGL_MakeCurrent(_this, NULL, NULL);
   1.426 -        SDL_EGL_DestroySurface(_this, data->egl_surface);
   1.427 -        data->egl_surface = EGL_NO_SURFACE;
   1.428 -    }
   1.429 -
   1.430 -    /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.431 -
   1.432  }
   1.433  
   1.434  /* Keydown */
   1.435  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
   1.436 -                                    JNIEnv* env, jclass jcls,
   1.437 +                                    JNIEnv *env, jclass jcls,
   1.438                                      jint keycode)
   1.439  {
   1.440      Android_OnKeyDown(keycode);
   1.441 @@ -710,7 +701,7 @@
   1.442  
   1.443  /* Keyup */
   1.444  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
   1.445 -                                    JNIEnv* env, jclass jcls,
   1.446 +                                    JNIEnv *env, jclass jcls,
   1.447                                      jint keycode)
   1.448  {
   1.449      Android_OnKeyUp(keycode);
   1.450 @@ -718,7 +709,7 @@
   1.451  
   1.452  /* Keyboard Focus Lost */
   1.453  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
   1.454 -                                    JNIEnv* env, jclass jcls)
   1.455 +                                    JNIEnv *env, jclass jcls)
   1.456  {
   1.457      /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
   1.458      SDL_StopTextInput();
   1.459 @@ -727,24 +718,24 @@
   1.460  
   1.461  /* Touch */
   1.462  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
   1.463 -                                    JNIEnv* env, jclass jcls,
   1.464 +                                    JNIEnv *env, jclass jcls,
   1.465                                      jint touch_device_id_in, jint pointer_finger_id_in,
   1.466                                      jint action, jfloat x, jfloat y, jfloat p)
   1.467  {
   1.468 -    Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p);
   1.469 +    Android_OnTouch(Android_Window, touch_device_id_in, pointer_finger_id_in, action, x, y, p);
   1.470  }
   1.471  
   1.472  /* Mouse */
   1.473  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
   1.474 -                                    JNIEnv* env, jclass jcls,
   1.475 +                                    JNIEnv *env, jclass jcls,
   1.476                                      jint button, jint action, jfloat x, jfloat y, jboolean relative)
   1.477  {
   1.478 -    Android_OnMouse(button, action, x, y, relative);
   1.479 +    Android_OnMouse(Android_Window, button, action, x, y, relative);
   1.480  }
   1.481  
   1.482  /* Accelerometer */
   1.483  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
   1.484 -                                    JNIEnv* env, jclass jcls,
   1.485 +                                    JNIEnv *env, jclass jcls,
   1.486                                      jfloat x, jfloat y, jfloat z)
   1.487  {
   1.488      fLastAccelerometer[0] = x;
   1.489 @@ -755,21 +746,21 @@
   1.490  
   1.491  /* Clipboard */
   1.492  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
   1.493 -                                    JNIEnv* env, jclass jcls)
   1.494 +                                    JNIEnv *env, jclass jcls)
   1.495  {
   1.496      SDL_SendClipboardUpdate();
   1.497  }
   1.498  
   1.499  /* Low memory */
   1.500  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
   1.501 -                                    JNIEnv* env, jclass cls)
   1.502 +                                    JNIEnv *env, jclass cls)
   1.503  {
   1.504      SDL_SendAppEvent(SDL_APP_LOWMEMORY);
   1.505  }
   1.506  
   1.507  /* Quit */
   1.508  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
   1.509 -                                    JNIEnv* env, jclass cls)
   1.510 +                                    JNIEnv *env, jclass cls)
   1.511  {
   1.512      /* Discard previous events. The user should have handled state storage
   1.513       * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
   1.514 @@ -785,7 +776,7 @@
   1.515  
   1.516  /* Pause */
   1.517  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
   1.518 -                                    JNIEnv* env, jclass cls)
   1.519 +                                    JNIEnv *env, jclass cls)
   1.520  {
   1.521      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
   1.522  
   1.523 @@ -803,7 +794,7 @@
   1.524  
   1.525  /* Resume */
   1.526  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
   1.527 -                                    JNIEnv* env, jclass cls)
   1.528 +                                    JNIEnv *env, jclass cls)
   1.529  {
   1.530      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
   1.531  
   1.532 @@ -828,7 +819,7 @@
   1.533  }
   1.534  
   1.535  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
   1.536 -                                    JNIEnv* env, jclass cls,
   1.537 +                                    JNIEnv *env, jclass cls,
   1.538                                      jstring text, jint newCursorPosition)
   1.539  {
   1.540      const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
   1.541 @@ -839,7 +830,7 @@
   1.542  }
   1.543  
   1.544  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar)(
   1.545 -                                    JNIEnv* env, jclass cls,
   1.546 +                                    JNIEnv *env, jclass cls,
   1.547                                      jchar chUnicode)
   1.548  {
   1.549      SDL_Scancode code = SDL_SCANCODE_UNKNOWN;
   1.550 @@ -869,7 +860,7 @@
   1.551  
   1.552  
   1.553  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
   1.554 -                                    JNIEnv* env, jclass cls,
   1.555 +                                    JNIEnv *env, jclass cls,
   1.556                                      jstring text, jint newCursorPosition)
   1.557  {
   1.558      const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
   1.559 @@ -880,7 +871,7 @@
   1.560  }
   1.561  
   1.562  JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
   1.563 -                                    JNIEnv* env, jclass cls,
   1.564 +                                    JNIEnv *env, jclass cls,
   1.565                                      jstring name)
   1.566  {
   1.567      const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
   1.568 @@ -893,7 +884,7 @@
   1.569  }
   1.570  
   1.571  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
   1.572 -                                    JNIEnv* env, jclass cls,
   1.573 +                                    JNIEnv *env, jclass cls,
   1.574                                      jstring name, jstring value)
   1.575  {
   1.576      const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
   1.577 @@ -946,7 +937,7 @@
   1.578      SDL_Log("Leaving function %s", refholder->m_func);
   1.579  #endif
   1.580      if (refholder->m_env) {
   1.581 -        JNIEnv* env = refholder->m_env;
   1.582 +        JNIEnv *env = refholder->m_env;
   1.583          (*env)->PopLocalFrame(env, NULL);
   1.584          --s_active;
   1.585      }
   1.586 @@ -1027,10 +1018,10 @@
   1.587      return retval;
   1.588  }
   1.589  
   1.590 -static void Android_JNI_ThreadDestroyed(void* value)
   1.591 +static void Android_JNI_ThreadDestroyed(void *value)
   1.592  {
   1.593      /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
   1.594 -    JNIEnv *env = (JNIEnv*) value;
   1.595 +    JNIEnv *env = (JNIEnv *) value;
   1.596      if (env != NULL) {
   1.597          (*mJavaVM)->DetachCurrentThread(mJavaVM);
   1.598          pthread_setspecific(mThreadKey, NULL);
   1.599 @@ -1053,7 +1044,7 @@
   1.600  
   1.601      JNIEnv *env;
   1.602      int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
   1.603 -    if(status < 0) {
   1.604 +    if (status < 0) {
   1.605          LOGE("failed to attach current thread");
   1.606          return 0;
   1.607      }
   1.608 @@ -1067,7 +1058,7 @@
   1.609       * Note: You can call this function any number of times for the same thread, there's no harm in it
   1.610       *       (except for some lost CPU cycles)
   1.611       */
   1.612 -    pthread_setspecific(mThreadKey, (void*) env);
   1.613 +    pthread_setspecific(mThreadKey, (void *)env);
   1.614  
   1.615      return env;
   1.616  }
   1.617 @@ -1083,7 +1074,7 @@
   1.618   */
   1.619  static int audioBufferFormat = 0;
   1.620  static jobject audioBuffer = NULL;
   1.621 -static void* audioBufferPinned = NULL;
   1.622 +static void *audioBufferPinned = NULL;
   1.623  static int captureBufferFormat = 0;
   1.624  static jobject captureBuffer = NULL;
   1.625  
   1.626 @@ -1413,7 +1404,7 @@
   1.627              jclass exceptionClass = (*mEnv)->GetObjectClass(mEnv, exception);
   1.628              jclass classClass = (*mEnv)->FindClass(mEnv, "java/lang/Class");
   1.629              jstring exceptionName;
   1.630 -            const char* exceptionNameUTF8;
   1.631 +            const char *exceptionNameUTF8;
   1.632              jstring exceptionMessage;
   1.633  
   1.634              mid = (*mEnv)->GetMethodID(mEnv, classClass, "getName", "()Ljava/lang/String;");
   1.635 @@ -1424,7 +1415,7 @@
   1.636              exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid);
   1.637  
   1.638              if (exceptionMessage != NULL) {
   1.639 -                const char* exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0);
   1.640 +                const char *exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0);
   1.641                  SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8);
   1.642                  (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionMessage, exceptionMessageUTF8);
   1.643              } else {
   1.644 @@ -1440,7 +1431,7 @@
   1.645      return SDL_FALSE;
   1.646  }
   1.647  
   1.648 -static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
   1.649 +static int Internal_Android_JNI_FileOpen(SDL_RWops *ctx)
   1.650  {
   1.651      struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
   1.652  
   1.653 @@ -1589,8 +1580,8 @@
   1.654      return result;
   1.655  }
   1.656  
   1.657 -int Android_JNI_FileOpen(SDL_RWops* ctx,
   1.658 -        const char* fileName, const char* mode)
   1.659 +int Android_JNI_FileOpen(SDL_RWops *ctx,
   1.660 +        const char *fileName, const char *mode)
   1.661  {
   1.662      struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
   1.663      JNIEnv *mEnv = Android_JNI_GetEnv();
   1.664 @@ -1619,7 +1610,7 @@
   1.665      return retval;
   1.666  }
   1.667  
   1.668 -size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
   1.669 +size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer,
   1.670          size_t size, size_t maxnum)
   1.671  {
   1.672      struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
   1.673 @@ -1682,14 +1673,14 @@
   1.674      }
   1.675  }
   1.676  
   1.677 -size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
   1.678 +size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer,
   1.679          size_t size, size_t num)
   1.680  {
   1.681      SDL_SetError("Cannot write to Android package filesystem");
   1.682      return 0;
   1.683  }
   1.684  
   1.685 -static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
   1.686 +static int Internal_Android_JNI_FileClose(SDL_RWops *ctx, SDL_bool release)
   1.687  {
   1.688      struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
   1.689  
   1.690 @@ -1740,12 +1731,12 @@
   1.691  }
   1.692  
   1.693  
   1.694 -Sint64 Android_JNI_FileSize(SDL_RWops* ctx)
   1.695 +Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
   1.696  {
   1.697      return ctx->hidden.androidio.size;
   1.698  }
   1.699  
   1.700 -Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
   1.701 +Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
   1.702  {
   1.703      if (ctx->hidden.androidio.assetFileDescriptorRef) {
   1.704          off_t ret;
   1.705 @@ -1829,14 +1820,14 @@
   1.706  
   1.707  }
   1.708  
   1.709 -int Android_JNI_FileClose(SDL_RWops* ctx)
   1.710 +int Android_JNI_FileClose(SDL_RWops *ctx)
   1.711  {
   1.712      return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
   1.713  }
   1.714  
   1.715 -int Android_JNI_SetClipboardText(const char* text)
   1.716 +int Android_JNI_SetClipboardText(const char *text)
   1.717  {
   1.718 -    JNIEnv* env = Android_JNI_GetEnv();
   1.719 +    JNIEnv *env = Android_JNI_GetEnv();
   1.720      jstring string = (*env)->NewStringUTF(env, text);
   1.721      (*env)->CallStaticVoidMethod(env, mActivityClass, midClipboardSetText, string);
   1.722      (*env)->DeleteLocalRef(env, string);
   1.723 @@ -1845,13 +1836,13 @@
   1.724  
   1.725  char* Android_JNI_GetClipboardText(void)
   1.726  {
   1.727 -    JNIEnv* env = Android_JNI_GetEnv();
   1.728 -    char* text = NULL;
   1.729 +    JNIEnv *env = Android_JNI_GetEnv();
   1.730 +    char *text = NULL;
   1.731      jstring string;
   1.732  
   1.733      string = (*env)->CallStaticObjectMethod(env, mActivityClass, midClipboardGetText);
   1.734      if (string) {
   1.735 -        const char* utf = (*env)->GetStringUTFChars(env, string, 0);
   1.736 +        const char *utf = (*env)->GetStringUTFChars(env, string, 0);
   1.737          if (utf) {
   1.738              text = SDL_strdup(utf);
   1.739              (*env)->ReleaseStringUTFChars(env, string, utf);
   1.740 @@ -1864,7 +1855,7 @@
   1.741  
   1.742  SDL_bool Android_JNI_HasClipboardText(void)
   1.743  {
   1.744 -    JNIEnv* env = Android_JNI_GetEnv();
   1.745 +    JNIEnv *env = Android_JNI_GetEnv();
   1.746      jboolean retval = (*env)->CallStaticBooleanMethod(env, mActivityClass, midClipboardHasText);
   1.747      return (retval == JNI_TRUE) ? SDL_TRUE : SDL_FALSE;
   1.748  }
   1.749 @@ -1873,10 +1864,10 @@
   1.750   * returns truthy or falsy value in plugged, charged and battery
   1.751   * returns the value in seconds and percent or -1 if not available
   1.752   */
   1.753 -int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent)
   1.754 +int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seconds, int *percent)
   1.755  {
   1.756      struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
   1.757 -    JNIEnv* env = Android_JNI_GetEnv();
   1.758 +    JNIEnv *env = Android_JNI_GetEnv();
   1.759      jmethodID mid;
   1.760      jobject context;
   1.761      jstring action;
   1.762 @@ -2000,7 +1991,7 @@
   1.763      if (array) {
   1.764          number = (int) (*env)->GetArrayLength(env, array);
   1.765          if (0 < number) {
   1.766 -            jint* elements = (*env)->GetIntArrayElements(env, array, NULL);
   1.767 +            jint *elements = (*env)->GetIntArrayElements(env, array, NULL);
   1.768              if (elements) {
   1.769                  int i;
   1.770                  *ids = SDL_malloc(number * sizeof (**ids));
     2.1 --- a/src/video/android/SDL_androidevents.c	Wed Jan 02 18:06:33 2019 +0100
     2.2 +++ b/src/video/android/SDL_androidevents.c	Thu Jan 03 13:14:16 2019 +0100
     2.3 @@ -40,27 +40,27 @@
     2.4  #endif
     2.5  
     2.6  static void 
     2.7 -android_egl_context_restore() 
     2.8 +android_egl_context_restore(SDL_Window *window) 
     2.9  {
    2.10      SDL_Event event;
    2.11 -    SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
    2.12 -    if (SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context) < 0) {
    2.13 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.14 +    if (SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context) < 0) {
    2.15          /* The context is no longer valid, create a new one */
    2.16 -        data->egl_context = (EGLContext) SDL_GL_CreateContext(Android_Window);
    2.17 -        SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context);
    2.18 +        data->egl_context = (EGLContext) SDL_GL_CreateContext(window);
    2.19 +        SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context);
    2.20          event.type = SDL_RENDER_DEVICE_RESET;
    2.21          SDL_PushEvent(&event);
    2.22      }
    2.23  }
    2.24  
    2.25  static void 
    2.26 -android_egl_context_backup() 
    2.27 +android_egl_context_backup(SDL_Window *window) 
    2.28  {
    2.29      /* Keep a copy of the EGL Context so we can try to restore it when we resume */
    2.30 -    SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
    2.31 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.32      data->egl_context = SDL_GL_GetCurrentContext();
    2.33      /* We need to do this so the EGLSurface can be freed */
    2.34 -    SDL_GL_MakeCurrent(Android_Window, NULL);
    2.35 +    SDL_GL_MakeCurrent(window, NULL);
    2.36  }
    2.37  
    2.38  void
    2.39 @@ -80,24 +80,24 @@
    2.40  #if SDL_ANDROID_BLOCK_ON_PAUSE
    2.41      if (isPaused && !isPausing) {
    2.42          /* Make sure this is the last thing we do before pausing */
    2.43 -        android_egl_context_backup();
    2.44 +        android_egl_context_backup(Android_Window);
    2.45          ANDROIDAUDIO_PauseDevices();
    2.46 -        if(SDL_SemWait(Android_ResumeSem) == 0) {
    2.47 +        if (SDL_SemWait(Android_ResumeSem) == 0) {
    2.48  #else
    2.49      if (isPaused) {
    2.50 -        if(SDL_SemTryWait(Android_ResumeSem) == 0) {
    2.51 +        if (SDL_SemTryWait(Android_ResumeSem) == 0) {
    2.52  #endif
    2.53              isPaused = 0;
    2.54              ANDROIDAUDIO_ResumeDevices();
    2.55              /* Restore the GL Context from here, as this operation is thread dependent */
    2.56              if (!SDL_HasEvent(SDL_QUIT)) {
    2.57 -                android_egl_context_restore();
    2.58 +                android_egl_context_restore(Android_Window);
    2.59              }
    2.60          }
    2.61      }
    2.62      else {
    2.63  #if SDL_ANDROID_BLOCK_ON_PAUSE
    2.64 -        if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
    2.65 +        if (isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
    2.66              /* We've been signaled to pause, but before we block ourselves, 
    2.67              we need to make sure that certain key events have reached the app */
    2.68              if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
    2.69 @@ -109,8 +109,8 @@
    2.70              }
    2.71          }
    2.72  #else
    2.73 -        if(SDL_SemTryWait(Android_PauseSem) == 0) {
    2.74 -            android_egl_context_backup();
    2.75 +        if (SDL_SemTryWait(Android_PauseSem) == 0) {
    2.76 +            android_egl_context_backup(Android_Window);
    2.77              ANDROIDAUDIO_PauseDevices();
    2.78              isPaused = 1;
    2.79          }
     3.1 --- a/src/video/android/SDL_androidmouse.c	Wed Jan 02 18:06:33 2019 +0100
     3.2 +++ b/src/video/android/SDL_androidmouse.c	Thu Jan 03 13:14:16 2019 +0100
     3.3 @@ -62,7 +62,7 @@
     3.4  
     3.5      cursor = SDL_calloc(1, sizeof(*cursor));
     3.6      if (cursor) {
     3.7 -        SDL_AndroidCursorData *data = (SDL_AndroidCursorData*)SDL_calloc(1, sizeof(*data));
     3.8 +        SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)SDL_calloc(1, sizeof(*data));
     3.9          if (data) {
    3.10              data->custom_cursor = custom_cursor;
    3.11              data->system_cursor = system_cursor;
    3.12 @@ -141,13 +141,13 @@
    3.13  }
    3.14  
    3.15  static int
    3.16 -Android_ShowCursor(SDL_Cursor * cursor)
    3.17 +Android_ShowCursor(SDL_Cursor *cursor)
    3.18  {
    3.19      if (!cursor) {
    3.20          cursor = Android_CreateEmptyCursor();
    3.21      }
    3.22      if (cursor) {
    3.23 -        SDL_AndroidCursorData *data = (SDL_AndroidCursorData*)cursor->driverdata;
    3.24 +        SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)cursor->driverdata;
    3.25          if (data->custom_cursor) {
    3.26              if (!Android_JNI_SetCustomCursor(data->custom_cursor)) {
    3.27                  return SDL_Unsupported();
    3.28 @@ -220,12 +220,12 @@
    3.29  }
    3.30  
    3.31  void
    3.32 -Android_OnMouse(int state, int action, float x, float y, SDL_bool relative)
    3.33 +Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
    3.34  {
    3.35      int changes;
    3.36      Uint8 button;
    3.37  
    3.38 -    if (!Android_Window) {
    3.39 +    if (!window) {
    3.40          return;
    3.41      }
    3.42  
    3.43 @@ -234,25 +234,25 @@
    3.44              changes = state & ~last_state;
    3.45              button = TranslateButton(changes);
    3.46              last_state = state;
    3.47 -            SDL_SendMouseMotion(Android_Window, 0, relative, (int)x, (int)y);
    3.48 -            SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
    3.49 +            SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
    3.50 +            SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
    3.51              break;
    3.52  
    3.53          case ACTION_UP:
    3.54              changes = last_state & ~state;
    3.55              button = TranslateButton(changes);
    3.56              last_state = state;
    3.57 -            SDL_SendMouseMotion(Android_Window, 0, relative, (int)x, (int)y);
    3.58 -            SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
    3.59 +            SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
    3.60 +            SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
    3.61              break;
    3.62  
    3.63          case ACTION_MOVE:
    3.64          case ACTION_HOVER_MOVE:
    3.65 -            SDL_SendMouseMotion(Android_Window, 0, relative, (int)x, (int)y);
    3.66 +            SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
    3.67              break;
    3.68  
    3.69          case ACTION_SCROLL:
    3.70 -            SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
    3.71 +            SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
    3.72              break;
    3.73  
    3.74          default:
     4.1 --- a/src/video/android/SDL_androidmouse.h	Wed Jan 02 18:06:33 2019 +0100
     4.2 +++ b/src/video/android/SDL_androidmouse.h	Thu Jan 03 13:14:16 2019 +0100
     4.3 @@ -25,7 +25,7 @@
     4.4  #include "SDL_androidvideo.h"
     4.5  
     4.6  extern void Android_InitMouse(void);
     4.7 -extern void Android_OnMouse(int button, int action, float x, float y, SDL_bool relative);
     4.8 +extern void Android_OnMouse(SDL_Window *window, int button, int action, float x, float y, SDL_bool relative);
     4.9  extern void Android_QuitMouse(void);
    4.10  
    4.11  #endif /* SDL_androidmouse_h_ */
     5.1 --- a/src/video/android/SDL_androidtouch.c	Wed Jan 02 18:06:33 2019 +0100
     5.2 +++ b/src/video/android/SDL_androidtouch.c	Thu Jan 03 13:14:16 2019 +0100
     5.3 @@ -40,12 +40,12 @@
     5.4  #define ACTION_POINTER_DOWN 5
     5.5  #define ACTION_POINTER_UP 6
     5.6  
     5.7 -static void Android_GetWindowCoordinates(float x, float y,
     5.8 +static void Android_GetWindowCoordinates(SDL_Window *window, float x, float y,
     5.9                                           int *window_x, int *window_y)
    5.10  {
    5.11      int window_w, window_h;
    5.12  
    5.13 -    SDL_GetWindowSize(Android_Window, &window_w, &window_h);
    5.14 +    SDL_GetWindowSize(window, &window_w, &window_h);
    5.15      *window_x = (int)(x * window_w);
    5.16      *window_y = (int)(y * window_h);
    5.17  }
    5.18 @@ -64,7 +64,7 @@
    5.19  void Android_InitTouch(void)
    5.20  {
    5.21      int i;
    5.22 -    int* ids;
    5.23 +    int *ids;
    5.24      const int number = Android_JNI_GetTouchDeviceIds(&ids);
    5.25  
    5.26      SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    5.27 @@ -85,14 +85,14 @@
    5.28      separate_mouse_and_touch = SDL_FALSE;
    5.29  }
    5.30  
    5.31 -void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    5.32 +void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    5.33  {
    5.34      SDL_TouchID touchDeviceId = 0;
    5.35      SDL_FingerID fingerId = 0;
    5.36      int window_x, window_y;
    5.37      static SDL_FingerID pointerFingerID = 0;
    5.38  
    5.39 -    if (!Android_Window) {
    5.40 +    if (!window) {
    5.41          return;
    5.42      }
    5.43  
    5.44 @@ -106,11 +106,11 @@
    5.45          case ACTION_DOWN:
    5.46              /* Primary pointer down */
    5.47              if (!separate_mouse_and_touch) {
    5.48 -                Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    5.49 +                Android_GetWindowCoordinates(window, x, y, &window_x, &window_y);
    5.50                  /* send moved event */
    5.51 -                SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    5.52 +                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    5.53                  /* send mouse down event */
    5.54 -                SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    5.55 +                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    5.56              }
    5.57              pointerFingerID = fingerId;
    5.58          case ACTION_POINTER_DOWN:
    5.59 @@ -121,9 +121,9 @@
    5.60          case ACTION_MOVE:
    5.61              if (!pointerFingerID) {
    5.62                  if (!separate_mouse_and_touch) {
    5.63 -                    Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    5.64 +                    Android_GetWindowCoordinates(window, x, y, &window_x, &window_y);
    5.65                      /* send moved event */
    5.66 -                    SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    5.67 +                    SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    5.68                  }
    5.69              }
    5.70              SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
    5.71 @@ -133,7 +133,7 @@
    5.72              /* Primary pointer up */
    5.73              if (!separate_mouse_and_touch) {
    5.74                  /* send mouse up */
    5.75 -                SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    5.76 +                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    5.77              }
    5.78              pointerFingerID = (SDL_FingerID) 0;
    5.79          case ACTION_POINTER_UP:
     6.1 --- a/src/video/android/SDL_androidtouch.h	Wed Jan 02 18:06:33 2019 +0100
     6.2 +++ b/src/video/android/SDL_androidtouch.h	Thu Jan 03 13:14:16 2019 +0100
     6.3 @@ -24,6 +24,6 @@
     6.4  
     6.5  extern void Android_InitTouch(void);
     6.6  extern void Android_QuitTouch(void);
     6.7 -extern void Android_OnTouch( int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
     6.8 +extern void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
     6.9  
    6.10  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/android/SDL_androidvideo.c	Wed Jan 02 18:06:33 2019 +0100
     7.2 +++ b/src/video/android/SDL_androidvideo.c	Thu Jan 03 13:14:16 2019 +0100
     7.3 @@ -22,8 +22,7 @@
     7.4  
     7.5  #if SDL_VIDEO_DRIVER_ANDROID
     7.6  
     7.7 -/* Android SDL video driver implementation
     7.8 -*/
     7.9 +/* Android SDL video driver implementation */
    7.10  
    7.11  #include "SDL_video.h"
    7.12  #include "SDL_mouse.h"
    7.13 @@ -47,7 +46,7 @@
    7.14  /* Initialization/Query functions */
    7.15  static int Android_VideoInit(_THIS);
    7.16  static void Android_VideoQuit(_THIS);
    7.17 -int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
    7.18 +int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
    7.19  
    7.20  #include "../SDL_egl_c.h"
    7.21  #define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
    7.22 @@ -69,9 +68,6 @@
    7.23  
    7.24  SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
    7.25  
    7.26 -/* Currently only one window */
    7.27 -SDL_Window *Android_Window = NULL;
    7.28 -
    7.29  static int
    7.30  Android_Available(void)
    7.31  {
    7.32 @@ -85,7 +81,7 @@
    7.33  }
    7.34  
    7.35  static void
    7.36 -Android_DeleteDevice(SDL_VideoDevice * device)
    7.37 +Android_DeleteDevice(SDL_VideoDevice *device)
    7.38  {
    7.39      SDL_free(device->driverdata);
    7.40      SDL_free(device);
    7.41 @@ -104,7 +100,7 @@
    7.42          return NULL;
    7.43      }
    7.44  
    7.45 -    data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
    7.46 +    data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    7.47      if (!data) {
    7.48          SDL_OutOfMemory();
    7.49          SDL_free(device);
    7.50 @@ -206,15 +202,15 @@
    7.51  }
    7.52  
    7.53  int
    7.54 -Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
    7.55 +Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
    7.56  {
    7.57      return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
    7.58  }
    7.59  
    7.60  void
    7.61 -Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
    7.62 +Android_SetScreenResolution(SDL_Window *window, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
    7.63  {
    7.64 -    SDL_VideoDevice* device;
    7.65 +    SDL_VideoDevice *device;
    7.66      SDL_VideoDisplay *display;
    7.67      Android_SurfaceWidth = surfaceWidth;
    7.68      Android_SurfaceHeight = surfaceHeight;
    7.69 @@ -239,10 +235,10 @@
    7.70          display->desktop_mode.refresh_rate  = Android_ScreenRate;
    7.71      }
    7.72  
    7.73 -    if (Android_Window) {
    7.74 +    if (window) {
    7.75          /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
    7.76           * will fall back to the old mode */
    7.77 -        display = SDL_GetDisplayForWindow(Android_Window);
    7.78 +        display = SDL_GetDisplayForWindow(window);
    7.79  
    7.80          display->display_modes[0].format = format;
    7.81          display->display_modes[0].w = Android_DeviceWidth;
    7.82 @@ -250,7 +246,7 @@
    7.83          display->display_modes[0].refresh_rate = (int)rate;
    7.84          display->current_mode = display->display_modes[0];
    7.85  
    7.86 -        SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, surfaceWidth, surfaceHeight);
    7.87 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, surfaceWidth, surfaceHeight);
    7.88      }
    7.89  }
    7.90  
     8.1 --- a/src/video/android/SDL_androidvideo.h	Wed Jan 02 18:06:33 2019 +0100
     8.2 +++ b/src/video/android/SDL_androidvideo.h	Thu Jan 03 13:14:16 2019 +0100
     8.3 @@ -28,7 +28,7 @@
     8.4  #include "../SDL_sysvideo.h"
     8.5  
     8.6  /* Called by the JNI layer when the screen changes size or format */
     8.7 -extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
     8.8 +extern void Android_SetScreenResolution(SDL_Window *window, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
     8.9  
    8.10  /* Private display data */
    8.11  
    8.12 @@ -42,8 +42,6 @@
    8.13  extern int Android_DeviceWidth;
    8.14  extern int Android_DeviceHeight;
    8.15  extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
    8.16 -extern SDL_Window *Android_Window;
    8.17 -
    8.18  
    8.19  #endif /* SDL_androidvideo_h_ */
    8.20  
     9.1 --- a/src/video/android/SDL_androidwindow.c	Wed Jan 02 18:06:33 2019 +0100
     9.2 +++ b/src/video/android/SDL_androidwindow.c	Thu Jan 03 13:14:16 2019 +0100
     9.3 @@ -33,6 +33,9 @@
     9.4  #include "SDL_androidwindow.h"
     9.5  #include "SDL_hints.h"
     9.6  
     9.7 +/* Currently only one window */
     9.8 +SDL_Window *Android_Window = NULL;
     9.9 +
    9.10  int
    9.11  Android_CreateWindow(_THIS, SDL_Window * window)
    9.12  {
    9.13 @@ -94,13 +97,13 @@
    9.14  }
    9.15  
    9.16  void
    9.17 -Android_SetWindowTitle(_THIS, SDL_Window * window)
    9.18 +Android_SetWindowTitle(_THIS, SDL_Window *window)
    9.19  {
    9.20      Android_JNI_SetActivityTitle(window->title);
    9.21  }
    9.22  
    9.23  void
    9.24 -Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
    9.25 +Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
    9.26  {
    9.27      /* If the window is being destroyed don't change visible state */
    9.28      if (!window->is_destroying) {
    9.29 @@ -117,7 +120,7 @@
    9.30          return;
    9.31      }
    9.32  
    9.33 -    SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
    9.34 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    9.35  
    9.36      if (!data || !data->native_window) {
    9.37          return;
    9.38 @@ -135,7 +138,7 @@
    9.39  }
    9.40  
    9.41  void
    9.42 -Android_DestroyWindow(_THIS, SDL_Window * window)
    9.43 +Android_DestroyWindow(_THIS, SDL_Window *window)
    9.44  {
    9.45      SDL_WindowData *data;
    9.46      
    9.47 @@ -161,7 +164,7 @@
    9.48  }
    9.49  
    9.50  SDL_bool
    9.51 -Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
    9.52 +Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
    9.53  {
    9.54      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    9.55  
    10.1 --- a/src/video/android/SDL_androidwindow.h	Wed Jan 02 18:06:33 2019 +0100
    10.2 +++ b/src/video/android/SDL_androidwindow.h	Thu Jan 03 13:14:16 2019 +0100
    10.3 @@ -26,17 +26,18 @@
    10.4  #include "../../core/android/SDL_android.h"
    10.5  #include "../SDL_egl_c.h"
    10.6  
    10.7 -extern int Android_CreateWindow(_THIS, SDL_Window * window);
    10.8 -extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
    10.9 -extern void Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   10.10 -extern void Android_DestroyWindow(_THIS, SDL_Window * window);
   10.11 -extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);
   10.12 +extern int Android_CreateWindow(_THIS, SDL_Window *window);
   10.13 +extern void Android_SetWindowTitle(_THIS, SDL_Window *window);
   10.14 +extern void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
   10.15 +extern void Android_DestroyWindow(_THIS, SDL_Window *window);
   10.16 +extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
   10.17 +extern SDL_Window *Android_Window;
   10.18  
   10.19  typedef struct
   10.20  {
   10.21      EGLSurface egl_surface;
   10.22      EGLContext egl_context; /* We use this to preserve the context when losing focus */
   10.23 -    ANativeWindow* native_window;
   10.24 +    ANativeWindow *native_window;
   10.25      
   10.26  } SDL_WindowData;
   10.27