summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Becker <sylvain.becker@gmail.com>2019-04-05 09:16:30 +0200
committerSylvain Becker <sylvain.becker@gmail.com>2019-04-05 09:16:30 +0200
commita5dea6a05828935c37b2da1a4fd226817ea843fa (patch)
tree7e5593285e5949d8cbcae10fb54eac3a28b8ce78
parentc5078bff167cf4adee8546144a1431f898b0b2c6 (diff)
Android: add hint SDL_HINT_ANDROID_BLOCK_ON_PAUSE
to set whether the event loop will block itself when the app is paused.
-rw-r--r--WhatsNew.txt2
-rw-r--r--docs/README-android.md2
-rw-r--r--include/SDL_hints.h11
-rw-r--r--src/video/android/SDL_androidevents.c17
-rw-r--r--src/video/android/SDL_androidevents.h3
-rw-r--r--src/video/android/SDL_androidvideo.c9
6 files changed, 26 insertions, 18 deletions
diff --git a/WhatsNew.txt b/WhatsNew.txt
index 34860cb159..f9fe558e50 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -10,7 +10,7 @@ Android:
* Removed SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH (replaced by SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS)
SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH=1, should be replaced by setting both previous hints to 0.
SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH=0, should be replaced by setting both previous hints to 1.
-
+* Added the hint SDL_HINT_ANDROID_BLOCK_ON_PAUSE to set whether the event loop will block itself when the app is paused.
---------------------------------------------------------------------------
2.0.9:
diff --git a/docs/README-android.md b/docs/README-android.md
index 4feb42dc20..78dcdd42fc 100644
--- a/docs/README-android.md
+++ b/docs/README-android.md
@@ -174,7 +174,7 @@ http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-a
Pause / Resume behaviour
================================================================================
-If SDL is compiled with SDL_ANDROID_BLOCK_ON_PAUSE defined (the default),
+If SDL_HINT_ANDROID_BLOCK_ON_PAUSE hint is set (the default),
the event loop will block itself when the app is paused (ie, when the user
returns to the main Android dashboard). Blocking is better in terms of battery
use, and it allows your app to spring back to life instantaneously after resume
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 20d510be3e..666c6eafac 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -887,6 +887,17 @@ extern "C" {
*/
#define SDL_HINT_ANDROID_TRAP_BACK_BUTTON "SDL_ANDROID_TRAP_BACK_BUTTON"
+/**
+ * \brief A variable to control whether the event loop will block itself when the app is paused.
+ *
+ * The variable can be set to the following values:
+ * "0" - Non blocking.
+ * "1" - Blocking. (default)
+ *
+ * The value should be set before SDL is initialized.
+ */
+#define SDL_HINT_ANDROID_BLOCK_ON_PAUSE "SDL_ANDROID_BLOCK_ON_PAUSE"
+
/**
* \brief A variable to control whether the return key on the soft keyboard
* should hide the soft keyboard on Android and iOS.
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index a021e2b133..e13916f43a 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -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: */
diff --git a/src/video/android/SDL_androidevents.h b/src/video/android/SDL_androidevents.h
index 2ccb746d7a..07d157061a 100644
--- a/src/video/android/SDL_androidevents.h
+++ b/src/video/android/SDL_androidevents.h
@@ -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: */
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index 9ee60d7182..3057ee9ac0 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -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;