Mac and Linux SDL2 binary snapshots
Edward Rudd
2020-05-02 03f8528315fa46c95991a34f3325d7b33ae5538c
source/src/video/emscripten/SDL_emscriptenvideo.c
@@ -1,6 +1,6 @@
/*
  Simple DirectMedia Layer
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
@@ -156,7 +156,6 @@
        return -1;
    }
    SDL_zero(mode);
    SDL_AddDisplayMode(&_this->displays[0], &mode);
    Emscripten_InitMouse();
@@ -197,6 +196,8 @@
        return SDL_OutOfMemory();
    }
    wdata->canvas_id = SDL_strdup("#canvas");
    if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
        wdata->pixel_ratio = emscripten_get_device_pixel_ratio();
    } else {
@@ -206,26 +207,26 @@
    scaled_w = SDL_floor(window->w * wdata->pixel_ratio);
    scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
    emscripten_set_canvas_size(scaled_w, scaled_h);
    /* set a fake size to check if there is any CSS sizing the canvas */
    emscripten_set_canvas_element_size(wdata->canvas_id, 1, 1);
    emscripten_get_element_css_size(wdata->canvas_id, &css_w, &css_h);
    emscripten_get_element_css_size(NULL, &css_w, &css_h);
    wdata->external_size = SDL_floor(css_w) != scaled_w || SDL_floor(css_h) != scaled_h;
    wdata->external_size = SDL_floor(css_w) != 1 || SDL_floor(css_h) != 1;
    if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
        /* external css has resized us */
        scaled_w = css_w * wdata->pixel_ratio;
        scaled_h = css_h * wdata->pixel_ratio;
        emscripten_set_canvas_size(scaled_w, scaled_h);
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
    }
    emscripten_set_canvas_element_size(wdata->canvas_id, scaled_w, scaled_h);
    /* if the size is not being controlled by css, we need to scale down for hidpi */
    if (!wdata->external_size) {
        if (wdata->pixel_ratio != 1.0f) {
            /*scale canvas down*/
            emscripten_set_element_css_size(NULL, window->w, window->h);
            emscripten_set_element_css_size(wdata->canvas_id, window->w, window->h);
        }
    }
@@ -269,11 +270,11 @@
        if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
            data->pixel_ratio = emscripten_get_device_pixel_ratio();
        }
        emscripten_set_canvas_size(window->w * data->pixel_ratio, window->h * data->pixel_ratio);
        emscripten_set_canvas_element_size(data->canvas_id, window->w * data->pixel_ratio, window->h * data->pixel_ratio);
        /*scale canvas down*/
        if (!data->external_size && data->pixel_ratio != 1.0f) {
            emscripten_set_element_css_size(NULL, window->w, window->h);
            emscripten_set_element_css_size(data->canvas_id, window->w, window->h);
        }
    }
}
@@ -293,6 +294,11 @@
            data->egl_surface = EGL_NO_SURFACE;
        }
#endif
        /* We can't destroy the canvas, so resize it to zero instead */
        emscripten_set_canvas_element_size(data->canvas_id, 0, 0);
        SDL_free(data->canvas_id);
        SDL_free(window->driverdata);
        window->driverdata = NULL;
    }
@@ -328,7 +334,7 @@
            data->requested_fullscreen_mode = window->flags & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
            data->fullscreen_resize = is_desktop_fullscreen;
            res = emscripten_request_fullscreen_strategy(NULL, 1, &strategy);
            res = emscripten_request_fullscreen_strategy(data->canvas_id, 1, &strategy);
            if(res != EMSCRIPTEN_RESULT_SUCCESS && res != EMSCRIPTEN_RESULT_DEFERRED) {
                /* unset flags, fullscreen failed */
                window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
@@ -343,7 +349,7 @@
Emscripten_SetWindowTitle(_THIS, SDL_Window * window) {
    EM_ASM_INT({
      if (typeof Module['setWindowTitle'] !== 'undefined') {
        Module['setWindowTitle'](Module['Pointer_stringify']($0));
        Module['setWindowTitle'](UTF8ToString($0));
      }
      return 0;
    }, window->title);