Fix/document emscripten_set_fullscreenchange_callback behaviour · Issue #2556 · emscripten-core/emscripten (original) (raw)
The current behaviour of the elementWidth and elementHeight members in EmscriptenFullscreenChangeEvent (html5.h) produces strange values and differs between browsers (see discussion thread here: https://groups.google.com/forum/#!topic/emscripten-discuss/mc3T1SYycdw)
The documentation for these elements is currently:
// The new pixel size of the element that changed fullscreen status.
int elementWidth;
int elementHeight;
It would be at least a good idea to state there that this currently doesn't work as expected in some/all browsers, and the screenWidth/screenHeight members should be used if the actual display resolution of fullscreen is required.
From the view of a game engine I would expect that switchting to fullscreen has the effect that rendering happens in a decoration-less fullscreen window at the system's native fullscreen resolution covering the entire display (although the engine should be able to intercept and set the canvas resolution to (for instance) half the native display resolution), in this case I would expect that the canvas is stretched/upscaled to cover the entire screen.
As a workaround, I'm currently using the screenWidth/screenHeight members for switching to fullscreen, and store the previous canvas size when switching back from fullscreen, for example: https://github.com/floooh/oryol/blob/f19b1e4a943618e6028dfcbdf14000df61ed77cb/code/Modules/Render/egl/eglDisplayMgr.cc#L193
Live demos with console messages when switching to/from fullscreen: