From 0f40391924b782c93bce1add9fedfb35eab31b9b Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 30 Nov 2020 10:54:51 +0100 Subject: [PATCH] [HTML5] Fix broken layout on load in HiDPI screens This was caused by the devicePixelRatio being applied twice, once by the HTML code, once by the OS code. More specifically, OS.get_window_size() would return the canvas element size, while OS.set_window_size() would set the element size to the specified value times the devicePixelRatio. Calling OS.set_window_size(OS.get_window_size()) would reapply the devicePixelRatio every time. This commit changes the behaviour so that OS.set_window_size() do not apply the devicePixelRatio to the canvas element size, by it divides the CSS size instead. --- platform/javascript/os_javascript.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 90998d9df79..e9132787ddb 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -174,8 +174,8 @@ void OS_JavaScript::set_window_size(const Size2 p_size) { window_maximized = false; } double scale = godot_js_display_pixel_ratio_get(); - emscripten_set_canvas_element_size(canvas_id, p_size.x * scale, p_size.y * scale); - emscripten_set_element_css_size(canvas_id, p_size.x, p_size.y); + emscripten_set_canvas_element_size(canvas_id, p_size.x, p_size.y); + emscripten_set_element_css_size(canvas_id, p_size.x / scale, p_size.y / scale); } }