Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -759,8 +759,16 @@ static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent
}
id = touchEvent->touches[i].identifier;
x = touchEvent->touches[i].targetX / client_w;
y = touchEvent->touches[i].targetY / client_h;
if (client_w <= 1) {
x = 0.5f;
} else {
x = touchEvent->touches[i].targetX / (client_w - 1);
}
if (client_h <= 1) {
y = 0.5f;
} else {
y = touchEvent->touches[i].targetY / (client_h - 1);
}
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
SDL_SendTouch(0, deviceId, id, window_data->window, SDL_TRUE, x, y, 1.0f);
@ -835,23 +843,16 @@ static EM_BOOL Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboard
static EM_BOOL Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
{
SDL_WindowData *window_data = userData;
SDL_VideoDisplay *display;
if (fullscreenChangeEvent->isFullscreen) {
window_data->window->flags |= window_data->fullscreen_mode_flags;
SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_ENTER_FULLSCREEN, 0, 0);
window_data->fullscreen_mode_flags = 0;
} else {
window_data->window->flags &= ~SDL_WINDOW_FULLSCREEN;
/* reset fullscreen window if the browser left fullscreen */
display = SDL_GetVideoDisplayForWindow(window_data->window);
if (display->fullscreen_window == window_data->window) {
display->fullscreen_window = NULL;
}
SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_LEAVE_FULLSCREEN, 0, 0);
}
SDL_UpdateFullscreenMode(window_data->window, fullscreenChangeEvent->isFullscreen, SDL_FALSE);
return 0;
}
@ -956,7 +957,7 @@ void Emscripten_RegisterEventHandlers(SDL_WindowData *data)
/* Keyboard events are awkward */
keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
if (keyElement == NULL) {
if (!keyElement) {
keyElement = EMSCRIPTEN_EVENT_TARGET_WINDOW;
}
@ -999,7 +1000,7 @@ void Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, 0, NULL);
target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
if (target == NULL) {
if (!target) {
target = EMSCRIPTEN_EVENT_TARGET_WINDOW;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,7 +42,7 @@ int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateSurface(w, h, surface_format);
if (surface == NULL) {
if (!surface) {
return -1;
}
@ -60,7 +60,7 @@ int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo
SDL_WindowData *data = window->driverdata;
surface = data->surface;
if (surface == NULL) {
if (!surface) {
return SDL_SetError("Couldn't find framebuffer surface for window");
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,14 +42,11 @@
static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, SDL_bool is_custom)
{
SDL_Cursor *cursor;
Emscripten_CursorData *curdata;
cursor = SDL_calloc(1, sizeof(SDL_Cursor));
SDL_Cursor *cursor = SDL_calloc(1, sizeof(SDL_Cursor));
if (cursor) {
curdata = (Emscripten_CursorData *)SDL_calloc(1, sizeof(*curdata));
if (curdata == NULL) {
SDL_OutOfMemory();
if (!curdata) {
SDL_free(cursor);
return NULL;
}
@ -57,8 +54,6 @@ static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, SDL
curdata->system_cursor = cursor_str;
curdata->is_custom = is_custom;
cursor->driverdata = curdata;
} else {
SDL_OutOfMemory();
}
return cursor;
@ -78,7 +73,7 @@ static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int
conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888);
if (conv_surf == NULL) {
if (!conv_surf) {
return NULL;
}
@ -161,6 +156,30 @@ static SDL_Cursor *Emscripten_CreateSystemCursor(SDL_SystemCursor id)
case SDL_SYSTEM_CURSOR_HAND:
cursor_name = "pointer";
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
cursor_name = "nwse-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOP:
cursor_name = "ns-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
cursor_name = "nesw-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
cursor_name = "ew-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
cursor_name = "nwse-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
cursor_name = "ns-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
cursor_name = "nesw-resize";
break;
case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
cursor_name = "ew-resize";
break;
default:
SDL_assert(0);
return NULL;
@ -175,7 +194,7 @@ static void Emscripten_FreeCursor(SDL_Cursor *cursor)
if (cursor) {
curdata = (Emscripten_CursorData *)cursor->driverdata;
if (curdata != NULL) {
if (curdata) {
if (curdata->is_custom) {
SDL_free((char *)curdata->system_cursor);
}
@ -223,7 +242,7 @@ static int Emscripten_SetRelativeMouseMode(SDL_bool enabled)
/* TODO: pointer lock isn't actually enabled yet */
if (enabled) {
window = SDL_GetMouseFocus();
if (window == NULL) {
if (!window) {
return -1;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -117,7 +117,7 @@ int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
SDL_Window *window;
/* remove the context from its window */
for (window = _this->windows; window != NULL; window = window->next) {
for (window = _this->windows; window; window = window->next) {
SDL_WindowData *window_data = window->driverdata;
if (window_data->gl_context == context) {

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,11 +40,11 @@ static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *d
static void Emscripten_VideoQuit(SDL_VideoDevice *_this);
static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
static void Emscripten_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
static void Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
static void Emscripten_PumpEvents(SDL_VideoDevice *_this);
static void Emscripten_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
@ -61,8 +61,7 @@ static SDL_VideoDevice *Emscripten_CreateDevice(void)
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
if (!device) {
return 0;
}
@ -171,7 +170,7 @@ static void Emscripten_PumpEvents(SDL_VideoDevice *_this)
/* do nothing. */
}
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
SDL_WindowData *wdata;
double scaled_w, scaled_h;
@ -180,8 +179,8 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
/* Allocate window internal data */
wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (wdata == NULL) {
return SDL_OutOfMemory();
if (!wdata) {
return -1;
}
selector = SDL_GetHint(SDL_HINT_EMSCRIPTEN_CANVAS_SELECTOR);
@ -248,12 +247,14 @@ static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
data->pixel_ratio = emscripten_get_device_pixel_ratio();
}
emscripten_set_canvas_element_size(data->canvas_id, window->w * data->pixel_ratio, window->h * data->pixel_ratio);
emscripten_set_canvas_element_size(data->canvas_id, window->floating.w * data->pixel_ratio, window->floating.h * data->pixel_ratio);
/*scale canvas down*/
if (!data->external_size && data->pixel_ratio != 1.0f) {
emscripten_set_element_css_size(data->canvas_id, window->w, window->h);
emscripten_set_element_css_size(data->canvas_id, window->floating.w, window->floating.h);
}
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->floating.w, window->floating.h);
}
}
@ -285,16 +286,17 @@ static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
static void Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
{
SDL_WindowData *data;
int res = -1;
if (window->driverdata) {
data = window->driverdata;
if (fullscreen) {
EmscriptenFullscreenStrategy strategy;
SDL_bool is_fullscreen_desktop = window->fullscreen_exclusive ? SDL_FALSE : SDL_TRUE;
int res;
SDL_bool is_fullscreen_desktop = !window->fullscreen_exclusive;
strategy.scaleMode = is_fullscreen_desktop ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
@ -315,12 +317,17 @@ static void Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *w
data->fullscreen_resize = is_fullscreen_desktop;
res = emscripten_request_fullscreen_strategy(data->canvas_id, 1, &strategy);
if (res != EMSCRIPTEN_RESULT_SUCCESS && res != EMSCRIPTEN_RESULT_DEFERRED) {
/* unset flags, fullscreen failed */
window->flags &= ~SDL_WINDOW_FULLSCREEN;
}
} else
emscripten_exit_fullscreen();
} else {
res = emscripten_exit_fullscreen();
}
}
if (res == EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
} else if (res == EMSCRIPTEN_RESULT_DEFERRED) {
return 1;
} else {
return -1;
}
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages