src/video/emscripten/SDL_emscriptenvideo.c
changeset 10317 4a45690d5d82
parent 9998 f67cf37e9cd4
child 10331 710c2ae96681
     1.1 --- a/src/video/emscripten/SDL_emscriptenvideo.c	Mon Sep 12 23:58:08 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenvideo.c	Tue Sep 13 00:03:28 2016 -0700
     1.3 @@ -218,9 +218,6 @@
     1.4          }
     1.5      }
     1.6  
     1.7 -    wdata->windowed_width = scaled_w;
     1.8 -    wdata->windowed_height = scaled_h;
     1.9 -
    1.10      if (window->flags & SDL_WINDOW_OPENGL) {
    1.11          if (!_this->egl_data) {
    1.12              if (SDL_GL_LoadLibrary(NULL) < 0) {
    1.13 @@ -290,24 +287,30 @@
    1.14          data = (SDL_WindowData *) window->driverdata;
    1.15  
    1.16          if(fullscreen) {
    1.17 +            EmscriptenFullscreenStrategy strategy;
    1.18 +            SDL_bool is_desktop_fullscreen = (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.19 +
    1.20 +            strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
    1.21 +
    1.22 +            if(!is_desktop_fullscreen) {
    1.23 +                strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
    1.24 +            } else if(window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
    1.25 +                strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
    1.26 +            } else {
    1.27 +                strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
    1.28 +            }
    1.29 +
    1.30 +            strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
    1.31 +
    1.32 +            strategy.canvasResizedCallback = Emscripten_HandleCanvasResize;
    1.33 +            strategy.canvasResizedCallbackUserData = data;
    1.34 +
    1.35              data->requested_fullscreen_mode = window->flags & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
    1.36 +            data->fullscreen_resize = is_desktop_fullscreen;
    1.37              /*unset the fullscreen flags as we're not actually fullscreen yet*/
    1.38              window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
    1.39  
    1.40 -            EM_ASM({
    1.41 -                //reparent canvas (similar to Module.requestFullscreen)
    1.42 -                var canvas = Module['canvas'];
    1.43 -                if(canvas.parentNode.id != "SDLFullscreenElement") {
    1.44 -                    var canvasContainer = document.createElement("div");
    1.45 -                    canvasContainer.id = "SDLFullscreenElement";
    1.46 -                    canvas.parentNode.insertBefore(canvasContainer, canvas);
    1.47 -                    canvasContainer.appendChild(canvas);
    1.48 -                }
    1.49 -            });
    1.50 -
    1.51 -            int is_fullscreen;
    1.52 -            emscripten_get_canvas_size(&data->windowed_width, &data->windowed_height, &is_fullscreen);
    1.53 -            emscripten_request_fullscreen("SDLFullscreenElement", 1);
    1.54 +            emscripten_request_fullscreen_strategy(NULL, 1, &strategy);
    1.55          }
    1.56          else
    1.57              emscripten_exit_fullscreen();