Skip to content

Emscripten canvas issues #14533

@LloydJHowarth

Description

@LloydJHowarth

There is quite a few issues with Emscripten Canvas handling as of right now that requires some heavy patching on my end. I'm struggling to debug what's happening as different things keep happening in different situations so I've made multiple edits which you can just ignore.

Setup Requirements

  • SDL_HINT_EMSCRIPTEN_FILL_DOCUMENT to not be used or set.
  • Non fullscreen window for this example I've used 600x400.

1. Canvas scaling

Lets say we can toggle enter & exit fullscreen mode using "F" key. If we press "F" we expect to enter fullscreen mode and the canvas scales to the document size, then if we press "F" again to exit fullscreen the canvas should revert to the restored windowed mode size we created or set (This does work). However if we fast spam toggle "F" to enter and exit fullscreen the canvas scaling breaks completely. Also fullscreen mode in mobile view on desktop browsers (developer tools) when entering fullscreen doesn't scale to the size of the mobile view, I think its still using the desktop document size or something else.

2. Black Document

If we set SDL_SetWindowFullscreen to true multiple times in a row then use "Escape" to exit fullscreen the canvas scaling is either broken or the canvas scale does revert back to the correct size but now the background document is black. I do however believe this to be linked to the first issue.

This can be fixed by using sanity checks on SDL_SetWindowFullscreen for example:

  1. If window is already fullscreen: (from checking for fullscreen flag in SDL_WindowFlags)
  2. then dont set SDL_SetWindowFullscreen to true again

3. Fill Document

It would make sense to have some toggle that we can choose to fill the canvas to document or not, right now we have SDL_HINT_EMSCRIPTEN_FILL_DOCUMENT however this is required to be set before window creation, changing its value after that does nothing. However when you need to support both mobile and desktop for your web app ideally you want mobile to always fill the document but desktop to only fill the document in fullscreen mode, if not in fullscreen mode use the restored windowed mode size like other platforms.

Using SDL_HINT_EMSCRIPTEN_FILL_DOCUMENT on scales the canvas correctly regardless mobile, desktop, mobile view on desktop, etc. However now we don't have a Windowed mode view for desktop.

This becomes a little odd, because only on emscripten there is 3 'modes' such as Windowed mode, filled document mode and actual Fullscreen mode. So I'm unsure how this could be handled other than adding a toggle to SDL_HINT_EMSCRIPTEN_FILL_DOCUMENT that can be changed after window creation or implementing a function that does something similar specifically for emscripten.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions