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);
51 static void Emscripten_PumpEvents(
_THIS);
64 Emscripten_CreateDevice(
int devindex)
82 device->VideoInit = Emscripten_VideoInit;
83 device->VideoQuit = Emscripten_VideoQuit;
84 device->GetDisplayUsableBounds = Emscripten_GetDisplayUsableBounds;
85 device->SetDisplayMode = Emscripten_SetDisplayMode;
88 device->PumpEvents = Emscripten_PumpEvents;
90 device->CreateSDLWindow = Emscripten_CreateWindow;
91 device->SetWindowTitle = Emscripten_SetWindowTitle;
94 device->SetWindowSize = Emscripten_SetWindowSize;
102 device->DestroyWindow = Emscripten_DestroyWindow;
103 device->SetWindowFullscreen = Emscripten_SetWindowFullscreen;
109 #if SDL_VIDEO_OPENGL_EGL
110 device->GL_LoadLibrary = Emscripten_GLES_LoadLibrary;
111 device->GL_GetProcAddress = Emscripten_GLES_GetProcAddress;
112 device->GL_UnloadLibrary = Emscripten_GLES_UnloadLibrary;
113 device->GL_CreateContext = Emscripten_GLES_CreateContext;
114 device->GL_MakeCurrent = Emscripten_GLES_MakeCurrent;
115 device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval;
116 device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval;
117 device->GL_SwapWindow = Emscripten_GLES_SwapWindow;
118 device->GL_DeleteContext = Emscripten_GLES_DeleteContext;
119 device->GL_GetDrawableSize = Emscripten_GLES_GetDrawableSize;
122 device->free = Emscripten_DeleteDevice;
128 EMSCRIPTENVID_DRIVER_NAME,
"SDL emscripten video driver",
129 Emscripten_CreateDevice
134 Emscripten_VideoInit(
_THIS)
141 mode.w = EM_ASM_INT_V({
145 mode.h = EM_ASM_INT_V({
149 mode.refresh_rate = 0;
171 Emscripten_VideoQuit(
_THIS)
182 rect->
w = EM_ASM_INT_V({
185 rect->
h = EM_ASM_INT_V({
186 return window.innerHeight;
193 Emscripten_PumpEvents(
_THIS)
202 double scaled_w, scaled_h;
214 wdata->
pixel_ratio = emscripten_get_device_pixel_ratio();
223 emscripten_set_canvas_element_size(wdata->
canvas_id, 1, 1);
224 emscripten_get_element_css_size(wdata->
canvas_id, &css_w, &css_h);
235 emscripten_set_canvas_element_size(wdata->
canvas_id, scaled_w, scaled_h);
245 #if SDL_VIDEO_OPENGL_EGL
247 if (!
_this->egl_data) {
255 return SDL_SetError(
"Could not create GLES window surface");
263 window->driverdata = wdata;
283 data->pixel_ratio = emscripten_get_device_pixel_ratio();
288 if (!
data->external_size &&
data->pixel_ratio != 1.0f) {
303 #if SDL_VIDEO_OPENGL_EGL
305 SDL_EGL_DestroySurface(
_this,
data->egl_surface);
311 emscripten_set_canvas_element_size(
data->canvas_id, 0, 0);
327 EmscriptenFullscreenStrategy strategy;
331 strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
333 if(!is_desktop_fullscreen) {
334 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
336 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
338 strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
341 strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
344 strategy.canvasResizedCallbackUserData =
data;
347 data->fullscreen_resize = is_desktop_fullscreen;
349 res = emscripten_request_fullscreen_strategy(
data->canvas_id, 1, &strategy);
350 if(
res != EMSCRIPTEN_RESULT_SUCCESS &&
res != EMSCRIPTEN_RESULT_DEFERRED) {
356 emscripten_exit_fullscreen();
363 if (typeof setWindowTitle !==
'undefined') {
364 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 false.
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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
The structure that defines a display mode.
A rectangle, with the origin at the upper left (integer).
SDL_VideoDisplay * displays
The type used to identify a window.