Android life cycle behavior more closely matches iOS

This change also decouples the pause/resume handling from the video subsystem on Android, so applications that don't use SDL for video can get application life cycle events.

The semantics for the life cycle events are that they need to be handled in an event watch callback, and once they've been delivered, the application will block until it's been resumed. SDL_HINT_ANDROID_BLOCK_ON_PAUSE can be used to control that behavior, and if that's set to "0", then the application will continue to run in the background at low CPU usage until being resumed or stopped.

SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO has been removed, and the audio will be paused when the application is paused.

Fixes https://github.com/libsdl-org/SDL/issues/3193
This commit is contained in:
Sam Lantinga
2024-07-23 20:55:24 -07:00
parent fff783de6c
commit ca4bd4b63c
15 changed files with 183 additions and 207 deletions

View File

@@ -40,7 +40,7 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
SDL_WindowData *data;
int retval = 0;
Android_ActivityMutex_Lock_Running();
Android_LockActivityMutexOnceRunning();
if (Android_Window) {
retval = SDL_SetError("Android only supports one window");
@@ -95,7 +95,7 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
Android_UnlockActivityMutex();
return retval;
}
@@ -107,7 +107,7 @@ void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
{
SDL_LockMutex(Android_ActivityMutex);
Android_LockActivityMutex();
if (window == Android_Window) {
SDL_WindowData *data;
@@ -153,7 +153,7 @@ int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_
endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
Android_UnlockActivityMutex();
return 0;
}
@@ -170,7 +170,7 @@ void Android_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, SDL_
void Android_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_LockMutex(Android_ActivityMutex);
Android_LockActivityMutex();
if (window == Android_Window) {
Android_Window = NULL;
@@ -192,7 +192,7 @@ void Android_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
SDL_UnlockMutex(Android_ActivityMutex);
Android_UnlockActivityMutex();
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */