From 01f62736751bd028c0a1074c845fd3ab96adcd7b Mon Sep 17 00:00:00 2001 From: Csongor Szabo Date: Fri, 14 Oct 2016 17:06:28 +0100 Subject: [PATCH] emscripten: check if device pixel ratio has changed --- src/video/emscripten/SDL_emscriptenevents.c | 4 ++++ src/video/emscripten/SDL_emscriptenvideo.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 776bd3d9b..a4720e402 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -545,6 +545,10 @@ EM_BOOL Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) { SDL_WindowData *window_data = userData; + + /* update pixel ratio */ + window_data->pixel_ratio = emscripten_get_device_pixel_ratio(); + if(!(window_data->window->flags & FULLSCREEN_MASK)) { /* this will only work if the canvas size is set through css */ diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index 4331a9162..847bb4cf8 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -209,7 +209,7 @@ Emscripten_CreateWindow(_THIS, SDL_Window * window) emscripten_get_element_css_size(NULL, &css_w, &css_h); - wdata->external_size = css_w != scaled_w || css_h != scaled_h; + wdata->external_size = SDL_floor(css_w) != scaled_w || SDL_floor(css_h) != scaled_h; if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) { /* external css has resized us */ @@ -262,6 +262,8 @@ static void Emscripten_SetWindowSize(_THIS, SDL_Window * window) if (window->driverdata) { data = (SDL_WindowData *) window->driverdata; + /* update pixel ratio */ + data->pixel_ratio = emscripten_get_device_pixel_ratio(); emscripten_set_canvas_size(window->w * data->pixel_ratio, window->h * data->pixel_ratio); /*scale canvas down*/