Android: when event loop is not blocking in pause, backup EGL context (Bug 4578)
authorSylvain Becker <sylvain.becker@gmail.com>
Fri, 12 Apr 2019 23:15:26 +0200
changeset 12703f6c7e5e03f60
parent 12702 0ff5bbe35bf5
child 12704 704ec541957d
Android: when event loop is not blocking in pause, backup EGL context (Bug 4578)
Backup the EGL context when SDL_APP_DIDENTERBACKGROUND has been removed from the
event queue.
src/video/android/SDL_androidevents.c
     1.1 --- a/src/video/android/SDL_androidevents.c	Wed Apr 10 22:30:58 2019 -0300
     1.2 +++ b/src/video/android/SDL_androidevents.c	Fri Apr 12 23:15:26 2019 +0200
     1.3 @@ -130,8 +130,7 @@
     1.4               * has reached the app */
     1.5              if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
     1.6                  videodata->isPausing = 1;
     1.7 -            }
     1.8 -            else {
     1.9 +            } else {
    1.10                  videodata->isPausing = 0;
    1.11                  videodata->isPaused = 1;
    1.12              }
    1.13 @@ -143,8 +142,23 @@
    1.14  Android_PumpEvents_NonBlocking(_THIS)
    1.15  {
    1.16      SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
    1.17 +    static int backup_context;
    1.18  
    1.19      if (videodata->isPaused) {
    1.20 +
    1.21 +        if (backup_context) {
    1.22 +
    1.23 +            SDL_LockMutex(Android_ActivityMutex);
    1.24 +            android_egl_context_backup(Android_Window);
    1.25 +            SDL_UnlockMutex(Android_ActivityMutex);
    1.26 +
    1.27 +            ANDROIDAUDIO_PauseDevices();
    1.28 +            openslES_PauseDevices();
    1.29 +
    1.30 +            backup_context = 0;
    1.31 +        }
    1.32 +
    1.33 +
    1.34          if (SDL_SemTryWait(Android_ResumeSem) == 0) {
    1.35  
    1.36              videodata->isPaused = 0;
    1.37 @@ -165,16 +179,17 @@
    1.38              }
    1.39          }
    1.40      } else {
    1.41 -        if (SDL_SemTryWait(Android_PauseSem) == 0) {
    1.42 -
    1.43 -            SDL_LockMutex(Android_ActivityMutex);
    1.44 -            android_egl_context_backup(Android_Window);
    1.45 -            SDL_UnlockMutex(Android_ActivityMutex);
    1.46 -
    1.47 -            ANDROIDAUDIO_PauseDevices();
    1.48 -            openslES_PauseDevices();
    1.49 -
    1.50 -            videodata->isPaused = 1;
    1.51 +        if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
    1.52 +            /* We've been signaled to pause (potentially several times), but before we block ourselves,
    1.53 +             * we need to make sure that the very last event (of the first pause sequence, if several)
    1.54 +             * has reached the app */
    1.55 +            if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
    1.56 +                videodata->isPausing = 1;
    1.57 +            } else {
    1.58 +                videodata->isPausing = 0;
    1.59 +                videodata->isPaused = 1;
    1.60 +                backup_context = 1;
    1.61 +            }
    1.62          }
    1.63      }
    1.64  }