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

emscripten_request_fullscreen_strategy callback order #9097

Closed
Daft-Freak opened this issue Jul 27, 2019 · 3 comments · Fixed by #9765
Closed

emscripten_request_fullscreen_strategy callback order #9097

Daft-Freak opened this issue Jul 27, 2019 · 3 comments · Fixed by #9765

Comments

@Daft-Freak
Copy link
Collaborator

With this test code:

#include <stdio.h>

#include <emscripten/emscripten.h>
#include <emscripten/html5.h>

EM_BOOL is_fs = EM_FALSE;

EM_BOOL fullscreen_change(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
{
    is_fs = fullscreenChangeEvent->isFullscreen;

    printf("%s fullscreen\n", is_fs ? "entered" : "left");

    return 0;
}

EM_BOOL canvas_resize(int eventType, const void *reserved, void *userData)
{

    double css_w, css_h;
    emscripten_get_element_css_size("#canvas", &css_w, &css_h);

    printf("resized to %fx%f\n", css_w, css_h);

    return 0;
}

EM_BOOL key_down(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
{
    if(keyEvent->keyCode == 0x46/*f*/) {
        if(is_fs)
            emscripten_exit_fullscreen();
        else {
            EmscriptenFullscreenStrategy strategy;
            strategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
            strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
            strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
            strategy.canvasResizedCallback = canvas_resize;
            strategy.canvasResizedCallbackUserData = NULL;

            emscripten_request_fullscreen_strategy("#canvas", 1, &strategy);
        }
    }

    return 1;
}

void loop() {}

int main(int argc, char** argv) {

    emscripten_set_canvas_element_size("#canvas", 800, 600);

    emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, 0, fullscreen_change);
    emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 0, key_down);
    emscripten_set_main_loop(loop, 0, 1);

    return 0;
}

Pressing F, F (using emscripten_exit_fullscreen) results in:

resized to 1920.000000x1080.000000
entered fullscreen
resized to 1920.000000x1080.000000
left fullscreen

And pressing F, Esc (cancelling through the browser) results in:

resized to 1920.000000x1080.000000
entered fullscreen
left fullscreen
resized to 800.000000x600.000000

When using emscripten_exit_fullscreen, the resize callback gets called before restoring the old size. It looks like what happens is:

  • emscripten_exit_fullscreen calls .exitFullscreen
  • Then it calls the resize callback and resets __currentFullscreenStrategy
  • The fullscreen change happens and the fullscreenchange handler for restoreOldStyle gets called
  • The canvas style is restored, but __currentFullscreenStrategy is 0 so the resize callback doesn't get called.

Removing the if (__currentFullscreenStrategy.canvasResizedCallback) block in emscripten_exit_fullscreen seems to work, but I'm not sure if that would break something else.

See: emscripten-ports/SDL2#87

@kripken
Copy link
Member

kripken commented Aug 1, 2019

Interesting. It may be worth looking at the fullscreen tests in the interactive test suite. Those may not be up to date, but maybe they'll show a possible problem with your proposed fix.

cc @juj who wrote most of that code.

@Beuc
Copy link
Contributor

Beuc commented Nov 1, 2019

For the record no issues to report in RenPyWeb so far (besides actually fixing full-screen support ;)).

@kripken
Copy link
Member

kripken commented Nov 1, 2019

Thanks, yeah, that seems right to me. I opened #9765

kripken added a commit that referenced this issue Nov 13, 2019
That is before the screen has actually resized. The callback
will be called at the proper time later.

Fixes #9097
belraquib pushed a commit to belraquib/emscripten that referenced this issue Dec 23, 2020
…ipten-core#9765)

That is before the screen has actually resized. The callback
will be called at the proper time later.

Fixes emscripten-core#9097
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 a pull request may close this issue.

3 participants