simplify fullscreen handling using new fullscreen_strategy api, patch contributed by Charlie Birks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 74a4393..02a5478 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -472,59 +472,19 @@ Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboardEvent *keyEvent
EM_BOOL
Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
{
- /*make sure this is actually our element going fullscreen*/
- if(SDL_strcmp(fullscreenChangeEvent->id, "SDLFullscreenElement") != 0)
- return 0;
-
SDL_WindowData *window_data = userData;
if(fullscreenChangeEvent->isFullscreen)
{
SDL_bool is_desktop_fullscreen;
window_data->window->flags |= window_data->requested_fullscreen_mode;
- if(!window_data->requested_fullscreen_mode)
- window_data->window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; /*we didn't reqest fullscreen*/
-
window_data->requested_fullscreen_mode = 0;
- is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
-
- /*update size*/
- if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
- {
- emscripten_set_canvas_size(fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
- SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
- }
- else
- {
- /*preserve ratio*/
- double w = window_data->window->w;
- double h = window_data->window->h;
- double factor = SDL_min(fullscreenChangeEvent->screenWidth / w, fullscreenChangeEvent->screenHeight / h);
- emscripten_set_element_css_size(NULL, w * factor, h * factor);
- }
+ if(!window_data->requested_fullscreen_mode)
+ window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't reqest fullscreen*/
}
else
{
- EM_ASM({
- //un-reparent canvas (similar to Module.requestFullscreen)
- var canvas = Module['canvas'];
- if(canvas.parentNode.id == "SDLFullscreenElement") {
- var canvasContainer = canvas.parentNode;
- canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
- canvasContainer.parentNode.removeChild(canvasContainer);
- }
- });
- double unscaled_w = window_data->windowed_width / window_data->pixel_ratio;
- double unscaled_h = window_data->windowed_height / window_data->pixel_ratio;
- emscripten_set_canvas_size(window_data->windowed_width, window_data->windowed_height);
-
- if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
- emscripten_set_element_css_size(NULL, unscaled_w, unscaled_h);
- }
-
- SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, unscaled_w, unscaled_h);
-
window_data->window->flags &= ~FULLSCREEN_MASK;
}
@@ -535,17 +495,7 @@ EM_BOOL
Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
{
SDL_WindowData *window_data = userData;
- if(window_data->window->flags & FULLSCREEN_MASK)
- {
- SDL_bool is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
-
- if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
- {
- emscripten_set_canvas_size(uiEvent->windowInnerWidth * window_data->pixel_ratio, uiEvent->windowInnerHeight * window_data->pixel_ratio);
- SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, uiEvent->windowInnerWidth, uiEvent->windowInnerHeight);
- }
- }
- else
+ if(!(window_data->window->flags & FULLSCREEN_MASK))
{
/* this will only work if the canvas size is set through css */
if(window_data->window->flags & SDL_WINDOW_RESIZABLE)
@@ -572,6 +522,22 @@ Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *u
}
EM_BOOL
+Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData)
+{
+ /*this is used during fullscreen changes*/
+ SDL_WindowData *window_data = userData;
+
+ if(window_data->fullscreen_resize)
+ {
+ double css_w, css_h;
+ emscripten_get_element_css_size(NULL, &css_w, &css_h);
+ SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
+ }
+
+ return 0;
+}
+
+EM_BOOL
Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChangeEvent *visEvent, void *userData)
{
SDL_WindowData *window_data = userData;
diff --git a/src/video/emscripten/SDL_emscriptenevents.h b/src/video/emscripten/SDL_emscriptenevents.h
index d5b65f8..089ff60 100644
--- a/src/video/emscripten/SDL_emscriptenevents.h
+++ b/src/video/emscripten/SDL_emscriptenevents.h
@@ -30,6 +30,9 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data);
extern void
Emscripten_UnregisterEventHandlers(SDL_WindowData *data);
+
+extern int
+Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData);
#endif /* _SDL_emscriptenevents_h */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c
index 302ca87..ef418cf 100644
--- a/src/video/emscripten/SDL_emscriptenvideo.c
+++ b/src/video/emscripten/SDL_emscriptenvideo.c
@@ -218,9 +218,6 @@ Emscripten_CreateWindow(_THIS, SDL_Window * window)
}
}
- wdata->windowed_width = scaled_w;
- wdata->windowed_height = scaled_h;
-
if (window->flags & SDL_WINDOW_OPENGL) {
if (!_this->egl_data) {
if (SDL_GL_LoadLibrary(NULL) < 0) {
@@ -290,24 +287,30 @@ Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * di
data = (SDL_WindowData *) window->driverdata;
if(fullscreen) {
+ EmscriptenFullscreenStrategy strategy;
+ SDL_bool is_desktop_fullscreen = (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
+
+ strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
+
+ if(!is_desktop_fullscreen) {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
+ } else if(window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
+ } else {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ }
+
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+
+ strategy.canvasResizedCallback = Emscripten_HandleCanvasResize;
+ strategy.canvasResizedCallbackUserData = data;
+
data->requested_fullscreen_mode = window->flags & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
+ data->fullscreen_resize = is_desktop_fullscreen;
/*unset the fullscreen flags as we're not actually fullscreen yet*/
window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
- EM_ASM({
- //reparent canvas (similar to Module.requestFullscreen)
- var canvas = Module['canvas'];
- if(canvas.parentNode.id != "SDLFullscreenElement") {
- var canvasContainer = document.createElement("div");
- canvasContainer.id = "SDLFullscreenElement";
- canvas.parentNode.insertBefore(canvasContainer, canvas);
- canvasContainer.appendChild(canvas);
- }
- });
-
- int is_fullscreen;
- emscripten_get_canvas_size(&data->windowed_width, &data->windowed_height, &is_fullscreen);
- emscripten_request_fullscreen("SDLFullscreenElement", 1);
+ emscripten_request_fullscreen_strategy(NULL, 1, &strategy);
}
else
emscripten_exit_fullscreen();
diff --git a/src/video/emscripten/SDL_emscriptenvideo.h b/src/video/emscripten/SDL_emscriptenvideo.h
index 49b0b35..7618ab6 100644
--- a/src/video/emscripten/SDL_emscriptenvideo.h
+++ b/src/video/emscripten/SDL_emscriptenvideo.h
@@ -38,14 +38,12 @@ typedef struct SDL_WindowData
SDL_Window *window;
SDL_Surface *surface;
- int windowed_width;
- int windowed_height;
-
float pixel_ratio;
SDL_bool external_size;
int requested_fullscreen_mode;
+ SDL_bool fullscreen_resize;
SDL_bool finger_touching; /* for mapping touch events to mice */
SDL_FingerID first_finger;