Compare commits

...

24 Commits

Author SHA1 Message Date
Sam Lantinga
4761467b2e Updated to version 2.28.1 for release 2023-07-01 09:56:20 -07:00
Ryan C. Gordon
cd662ceb54 rwops: Use SetFilePointerEx on Windows for appending writes.
Fixes #7900.

(cherry picked from commit 769bf2ebcc)
2023-07-01 00:40:51 -04:00
Sam Lantinga
7207f5155b Added Linux mapping for the Logitech Chillstream
Fixes https://github.com/libsdl-org/SDL/issues/7829

(cherry picked from commit 675fc8c38f)
(cherry picked from commit fc0854651b)
2023-06-29 16:16:10 -07:00
Anonymous Maarten
5d9013beb9 wayland: don't use libdecor_frame_get_* functions when header doesn't have it
and we're statically linking to the library.
This fixes building SDL with -DSDL_WAYLAND_SHARED=OFF

(cherry picked from commit 5b5b67df20)
(cherry picked from commit e6f635ca17)
2023-06-29 16:14:23 -04:00
Sam Lantinga
4af1f6ed0c Fixed build
(cherry picked from commit 099e53f3a5)
2023-06-29 11:26:16 -07:00
Sam Lantinga
446fb3028e Added support for the Nintendo Online Famicom controllers
(cherry picked from commit baa9c57581)
(cherry picked from commit 0f940cb6ce)
2023-06-29 11:18:30 -07:00
Sam Lantinga
ba170daf84 Don't crash if SDL_MapRGB() and SDL_MapRGBA() are passed a NULL format
(cherry picked from commit fadc4916a9bcc410c2148a91bf0adf742410a4ba)
(cherry picked from commit 0ba93e4aac)
2023-06-27 16:10:49 -07:00
Sam Lantinga
7fa2ddb0de Fixed Nintendo Switch Pro controllers that don't have readable user calibration
(cherry picked from commit 9ee1200e6f)
(cherry picked from commit 170428b107)
2023-06-27 07:50:41 -07:00
Narr the Reg
9aca2a4339 hidapi: switch: Handle MCU input reports
(cherry picked from commit 425062c123)
(cherry picked from commit 950ff0056a)
2023-06-26 10:07:35 -07:00
Sam Lantinga
491fba1d06 SDL_FindFreePlayerIndex() will always return the next available player index
Fixes https://github.com/libsdl-org/SDL/issues/7868

(cherry picked from commit 87e916dd21)
(cherry picked from commit 38619bb28d)
2023-06-24 15:40:30 -07:00
Sam Lantinga
c27f3ead7c Removed 100 ms hitch when querying third party Nintendo Switch controllers that don't respond to request for info
(cherry picked from commit 8acf729650)
2023-06-21 14:13:09 -07:00
Sam Lantinga
1429e525fb Use default sensor calibration if we can't read it from the Nintendo Switch controller
Fixes https://github.com/libsdl-org/SDL/issues/7830

(cherry picked from commit 3694dabe7c)
(cherry picked from commit dfbdaca2b8)
2023-06-21 10:41:58 -07:00
Sam Lantinga
de6963ea99 Apply DPI scale to mouse coordinates in SDL_WarpMouseInWindow()
Fixes https://github.com/libsdl-org/SDL/issues/7855

(cherry picked from commit 657c346556)
2023-06-21 08:46:45 -07:00
Sam Lantinga
ffa78e6bea Updated to version 2.28.0 for release 2023-06-20 11:00:20 -07:00
Simon McVittie
4ce5c3a694 ibus: Handle error when getting the D-Bus machine ID
It is possible for retrieving the machine ID to fail, either because
dbus was installed incorrectly (machine ID absent or corrupt), or in
32-bit builds, because stat() on the machine ID fails with EOVERFLOW
if it has an out-of-range timestamp or inode number.

dbus has historically treated this as a faulty installation, raising
a warning which by default causes the process to crash. Unfortunately,
dbus_get_local_machine_id() never had a way to report errors, so it has
no alternative for that (bad) error handling.

In dbus >= 1.12.0, we can use dbus_try_get_local_machine_id() to get
the same information, but with the ability to cope gracefully with
errors. ibus won't work in this situation, but that's better than
crashing.

(cherry picked from commit 91198baed4)

Mitigates: https://github.com/ValveSoftware/steam-for-linux/issues/9605
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-06-20 09:45:25 -07:00
Sam Lantinga
a3d4fd71c3 Added support for blitting SDL_PIXELFORMAT_INDEX1LSB
Fixes https://github.com/libsdl-org/SDL/issues/7844
2023-06-19 08:36:30 -07:00
Sam Lantinga
d97423ebab Fixed DualSense controllers not being picked up by the HIDAPI driver
The hidraw device may take additional time to get the correct permissions for us to open it. In my tests on Steam Deck hardware, this ranges between 5-8ms.

(cherry picked from commit c6ee9780df)
2023-06-18 12:22:06 -07:00
Sam Lantinga
333a03f1ec We don't know in advance whether a device is connected over Bluetooth in SDL2 2023-06-17 13:15:07 -07:00
Sam Lantinga
5b8fc907df Added support for the GameSir G4 Pro
We can't read device info or IMU calibration from this controller, and it has no gyro or accelerometer, but is otherwise perfectly functional.

(cherry picked from commit f168f9c813)
2023-06-17 13:07:03 -07:00
Eric Wasylishen
76392f4fe1 Handle DPI scaling in SDL_GetWindowSurface
Fixes DPI awareness of testdrawchessboard (previously, the surface was
being created in points instead of pixels, resulting in the demo app
only drawing in a corner of the screen on High-DPI displays)

*_CreateWindowFramebuffer()/*_UpdateWindowFramebuffer(): are updated
to use SDL_GetWindowSizeInPixels instead of SDL_GetWindowSize() or
window->w/window->h.

Most of the _CreateWindowFramebuffer backends are untested except
for Windows.

Fixes #7047

(cherry picked from commit 67c91353e0)
2023-06-14 17:23:54 -07:00
Sam Lantinga
3a5abee512 Removed unused function
(cherry picked from commit 73927b0948)
2023-06-14 15:16:44 -07:00
Sam Lantinga
e7ee375f22 Fixed third-party Nintendo Switch Pro controllers shutting down when we try to set the home LED.
This fixes the PDP Afterglow Wireless Deluxe Controller.

(cherry picked from commit 0c16f4faf0)
2023-06-14 15:15:27 -07:00
Sam Lantinga
4aec54988c Allow switching licensed Nintendo Switch Pro controllers into gyro input mode
(cherry picked from commit 8c95bd814b)
2023-06-14 15:13:11 -07:00
Sam Lantinga
271e03f0d7 Added support for the PowerA Fusion Pro Wireless Controller in Bluetooth mode
This controller shows up with a VID/PID of 0, but has full functionality over Bluetooth

(cherry picked from commit cdfc0c5a33)
2023-06-14 15:12:56 -07:00
38 changed files with 729 additions and 350 deletions

View File

@@ -83,7 +83,7 @@ endif()
# See docs/release_checklist.md
set(SDL_MAJOR_VERSION 2)
set(SDL_MINOR_VERSION 27)
set(SDL_MINOR_VERSION 28)
set(SDL_MICRO_VERSION 1)
set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")

View File

@@ -14,7 +14,7 @@
LIBNAME = SDL2
MAJOR_VERSION = 2
MINOR_VERSION = 27
MINOR_VERSION = 28
MICRO_VERSION = 1
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
DESCRIPTION = Simple DirectMedia Layer 2

View File

@@ -5,7 +5,7 @@
LIBNAME = SDL2
MAJOR_VERSION = 2
MINOR_VERSION = 27
MINOR_VERSION = 28
MICRO_VERSION = 1
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)

View File

@@ -19,10 +19,10 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.27.1</string>
<string>2.28.1</string>
<key>CFBundleSignature</key>
<string>SDLX</string>
<key>CFBundleVersion</key>
<string>2.27.1</string>
<string>2.28.1</string>
</dict>
</plist>

View File

@@ -9528,8 +9528,8 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEPLOYMENT_POSTPROCESSING = YES;
DYLIB_COMPATIBILITY_VERSION = 2702.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0;
DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2801.1.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_ALTIVEC_EXTENSIONS = YES;
@@ -9570,7 +9570,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_LINK_OBJC_RUNTIME = NO;
MARKETING_VERSION = 2.27.1;
MARKETING_VERSION = 2.28.1;
OTHER_LDFLAGS = "-liconv";
};
name = Release;
@@ -9613,8 +9613,8 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 2702.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0;
DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2801.1.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@@ -9656,7 +9656,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_LINK_OBJC_RUNTIME = NO;
MARKETING_VERSION = 2.27.1;
MARKETING_VERSION = 2.28.1;
OTHER_LDFLAGS = "-liconv";
};
name = Debug;
@@ -9862,8 +9862,8 @@
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 2702.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0;
DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2801.1.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
@@ -9914,8 +9914,8 @@
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 2702.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0;
DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2801.1.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;

View File

@@ -1,4 +1,4 @@
Title SDL 2.27.1
Title SDL 2.28.1
Version 1
Description SDL Library for Mac OS X (http://www.libsdl.org)
DefaultLocation /Library/Frameworks

View File

@@ -60,7 +60,7 @@ import java.util.Locale;
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL";
private static final int SDL_MAJOR_VERSION = 2;
private static final int SDL_MINOR_VERSION = 27;
private static final int SDL_MINOR_VERSION = 28;
private static final int SDL_MICRO_VERSION = 1;
/*
// Display InputType.SOURCE/CLASS of events and devices

2
configure vendored
View File

@@ -3506,7 +3506,7 @@ orig_CFLAGS="$CFLAGS"
# See docs/release_checklist.md
SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=27
SDL_MINOR_VERSION=28
SDL_MICRO_VERSION=1
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION

View File

@@ -12,7 +12,7 @@ orig_CFLAGS="$CFLAGS"
dnl Set various version strings - taken gratefully from the GTk sources
# See docs/release_checklist.md
SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=27
SDL_MINOR_VERSION=28
SDL_MICRO_VERSION=1
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION

View File

@@ -58,7 +58,7 @@ typedef struct SDL_version
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
#define SDL_MAJOR_VERSION 2
#define SDL_MINOR_VERSION 27
#define SDL_MINOR_VERSION 28
#define SDL_PATCHLEVEL 1
/**

View File

@@ -1342,7 +1342,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
*
* \param window the window to update
* \param rects an array of SDL_Rect structures representing areas of the
* surface to copy
* surface to copy, in pixels
* \param numrects the number of rectangles
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.

View File

@@ -36,6 +36,9 @@ static SDL_DBusContext dbus;
static int LoadDBUSSyms(void)
{
#define SDL_DBUS_SYM2_OPTIONAL(x, y) \
dbus.x = SDL_LoadFunction(dbus_handle, #y)
#define SDL_DBUS_SYM2(x, y) \
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) \
return -1
@@ -43,6 +46,9 @@ static int LoadDBUSSyms(void)
#define SDL_DBUS_SYM(x) \
SDL_DBUS_SYM2(x, dbus_##x)
#define SDL_DBUS_SYM_OPTIONAL(x) \
SDL_DBUS_SYM2_OPTIONAL(x, dbus_##x)
SDL_DBUS_SYM(bus_get_private);
SDL_DBUS_SYM(bus_register);
SDL_DBUS_SYM(bus_add_match);
@@ -80,6 +86,7 @@ static int LoadDBUSSyms(void)
SDL_DBUS_SYM(error_is_set);
SDL_DBUS_SYM(error_free);
SDL_DBUS_SYM(get_local_machine_id);
SDL_DBUS_SYM_OPTIONAL(try_get_local_machine_id);
SDL_DBUS_SYM(free);
SDL_DBUS_SYM(free_string_array);
SDL_DBUS_SYM(shutdown);
@@ -493,6 +500,40 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
return SDL_TRUE;
}
/*
* Get the machine ID if possible. Result must be freed with dbus->free().
*/
char *SDL_DBus_GetLocalMachineId(void)
{
DBusError err;
char *result;
dbus.error_init(&err);
if (dbus.try_get_local_machine_id) {
/* Available since dbus 1.12.0, has proper error-handling */
result = dbus.try_get_local_machine_id(&err);
} else {
/* Available since time immemorial, but has no error-handling:
* if the machine ID can't be read, many versions of libdbus will
* treat that as a fatal mis-installation and abort() */
result = dbus.get_local_machine_id();
}
if (result) {
return result;
}
if (dbus.error_is_set(&err)) {
SDL_SetError("%s: %s", err.name, err.message);
dbus.error_free(&err);
} else {
SDL_SetError("Error getting D-Bus machine ID");
}
return NULL;
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -72,6 +72,7 @@ typedef struct SDL_DBusContext
dbus_bool_t (*error_is_set)(const DBusError *);
void (*error_free)(DBusError *);
char *(*get_local_machine_id)(void);
char *(*try_get_local_machine_id)(DBusError *);
void (*free)(void *);
void (*free_string_array)(char **);
void (*shutdown)(void);
@@ -95,6 +96,8 @@ extern SDL_bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const c
extern void SDL_DBus_ScreensaverTickle(void);
extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
extern char *SDL_DBus_GetLocalMachineId(void);
#endif /* HAVE_DBUS_DBUS_H */
#endif /* SDL_dbus_h_ */

View File

@@ -410,7 +410,12 @@ static char *IBus_GetDBusAddressFilename(void)
(void)SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
}
key = dbus->get_local_machine_id();
key = SDL_DBus_GetLocalMachineId();
if (key == NULL) {
SDL_free(display);
return NULL;
}
SDL_memset(file_path, 0, sizeof(file_path));
(void)SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",

View File

@@ -277,8 +277,9 @@ windows_file_write(SDL_RWops *context, const void *ptr, size_t size,
/* if in append mode, we must go to the EOF before write */
if (context->hidden.windowsio.append) {
if (SetFilePointer(context->hidden.windowsio.h, 0L, NULL, FILE_END) ==
INVALID_SET_FILE_POINTER) {
LARGE_INTEGER windowsoffset;
windowsoffset.QuadPart = 0;
if (!SetFilePointerEx(context->hidden.windowsio.h, windowsoffset, &windowsoffset, FILE_END)) {
SDL_Error(SDL_EFWRITE);
return 0;
}

View File

@@ -729,6 +729,8 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const
hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
{
const int MAX_ATTEMPTS = 10;
int attempt;
hid_device *dev = NULL;
hid_init();
@@ -736,7 +738,15 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
dev = new_hid_device();
/* OPEN HERE */
dev->device_handle = open(path, O_RDWR | O_CLOEXEC);
for (attempt = 1; attempt <= MAX_ATTEMPTS; ++attempt) {
dev->device_handle = open(path, O_RDWR | O_CLOEXEC);
if (dev->device_handle < 0 && errno == EACCES) {
/* udev might be setting up permissions, wait a bit and try again */
usleep(1 * 1000);
continue;
}
break;
}
/* If we have a good handle, return it. */
if (dev->device_handle >= 0) {

View File

@@ -572,11 +572,23 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
/* GameCube driver has 12 buttons and 6 axes */
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b6,dpleft:b4,dpright:b5,dpup:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,righttrigger:a5,rightx:a2,righty:a3,start:b8,x:b2,y:b3,", sizeof(mapping_string));
} else if (vendor == USB_VENDOR_NINTENDO &&
guid.data[15] != k_eSwitchDeviceInfoControllerType_Unknown &&
guid.data[15] != k_eSwitchDeviceInfoControllerType_ProController &&
guid.data[15] != k_eWiiExtensionControllerType_Gamepad &&
guid.data[15] != k_eWiiExtensionControllerType_WiiUPro) {
(guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCRight ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_NESLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_NESRight ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_SNES ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_N64 ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_SEGA_Genesis ||
guid.data[15] == k_eWiiExtensionControllerType_None ||
guid.data[15] == k_eWiiExtensionControllerType_Nunchuk ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConRight)) {
switch (guid.data[15]) {
case k_eSwitchDeviceInfoControllerType_HVCLeft:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,start:b6,", sizeof(mapping_string));
case k_eSwitchDeviceInfoControllerType_HVCRight:
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_NESLeft:
case k_eSwitchDeviceInfoControllerType_NESRight:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,start:b6,", sizeof(mapping_string));

View File

@@ -660,6 +660,7 @@ static const char *s_ControllerMappings[] = {
"03000000300f00001001000010010000,Jess Tech Dual Analog Rumble Pad,a:b2,b:b3,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b0,y:b1,",
"03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
"030000006f0e00000103000000020000,Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000006d040000d1ca000011010000,Logitech Chillstream,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000016c2000010010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000016c2000011010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",

View File

@@ -221,10 +221,10 @@ static int SDL_FindFreePlayerIndex()
for (player_index = 0; player_index < SDL_joystick_player_count; ++player_index) {
if (SDL_joystick_players[player_index] == -1) {
return player_index;
break;
}
}
return -1;
return player_index;
}
static int SDL_GetPlayerIndexForJoystickID(SDL_JoystickID instance_id)

View File

@@ -28,6 +28,9 @@ typedef enum
k_eSwitchDeviceInfoControllerType_JoyConLeft = 1,
k_eSwitchDeviceInfoControllerType_JoyConRight = 2,
k_eSwitchDeviceInfoControllerType_ProController = 3,
k_eSwitchDeviceInfoControllerType_LicProController = 6,
k_eSwitchDeviceInfoControllerType_HVCLeft = 7,
k_eSwitchDeviceInfoControllerType_HVCRight = 8,
k_eSwitchDeviceInfoControllerType_NESLeft = 9,
k_eSwitchDeviceInfoControllerType_NESRight = 10,
k_eSwitchDeviceInfoControllerType_SNES = 11,

View File

@@ -71,6 +71,7 @@ typedef enum
{
k_eSwitchInputReportIDs_SubcommandReply = 0x21,
k_eSwitchInputReportIDs_FullControllerState = 0x30,
k_eSwitchInputReportIDs_FullControllerAndMcuState = 0x31,
k_eSwitchInputReportIDs_SimpleControllerState = 0x3F,
k_eSwitchInputReportIDs_CommandAck = 0x81,
} ESwitchInputReportIDs;
@@ -619,8 +620,6 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
return SDL_TRUE;
}
ctx->device->is_bluetooth = SDL_FALSE;
return SDL_FALSE;
}
@@ -720,13 +719,35 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
}
}
static Uint8 GetDefaultInputMode(SDL_DriverSwitch_Context *ctx)
{
Uint8 input_mode;
/* Determine the desired input mode */
if (ctx->device->is_bluetooth) {
input_mode = k_eSwitchInputReportIDs_SimpleControllerState;
} else {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
}
/* The official Nintendo Switch Pro Controller supports FullControllerState over Bluetooth
* just fine. We really should use that, or else the epowerlevel code in HandleFullControllerState
* is completely pointless. We need full state if we want battery level and we only care about
* battery level over Bluetooth anyway.
*/
if (ctx->device->vendor_id == USB_VENDOR_NINTENDO) {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
}
return input_mode;
}
static SDL_bool SetIMUEnabled(SDL_DriverSwitch_Context *ctx, SDL_bool enabled)
{
Uint8 imu_data = enabled ? 1 : 0;
return WriteSubcommand(ctx, k_eSwitchSubcommandIDs_EnableIMU, &imu_data, sizeof(imu_data), NULL);
}
static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_mode)
static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
{
Uint8 *pLeftStickCal;
Uint8 *pRightStickCal;
@@ -740,9 +761,8 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
readUserParams.unAddress = k_unSPIStickUserCalibrationStartOffset;
readUserParams.ucLength = k_unSPIStickUserCalibrationLength;
if (!WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readUserParams, sizeof(readUserParams), &user_reply)) {
return SDL_FALSE;
}
/* This isn't readable on all controllers, so ignore failure */
WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readUserParams, sizeof(readUserParams), &user_reply);
/* Read Factory Calibration Info */
readFactoryParams.unAddress = k_unSPIStickFactoryCalibrationStartOffset;
@@ -753,13 +773,13 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
}
/* Automatically select the user calibration if magic bytes are set */
if (user_reply->stickUserCalibration.rgucLeftMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucLeftMagic[1] == 0xA1) {
if (user_reply && user_reply->stickUserCalibration.rgucLeftMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucLeftMagic[1] == 0xA1) {
pLeftStickCal = user_reply->stickUserCalibration.rgucLeftCalibration;
} else {
pLeftStickCal = factory_reply->stickFactoryCalibration.rgucLeftCalibration;
}
if (user_reply->stickUserCalibration.rgucRightMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucRightMagic[1] == 0xA1) {
if (user_reply && user_reply->stickUserCalibration.rgucRightMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucRightMagic[1] == 0xA1) {
pRightStickCal = user_reply->stickUserCalibration.rgucRightCalibration;
} else {
pRightStickCal = factory_reply->stickFactoryCalibration.rgucRightCalibration;
@@ -821,16 +841,55 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context *ctx)
{
Uint8 *pIMUScale;
SwitchSubcommandInputPacket_t *reply = NULL;
Sint16 sAccelRawX, sAccelRawY, sAccelRawZ, sGyroRawX, sGyroRawY, sGyroRawZ;
/* Read Calibration Info */
SwitchSPIOpData_t readParams;
readParams.unAddress = k_unSPIIMUScaleStartOffset;
readParams.ucLength = k_unSPIIMUScaleLength;
if (!WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readParams, sizeof(readParams), &reply)) {
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readParams, sizeof(readParams), &reply)) {
Uint8 *pIMUScale;
Sint16 sAccelRawX, sAccelRawY, sAccelRawZ, sGyroRawX, sGyroRawY, sGyroRawZ;
/* IMU scale gives us multipliers for converting raw values to real world values */
pIMUScale = reply->spiReadData.rgucReadData;
sAccelRawX = (pIMUScale[1] << 8) | pIMUScale[0];
sAccelRawY = (pIMUScale[3] << 8) | pIMUScale[2];
sAccelRawZ = (pIMUScale[5] << 8) | pIMUScale[4];
sGyroRawX = (pIMUScale[13] << 8) | pIMUScale[12];
sGyroRawY = (pIMUScale[15] << 8) | pIMUScale[14];
sGyroRawZ = (pIMUScale[17] << 8) | pIMUScale[16];
/* Check for user calibration data. If it's present and set, it'll override the factory settings */
readParams.unAddress = k_unSPIIMUUserScaleStartOffset;
readParams.ucLength = k_unSPIIMUUserScaleLength;
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readParams, sizeof(readParams), &reply) && (pIMUScale[0] | pIMUScale[1] << 8) == 0xA1B2) {
pIMUScale = reply->spiReadData.rgucReadData;
sAccelRawX = (pIMUScale[3] << 8) | pIMUScale[2];
sAccelRawY = (pIMUScale[5] << 8) | pIMUScale[4];
sAccelRawZ = (pIMUScale[7] << 8) | pIMUScale[6];
sGyroRawX = (pIMUScale[15] << 8) | pIMUScale[14];
sGyroRawY = (pIMUScale[17] << 8) | pIMUScale[16];
sGyroRawZ = (pIMUScale[19] << 8) | pIMUScale[18];
}
/* Accelerometer scale */
ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
/* Gyro scale */
ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleY = SWITCH_GYRO_SCALE_MULT / (SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawY) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleZ = SWITCH_GYRO_SCALE_MULT / (SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawZ) * (float)M_PI / 180.0f;
} else {
/* Use default values */
const float accelScale = SDL_STANDARD_GRAVITY / SWITCH_ACCEL_SCALE;
const float gyroScale = (float)M_PI / 180.0f / SWITCH_GYRO_SCALE;
@@ -841,46 +900,7 @@ static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context *ctx)
ctx->m_IMUScaleData.fGyroScaleX = gyroScale;
ctx->m_IMUScaleData.fGyroScaleY = gyroScale;
ctx->m_IMUScaleData.fGyroScaleZ = gyroScale;
return SDL_FALSE;
}
/* IMU scale gives us multipliers for converting raw values to real world values */
pIMUScale = reply->spiReadData.rgucReadData;
sAccelRawX = (pIMUScale[1] << 8) | pIMUScale[0];
sAccelRawY = (pIMUScale[3] << 8) | pIMUScale[2];
sAccelRawZ = (pIMUScale[5] << 8) | pIMUScale[4];
sGyroRawX = (pIMUScale[13] << 8) | pIMUScale[12];
sGyroRawY = (pIMUScale[15] << 8) | pIMUScale[14];
sGyroRawZ = (pIMUScale[17] << 8) | pIMUScale[16];
/* Check for user calibration data. If it's present and set, it'll override the factory settings */
readParams.unAddress = k_unSPIIMUUserScaleStartOffset;
readParams.ucLength = k_unSPIIMUUserScaleLength;
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t *)&readParams, sizeof(readParams), &reply) && (pIMUScale[0] | pIMUScale[1] << 8) == 0xA1B2) {
pIMUScale = reply->spiReadData.rgucReadData;
sAccelRawX = (pIMUScale[3] << 8) | pIMUScale[2];
sAccelRawY = (pIMUScale[5] << 8) | pIMUScale[4];
sAccelRawZ = (pIMUScale[7] << 8) | pIMUScale[6];
sGyroRawX = (pIMUScale[15] << 8) | pIMUScale[14];
sGyroRawY = (pIMUScale[17] << 8) | pIMUScale[16];
sGyroRawZ = (pIMUScale[19] << 8) | pIMUScale[18];
}
/* Accelerometer scale */
ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
/* Gyro scale */
ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleY = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawY) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleZ = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawZ) * (float)M_PI / 180.0f;
return SDL_TRUE;
}
@@ -978,7 +998,9 @@ static ESwitchDeviceInfoControllerType ReadJoyConControllerType(SDL_HIDAPI_Devic
ctx->m_bSyncWrite = SDL_TRUE;
ctx->m_nMaxWriteAttempts = GetMaxWriteAttempts(device);
for (attempts = 0; attempts < MAX_ATTEMPTS; ++attempts) {
for ( ; ; ) {
++attempts;
device->is_bluetooth = SDL_FALSE;
if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
@@ -991,13 +1013,12 @@ static ESwitchDeviceInfoControllerType ReadJoyConControllerType(SDL_HIDAPI_Devic
eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType);
}
}
if (eControllerType == k_eSwitchDeviceInfoControllerType_Unknown) {
if (eControllerType == k_eSwitchDeviceInfoControllerType_Unknown && attempts < MAX_ATTEMPTS) {
/* Wait a bit and try again */
SDL_Delay(100);
continue;
} else {
break;
}
break;
}
SDL_free(ctx);
}
@@ -1019,6 +1040,12 @@ static SDL_bool HasHomeLED(SDL_DriverSwitch_Context *ctx)
return SDL_FALSE;
}
/* Third party controllers don't have a home LED and will shut off if we try to set it */
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_Unknown ||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_LicProController) {
return SDL_FALSE;
}
/* The Nintendo Online classic controllers don't have a Home LED */
if (vendor_id == USB_VENDOR_NINTENDO &&
ctx->m_eControllerType > k_eSwitchDeviceInfoControllerType_ProController) {
@@ -1032,6 +1059,8 @@ static SDL_bool AlwaysUsesLabels(int vendor_id, int product_id, ESwitchDeviceInf
{
/* These controllers don't have a diamond button configuration, so always use labels */
switch (eControllerType) {
case k_eSwitchDeviceInfoControllerType_HVCLeft:
case k_eSwitchDeviceInfoControllerType_HVCRight:
case k_eSwitchDeviceInfoControllerType_NESLeft:
case k_eSwitchDeviceInfoControllerType_NESRight:
case k_eSwitchDeviceInfoControllerType_N64:
@@ -1078,7 +1107,8 @@ static SDL_bool HIDAPI_DriverNintendoClassic_IsSupportedDevice(SDL_HIDAPI_Device
{
if (vendor_id == USB_VENDOR_NINTENDO) {
if (product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT) {
if (SDL_strncmp(name, "NES Controller", 14) == 0) {
if (SDL_strncmp(name, "NES Controller", 14) == 0 ||
SDL_strncmp(name, "HVC Controller", 14) == 0) {
return SDL_TRUE;
}
}
@@ -1179,19 +1209,28 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
switch (ctx->m_eControllerType) {
case k_eSwitchDeviceInfoControllerType_JoyConLeft:
HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (L)");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT);
device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
break;
case k_eSwitchDeviceInfoControllerType_JoyConRight:
HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (R)");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT);
device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT;
break;
case k_eSwitchDeviceInfoControllerType_ProController:
case k_eSwitchDeviceInfoControllerType_LicProController:
HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_SWITCH_PRO);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_PRO);
device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
break;
case k_eSwitchDeviceInfoControllerType_HVCLeft:
HIDAPI_SetDeviceName(device, "Nintendo HVC Controller (1)");
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
case k_eSwitchDeviceInfoControllerType_HVCRight:
HIDAPI_SetDeviceName(device, "Nintendo HVC Controller (2)");
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
case k_eSwitchDeviceInfoControllerType_NESLeft:
HIDAPI_SetDeviceName(device, "Nintendo NES Controller (L)");
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
@@ -1202,20 +1241,24 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
break;
case k_eSwitchDeviceInfoControllerType_SNES:
HIDAPI_SetDeviceName(device, "Nintendo SNES Controller");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_SNES_CONTROLLER);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SNES_CONTROLLER);
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
case k_eSwitchDeviceInfoControllerType_N64:
HIDAPI_SetDeviceName(device, "Nintendo N64 Controller");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_N64_CONTROLLER);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_N64_CONTROLLER);
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
HIDAPI_SetDeviceName(device, "Nintendo SEGA Genesis Controller");
HIDAPI_SetDeviceProduct(device, USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER);
HIDAPI_SetDeviceProduct(device, USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER);
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
case k_eSwitchDeviceInfoControllerType_Unknown:
/* We couldn't read the device info for this controller, might not be fully compliant */
return;
default:
device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break;
}
device->guid.data[15] = ctx->m_eControllerType;
@@ -1257,12 +1300,7 @@ static SDL_bool HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
if (!BReadDeviceInfo(ctx)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"HIDAPI_DriverSwitch_InitDevice(): Couldn't read device info");
return SDL_FALSE;
}
BReadDeviceInfo(ctx);
UpdateDeviceIdentity(device);
}
@@ -1298,7 +1336,6 @@ static void HIDAPI_DriverSwitch_SetDevicePlayerIndex(SDL_HIDAPI_Device *device,
static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context;
Uint8 input_mode;
SDL_AssertJoysticksLocked();
@@ -1318,54 +1355,36 @@ static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_
}
}
/* Determine the desired input mode (needed before loading stick calibration) */
if (device->is_bluetooth) {
input_mode = k_eSwitchInputReportIDs_SimpleControllerState;
} else {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
if (!LoadStickCalibration(ctx)) {
SDL_SetError("Couldn't load stick calibration");
return SDL_FALSE;
}
/* The official Nintendo Switch Pro Controller supports FullControllerState over bluetooth
* just fine. We really should use that, or else the epowerlevel code in
* HandleFullControllerState is completely pointless. We need full state if we want battery
* level and we only care about battery level over bluetooth anyway.
*/
if (device->vendor_id == USB_VENDOR_NINTENDO) {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
}
if (input_mode == k_eSwitchInputReportIDs_FullControllerState &&
if (ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_HVCLeft &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_HVCRight &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_NESLeft &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_NESRight &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SNES &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_N64 &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SEGA_Genesis) {
/* Use the right sensor in the combined Joy-Con pair */
if (!device->parent ||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 200.0f);
if (LoadIMUCalibration(ctx)) {
/* Use the right sensor in the combined Joy-Con pair */
if (!device->parent ||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 200.0f);
}
if (device->parent &&
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_L, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_L, 200.0f);
}
if (device->parent &&
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_R, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_R, 200.0f);
}
}
if (device->parent &&
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_L, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_L, 200.0f);
}
if (device->parent &&
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_R, 200.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_R, 200.0f);
}
}
if (!LoadStickCalibration(ctx, input_mode)) {
SDL_SetError("Couldn't load stick calibration");
return SDL_FALSE;
}
if (!LoadIMUCalibration(ctx)) {
SDL_SetError("Couldn't load sensor calibration");
return SDL_FALSE;
}
if (!SetVibrationEnabled(ctx, 1)) {
@@ -1374,7 +1393,7 @@ static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_
}
/* Set desired input mode */
if (!SetInputMode(ctx, input_mode)) {
if (!SetInputMode(ctx, GetDefaultInputMode(ctx))) {
SDL_SetError("Couldn't set input mode");
return SDL_FALSE;
}
@@ -1573,6 +1592,14 @@ static int HIDAPI_DriverSwitch_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL
static int HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context;
Uint8 input_mode;
if (enabled) {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
} else {
input_mode = GetDefaultInputMode(ctx);
}
SetInputMode(ctx, input_mode);
SetIMUEnabled(ctx, enabled);
ctx->m_bReportSensors = enabled;
@@ -2153,6 +2180,7 @@ static SDL_bool HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
HandleSimpleControllerState(joystick, ctx, (SwitchSimpleStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
break;
case k_eSwitchInputReportIDs_FullControllerState:
case k_eSwitchInputReportIDs_FullControllerAndMcuState:
HandleFullControllerState(joystick, ctx, (SwitchStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
break;
default:

View File

@@ -657,10 +657,10 @@ void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name)
}
}
void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 product_id)
void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id)
{
/* Don't set the device product ID directly, or we'll constantly re-enumerate this device */
SDL_SetJoystickGUIDProduct(&device->guid, product_id);
device->guid = SDL_CreateJoystickGUID(device->guid.data[0], vendor_id, product_id, device->version, device->name, 'h', 0);
}
static void HIDAPI_UpdateJoystickSerial(SDL_HIDAPI_Device *device)

View File

@@ -152,7 +152,7 @@ extern SDL_GameControllerType HIDAPI_GetGameControllerTypeFromGUID(SDL_JoystickG
extern void HIDAPI_UpdateDevices(void);
extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name);
extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 product_id);
extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id);
extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);
extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial);
extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);

View File

@@ -9,8 +9,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,27,1,0
PRODUCTVERSION 2,27,1,0
FILEVERSION 2,28,1,0
PRODUCTVERSION 2,28,1,0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x40004L
@@ -23,12 +23,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "SDL\0"
VALUE "FileVersion", "2, 27, 1, 0\0"
VALUE "FileVersion", "2, 28, 1, 0\0"
VALUE "InternalName", "SDL\0"
VALUE "LegalCopyright", "Copyright (C) 2023 Sam Lantinga\0"
VALUE "OriginalFilename", "SDL2.dll\0"
VALUE "ProductName", "Simple DirectMedia Layer\0"
VALUE "ProductVersion", "2, 27, 1, 0\0"
VALUE "ProductVersion", "2, 28, 1, 0\0"
END
END
BLOCK "VarFileInfo"

View File

@@ -91,7 +91,7 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
}
if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h);
SDL_GetWindowSizeInPixels(renderer->window, w, h);
return 0;
}

View File

@@ -45,38 +45,76 @@ static void BlitBto1(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8;
if (map) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = bit;
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
}
@@ -99,21 +137,40 @@ static void BlitBto2(SDL_BlitInfo *info)
map = (Uint16 *)info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
@@ -134,24 +191,46 @@ static void BlitBto3(SDL_BlitInfo *info)
map = info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte >>= 1;
dst += 3;
}
bit = (byte & 0x80) >> 7;
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte <<= 1;
dst += 3;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
@@ -173,21 +252,40 @@ static void BlitBto4(SDL_BlitInfo *info)
map = (Uint32 *)info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
@@ -207,38 +305,76 @@ static void BlitBto1Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8;
if (palmap) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = bit;
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
}
@@ -259,21 +395,40 @@ static void BlitBto2Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8;
dstskip /= 2;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte >>= 1;
dstp++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte <<= 1;
dstp++;
src += srcskip;
dstp += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
src += srcskip;
dstp += dstskip;
}
}
@@ -292,21 +447,40 @@ static void BlitBto3Key(SDL_BlitInfo *info)
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte >>= 1;
dst += 3;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
@@ -326,21 +500,40 @@ static void BlitBto4Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8;
dstskip /= 4;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte >>= 1;
dstp++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte <<= 1;
dstp++;
src += srcskip;
dstp += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
src += srcskip;
dstp += dstskip;
}
}
@@ -365,26 +558,50 @@ static void BlitBtoNAlpha(SDL_BlitInfo *info)
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte >>= 1;
dst += dstbpp;
}
bit = (byte & 0x80) >> 7;
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
@@ -411,26 +628,50 @@ static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte >>= 1;
dst += dstbpp;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}

View File

@@ -852,6 +852,10 @@ void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alph
/* Find the opaque pixel value corresponding to an RGB triple */
Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
{
if (!format) {
SDL_InvalidParamError("format");
return 0;
}
if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
} else {
@@ -862,6 +866,10 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
/* Find the pixel value corresponding to an RGBA quadruple */
Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
if (!format) {
SDL_InvalidParamError("format");
return 0;
}
if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
} else {

View File

@@ -219,6 +219,9 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
SDL_RendererInfo info;
SDL_WindowTextureData *data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
int i;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
if (data == NULL) {
SDL_Renderer *renderer = NULL;
@@ -301,7 +304,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
data->texture = SDL_CreateTexture(data->renderer, *format,
SDL_TEXTUREACCESS_STREAMING,
window->w, window->h);
w, h);
if (!data->texture) {
/* codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_WINDOWTEXTUREDATA and not leaked here. */
return -1; /* NOLINT(clang-analyzer-unix.Malloc) */
@@ -309,11 +312,11 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
/* Create framebuffer data */
data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
data->pitch = (((w * data->bytes_per_pixel) + 3) & ~3);
{
/* Make static analysis happy about potential SDL_malloc(0) calls. */
const size_t allocsize = (size_t)window->h * data->pitch;
const size_t allocsize = (size_t)h * data->pitch;
data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
if (!data->pixels) {
return SDL_OutOfMemory();
@@ -337,6 +340,9 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window *window,
SDL_WindowTextureData *data;
SDL_Rect rect;
void *src;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
if (data == NULL || !data->texture) {
@@ -344,7 +350,7 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window *window,
}
/* Update a single rect that contains subrects for best DMA performance */
if (SDL_GetSpanEnclosingRect(window->w, window->h, numrects, rects, &rect)) {
if (SDL_GetSpanEnclosingRect(w, h, numrects, rects, &rect)) {
src = (void *)((Uint8 *)data->pixels +
rect.y * data->pitch +
rect.x * data->bytes_per_pixel);
@@ -2584,6 +2590,9 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window)
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_bool created_framebuffer = SDL_FALSE;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* This will switch the video backend from using a software surface to
using a GPU texture through the 2D render API, if we think this would
@@ -2662,7 +2671,7 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window)
return NULL;
}
return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
return SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
}
SDL_bool SDL_HasWindowSurface(SDL_Window *window)
@@ -2695,8 +2704,8 @@ int SDL_UpdateWindowSurface(SDL_Window *window)
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = window->w;
full_rect.h = window->h;
SDL_GetWindowSizeInPixels(window, &full_rect.w, &full_rect.h);
return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
}

View File

@@ -37,7 +37,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
SDL_DUMMY_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) {
return -1;

View File

@@ -43,7 +43,7 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format
/* Create a new one */
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
if (surface == NULL) {

View File

@@ -71,7 +71,7 @@ CreateNewWindowFramebuffer(SDL_Window *window)
int w, h, bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(FRAMEBUFFER_FORMAT, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
return SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
}

View File

@@ -55,7 +55,7 @@ int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
SDL_NGAGE_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) {
return -1;

View File

@@ -37,7 +37,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *for
SDL_OFFSCREEN_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) {
return -1;

View File

@@ -39,6 +39,9 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo
_kernel_swi_regs regs;
SDL_DisplayMode mode;
int size;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */
RISCOS_DestroyWindowFramebuffer(_this, window);
@@ -54,10 +57,10 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo
}
/* Calculate pitch */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
*pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
/* Allocate the sprite area */
size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * window->h);
size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * h);
driverdata->fb_area = SDL_malloc(size);
if (!driverdata->fb_area) {
return SDL_OutOfMemory();
@@ -73,8 +76,8 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo
regs.r[1] = (int)driverdata->fb_area;
regs.r[2] = (int)sprite_name;
regs.r[3] = 0;
regs.r[4] = window->w;
regs.r[5] = window->h;
regs.r[4] = w;
regs.r[5] = h;
regs.r[6] = sprite_mode;
error = _kernel_swi(OS_SpriteOp, &regs, &regs);
if (error != NULL) {

View File

@@ -217,6 +217,7 @@ SDL_WAYLAND_SYM(bool, libdecor_configuration_get_window_state, (struct libdecor_
enum libdecor_window_state *))
SDL_WAYLAND_SYM(int, libdecor_dispatch, (struct libdecor *, int))
#if defined(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR) || defined(SDL_HAVE_LIBDECOR_GET_MIN_MAX)
/* Only found in libdecor 0.1.1 or higher, so failure to load them is not fatal. */
SDL_WAYLAND_SYM_OPT(void, libdecor_frame_get_min_content_size, (struct libdecor_frame *,\
int *,\
@@ -226,6 +227,8 @@ SDL_WAYLAND_SYM_OPT(void, libdecor_frame_get_max_content_size, (struct libdecor_
int *))
#endif
#endif
#undef SDL_WAYLAND_MODULE
#undef SDL_WAYLAND_SYM
#undef SDL_WAYLAND_SYM_OPT

View File

@@ -31,6 +31,9 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void
size_t size;
LPBITMAPINFO info;
HBITMAP hbm;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */
if (data->mdc) {
@@ -78,10 +81,10 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void
}
/* Fill in the size information */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
info->bmiHeader.biWidth = window->w;
info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
info->bmiHeader.biSizeImage = (DWORD)window->h * (*pitch);
*pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
info->bmiHeader.biWidth = w;
info->bmiHeader.biHeight = -h; /* negative for topdown bitmap */
info->bmiHeader.biSizeImage = (DWORD)h * (*pitch);
data->mdc = CreateCompatibleDC(data->hdc);
data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);

View File

@@ -288,6 +288,7 @@ static void WIN_WarpMouse(SDL_Window *window, int x, int y)
return;
}
WIN_ClientPointFromSDL(window, &x, &y);
pt.x = x;
pt.y = y;
ClientToScreen(hwnd, &pt);

View File

@@ -54,6 +54,9 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
Display *display = data->videodata->display;
XGCValues gcv;
XVisualInfo vinfo;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */
X11_DestroyWindowFramebuffer(_this, window);
@@ -76,14 +79,14 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
}
/* Calculate pitch */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
*pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
/* Create the actual image */
#ifndef NO_SHARED_MEMORY
if (have_mitshm(display)) {
XShmSegmentInfo *shminfo = &data->shminfo;
shminfo->shmid = shmget(IPC_PRIVATE, (size_t)window->h * (*pitch), IPC_CREAT | 0777);
shminfo->shmid = shmget(IPC_PRIVATE, (size_t)h * (*pitch), IPC_CREAT | 0777);
if (shminfo->shmid >= 0) {
shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0);
shminfo->readOnly = False;
@@ -107,7 +110,7 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
data->ximage = X11_XShmCreateImage(display, data->visual,
vinfo.depth, ZPixmap,
shminfo->shmaddr, shminfo,
window->w, window->h);
w, h);
if (!data->ximage) {
X11_XShmDetach(display, shminfo);
X11_XSync(display, False);
@@ -123,14 +126,14 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
}
#endif /* not NO_SHARED_MEMORY */
*pixels = SDL_malloc((size_t)window->h * (*pitch));
*pixels = SDL_malloc((size_t)h * (*pitch));
if (*pixels == NULL) {
return SDL_OutOfMemory();
}
data->ximage = X11_XCreateImage(display, data->visual,
vinfo.depth, ZPixmap, 0, (char *)(*pixels),
window->w, window->h, 32, 0);
w, h, 32, 0);
if (!data->ximage) {
SDL_free(*pixels);
return SDL_SetError("Couldn't create XImage");
@@ -146,6 +149,10 @@ int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects
Display *display = data->videodata->display;
int i;
int x, y, w, h;
int window_w, window_h;
SDL_GetWindowSizeInPixels(window, &window_w, &window_h);
#ifndef NO_SHARED_MEMORY
if (data->use_mitshm) {
for (i = 0; i < numrects; ++i) {
@@ -166,11 +173,11 @@ int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects
y += h;
h += rects[i].y;
}
if (x + w > window->w) {
w = window->w - x;
if (x + w > window_w) {
w = window_w - x;
}
if (y + h > window->h) {
h = window->h - y;
if (y + h > window_h) {
h = window_h - y;
}
X11_XShmPutImage(display, data->xwindow, data->gc, data->ximage,
@@ -197,11 +204,11 @@ int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects
y += h;
h += rects[i].y;
}
if (x + w > window->w) {
w = window->w - x;
if (x + w > window_w) {
w = window_w - x;
}
if (y + h > window->h) {
h = window->h - y;
if (y + h > window_h) {
h = window_h - y;
}
X11_XPutImage(display, data->xwindow, data->gc, data->ximage,