Don't block Android event loop until all relevant events reach the app.
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 27 Sep 2012 15:00:34 -0300
changeset 6469ce84310d85ef
parent 6468 6af2a8db95d0
child 6470 ca793191b67a
Don't block Android event loop until all relevant events reach the app.
src/video/android/SDL_androidevents.c
     1.1 --- a/src/video/android/SDL_androidevents.c	Thu Sep 27 10:41:16 2012 -0700
     1.2 +++ b/src/video/android/SDL_androidevents.c	Thu Sep 27 15:00:34 2012 -0300
     1.3 @@ -23,11 +23,15 @@
     1.4  #if SDL_VIDEO_DRIVER_ANDROID
     1.5  
     1.6  #include "SDL_androidevents.h"
     1.7 +#include "SDL_events.h"
     1.8  
     1.9  void
    1.10  Android_PumpEvents(_THIS)
    1.11  {
    1.12      static int isPaused = 0;
    1.13 +#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.14 +    static int isPausing = 0;
    1.15 +#endif
    1.16      /* No polling necessary */
    1.17  
    1.18      /*
    1.19 @@ -36,10 +40,12 @@
    1.20       * When the resume semaphore is signaled, SDL_GL_CreateContext is called which in turn calls Java code
    1.21       * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
    1.22       */
    1.23 -    if (isPaused) {
    1.24 +
    1.25  #if SDL_ANDROID_BLOCK_ON_PAUSE
    1.26 +    if (isPaused && !isPausing) {
    1.27          if(SDL_SemWait(Android_ResumeSem) == 0) {
    1.28  #else
    1.29 +    if (isPaused) {
    1.30          if(SDL_SemTryWait(Android_ResumeSem) == 0) {
    1.31  #endif
    1.32              isPaused = 0;
    1.33 @@ -53,10 +59,25 @@
    1.34          }
    1.35      }
    1.36      else {
    1.37 +#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.38 +        if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
    1.39 +            /* We've been signaled to pause, but before we block ourselves, we need to make sure that
    1.40 +            SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED have reached the app */
    1.41 +            if (SDL_HasEvent(SDL_WINDOWEVENT)) {
    1.42 +                isPausing = 1;
    1.43 +            }
    1.44 +            else {
    1.45 +                isPausing = 0;
    1.46 +                isPaused = 1;
    1.47 +            }
    1.48 +        }
    1.49 +#else
    1.50          if(SDL_SemTryWait(Android_PauseSem) == 0) {
    1.51              /* If we fall in here, the system is/was paused */
    1.52              isPaused = 1;
    1.53          }
    1.54 +#endif
    1.55 +
    1.56      }
    1.57  }
    1.58