emscripten: Introduce SDL_HINT_EMSCRIPTEN_ASYNCIFY See https://github.com/emscripten-core/emscripten/issues/10746 and https://github.com/emscripten-ports/SDL2/pull/112 Fixes Bugzilla #4997.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index cd4d4ea..fd55a55 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1043,6 +1043,21 @@ extern "C" {
#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
/**
+ * \brief Disable giving back control to the browser automatically
+ * when running with asyncify
+ *
+ * With -s ASYNCIFY, SDL2 calls emscripten_sleep during operations
+ * such as refreshing the screen or polling events.
+ *
+ * This hint only applies to the emscripten platform
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable emscripten_sleep calls (if you give back browser control manually or use asyncify for other purposes)
+ * "1" - Enable emscripten_sleep calls (the default)
+ */
+#define SDL_HINT_EMSCRIPTEN_ASYNCIFY "SDL_EMSCRIPTEN_ASYNCIFY"
+
+/**
* \brief Tell SDL not to catch the SIGINT or SIGTERM signals.
*
* This hint only applies to Unix-like platforms, and should set before
diff --git a/src/timer/unix/SDL_systimer.c b/src/timer/unix/SDL_systimer.c
index 7a44d05..bfe0fc4 100644
--- a/src/timer/unix/SDL_systimer.c
+++ b/src/timer/unix/SDL_systimer.c
@@ -29,6 +29,7 @@
#include "SDL_timer.h"
#include "SDL_assert.h"
+#include "SDL_hints.h"
#include "../SDL_timer_c.h"
#ifdef __EMSCRIPTEN__
@@ -191,8 +192,8 @@ void
SDL_Delay(Uint32 ms)
{
#ifdef __EMSCRIPTEN__
- if (emscripten_has_asyncify()) {
- /* pseudo-synchronous pause */
+ if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
+ /* pseudo-synchronous pause, used directly or through e.g. SDL_WaitEvent */
emscripten_sleep(ms);
return;
}
diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c
index 5c845fd..62193b9 100644
--- a/src/video/emscripten/SDL_emscriptenframebuffer.c
+++ b/src/video/emscripten/SDL_emscriptenframebuffer.c
@@ -24,6 +24,7 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenframebuffer.h"
+#include "SDL_hints.h"
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
@@ -163,7 +164,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
SDL_SaveBMP(surface, file);
}*/
- if (emscripten_has_asyncify()) {
+ if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
/* give back control to browser for screen refresh */
emscripten_sleep(0);
}
diff --git a/src/video/emscripten/SDL_emscriptenopengles.c b/src/video/emscripten/SDL_emscriptenopengles.c
index 3852fc7..6544bc6 100644
--- a/src/video/emscripten/SDL_emscriptenopengles.c
+++ b/src/video/emscripten/SDL_emscriptenopengles.c
@@ -27,6 +27,7 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenopengles.h"
+#include "SDL_hints.h"
#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
@@ -88,7 +89,7 @@ int
Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window)
{
EGLBoolean ret = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
- if (emscripten_has_asyncify()) {
+ if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
/* give back control to browser for screen refresh */
emscripten_sleep(0);
}