From a77f9c37c63afc051c1f576eee011ac0d93d175a Mon Sep 17 00:00:00 2001 From: Toad King Date: Sat, 13 Jan 2018 00:05:07 -0600 Subject: [PATCH] start on bringing the emscripten video code up to speed with latest emscripten fix rwebinput --- Makefile.emscripten | 4 +- gfx/drivers_context/emscriptenegl_ctx.c | 69 +++++++++++++++++++------ input/drivers/rwebinput_input.c | 10 +--- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/Makefile.emscripten b/Makefile.emscripten index 3613fbe7a2..2942e49c52 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -18,7 +18,7 @@ HAVE_RPNG = 1 HAVE_EMSCRIPTEN = 1 HAVE_RGUI = 1 HAVE_SDL = 0 -HAVE_SDL2 = 1 +HAVE_SDL2 = 0 HAVE_ZLIB = 1 WANT_ZLIB = 1 HAVE_STATIC_VIDEO_FILTERS = 1 @@ -50,7 +50,7 @@ endif ifeq ($(ASYNC), 1) LDFLAGS += -s ASYNCIFY=$(ASYNC) -endif +endif include Makefile.common diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index 76d4bddc00..9c3738cd29 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -20,6 +20,7 @@ #include #include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -51,23 +52,71 @@ static void gfx_ctx_emscripten_swap_interval(void *data, unsigned interval) (void)interval; } +static void gfx_ctx_emscripten_get_canvas_size(int *width, int *height) +{ + EMSCRIPTEN_RESULT r; + EmscriptenFullscreenChangeEvent fullscreen_status; + bool is_fullscreen = false; + + r = emscripten_get_fullscreen_status(&fullscreen_status); + + if (r == EMSCRIPTEN_RESULT_SUCCESS) + { + if (fullscreen_status.isFullscreen) + { + is_fullscreen = true; + *width = fullscreen_status.screenWidth; + *height = fullscreen_status.screenHeight; + } + } + + if (!is_fullscreen) + { + r = emscripten_get_canvas_element_size("#canvas", width, height); + + if (r != EMSCRIPTEN_RESULT_SUCCESS) + { + RARCH_ERR("[EMSCRIPTEN/EGL]: Could not get screen dimensions: %d\n", r); + *width = 800; + *height = 600; + } + } +} + static void gfx_ctx_emscripten_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height, bool is_shutdown) { + EMSCRIPTEN_RESULT r; int input_width; int input_height; - int is_fullscreen; emscripten_ctx_data_t *emscripten = (emscripten_ctx_data_t*)data; - (void)data; + gfx_ctx_emscripten_get_canvas_size(&input_width, &input_height); - emscripten_get_canvas_size(&input_width, &input_height, &is_fullscreen); *width = (unsigned)input_width; *height = (unsigned)input_height; *resize = false; if (*width != emscripten->fb_width || *height != emscripten->fb_height) + { + printf("RESIZE: %dx%d\n", input_width, input_height); + r = emscripten_set_canvas_element_size("#canvas", input_width, input_height); + + if (r != EMSCRIPTEN_RESULT_SUCCESS) + { + RARCH_ERR("[EMSCRIPTEN/EGL]: error resizing canvas: %d\n", r); + } + + /* fix Module.requestFullscreen messing with the canvas size */ + r = emscripten_set_element_css_size("#canvas", (double)input_width, (double)input_height); + + if (r != EMSCRIPTEN_RESULT_SUCCESS) + { + RARCH_ERR("[EMSCRIPTEN/EGL]: error resizing canvas css: %d\n", r); + } + *resize = true; + } emscripten->fb_width = (unsigned)input_width; emscripten->fb_height = (unsigned)input_height; @@ -202,20 +251,10 @@ static void gfx_ctx_emscripten_input_driver(void *data, const char *name, const input_driver_t **input, void **input_data) { - void *rwebinput = NULL; + void *rwebinput = input_rwebinput.init(name); - *input = NULL; - *input_data = NULL; - -#ifndef HAVE_SDL2 - rwebinput = input_rwebinput.init(); - - if (!rwebinput) - return; - - *input = &input_rwebinput; + *input = rwebinput ? &input_rwebinput : NULL; *input_data = rwebinput; -#endif } static bool gfx_ctx_emscripten_has_focus(void *data) diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index a795a3ff2a..dcea18a2ab 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -66,7 +66,7 @@ error: return NULL; } -static bool rwebinput_key_pressed_internal(void *data, int key) +static bool rwebinput_key_pressed(void *data, int key) { unsigned sym; bool ret; @@ -89,18 +89,12 @@ static bool rwebinput_is_pressed(rwebinput_input_t *rwebinput, const struct retro_keybind *bind = &binds[id]; int key = binds[id].key; return bind->valid && (key < RETROK_LAST) - && rwebinput_key_pressed_internal(rwebinput, key); + && rwebinput_key_pressed(rwebinput, key); } return false; } -static bool rwebinput_key_pressed(void *data, int key) -{ - rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; - return rwebinput_is_pressed(rwebinput, input_config_binds[0], key); -} - static int16_t rwebinput_mouse_state(rwebinput_input_t *rwebinput, unsigned id) { switch (id)