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"
42static int Emscripten_VideoInit(
_THIS);
44static void Emscripten_VideoQuit(
_THIS);
50static void Emscripten_PumpEvents(
_THIS);
57Emscripten_Available(
void)
69Emscripten_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
138Emscripten_VideoInit(
_THIS)
145 mode.w = EM_ASM_INT_V({
149 mode.h = EM_ASM_INT_V({
153 mode.refresh_rate = 0;
175Emscripten_VideoQuit(
_THIS)
181Emscripten_PumpEvents(
_THIS)
190 double scaled_w, scaled_h;
202 wdata->
pixel_ratio = emscripten_get_device_pixel_ratio();
211 emscripten_set_canvas_element_size(wdata->
canvas_id, 1, 1);
212 emscripten_get_element_css_size(wdata->
canvas_id, &css_w, &css_h);
223 emscripten_set_canvas_element_size(wdata->
canvas_id, scaled_w, scaled_h);
233#if SDL_VIDEO_OPENGL_EGL
235 if (!
_this->egl_data) {
243 return SDL_SetError(
"Could not create GLES window surface");
251 window->driverdata = wdata;
271 data->pixel_ratio = emscripten_get_device_pixel_ratio();
276 if (!
data->external_size &&
data->pixel_ratio != 1.0f) {
291#if SDL_VIDEO_OPENGL_EGL
293 SDL_EGL_DestroySurface(
_this,
data->egl_surface);
299 emscripten_set_canvas_element_size(
data->canvas_id, 0, 0);
315 EmscriptenFullscreenStrategy strategy;
319 strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
321 if(!is_desktop_fullscreen) {
322 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
324 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
326 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
329 strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
332 strategy.canvasResizedCallbackUserData =
data;
335 data->fullscreen_resize = is_desktop_fullscreen;
337 res = emscripten_request_fullscreen_strategy(
data->canvas_id, 1, &strategy);
338 if(
res != EMSCRIPTEN_RESULT_SUCCESS &&
res != EMSCRIPTEN_RESULT_DEFERRED) {
344 emscripten_exit_fullscreen();
351 if (typeof Module[
'setWindowTitle'] !==
'undefined') {
352 Module[
'setWindowTitle'](UTF8ToString($0));
#define SDL_GL_LoadLibrary
void Emscripten_RegisterEventHandlers(SDL_WindowData *data)
EM_BOOL Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData)
void Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
void Emscripten_FiniMouse()
void Emscripten_InitMouse()
#define SDL_OutOfMemory()
#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS
Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to true.
void SDL_SetKeyboardFocus(SDL_Window *window)
void SDL_SetMouseFocus(SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
VideoBootStrap Emscripten_bootstrap
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
static SDL_VideoDevice * _this
@ SDL_WINDOW_ALLOW_HIGHDPI
@ SDL_WINDOW_FULLSCREEN_DESKTOP
@ SDL_WINDOWEVENT_RESIZED
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
EGLSurface EGLNativeWindowType * window
static SDL_AudioDeviceID device
The structure that defines a display mode.
SDL_VideoDisplay * displays
The type used to identify a window.