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.
Sylvain Becker 2019-04-12 23:15:26 +02:00
parent 00c824a8b0
commit bd344c2287
1 changed files with 27 additions and 12 deletions

View File

@ -130,8 +130,7 @@ Android_PumpEvents_Blocking(_THIS)
* has reached the app */ * has reached the app */
if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) { if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
videodata->isPausing = 1; videodata->isPausing = 1;
} } else {
else {
videodata->isPausing = 0; videodata->isPausing = 0;
videodata->isPaused = 1; videodata->isPaused = 1;
} }
@ -143,8 +142,23 @@ void
Android_PumpEvents_NonBlocking(_THIS) Android_PumpEvents_NonBlocking(_THIS)
{ {
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
static int backup_context;
if (videodata->isPaused) { if (videodata->isPaused) {
if (backup_context) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
ANDROIDAUDIO_PauseDevices();
openslES_PauseDevices();
backup_context = 0;
}
if (SDL_SemTryWait(Android_ResumeSem) == 0) { if (SDL_SemTryWait(Android_ResumeSem) == 0) {
videodata->isPaused = 0; videodata->isPaused = 0;
@ -165,16 +179,17 @@ Android_PumpEvents_NonBlocking(_THIS)
} }
} }
} else { } else {
if (SDL_SemTryWait(Android_PauseSem) == 0) { if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
/* We've been signaled to pause (potentially several times), but before we block ourselves,
SDL_LockMutex(Android_ActivityMutex); * we need to make sure that the very last event (of the first pause sequence, if several)
android_egl_context_backup(Android_Window); * has reached the app */
SDL_UnlockMutex(Android_ActivityMutex); if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
videodata->isPausing = 1;
ANDROIDAUDIO_PauseDevices(); } else {
openslES_PauseDevices(); videodata->isPausing = 0;
videodata->isPaused = 1; videodata->isPaused = 1;
backup_context = 1;
}
} }
} }
} }