mirror of
https://github.com/love2d/megasource.git
synced 2026-08-20 04:30:45 +02:00
update SDL3 to 3.2.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
@@ -24,6 +24,7 @@
|
||||
// The high-level video driver subsystem
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
#include "SDL_clipboard_c.h"
|
||||
#include "SDL_egl_c.h"
|
||||
#include "SDL_surface_c.h"
|
||||
#include "SDL_pixels_c.h"
|
||||
@@ -50,10 +51,14 @@
|
||||
#include <SDL3/SDL_opengles2.h>
|
||||
#endif // SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
|
||||
|
||||
#ifndef SDL_VIDEO_OPENGL
|
||||
#ifndef GL_CONTEXT_RELEASE_BEHAVIOR_KHR
|
||||
#define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB
|
||||
// GL_CONTEXT_RELEASE_BEHAVIOR and GL_CONTEXT_RELEASE_BEHAVIOR_KHR have the same number.
|
||||
#ifndef GL_CONTEXT_RELEASE_BEHAVIOR
|
||||
#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB
|
||||
#endif
|
||||
|
||||
// GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH and GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR have the same number.
|
||||
#ifndef GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH
|
||||
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
|
||||
#endif
|
||||
|
||||
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
||||
@@ -171,6 +176,10 @@ extern bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window);
|
||||
extern bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blocking);
|
||||
#endif
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||
extern void SDL_UpdateLifecycleObserver(void);
|
||||
#endif
|
||||
|
||||
static void SDL_CheckWindowDisplayChanged(SDL_Window *window);
|
||||
static void SDL_CheckWindowDisplayScaleChanged(SDL_Window *window);
|
||||
static void SDL_CheckWindowSafeAreaChanged(SDL_Window *window);
|
||||
@@ -312,10 +321,9 @@ static bool SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window,
|
||||
if (!data) {
|
||||
SDL_Renderer *renderer = NULL;
|
||||
const char *render_driver = NULL;
|
||||
const char *hint;
|
||||
|
||||
// See if there's a render driver being requested
|
||||
hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
||||
const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
||||
if (hint && *hint != '0' && *hint != '1' &&
|
||||
SDL_strcasecmp(hint, "true") != 0 &&
|
||||
SDL_strcasecmp(hint, "false") != 0 &&
|
||||
@@ -324,20 +332,45 @@ static bool SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window,
|
||||
}
|
||||
|
||||
if (!render_driver) {
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
|
||||
if (hint && *hint && SDL_strcasecmp(hint, SDL_SOFTWARE_RENDERER) != 0) {
|
||||
render_driver = hint;
|
||||
render_driver = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
|
||||
}
|
||||
|
||||
char *render_driver_copy = NULL;
|
||||
if (render_driver && *render_driver) {
|
||||
render_driver_copy = SDL_strdup(render_driver);
|
||||
render_driver = render_driver_copy;
|
||||
if (render_driver_copy) { // turn any "software" requests into "xxxxxxxx" so we don't end up in infinite recursion.
|
||||
char *prev = render_driver_copy;
|
||||
char *ptr = prev;
|
||||
while ((ptr = SDL_strchr(ptr, ',')) != NULL) {
|
||||
*ptr = '\0';
|
||||
const bool is_sw = (SDL_strcasecmp(prev, SDL_SOFTWARE_RENDERER) == 0);
|
||||
*ptr = ',';
|
||||
if (is_sw) {
|
||||
SDL_memset(prev, 'x', SDL_strlen(SDL_SOFTWARE_RENDERER));
|
||||
ptr = prev;
|
||||
} else {
|
||||
ptr++;
|
||||
prev = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_strcasecmp(prev, SDL_SOFTWARE_RENDERER) == 0) {
|
||||
SDL_memset(prev, 'x', SDL_strlen(SDL_SOFTWARE_RENDERER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if there's a specific driver requested
|
||||
if (render_driver) {
|
||||
renderer = SDL_CreateRenderer(window, render_driver);
|
||||
SDL_free(render_driver_copy);
|
||||
if (!renderer) {
|
||||
// The error for this specific renderer has already been set
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
SDL_assert(render_driver_copy == NULL);
|
||||
const int total = SDL_GetNumRenderDrivers();
|
||||
for (i = 0; i < total; ++i) {
|
||||
const char *name = SDL_GetRenderDriver(i);
|
||||
@@ -519,7 +552,7 @@ static int SDLCALL cmpmodes(const void *A, const void *B)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool SDL_UninitializedVideo(void)
|
||||
bool SDL_UninitializedVideo(void)
|
||||
{
|
||||
return SDL_SetError("Video subsystem has not been initialized");
|
||||
}
|
||||
@@ -742,7 +775,7 @@ SDL_SystemTheme SDL_GetSystemTheme(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void SDL_UpdateDesktopBounds(void)
|
||||
void SDL_UpdateDesktopBounds(void)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
SDL_zero(rect);
|
||||
@@ -1561,6 +1594,10 @@ void SDL_RelativeToGlobalForWindow(SDL_Window *window, int rel_x, int rel_y, int
|
||||
for (w = window->parent; w; w = w->parent) {
|
||||
rel_x += w->x;
|
||||
rel_y += w->y;
|
||||
|
||||
if (!SDL_WINDOW_IS_POPUP(w)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1581,6 +1618,10 @@ void SDL_GlobalToRelativeForWindow(SDL_Window *window, int abs_x, int abs_y, int
|
||||
for (w = window->parent; w; w = w->parent) {
|
||||
abs_x -= w->x;
|
||||
abs_y -= w->y;
|
||||
|
||||
if (!SDL_WINDOW_IS_POPUP(w)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2458,6 +2499,10 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
|
||||
// Make sure window pixel size is up to date
|
||||
SDL_CheckWindowPixelSizeChanged(window);
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||
SDL_UpdateLifecycleObserver();
|
||||
#endif
|
||||
|
||||
SDL_ClearError();
|
||||
|
||||
return window;
|
||||
@@ -3069,8 +3114,6 @@ bool SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h)
|
||||
|
||||
bool SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
CHECK_WINDOW_MAGIC(window, false);
|
||||
if (min_w < 0) {
|
||||
return SDL_InvalidParamError("min_w");
|
||||
@@ -3092,8 +3135,10 @@ bool SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h)
|
||||
}
|
||||
|
||||
// Ensure that window is not smaller than minimal size
|
||||
w = window->min_w ? SDL_max(window->floating.w, window->min_w) : window->floating.w;
|
||||
h = window->min_h ? SDL_max(window->floating.h, window->min_h) : window->floating.h;
|
||||
int w = window->last_size_pending ? window->pending.w : window->floating.w;
|
||||
int h = window->last_size_pending ? window->pending.h : window->floating.h;
|
||||
w = window->min_w ? SDL_max(w, window->min_w) : w;
|
||||
h = window->min_h ? SDL_max(h, window->min_h) : h;
|
||||
return SDL_SetWindowSize(window, w, h);
|
||||
}
|
||||
|
||||
@@ -3111,8 +3156,6 @@ bool SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h)
|
||||
|
||||
bool SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
CHECK_WINDOW_MAGIC(window, false);
|
||||
if (max_w < 0) {
|
||||
return SDL_InvalidParamError("max_w");
|
||||
@@ -3134,8 +3177,10 @@ bool SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h)
|
||||
}
|
||||
|
||||
// Ensure that window is not larger than maximal size
|
||||
w = window->max_w ? SDL_min(window->floating.w, window->max_w) : window->floating.w;
|
||||
h = window->max_h ? SDL_min(window->floating.h, window->max_h) : window->floating.h;
|
||||
int w = window->last_size_pending ? window->pending.w : window->floating.w;
|
||||
int h = window->last_size_pending ? window->pending.h : window->floating.h;
|
||||
w = window->max_w ? SDL_min(w, window->max_w) : w;
|
||||
h = window->max_h ? SDL_min(h, window->max_h) : h;
|
||||
return SDL_SetWindowSize(window, w, h);
|
||||
}
|
||||
|
||||
@@ -3930,6 +3975,8 @@ void SDL_OnWindowLiveResizeUpdate(SDL_Window *window)
|
||||
// Send an expose event so the application can redraw
|
||||
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_EXPOSED, 0, 0);
|
||||
}
|
||||
|
||||
SDL_PumpEventMaintenance();
|
||||
}
|
||||
|
||||
static void SDL_CheckWindowSafeAreaChanged(SDL_Window *window)
|
||||
@@ -4189,6 +4236,10 @@ void SDL_DestroyWindow(SDL_Window *window)
|
||||
}
|
||||
|
||||
SDL_free(window);
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||
SDL_UpdateLifecycleObserver();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SDL_ScreenSaverEnabled(void)
|
||||
@@ -4263,6 +4314,8 @@ void SDL_VideoQuit(void)
|
||||
SDL_free(_this->displays);
|
||||
_this->displays = NULL;
|
||||
|
||||
SDL_CancelClipboardData(0);
|
||||
|
||||
if (_this->primary_selection_text) {
|
||||
SDL_free(_this->primary_selection_text);
|
||||
_this->primary_selection_text = NULL;
|
||||
@@ -4797,11 +4850,7 @@ bool SDL_GL_GetAttribute(SDL_GLAttr attr, int *value)
|
||||
attrib = GL_SAMPLES;
|
||||
break;
|
||||
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
|
||||
#ifdef SDL_VIDEO_OPENGL
|
||||
attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
|
||||
#else
|
||||
attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
|
||||
#endif
|
||||
break;
|
||||
case SDL_GL_BUFFER_SIZE:
|
||||
{
|
||||
@@ -4899,7 +4948,22 @@ bool SDL_GL_GetAttribute(SDL_GLAttr attr, int *value)
|
||||
if (glBindFramebufferFunc && (current_fbo != 0)) {
|
||||
glBindFramebufferFunc(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *)value);
|
||||
// glGetFramebufferAttachmentParameterivFunc may cause GL_INVALID_OPERATION when querying depth/stencil size if the
|
||||
// bits is 0. From the GL docs:
|
||||
// If the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE, then either no framebuffer is bound to target;
|
||||
// or a default framebuffer is queried, attachment is GL_DEPTH or GL_STENCIL, and the number of depth or stencil bits,
|
||||
// respectively, is zero. In this case querying pname GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all
|
||||
// other queries will generate an error.
|
||||
GLint fbo_type = GL_FRAMEBUFFER_DEFAULT;
|
||||
if (attachment == GL_DEPTH || attachment == GL_STENCIL) {
|
||||
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &fbo_type);
|
||||
}
|
||||
if (fbo_type != GL_NONE) {
|
||||
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *)value);
|
||||
}
|
||||
else {
|
||||
*value = 0;
|
||||
}
|
||||
if (glBindFramebufferFunc && (current_fbo != 0)) {
|
||||
glBindFramebufferFunc(GL_DRAW_FRAMEBUFFER, current_fbo);
|
||||
}
|
||||
@@ -4931,6 +4995,12 @@ bool SDL_GL_GetAttribute(SDL_GLAttr attr, int *value)
|
||||
}
|
||||
return SDL_SetError("OpenGL error: %08X", error);
|
||||
}
|
||||
|
||||
// convert GL_CONTEXT_RELEASE_BEHAVIOR values back to SDL_GL_CONTEXT_RELEASE_BEHAVIOR values
|
||||
if (attr == SDL_GL_CONTEXT_RELEASE_BEHAVIOR) {
|
||||
*value = (*value == GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH) ? SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH : SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE;
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
return SDL_Unsupported();
|
||||
@@ -5476,7 +5546,7 @@ bool SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
|
||||
if (!titlecpy) {
|
||||
return false;
|
||||
}
|
||||
SDL_strlcpy(titlecpy, messageboxdata->title, slen);
|
||||
SDL_memcpy(titlecpy, messageboxdata->title, slen);
|
||||
}
|
||||
|
||||
if (messageboxdata->message) {
|
||||
@@ -5486,7 +5556,7 @@ bool SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
|
||||
SDL_small_free(titlecpy, titleisstack);
|
||||
return false;
|
||||
}
|
||||
SDL_strlcpy(msgcpy, messageboxdata->message, slen);
|
||||
SDL_memcpy(msgcpy, messageboxdata->message, slen);
|
||||
}
|
||||
|
||||
(void)SDL_AtomicIncRef(&SDL_messagebox_count);
|
||||
|
||||
Reference in New Issue
Block a user