| | |
| | | /* |
| | | 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 |
| | |
| | | return -1; |
| | | } |
| | | |
| | | SDL_zero(mode); |
| | | SDL_AddDisplayMode(&_this->displays[0], &mode); |
| | | |
| | | Emscripten_InitMouse(); |
| | |
| | | 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 { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); |