Skip to content

Commit 2e96555

Browse files
FMFlukekripken
authored andcommitted
Fix SDL_SetVideoMode to always call browser.setCanvasSize (#7321)
In reference to #7212, I removed the condition so browser.setCanvasSize is always called even if canvas already have the same size with what SDL_SetVideoMode want to set. Also add an interactive test case for this scenario. fixes #7212
1 parent 5e33efb commit 2e96555

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,5 @@ a license to everyone to use it as detailed in LICENSE.)
364364
* Zoltán Žarkov <[email protected]>
365365
* Roman Yurchak <[email protected]>
366366
* Hampton Maxwell <[email protected]>
367+
* Sirapop Wongstapornpat <[email protected]>
367368
* Matt Kane <[email protected]>

src/library_sdl.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,11 +1477,9 @@ var LibrarySDL = {
14771477
});
14781478
}
14791479

1480-
if (width !== canvas.width || height !== canvas.height) {
1481-
SDL.settingVideoMode = true; // SetVideoMode itself should not trigger resize events
1482-
Browser.setCanvasSize(width, height);
1483-
SDL.settingVideoMode = false;
1484-
}
1480+
SDL.settingVideoMode = true; // SetVideoMode itself should not trigger resize events
1481+
Browser.setCanvasSize(width, height);
1482+
SDL.settingVideoMode = false;
14851483

14861484
// Free the old surface first if there is one
14871485
if (SDL.screen) {

tests/sdl_fullscreen_samecanvassize.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2014 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <stdio.h>
9+
#include <SDL/SDL.h>
10+
#include <SDL/SDL_ttf.h>
11+
#include <assert.h>
12+
#include <emscripten.h>
13+
14+
int result = 1;
15+
16+
SDL_Surface *screen = 0;
17+
18+
int inFullscreen = 0;
19+
20+
int wasFullscreen = 0;
21+
22+
int finished = 0;
23+
24+
void render() {
25+
int width, height, isfs;
26+
emscripten_get_canvas_size(&width, &height, &isfs);
27+
SDL_Rect rect = { 0, 0, width, height };
28+
SDL_FillRect(screen, &rect, 0xff00ffff);
29+
}
30+
31+
void mainloop() {
32+
render();
33+
34+
if (finished) return;
35+
36+
SDL_Event event;
37+
int isInFullscreen = EM_ASM_INT(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement));
38+
if (isInFullscreen && !wasFullscreen) {
39+
printf("Successfully transitioned to fullscreen mode!\n");
40+
wasFullscreen = isInFullscreen;
41+
}
42+
43+
if (wasFullscreen && !isInFullscreen) {
44+
printf("Exited fullscreen. Test succeeded.\n");
45+
#ifdef REPORT_RESULT
46+
REPORT_RESULT(1);
47+
#endif
48+
wasFullscreen = isInFullscreen;
49+
finished = 1;
50+
return;
51+
}
52+
53+
int haveEvent = SDL_PollEvent(&event);
54+
if (haveEvent) {
55+
switch(event.type) {
56+
case SDL_MOUSEBUTTONDOWN: {
57+
SDL_WM_ToggleFullScreen(screen);
58+
inFullscreen = 1 - inFullscreen;
59+
if (inFullscreen == 0) {
60+
result = wasFullscreen;
61+
if (result) {
62+
printf("Exited fullscreen. Test succeeded.\n");
63+
} else {
64+
printf("Exited fullscreen. Test failed, fullscreen transition did not happen!\n");
65+
}
66+
#ifdef REPORT_RESULT
67+
REPORT_RESULT(result);
68+
#endif
69+
finished = 1;
70+
return;
71+
} else {
72+
printf("Entering fullscreen...\n");
73+
}
74+
break;
75+
}
76+
}
77+
}
78+
}
79+
80+
int main() {
81+
int w, h, fs;
82+
emscripten_get_canvas_size(&w, &h, &fs);
83+
printf("w:%d,h:%d\n", w,h);
84+
85+
SDL_Init(SDL_INIT_VIDEO);
86+
87+
screen = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE); //set with the same size with canvas. this used to break full screen
88+
89+
printf("You should see a yellow canvas.\n");
90+
printf("Click on the canvas to enter full screen, and then click on the canvas again to finish the test.\n");
91+
printf("When in full screen, you should see the whole screen filled yellow, and after exiting, the yellow canvas should be restored in the window.\n");
92+
emscripten_set_main_loop(mainloop, 0, 0);
93+
return 0;
94+
}

tests/test_interactive.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def test_sdl_touch(self):
3737
def test_sdl_wm_togglefullscreen(self):
3838
self.btest('sdl_wm_togglefullscreen.c', expected='1')
3939

40+
def test_sdl_fullscreen_samecanvassize(self):
41+
self.btest('sdl_fullscreen_samecanvassize.c', expected='1')
42+
4043
def test_sdl2_togglefullscreen(self):
4144
self.btest('sdl_togglefullscreen.c', expected='1', args=['-s', 'USE_SDL=2'])
4245

0 commit comments

Comments
 (0)