Android: add hint SDL_HINT_ANDROID_BLOCK_ON_PAUSE

to set whether the event loop will block itself when the app is paused.
This commit is contained in:
Sylvain Becker
2019-04-05 09:16:30 +02:00
parent b470cd9b09
commit 05333a6e9f
6 changed files with 26 additions and 18 deletions

View File

@@ -22,9 +22,6 @@
#if SDL_VIDEO_DRIVER_ANDROID
/* We're going to do this by default */
#define SDL_ANDROID_BLOCK_ON_PAUSE 1
#include "SDL_androidevents.h"
#include "SDL_events.h"
#include "SDL_androidkeyboard.h"
@@ -49,14 +46,12 @@ static void openslES_ResumeDevices(void) {}
static void openslES_PauseDevices(void) {}
#endif
#if SDL_ANDROID_BLOCK_ON_PAUSE
/* Number of 'type' events in the event queue */
static int
SDL_NumberOfEvents(Uint32 type)
{
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type);
}
#endif /* SDL_ANDROID_BLOCK_ON_PAUSE */
static void
android_egl_context_restore(SDL_Window *window)
@@ -89,15 +84,13 @@ android_egl_context_backup(SDL_Window *window)
/*
* Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
* 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.
* When the pause semaphore is signaled, if Android_PumpEvents_Blocking is used, the event loop will block until the resume signal is emitted.
*
* No polling necessary
*/
#if SDL_ANDROID_BLOCK_ON_PAUSE
void
Android_PumpEvents(_THIS)
Android_PumpEvents_Blocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
@@ -146,10 +139,8 @@ Android_PumpEvents(_THIS)
}
}
#else
void
Android_PumpEvents(_THIS)
Android_PumpEvents_NonBlocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
@@ -188,8 +179,6 @@ Android_PumpEvents(_THIS)
}
}
#endif /* SDL_ANDROID_BLOCK_ON_PAUSE */
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -22,6 +22,7 @@
#include "SDL_androidvideo.h"
extern void Android_PumpEvents(_THIS);
extern void Android_PumpEvents_Blocking(_THIS);
extern void Android_PumpEvents_NonBlocking(_THIS);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -26,6 +26,7 @@
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
@@ -93,6 +94,7 @@ Android_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
SDL_bool block_on_pause;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
@@ -113,7 +115,12 @@ Android_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = Android_VideoInit;
device->VideoQuit = Android_VideoQuit;
device->PumpEvents = Android_PumpEvents;
block_on_pause = SDL_GetHintBoolean(SDL_HINT_ANDROID_BLOCK_ON_PAUSE, SDL_TRUE);
if (block_on_pause) {
device->PumpEvents = Android_PumpEvents_Blocking;
} else {
device->PumpEvents = Android_PumpEvents_NonBlocking;
}
device->GetDisplayDPI = Android_GetDisplayDPI;