Emscripten fullscreen issues

Hi,

Not sure if this is the right place to post this, but I couldn’t find an
’issues’ section at mercurial SDL repos so here goes…

Anyway, I was having serious problems with emscripten and fullscreen mode -
in particular, clicking on the standard ‘go fullscreen’ button in the
standard html page wasn’t resizing the canvas properly, or notifying my app
that window had been resized.

I eventually got it working (with the latest ‘official’ sdl source) by
tweaking emscriptenevents.c like this…

EM_BOOL

Emscripten_HandleFullscreenChange(int eventType, const
EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)

{

/make sure this is actually our element going fullscreen/

/* removed by mark!

if(SDL_strcmp(fullscreenChangeEvent->id, “SDLFullscreenElement”) != 0)

return 0;

*/

SDL_WindowData *window_data = userData;

if(fullscreenChangeEvent->isFullscreen)

{

//added by mark!

window_data->windowed_width=window_data->window->w;

window_data->windowed_height=window_data->window->h;

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);

}

}

else

{

/* removed by mark!

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;

}

return 0;

}

Note that I had to comment out code that referenced ‘SDLFullscreenElement’,
and added some code to ‘save’ the window size before going fullscreen. The
latter I think is due to the fact I use SDL_SetWindowSize, and that doesn’t
seem to update windowed_width/windowed_height anywhere, so when I returned
from fullscreen window size was wrong.

This is probably not the right way to fix this stuff, but it should be
enough for someone who knows what they’re doing to fix it properly.

Finally, is this the correct version of SDL for me to be tweaking? Or is
the ‘emscripten ports’ version the right one to be messing with? It seems
to be pretty old, but thought I’d check.

Bye!

Mark

The bugtracker is at https://bugzilla.libsdl.org/

(It often makes sense to post here as well for discussion and to
hopefully get more attention for the bug)

Cheers,
DanielOn 12/08/2015 01:49 AM, Mark Sibly wrote:

Hi,

Not sure if this is the right place to post this, but I couldn’t find an
’issues’ section at mercurial SDL repos so here goes…

Thanks, I’ve reported it on bugzilla.On Tue, Dec 8, 2015 at 2:00 PM, Daniel Gibson wrote:

On 12/08/2015 01:49 AM, Mark Sibly wrote:

Hi,

Not sure if this is the right place to post this, but I couldn’t find an
’issues’ section at mercurial SDL repos so here goes…

The bugtracker is at https://bugzilla.libsdl.org/

(It often makes sense to post here as well for discussion and to hopefully
get more attention for the bug)

Cheers,
Daniel


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org