Android: make Android_PumpEvents() more readable
authorSylvain Becker <sylvain.becker@gmail.com>
Fri, 04 Jan 2019 23:11:21 +0100
changeset 1250042a61bf08873
parent 12499 e6130a4cca7a
child 12501 bedfecf09e71
Android: make Android_PumpEvents() more readable
No behavior change in this commit.
src/video/android/SDL_androidevents.c
     1.1 --- a/src/video/android/SDL_androidevents.c	Thu Jan 03 23:22:50 2019 +0100
     1.2 +++ b/src/video/android/SDL_androidevents.c	Fri Jan 04 23:11:21 2019 +0100
     1.3 @@ -63,35 +63,37 @@
     1.4      SDL_GL_MakeCurrent(window, NULL);
     1.5  }
     1.6  
     1.7 +
     1.8 +/*
     1.9 + * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
    1.10 + * 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.
    1.11 + *
    1.12 + * No polling necessary
    1.13 + */
    1.14 +
    1.15 +#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.16 +
    1.17  void
    1.18  Android_PumpEvents(_THIS)
    1.19  {
    1.20      static int isPaused = 0;
    1.21 -#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.22      static int isPausing = 0;
    1.23 -#endif
    1.24 -    /* No polling necessary */
    1.25  
    1.26 -    /*
    1.27 -     * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
    1.28 -     * 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.
    1.29 -     */
    1.30 +    if (isPaused && !isPausing) {
    1.31  
    1.32 -#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.33 -    if (isPaused && !isPausing) {
    1.34          /* Make sure this is the last thing we do before pausing */
    1.35          SDL_LockMutex(Android_ActivityMutex);
    1.36          android_egl_context_backup(Android_Window);
    1.37          SDL_UnlockMutex(Android_ActivityMutex);
    1.38  
    1.39          ANDROIDAUDIO_PauseDevices();
    1.40 +
    1.41          if (SDL_SemWait(Android_ResumeSem) == 0) {
    1.42 -#else
    1.43 -    if (isPaused) {
    1.44 -        if (SDL_SemTryWait(Android_ResumeSem) == 0) {
    1.45 -#endif
    1.46 +
    1.47              isPaused = 0;
    1.48 +
    1.49              ANDROIDAUDIO_ResumeDevices();
    1.50 +
    1.51              /* Restore the GL Context from here, as this operation is thread dependent */
    1.52              if (!SDL_HasEvent(SDL_QUIT)) {
    1.53                  SDL_LockMutex(Android_ActivityMutex);
    1.54 @@ -99,11 +101,9 @@
    1.55                  SDL_UnlockMutex(Android_ActivityMutex);
    1.56              }
    1.57          }
    1.58 -    }
    1.59 -    else {
    1.60 -#if SDL_ANDROID_BLOCK_ON_PAUSE
    1.61 +    } else {
    1.62          if (isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
    1.63 -            /* We've been signaled to pause, but before we block ourselves, 
    1.64 +            /* We've been signaled to pause, but before we block ourselves,
    1.65              we need to make sure that certain key events have reached the app */
    1.66              if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
    1.67                  isPausing = 1;
    1.68 @@ -113,19 +113,46 @@
    1.69                  isPaused = 1;
    1.70              }
    1.71          }
    1.72 +    }
    1.73 +}
    1.74 +
    1.75  #else
    1.76 +
    1.77 +void
    1.78 +Android_PumpEvents(_THIS)
    1.79 +{
    1.80 +    static int isPaused = 0;
    1.81 +
    1.82 +    if (isPaused) {
    1.83 +        if (SDL_SemTryWait(Android_ResumeSem) == 0) {
    1.84 +
    1.85 +            isPaused = 0;
    1.86 +
    1.87 +            ANDROIDAUDIO_ResumeDevices();
    1.88 +
    1.89 +            /* Restore the GL Context from here, as this operation is thread dependent */
    1.90 +            if (!SDL_HasEvent(SDL_QUIT)) {
    1.91 +                SDL_LockMutex(Android_ActivityMutex);
    1.92 +                android_egl_context_restore(Android_Window);
    1.93 +                SDL_UnlockMutex(Android_ActivityMutex);
    1.94 +            }
    1.95 +        }
    1.96 +    } else {
    1.97          if (SDL_SemTryWait(Android_PauseSem) == 0) {
    1.98 +
    1.99              SDL_LockMutex(Android_ActivityMutex);
   1.100              android_egl_context_backup(Android_Window);
   1.101              SDL_UnlockMutex(Android_ActivityMutex);
   1.102  
   1.103              ANDROIDAUDIO_PauseDevices();
   1.104 +
   1.105              isPaused = 1;
   1.106          }
   1.107 -#endif
   1.108      }
   1.109  }
   1.110  
   1.111 +#endif
   1.112 +
   1.113  #endif /* SDL_VIDEO_DRIVER_ANDROID */
   1.114  
   1.115  /* vi: set ts=4 sw=4 expandtab: */