Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Fix for #20600 #20695

Closed
wants to merge 21 commits into from
Closed

Conversation

ypujante
Copy link
Contributor

@ypujante ypujante commented Nov 12, 2023

I am creating a draft PR for the fix for #20600 so that you can provide feedback if you want to.

Mostly the goal of the PR is to check that the tests run on CI

  • it is a draft because this PR includes the changes from the Add Hi DPI Support for GLFW PR, because this fix depends on these changes
  • there is a ton of logging to be able to follow what is happening (asynchronicity / callbacks...)

For the implementation of the fix itself, the key is to handle the errors coming from the promise.

  • Browser.requestFullscreen now handles the error and return the promise for handling by the clients (this function did not return anything before so the other calling code is not affected)
  • Browser.exifFullscreen now handles the error and return the promise for handling by the clients (or null). This function used to return a boolean instead and as far as I can tell, the only calling code that was using the return value is library_sdl.js (if (Browser.exitFullscreen())) so no impact there

ypujante and others added 21 commits October 29, 2023 06:58
- added Browser.isHiDPIAware flag that gets initialized from Module.isHiDPIAware
- from the webgpu samples (https://webgpu.github.io/webgpu-samples/samples/helloTriangle), the gist of the logic is to scale canvas.width (resp. canvas.height) by the devicePixelRatio and set canvas.clientWidth to the width
- coordinates are then scaled down to reflect what the client is expecting
- calling Browser.requestFullscreen raises "Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture"
- handle case where the canvas size is fixed (default shell)
- handle case where request full screen is issued by the user (default shell)
- created issue emscripten-core#20600 to implement in a separate PR
- the rationale is that the client can simply call Module.setHiDPIAware based on the needs
- ironically, although the call was wrong, it ended up doing the right thing...
# Conflicts:
#	src/library_glfw.js
- mocking devicePixelRatio allow to write a comprehensive test
- added handling dynamic changes to devicePixelRatio by installing a listener
- unclear why it works locally
The issue is that requestFullscreen (resp. exitFullscreen) is an asynchronous call which can fail: as a result, the code must handle errors using the Promise mechanism.

- now requestFullscreen returns a promise (since it was returning nothing before, any calling code should not be affected)
- now exitFullscreen returns a promise or null (was returning a boolean so the SDL code
  if (Browser.exitFullscreen()) {
      return 1;
    }
  is still valid)
- requestFullscreen handles the error first and call fullscreenChange() which has the effect of removing the div that was set
- requestFullscreen then propagates the error so that the calling code can handle it as well
- glfw detects the error and act appropriately (similarly for exitFullscreen)

Note that this check in contains a bunch of logging to trace what is going on since the asynchronicity makes it hard to trace. These logs will be removed prior to submitting the PR.
- it seems that with Google Chrome the default is to hide navigation, but on Firefox it keeps it (search bar, shortcuts, etc...) which does not seem what fullscreen is all about. Adding the option makes it consistent.
- test that when the fullscreen request is denied, glfw handles the failure properly
@ypujante
Copy link
Contributor Author

Closing this draft PR as it is replaced by this other one

@ypujante ypujante closed this Nov 13, 2023
@ypujante ypujante deleted the issue-20600 branch November 14, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant