21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_EMSCRIPTEN
28 #include "../SDL_sysvideo.h"
29 #include "../SDL_pixels_c.h"
30 #include "../SDL_egl_c.h"
31 #include "../../events/SDL_events_c.h"
39 #define EMSCRIPTENVID_DRIVER_NAME "emscripten"
42 static int Emscripten_VideoInit(
_THIS);
44 static void Emscripten_VideoQuit(
_THIS);
50 static void Emscripten_PumpEvents(
_THIS);
57 Emscripten_Available(
void)
69 Emscripten_CreateDevice(
int devindex)
87 device->VideoInit = Emscripten_VideoInit;
88 device->VideoQuit = Emscripten_VideoQuit;
89 device->SetDisplayMode = Emscripten_SetDisplayMode;
92 device->PumpEvents = Emscripten_PumpEvents;
94 device->CreateSDLWindow = Emscripten_CreateWindow;
95 device->SetWindowTitle = Emscripten_SetWindowTitle;
98 device->SetWindowSize = Emscripten_SetWindowSize;
106 device->DestroyWindow = Emscripten_DestroyWindow;
107 device->SetWindowFullscreen = Emscripten_SetWindowFullscreen;
113 #if SDL_VIDEO_OPENGL_EGL
114 device->GL_LoadLibrary = Emscripten_GLES_LoadLibrary;
115 device->GL_GetProcAddress = Emscripten_GLES_GetProcAddress;
116 device->GL_UnloadLibrary = Emscripten_GLES_UnloadLibrary;
117 device->GL_CreateContext = Emscripten_GLES_CreateContext;
118 device->GL_MakeCurrent = Emscripten_GLES_MakeCurrent;
119 device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval;
120 device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval;
121 device->GL_SwapWindow = Emscripten_GLES_SwapWindow;
122 device->GL_DeleteContext = Emscripten_GLES_DeleteContext;
123 device->GL_GetDrawableSize = Emscripten_GLES_GetDrawableSize;
126 device->free = Emscripten_DeleteDevice;
132 EMSCRIPTENVID_DRIVER_NAME,
"SDL emscripten video driver",
133 Emscripten_Available, Emscripten_CreateDevice
138 Emscripten_VideoInit(
_THIS)
145 mode.w = EM_ASM_INT_V({
149 mode.h = EM_ASM_INT_V({
153 mode.refresh_rate = 0;
176 Emscripten_VideoQuit(
_THIS)
182 Emscripten_PumpEvents(
_THIS)
191 double scaled_w, scaled_h;
201 wdata->
pixel_ratio = emscripten_get_device_pixel_ratio();
209 emscripten_set_canvas_size(scaled_w, scaled_h);
211 emscripten_get_element_css_size(
NULL, &css_w, &css_h);
220 emscripten_set_canvas_size(scaled_w, scaled_h);
232 #if SDL_VIDEO_OPENGL_EGL
234 if (!
_this->egl_data) {
242 return SDL_SetError(
"Could not create GLES window surface");
250 window->driverdata = wdata;
270 data->pixel_ratio = emscripten_get_device_pixel_ratio();
275 if (!
data->external_size &&
data->pixel_ratio != 1.0f) {
290 #if SDL_VIDEO_OPENGL_EGL
292 SDL_EGL_DestroySurface(
_this,
data->egl_surface);
309 EmscriptenFullscreenStrategy strategy;
313 strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
315 if(!is_desktop_fullscreen) {
316 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
318 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
320 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
323 strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
326 strategy.canvasResizedCallbackUserData =
data;
329 data->fullscreen_resize = is_desktop_fullscreen;
331 res = emscripten_request_fullscreen_strategy(
NULL, 1, &strategy);
332 if(
res != EMSCRIPTEN_RESULT_SUCCESS &&
res != EMSCRIPTEN_RESULT_DEFERRED) {
338 emscripten_exit_fullscreen();
345 if (typeof Module[
'setWindowTitle'] !==
'undefined') {
346 Module[
'setWindowTitle'](Module[
'Pointer_stringify']($0));