Skip to content

Commit

Permalink
emscripten: check if device pixel ratio has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Csongor Szabo committed Oct 14, 2016
1 parent bc93bdb commit 01f6273
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion src/video/emscripten/SDL_emscriptenvideo.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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*/
Expand Down

0 comments on commit 01f6273

Please sign in to comment.