From 55334aeffd71b01ffa9b4ae995eb7fdd29100f12 Mon Sep 17 00:00:00 2001
From: Toad King <toadking@toadking.com>
Date: Sat, 20 Jan 2018 13:01:24 -0600
Subject: [PATCH 1/2] fix black frame insertion in emscripten

---
 frontend/drivers/platform_emscripten.c | 26 +++++++++++++++++++++++++-
 gfx/drivers/gl.c                       |  3 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

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 <file/file_path.h>
 #include <string/stdstring.h>
 #include <retro_timers.h>
+#include <gfx/video_frame.h>
+#include <glsym/glsym.h>
 
 #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);
 

From 773dbcf1cc00ca45349786947915e802c3dd816a Mon Sep 17 00:00:00 2001
From: Toad King <toadking@toadking.com>
Date: Sat, 20 Jan 2018 13:01:34 -0600
Subject: [PATCH 2/2] small gitignore change

---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index 5e3fc5eb04..79f00e9182 100644
--- a/.gitignore
+++ b/.gitignore
@@ -140,3 +140,6 @@ retroarch.js
 retroarch.js.mem
 *.bc
 *.wasm
+
+# only ignore .js files in the repo root
+/*.js