Skip to content

Commit

Permalink
Merge branch 'libsdl-org-SDL2' into SDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
capehill committed Oct 28, 2023
2 parents fb2245e + 878f0c3 commit 05dcac2
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,9 @@ if(NOT SDL2_DISABLE_INSTALL)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if(MSVC AND NOT CMAKE_VERSION VERSION_LESS "3.1")
install(FILES $<TARGET_PDB_FILE:SDL2> DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)
endif()
endif()

if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
final int XB1_IFACE_SUBCLASS = 71;
final int XB1_IFACE_PROTOCOL = 208;
final int[] SUPPORTED_VENDORS = {
0x03f0, // HP
0x044f, // Thrustmaster
0x045e, // Microsoft
0x0738, // Mad Catz
Expand Down
16 changes: 3 additions & 13 deletions src/audio/n3ds/SDL_n3dsaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static SDL_AudioDevice *audio_device;
static void FreePrivateData(_THIS);
static int FindAudioFormat(_THIS);

/* fully local functions related to the wavebufs / DSP, not the same as the SDL-wide mixer lock */
static SDL_INLINE void contextLock(_THIS)
{
LightLock_Lock(&this->hidden->lock);
Expand All @@ -48,16 +49,6 @@ static SDL_INLINE void contextUnlock(_THIS)
LightLock_Unlock(&this->hidden->lock);
}

static void N3DSAUD_LockAudio(_THIS)
{
contextLock(this);
}

static void N3DSAUD_UnlockAudio(_THIS)
{
contextUnlock(this);
}

static void N3DSAUD_DspHook(DSP_HookType hook)
{
if (hook == DSPHOOK_ONCANCEL) {
Expand Down Expand Up @@ -195,6 +186,7 @@ static void N3DSAUDIO_PlayDevice(_THIS)
{
size_t nextbuf;
size_t sampleLen;

contextLock(this);

nextbuf = this->hidden->nextbuf;
Expand Down Expand Up @@ -254,7 +246,7 @@ static void N3DSAUDIO_CloseDevice(_THIS)

static void N3DSAUDIO_ThreadInit(_THIS)
{
s32 current_priority;
s32 current_priority = 0x30;
svcGetThreadPriority(&current_priority, CUR_THREAD_HANDLE);
current_priority--;
/* 0x18 is reserved for video, 0x30 is the default for main thread */
Expand All @@ -271,8 +263,6 @@ static SDL_bool N3DSAUDIO_Init(SDL_AudioDriverImpl *impl)
impl->GetDeviceBuf = N3DSAUDIO_GetDeviceBuf;
impl->CloseDevice = N3DSAUDIO_CloseDevice;
impl->ThreadInit = N3DSAUDIO_ThreadInit;
impl->LockDevice = N3DSAUD_LockAudio;
impl->UnlockDevice = N3DSAUD_UnlockAudio;
impl->OnlyHasDefaultOutputDevice = SDL_TRUE;

/* Should be possible, but micInit would fail */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/n3ds/SDL_n3dsaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this

#define NUM_BUFFERS 2 /* -- Don't lower this! */
#define NUM_BUFFERS 3 /* -- Minimum 2! */

struct SDL_PrivateAudioData
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/android/SDL_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,12 +1939,12 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
}

if (asset_manager == NULL) {
return -1;
return SDL_SetError("Couldn't create asset manager");
}

asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN);
if (asset == NULL) {
return -1;
return SDL_SetError("Couldn't open asset '%s'", fileName);
}

ctx->hidden.androidio.asset = (void *)asset;
Expand Down
1 change: 1 addition & 0 deletions src/hidapi/libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
static const int XB1_IFACE_SUBCLASS = 71;
static const int XB1_IFACE_PROTOCOL = 208;
static const int SUPPORTED_VENDORS[] = {
0x03f0, /* HP */
0x044f, /* Thrustmaster */
0x045e, /* Microsoft */
0x0738, /* Mad Catz */
Expand Down
4 changes: 4 additions & 0 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,10 @@ static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
MAKE_VIDPID(0x0eb7, 0x038e), /* Fanatec ClubSport Wheel Base V1 */
MAKE_VIDPID(0x0eb7, 0x0e03), /* Fanatec CSL Elite Wheel Base */
MAKE_VIDPID(0x11ff, 0x0511), /* DragonRise Inc. Wired Wheel (initial mode) (also known as PXN V900 (PS3), Superdrive SV-750, or a Genesis Seaborg 400) */
MAKE_VIDPID(0x2433, 0xf300), /* Asetek SimSports Invicta Wheelbase */
MAKE_VIDPID(0x2433, 0xf301), /* Asetek SimSports Forte Wheelbase */
MAKE_VIDPID(0x2433, 0xf303), /* Asetek SimSports La Prima Wheelbase */
MAKE_VIDPID(0x2433, 0xf306), /* Asetek SimSports Tony Kannan Wheelbase */
};
int i;

Expand Down
1 change: 1 addition & 0 deletions src/joystick/controller_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafd ), k_eControllerType_XBox360Controller, NULL }, // Afterglow Gamepad 3
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafe ), k_eControllerType_XBox360Controller, NULL }, // Rock Candy Gamepad for Xbox 360

{ MAKE_CONTROLLER_ID( 0x03f0, 0x0495 ), k_eControllerType_XBoxOneController, NULL }, // HP HyperX Clutch Gladiate
{ MAKE_CONTROLLER_ID( 0x044f, 0xd012 ), k_eControllerType_XBoxOneController, NULL }, // ThrustMaster eSwap PRO Controller Xbox
{ MAKE_CONTROLLER_ID( 0x045e, 0x02d1 ), k_eControllerType_XBoxOneController, "Xbox One Controller" }, // Microsoft X-Box One pad
{ MAKE_CONTROLLER_ID( 0x045e, 0x02dd ), k_eControllerType_XBoxOneController, "Xbox One Controller" }, // Microsoft X-Box One pad (Firmware 2015)
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ static SDL_GameControllerType SDL_GetJoystickGameControllerProtocol(const char *
interface_protocol == XBONE_IFACE_PROTOCOL) {

static const int SUPPORTED_VENDORS[] = {
0x03f0, /* HP */
0x044f, /* Thrustmaster */
0x045e, /* Microsoft */
0x0738, /* Mad Catz */
Expand Down Expand Up @@ -1436,6 +1437,12 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index)
device->updating = SDL_FALSE;
SDL_UnlockMutex(device->dev_lock);

/* UpdateDevice() may have called HIDAPI_JoystickDisconnected() if the device went away */
if (device->num_joysticks == 0) {
SDL_free(hwdata);
return SDL_SetError("HIDAPI device disconnected while opening");
}

if (!device->driver->OpenJoystick(device, joystick)) {
/* The open failed, mark this device as disconnected and update devices */
HIDAPI_JoystickDisconnected(device, joystickID);
Expand Down
5 changes: 5 additions & 0 deletions src/joystick/linux/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#include "../hidapi/SDL_hidapijoystick_c.h"

/* This isn't defined in older Linux kernel headers */
#ifndef MSC_TIMESTAMP
#define MSC_TIMESTAMP 0x05
#endif

#ifndef SYN_DROPPED
#define SYN_DROPPED 3
#endif
Expand Down Expand Up @@ -119,6 +123,7 @@
#define BTN_TRIGGER_HAPPY40 0x2e7
#endif


#include "../../core/linux/SDL_evdev_capabilities.h"
#include "../../core/linux/SDL_udev.h"
#include "../../core/linux/SDL_sandbox.h"
Expand Down
8 changes: 0 additions & 8 deletions src/joystick/windows/SDL_dinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ static BOOL CALLBACK EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInsta
char *hidPath = NULL;
char *name = NULL;
LPDIRECTINPUTDEVICE8 device = NULL;
DIDEVCAPS caps;

/* We are only supporting HID devices. */
CHECK(pDeviceInstance->dwDevType & DIDEVTYPE_HID);
Expand All @@ -463,13 +462,6 @@ static BOOL CALLBACK EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInsta
CHECK(QueryDevicePath(device, &hidPath));
CHECK(QueryDeviceInfo(device, &vendor, &product));

/* Check to make sure the device has buttons and axes.
* This fixes incorrectly detecting the ROG CHAKRAM X mouse as a game controller on Windows 10
*/
caps.dwSize = sizeof(caps);
CHECK(SUCCEEDED(IDirectInputDevice8_GetCapabilities(device, &caps)));
CHECK(caps.dwAxes > 0 && caps.dwButtons > 0);

CHECK(!SDL_IsXInputDevice(vendor, product, hidPath));

pNewJoystick = *(JoyStick_DeviceData **)pContext;
Expand Down
71 changes: 71 additions & 0 deletions src/stdlib/SDL_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,39 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
return vsscanf(text, fmt, ap);
}
#else
static SDL_bool CharacterMatchesSet(char c, const char *set, size_t set_len)
{
SDL_bool invert = SDL_FALSE;
SDL_bool result = SDL_FALSE;

if (*set == '^') {
invert = SDL_TRUE;
++set;
--set_len;
}
while (set_len > 0 && !result) {
if (set_len >= 3 && set[1] == '-') {
char low_char = SDL_min(set[0], set[2]);
char high_char = SDL_max(set[0], set[2]);
if (c >= low_char && c <= high_char) {
result = SDL_TRUE;
}
set += 3;
set_len -= 3;
} else {
if (c == *set) {
result = SDL_TRUE;
}
++set;
--set_len;
}
}
if (invert) {
result = result ? SDL_FALSE : SDL_TRUE;
}
return result;
}

/* NOLINTNEXTLINE(readability-non-const-parameter) */
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
Expand Down Expand Up @@ -1387,6 +1420,44 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
}
done = SDL_TRUE;
break;
case '[':
{
const char *set = fmt + 1;
while (*fmt && *fmt != ']') {
++fmt;
}
if (*fmt) {
size_t set_len = (fmt - set);
if (suppress) {
while (CharacterMatchesSet(*text, set, set_len)) {
++text;
if (count) {
if (--count == 0) {
break;
}
}
}
} else {
SDL_bool had_match = SDL_FALSE;
char *valuep = va_arg(ap, char *);
while (CharacterMatchesSet(*text, set, set_len)) {
had_match = SDL_TRUE;
*valuep++ = *text++;
if (count) {
if (--count == 0) {
break;
}
}
}
*valuep = '\0';
if (had_match) {
++retval;
}
}
}
}
done = SDL_TRUE;
break;
default:
done = SDL_TRUE;
break;
Expand Down
24 changes: 11 additions & 13 deletions src/thread/n3ds/SDL_systhread.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@

#include "../SDL_systhread.h"

/* N3DS has very limited RAM (128MB), so we put a limit on thread stack size. */
#define N3DS_THREAD_STACK_SIZE_MAX (16 * 1024)
#define N3DS_THREAD_STACK_SIZE_DEFAULT (4 * 1024)
/* N3DS has very limited RAM (128MB), so we set a low default thread stack size. */
#define N3DS_THREAD_STACK_SIZE_DEFAULT (80 * 1024)

#define N3DS_THREAD_PRIORITY_LOW 0x3F /**< Minimum priority */
#define N3DS_THREAD_PRIORITY_MEDIUM 0x2F /**< Slightly higher than main thread (0x30) */
Expand All @@ -49,15 +48,22 @@ static void ThreadEntry(void *arg)

int SDL_SYS_CreateThread(SDL_Thread *thread)
{
s32 priority;
s32 priority = 0x30;
int cpu = -1;
size_t stack_size = GetStackSize(thread->stacksize);

svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);

/* prefer putting audio thread on system core */
if (thread->name && (SDL_strncmp(thread->name, "SDLAudioP", 9) == 0) && R_SUCCEEDED(APT_SetAppCpuTimeLimit(30))) {
cpu = 1;
}

thread->handle = threadCreate(ThreadEntry,
thread,
stack_size,
priority,
-1,
cpu,
false);

if (thread->handle == NULL) {
Expand All @@ -73,14 +79,6 @@ static size_t GetStackSize(size_t requested_size)
return N3DS_THREAD_STACK_SIZE_DEFAULT;
}

if (requested_size > N3DS_THREAD_STACK_SIZE_MAX) {
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM,
"Requested a thread size of %zu,"
" falling back to the maximum supported of %zu\n",
requested_size,
N3DS_THREAD_STACK_SIZE_MAX);
requested_size = N3DS_THREAD_STACK_SIZE_MAX;
}
return requested_size;
}

Expand Down
1 change: 1 addition & 0 deletions src/video/android/SDL_androidevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void android_egl_context_restore(SDL_Window *window)
if (window) {
SDL_Event event;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
SDL_GL_MakeCurrent(window, NULL);
if (SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context) < 0) {
/* The context is no longer valid, create a new one */
data->egl_context = (EGLContext)SDL_GL_CreateContext(window);
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ if(SDL_INSTALL_TESTS)
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
)
endif()
if(MSVC)
foreach(test ${SDL_TEST_EXECUTABLES})
install(FILES $<TARGET_PDB_FILE:${test}> DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2" OPTIONAL)
endforeach()
endif()
install(
FILES ${RESOURCE_FILES}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
Expand Down
Loading

0 comments on commit 05dcac2

Please sign in to comment.