diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index 4671638609..72b28f027e 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -47,6 +49,7 @@ void RWebAudioRecalibrateTime(void); static unsigned emscripten_fullscreen_reinit; +static unsigned emscripten_frame_count = 0; static EM_BOOL emscripten_fullscreenchange_cb(int event_type, const EmscriptenFullscreenChangeEvent *fullscreen_change_event, @@ -63,11 +66,32 @@ static EM_BOOL emscripten_fullscreenchange_cb(int event_type, static void emscripten_mainloop(void) { - unsigned sleep_ms = 0; int ret; + video_frame_info_t video_info; + unsigned sleep_ms = 0; RWebAudioRecalibrateTime(); + emscripten_frame_count++; + + video_driver_build_info(&video_info); + + /* Disable BFI during fast forward, slow-motion, + * and pause to prevent flicker. */ + if ( + video_info.black_frame_insertion + && !video_info.input_driver_nonblock_state + && !video_info.runloop_is_slowmotion + && !video_info.runloop_is_paused) + { + if ((emscripten_frame_count & 1) == 0) + { + glClear(GL_COLOR_BUFFER_BIT); + video_info.cb_swap_buffers(video_info.context_data, &video_info); + return; + } + } + if (emscripten_fullscreen_reinit != 0) { if (--emscripten_fullscreen_reinit == 0) diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 4b8dad9976..45a76e7070 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -1188,6 +1188,8 @@ static bool gl_frame(void *data, const void *frame, #endif gl_pbo_async_readback(gl); + /* emscripten has to do black frame insertion in its main loop */ +#ifndef EMSCRIPTEN /* Disable BFI during fast forward, slow-motion, * and pause to prevent flicker. */ if ( @@ -1199,6 +1201,7 @@ static bool gl_frame(void *data, const void *frame, video_info->cb_swap_buffers(video_info->context_data, video_info); glClear(GL_COLOR_BUFFER_BIT); } +#endif video_info->cb_swap_buffers(video_info->context_data, video_info);