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.
This commit is contained in:
Sylvain Beucler
2020-06-27 16:25:47 -04:00
parent 01af7b0254
commit e594a6738a
4 changed files with 22 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}