Improve Android pause/resume behavior.
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 29 Nov 2013 10:06:08 -0300
changeset 80393b0346b37e0f
parent 8038 e1f2a85d9dda
child 8041 afd62b3fda31
Improve Android pause/resume behavior.
src/core/android/SDL_android.c
src/video/android/SDL_androidevents.c
     1.1 --- a/src/core/android/SDL_android.c	Thu Nov 28 02:31:32 2013 -0800
     1.2 +++ b/src/core/android/SDL_android.c	Fri Nov 29 10:06:08 2013 -0300
     1.3 @@ -300,16 +300,17 @@
     1.4  void Java_org_libsdl_app_SDLActivity_nativePause(
     1.5                                      JNIEnv* env, jclass cls)
     1.6  {
     1.7 +    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
     1.8      if (Android_Window) {
     1.9 -        /* Signal the pause semaphore so the event loop knows to pause and (optionally) block itself */
    1.10 -        if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
    1.11          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
    1.12          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    1.13 +        SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
    1.14 +        SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    1.15 +    
    1.16 +        /* *After* sending the relevant events, signal the pause semaphore 
    1.17 +         * so the event loop knows to pause and (optionally) block itself */
    1.18 +        if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
    1.19      }
    1.20 -
    1.21 -    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
    1.22 -    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
    1.23 -    SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    1.24  }
    1.25  
    1.26  /* Resume */
    1.27 @@ -317,8 +318,6 @@
    1.28                                      JNIEnv* env, jclass cls)
    1.29  {
    1.30      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
    1.31 -    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
    1.32 -    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
    1.33  
    1.34      if (Android_Window) {
    1.35          /* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
    1.36 @@ -326,6 +325,9 @@
    1.37           * and this function will be called from the Java thread instead.
    1.38           */
    1.39          if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
    1.40 +        
    1.41 +        SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
    1.42 +        SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
    1.43          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
    1.44          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    1.45      }
     2.1 --- a/src/video/android/SDL_androidevents.c	Thu Nov 28 02:31:32 2013 -0800
     2.2 +++ b/src/video/android/SDL_androidevents.c	Fri Nov 29 10:06:08 2013 -0300
     2.3 @@ -66,8 +66,6 @@
     2.4      /*
     2.5       * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
     2.6       * When the pause semaphore is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
     2.7 -     * When the resume semaphore is signaled, SDL_GL_CreateContext is called which in turn calls Java code
     2.8 -     * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
     2.9       */
    2.10  
    2.11  #if SDL_ANDROID_BLOCK_ON_PAUSE