emscripten: check if device pixel ratio has changed
authorCsongor Szabo <csongor.szabo@prezi.com>
Fri, 14 Oct 2016 17:06:28 +0100
changeset 10541727f7d796b8d
parent 10540 911d940ad2cf
child 10542 6a45cad101a4
emscripten: check if device pixel ratio has changed
src/video/emscripten/SDL_emscriptenevents.c
src/video/emscripten/SDL_emscriptenvideo.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Fri Oct 14 08:56:04 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Fri Oct 14 17:06:28 2016 +0100
     1.3 @@ -545,6 +545,10 @@
     1.4  Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
     1.5  {
     1.6      SDL_WindowData *window_data = userData;
     1.7 +
     1.8 +    /* update pixel ratio */
     1.9 +    window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
    1.10 +
    1.11      if(!(window_data->window->flags & FULLSCREEN_MASK))
    1.12      {
    1.13          /* this will only work if the canvas size is set through css */
     2.1 --- a/src/video/emscripten/SDL_emscriptenvideo.c	Fri Oct 14 08:56:04 2016 -0700
     2.2 +++ b/src/video/emscripten/SDL_emscriptenvideo.c	Fri Oct 14 17:06:28 2016 +0100
     2.3 @@ -209,7 +209,7 @@
     2.4  
     2.5      emscripten_get_element_css_size(NULL, &css_w, &css_h);
     2.6  
     2.7 -    wdata->external_size = css_w != scaled_w || css_h != scaled_h;
     2.8 +    wdata->external_size = SDL_floor(css_w) != scaled_w || SDL_floor(css_h) != scaled_h;
     2.9  
    2.10      if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
    2.11          /* external css has resized us */
    2.12 @@ -262,6 +262,8 @@
    2.13  
    2.14      if (window->driverdata) {
    2.15          data = (SDL_WindowData *) window->driverdata;
    2.16 +        /* update pixel ratio */
    2.17 +        data->pixel_ratio = emscripten_get_device_pixel_ratio();
    2.18          emscripten_set_canvas_size(window->w * data->pixel_ratio, window->h * data->pixel_ratio);
    2.19  
    2.20          /*scale canvas down*/