Compare commits

...
Author SHA1 Message Date
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
32 changed files with 633 additions and 293 deletions

No files matched your search

+2 -2
View File
@@ -83,8 +83,8 @@ endif()
# See docs/release_checklist.md # See docs/release_checklist.md
set(SDL_MAJOR_VERSION 2) set(SDL_MAJOR_VERSION 2)
set(SDL_MINOR_VERSION 27) set(SDL_MINOR_VERSION 28)
set(SDL_MICRO_VERSION 1) set(SDL_MICRO_VERSION 0)
set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}") set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
# Set defaults preventing destination file conflicts # Set defaults preventing destination file conflicts
+2 -2
View File
@@ -14,8 +14,8 @@
LIBNAME = SDL2 LIBNAME = SDL2
MAJOR_VERSION = 2 MAJOR_VERSION = 2
MINOR_VERSION = 27 MINOR_VERSION = 28
MICRO_VERSION = 1 MICRO_VERSION = 0
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION) VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
DESCRIPTION = Simple DirectMedia Layer 2 DESCRIPTION = Simple DirectMedia Layer 2
+2 -2
View File
@@ -5,8 +5,8 @@
LIBNAME = SDL2 LIBNAME = SDL2
MAJOR_VERSION = 2 MAJOR_VERSION = 2
MINOR_VERSION = 27 MINOR_VERSION = 28
MICRO_VERSION = 1 MICRO_VERSION = 0
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION) VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
LIBHOME = . LIBHOME = .
+2 -2
View File
@@ -19,10 +19,10 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.27.1</string> <string>2.28.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>SDLX</string> <string>SDLX</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2.27.1</string> <string>2.28.0</string>
</dict> </dict>
</plist> </plist>
+10 -10
View File
@@ -9528,8 +9528,8 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEPLOYMENT_POSTPROCESSING = YES; DEPLOYMENT_POSTPROCESSING = YES;
DYLIB_COMPATIBILITY_VERSION = 2702.0.0; DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0; DYLIB_CURRENT_VERSION = 2801.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_ALTIVEC_EXTENSIONS = YES; GCC_ALTIVEC_EXTENSIONS = YES;
@@ -9570,7 +9570,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_LINK_OBJC_RUNTIME = NO; CLANG_LINK_OBJC_RUNTIME = NO;
MARKETING_VERSION = 2.27.1; MARKETING_VERSION = 2.28.0;
OTHER_LDFLAGS = "-liconv"; OTHER_LDFLAGS = "-liconv";
}; };
name = Release; name = Release;
@@ -9613,8 +9613,8 @@
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 2702.0.0; DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0; DYLIB_CURRENT_VERSION = 2801.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
@@ -9656,7 +9656,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_LINK_OBJC_RUNTIME = NO; CLANG_LINK_OBJC_RUNTIME = NO;
MARKETING_VERSION = 2.27.1; MARKETING_VERSION = 2.28.0;
OTHER_LDFLAGS = "-liconv"; OTHER_LDFLAGS = "-liconv";
}; };
name = Debug; name = Debug;
@@ -9862,8 +9862,8 @@
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 2702.0.0; DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0; DYLIB_CURRENT_VERSION = 2801.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
@@ -9914,8 +9914,8 @@
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 2702.0.0; DYLIB_COMPATIBILITY_VERSION = 2801.0.0;
DYLIB_CURRENT_VERSION = 2702.0.0; DYLIB_CURRENT_VERSION = 2801.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
+1 -1
View File
@@ -1,4 +1,4 @@
Title SDL 2.27.1 Title SDL 2.28.0
Version 1 Version 1
Description SDL Library for Mac OS X (http://www.libsdl.org) Description SDL Library for Mac OS X (http://www.libsdl.org)
DefaultLocation /Library/Frameworks DefaultLocation /Library/Frameworks
@@ -60,8 +60,8 @@ import java.util.Locale;
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL"; private static final String TAG = "SDL";
private static final int SDL_MAJOR_VERSION = 2; 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; private static final int SDL_MICRO_VERSION = 0;
/* /*
// Display InputType.SOURCE/CLASS of events and devices // Display InputType.SOURCE/CLASS of events and devices
// //
Vendored
+2 -2
View File
@@ -3506,8 +3506,8 @@ orig_CFLAGS="$CFLAGS"
# See docs/release_checklist.md # See docs/release_checklist.md
SDL_MAJOR_VERSION=2 SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=27 SDL_MINOR_VERSION=28
SDL_MICRO_VERSION=1 SDL_MICRO_VERSION=0
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION` SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION`
+2 -2
View File
@@ -12,8 +12,8 @@ orig_CFLAGS="$CFLAGS"
dnl Set various version strings - taken gratefully from the GTk sources dnl Set various version strings - taken gratefully from the GTk sources
# See docs/release_checklist.md # See docs/release_checklist.md
SDL_MAJOR_VERSION=2 SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=27 SDL_MINOR_VERSION=28
SDL_MICRO_VERSION=1 SDL_MICRO_VERSION=0
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION` SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION`
+2 -2
View File
@@ -58,8 +58,8 @@ typedef struct SDL_version
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/ */
#define SDL_MAJOR_VERSION 2 #define SDL_MAJOR_VERSION 2
#define SDL_MINOR_VERSION 27 #define SDL_MINOR_VERSION 28
#define SDL_PATCHLEVEL 1 #define SDL_PATCHLEVEL 0
/** /**
* Macro to determine SDL version program was compiled against. * Macro to determine SDL version program was compiled against.
+1 -1
View File
@@ -1342,7 +1342,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
* *
* \param window the window to update * \param window the window to update
* \param rects an array of SDL_Rect structures representing areas of the * \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 * \param numrects the number of rectangles
* \returns 0 on success or a negative error code on failure; call * \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information. * SDL_GetError() for more information.
+41
View File
@@ -36,6 +36,9 @@ static SDL_DBusContext dbus;
static int LoadDBUSSyms(void) static int LoadDBUSSyms(void)
{ {
#define SDL_DBUS_SYM2_OPTIONAL(x, y) \
dbus.x = SDL_LoadFunction(dbus_handle, #y)
#define SDL_DBUS_SYM2(x, y) \ #define SDL_DBUS_SYM2(x, y) \
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) \ if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) \
return -1 return -1
@@ -43,6 +46,9 @@ static int LoadDBUSSyms(void)
#define SDL_DBUS_SYM(x) \ #define SDL_DBUS_SYM(x) \
SDL_DBUS_SYM2(x, dbus_##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_get_private);
SDL_DBUS_SYM(bus_register); SDL_DBUS_SYM(bus_register);
SDL_DBUS_SYM(bus_add_match); SDL_DBUS_SYM(bus_add_match);
@@ -80,6 +86,7 @@ static int LoadDBUSSyms(void)
SDL_DBUS_SYM(error_is_set); SDL_DBUS_SYM(error_is_set);
SDL_DBUS_SYM(error_free); SDL_DBUS_SYM(error_free);
SDL_DBUS_SYM(get_local_machine_id); SDL_DBUS_SYM(get_local_machine_id);
SDL_DBUS_SYM_OPTIONAL(try_get_local_machine_id);
SDL_DBUS_SYM(free); SDL_DBUS_SYM(free);
SDL_DBUS_SYM(free_string_array); SDL_DBUS_SYM(free_string_array);
SDL_DBUS_SYM(shutdown); SDL_DBUS_SYM(shutdown);
@@ -493,6 +500,40 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
return SDL_TRUE; 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 #endif
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
+3
View File
@@ -72,6 +72,7 @@ typedef struct SDL_DBusContext
dbus_bool_t (*error_is_set)(const DBusError *); dbus_bool_t (*error_is_set)(const DBusError *);
void (*error_free)(DBusError *); void (*error_free)(DBusError *);
char *(*get_local_machine_id)(void); char *(*get_local_machine_id)(void);
char *(*try_get_local_machine_id)(DBusError *);
void (*free)(void *); void (*free)(void *);
void (*free_string_array)(char **); void (*free_string_array)(char **);
void (*shutdown)(void); void (*shutdown)(void);
@@ -95,6 +96,8 @@ extern SDL_bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const c
extern void SDL_DBus_ScreensaverTickle(void); extern void SDL_DBus_ScreensaverTickle(void);
extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit); extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
extern char *SDL_DBus_GetLocalMachineId(void);
#endif /* HAVE_DBUS_DBUS_H */ #endif /* HAVE_DBUS_DBUS_H */
#endif /* SDL_dbus_h_ */ #endif /* SDL_dbus_h_ */
+6 -1
View File
@@ -410,7 +410,12 @@ static char *IBus_GetDBusAddressFilename(void)
(void)SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env); (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)); SDL_memset(file_path, 0, sizeof(file_path));
(void)SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s", (void)SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
+11 -1
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) 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_device *dev = NULL;
hid_init(); hid_init();
@@ -736,7 +738,15 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
dev = new_hid_device(); dev = new_hid_device();
/* OPEN HERE */ /* 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 we have a good handle, return it. */
if (dev->device_handle >= 0) { if (dev->device_handle >= 0) {
+9 -4
View File
@@ -572,10 +572,15 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
/* GameCube driver has 12 buttons and 6 axes */ /* 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)); 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 && } else if (vendor == USB_VENDOR_NINTENDO &&
guid.data[15] != k_eSwitchDeviceInfoControllerType_Unknown && (guid.data[15] == k_eSwitchDeviceInfoControllerType_NESLeft ||
guid.data[15] != k_eSwitchDeviceInfoControllerType_ProController && guid.data[15] == k_eSwitchDeviceInfoControllerType_NESRight ||
guid.data[15] != k_eWiiExtensionControllerType_Gamepad && guid.data[15] == k_eSwitchDeviceInfoControllerType_SNES ||
guid.data[15] != k_eWiiExtensionControllerType_WiiUPro) { 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]) { switch (guid.data[15]) {
case k_eSwitchDeviceInfoControllerType_NESLeft: case k_eSwitchDeviceInfoControllerType_NESLeft:
case k_eSwitchDeviceInfoControllerType_NESRight: case k_eSwitchDeviceInfoControllerType_NESRight:
@@ -28,6 +28,7 @@ typedef enum
k_eSwitchDeviceInfoControllerType_JoyConLeft = 1, k_eSwitchDeviceInfoControllerType_JoyConLeft = 1,
k_eSwitchDeviceInfoControllerType_JoyConRight = 2, k_eSwitchDeviceInfoControllerType_JoyConRight = 2,
k_eSwitchDeviceInfoControllerType_ProController = 3, k_eSwitchDeviceInfoControllerType_ProController = 3,
k_eSwitchDeviceInfoControllerType_LicProController = 6,
k_eSwitchDeviceInfoControllerType_NESLeft = 9, k_eSwitchDeviceInfoControllerType_NESLeft = 9,
k_eSwitchDeviceInfoControllerType_NESRight = 10, k_eSwitchDeviceInfoControllerType_NESRight = 10,
k_eSwitchDeviceInfoControllerType_SNES = 11, k_eSwitchDeviceInfoControllerType_SNES = 11,
+73 -61
View File
@@ -619,8 +619,6 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
return SDL_TRUE; return SDL_TRUE;
} }
ctx->device->is_bluetooth = SDL_FALSE;
return SDL_FALSE; return SDL_FALSE;
} }
@@ -720,13 +718,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) static SDL_bool SetIMUEnabled(SDL_DriverSwitch_Context *ctx, SDL_bool enabled)
{ {
Uint8 imu_data = enabled ? 1 : 0; Uint8 imu_data = enabled ? 1 : 0;
return WriteSubcommand(ctx, k_eSwitchSubcommandIDs_EnableIMU, &imu_data, sizeof(imu_data), NULL); 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 *pLeftStickCal;
Uint8 *pRightStickCal; Uint8 *pRightStickCal;
@@ -1019,6 +1039,12 @@ static SDL_bool HasHomeLED(SDL_DriverSwitch_Context *ctx)
return SDL_FALSE; 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 */ /* The Nintendo Online classic controllers don't have a Home LED */
if (vendor_id == USB_VENDOR_NINTENDO && if (vendor_id == USB_VENDOR_NINTENDO &&
ctx->m_eControllerType > k_eSwitchDeviceInfoControllerType_ProController) { ctx->m_eControllerType > k_eSwitchDeviceInfoControllerType_ProController) {
@@ -1179,17 +1205,18 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
switch (ctx->m_eControllerType) { switch (ctx->m_eControllerType) {
case k_eSwitchDeviceInfoControllerType_JoyConLeft: case k_eSwitchDeviceInfoControllerType_JoyConLeft:
HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (L)"); 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; device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
break; break;
case k_eSwitchDeviceInfoControllerType_JoyConRight: case k_eSwitchDeviceInfoControllerType_JoyConRight:
HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (R)"); 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; device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT;
break; break;
case k_eSwitchDeviceInfoControllerType_ProController: case k_eSwitchDeviceInfoControllerType_ProController:
case k_eSwitchDeviceInfoControllerType_LicProController:
HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller"); 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; device->type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
break; break;
case k_eSwitchDeviceInfoControllerType_NESLeft: case k_eSwitchDeviceInfoControllerType_NESLeft:
@@ -1202,19 +1229,22 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
break; break;
case k_eSwitchDeviceInfoControllerType_SNES: case k_eSwitchDeviceInfoControllerType_SNES:
HIDAPI_SetDeviceName(device, "Nintendo SNES Controller"); 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; device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break; break;
case k_eSwitchDeviceInfoControllerType_N64: case k_eSwitchDeviceInfoControllerType_N64:
HIDAPI_SetDeviceName(device, "Nintendo N64 Controller"); 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; device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break; break;
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis: case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
HIDAPI_SetDeviceName(device, "Nintendo SEGA Genesis Controller"); 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; device->type = SDL_CONTROLLER_TYPE_UNKNOWN;
break; break;
case k_eSwitchDeviceInfoControllerType_Unknown:
/* We couldn't read the device info for this controller, might not be fully compliant */
return;
default: default:
break; break;
} }
@@ -1257,12 +1287,7 @@ static SDL_bool HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]); SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]); SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
if (!BReadDeviceInfo(ctx)) { BReadDeviceInfo(ctx);
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"HIDAPI_DriverSwitch_InitDevice(): Couldn't read device info");
return SDL_FALSE;
}
UpdateDeviceIdentity(device); UpdateDeviceIdentity(device);
} }
@@ -1298,7 +1323,6 @@ static void HIDAPI_DriverSwitch_SetDevicePlayerIndex(SDL_HIDAPI_Device *device,
static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{ {
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context; SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context;
Uint8 input_mode;
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
@@ -1318,54 +1342,34 @@ static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_
} }
} }
/* Determine the desired input mode (needed before loading stick calibration) */ if (!LoadStickCalibration(ctx)) {
if (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 (device->vendor_id == USB_VENDOR_NINTENDO) {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
}
if (input_mode == k_eSwitchInputReportIDs_FullControllerState &&
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 (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"); SDL_SetError("Couldn't load stick calibration");
return SDL_FALSE; return SDL_FALSE;
} }
if (!LoadIMUCalibration(ctx)) { if (ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_NESLeft &&
SDL_SetError("Couldn't load sensor calibration"); ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_NESRight &&
return SDL_FALSE; ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SNES &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_N64 &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SEGA_Genesis) {
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 (!SetVibrationEnabled(ctx, 1)) { if (!SetVibrationEnabled(ctx, 1)) {
@@ -1374,7 +1378,7 @@ static SDL_bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_
} }
/* Set desired input mode */ /* Set desired input mode */
if (!SetInputMode(ctx, input_mode)) { if (!SetInputMode(ctx, GetDefaultInputMode(ctx))) {
SDL_SetError("Couldn't set input mode"); SDL_SetError("Couldn't set input mode");
return SDL_FALSE; return SDL_FALSE;
} }
@@ -1573,6 +1577,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) static int HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
{ {
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context; 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); SetIMUEnabled(ctx, enabled);
ctx->m_bReportSensors = enabled; ctx->m_bReportSensors = enabled;
+2 -2
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 */ /* 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) static void HIDAPI_UpdateJoystickSerial(SDL_HIDAPI_Device *device)
+1 -1
View File
@@ -152,7 +152,7 @@ extern SDL_GameControllerType HIDAPI_GetGameControllerTypeFromGUID(SDL_JoystickG
extern void HIDAPI_UpdateDevices(void); extern void HIDAPI_UpdateDevices(void);
extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name); 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 void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);
extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial); extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial);
extern void HIDAPI_DisconnectBluetoothDevice(const char *serial); extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);
+4 -4
View File
@@ -9,8 +9,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,27,1,0 FILEVERSION 2,28,0,0
PRODUCTVERSION 2,27,1,0 PRODUCTVERSION 2,28,0,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L FILEFLAGS 0x0L
FILEOS 0x40004L FILEOS 0x40004L
@@ -23,12 +23,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "\0" VALUE "CompanyName", "\0"
VALUE "FileDescription", "SDL\0" VALUE "FileDescription", "SDL\0"
VALUE "FileVersion", "2, 27, 1, 0\0" VALUE "FileVersion", "2, 28, 0, 0\0"
VALUE "InternalName", "SDL\0" VALUE "InternalName", "SDL\0"
VALUE "LegalCopyright", "Copyright (C) 2023 Sam Lantinga\0" VALUE "LegalCopyright", "Copyright (C) 2023 Sam Lantinga\0"
VALUE "OriginalFilename", "SDL2.dll\0" VALUE "OriginalFilename", "SDL2.dll\0"
VALUE "ProductName", "Simple DirectMedia Layer\0" VALUE "ProductName", "Simple DirectMedia Layer\0"
VALUE "ProductVersion", "2, 27, 1, 0\0" VALUE "ProductVersion", "2, 28, 0, 0\0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
+1 -1
View File
@@ -91,7 +91,7 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
} }
if (renderer->window) { if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h); SDL_GetWindowSizeInPixels(renderer->window, w, h);
return 0; return 0;
} }
+398 -157
View File
@@ -45,38 +45,76 @@ static void BlitBto1(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
if (map) { if (map) {
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
dst++;
byte >>= 1;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (1) { dst += dstskip;
*dst = map[bit]; }
} 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;
} }
dst++; src += srcskip;
byte <<= 1; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} else { } else {
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = bit;
}
dst++;
byte >>= 1;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (1) { dst += dstskip;
*dst = bit; }
} 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;
} }
dst++; src += srcskip;
byte <<= 1; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
} }
@@ -99,21 +137,40 @@ static void BlitBto2(SDL_BlitInfo *info)
map = (Uint16 *)info->table; map = (Uint16 *)info->table;
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (1) { dst += dstskip;
*dst = map[bit]; }
} 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++;
} }
byte <<= 1; src += srcskip;
dst++; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
@@ -134,24 +191,46 @@ static void BlitBto3(SDL_BlitInfo *info)
map = info->table; map = info->table;
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; 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; src += srcskip;
if (1) { dst += dstskip;
o = bit * 4; }
dst[0] = map[o++]; } else {
dst[1] = map[o++]; while (height--) {
dst[2] = map[o++]; 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;
} }
byte <<= 1; src += srcskip;
dst += 3; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
@@ -173,21 +252,40 @@ static void BlitBto4(SDL_BlitInfo *info)
map = (Uint32 *)info->table; map = (Uint32 *)info->table;
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (1) { dst += dstskip;
*dst = map[bit]; }
} 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++;
} }
byte <<= 1; src += srcskip;
dst++; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
@@ -207,38 +305,76 @@ static void BlitBto1Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
if (palmap) { if (palmap) {
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte >>= 1;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (bit != ckey) { dst += dstskip;
*dst = palmap[bit]; }
} 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;
} }
dst++; src += srcskip;
byte <<= 1; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} else { } else {
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = bit;
}
dst++;
byte >>= 1;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (bit != ckey) { dst += dstskip;
*dst = bit; }
} 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;
} }
dst++; src += srcskip;
byte <<= 1; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
} }
@@ -259,21 +395,40 @@ static void BlitBto2Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
dstskip /= 2; dstskip /= 2;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte >>= 1;
dstp++;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (bit != ckey) { dstp += dstskip;
*dstp = ((Uint16 *)palmap)[bit]; }
} 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++;
} }
byte <<= 1; src += srcskip;
dstp++; dstp += dstskip;
} }
src += srcskip;
dstp += dstskip;
} }
} }
@@ -292,21 +447,40 @@ static void BlitBto3Key(SDL_BlitInfo *info)
/* Set up some basic variables */ /* Set up some basic variables */
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; 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; src += srcskip;
if (bit != ckey) { dst += dstskip;
SDL_memcpy(dst, &palmap[bit * 4], 3); }
} 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;
} }
byte <<= 1; src += srcskip;
dst += 3; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
@@ -326,21 +500,40 @@ static void BlitBto4Key(SDL_BlitInfo *info)
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
dstskip /= 4; dstskip /= 4;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte >>= 1;
dstp++;
} }
bit = (byte & 0x80) >> 7; src += srcskip;
if (bit != ckey) { dstp += dstskip;
*dstp = ((Uint32 *)palmap)[bit]; }
} 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++;
} }
byte <<= 1; src += srcskip;
dstp++; dstp += dstskip;
} }
src += srcskip;
dstp += dstskip;
} }
} }
@@ -365,26 +558,50 @@ static void BlitBtoNAlpha(SDL_BlitInfo *info)
dstbpp = dstfmt->BytesPerPixel; dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; 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; src += srcskip;
if (1) { dst += dstskip;
sR = srcpal[bit].r; }
sG = srcpal[bit].g; } else {
sB = srcpal[bit].b; while (height--) {
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); Uint8 byte = 0, bit;
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); for (c = 0; c < width; ++c) {
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 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;
} }
byte <<= 1; src += srcskip;
dst += dstbpp; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
@@ -411,26 +628,50 @@ static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
dstbpp = dstfmt->BytesPerPixel; dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8; srcskip += width - (width + 7) / 8;
while (height--) { if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
Uint8 byte = 0, bit; while (height--) {
for (c = 0; c < width; ++c) { Uint8 byte = 0, bit;
if (!(c & 7)) { for (c = 0; c < width; ++c) {
byte = *src++; 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; src += srcskip;
if (bit != ckey) { dst += dstskip;
sR = srcpal[bit].r; }
sG = srcpal[bit].g; } else {
sB = srcpal[bit].b; while (height--) {
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); Uint8 byte = 0, bit;
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); for (c = 0; c < width; ++c) {
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 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;
} }
byte <<= 1; src += srcskip;
dst += dstbpp; dst += dstskip;
} }
src += srcskip;
dst += dstskip;
} }
} }
+16 -7
View File
@@ -219,6 +219,9 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
SDL_RendererInfo info; SDL_RendererInfo info;
SDL_WindowTextureData *data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); SDL_WindowTextureData *data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
int i; int i;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
if (data == NULL) { if (data == NULL) {
SDL_Renderer *renderer = 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, data->texture = SDL_CreateTexture(data->renderer, *format,
SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_STREAMING,
window->w, window->h); w, h);
if (!data->texture) { if (!data->texture) {
/* codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_WINDOWTEXTUREDATA and not leaked here. */ /* 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) */ 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 */ /* Create framebuffer data */
data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format); 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. */ /* 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); data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
if (!data->pixels) { if (!data->pixels) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@@ -337,6 +340,9 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window *window,
SDL_WindowTextureData *data; SDL_WindowTextureData *data;
SDL_Rect rect; SDL_Rect rect;
void *src; void *src;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
if (data == NULL || !data->texture) { 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 */ /* 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 + src = (void *)((Uint8 *)data->pixels +
rect.y * data->pitch + rect.y * data->pitch +
rect.x * data->bytes_per_pixel); rect.x * data->bytes_per_pixel);
@@ -2584,6 +2590,9 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window)
int bpp; int bpp;
Uint32 Rmask, Gmask, Bmask, Amask; Uint32 Rmask, Gmask, Bmask, Amask;
SDL_bool created_framebuffer = SDL_FALSE; 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 /* 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 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 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) SDL_bool SDL_HasWindowSurface(SDL_Window *window)
@@ -2695,8 +2704,8 @@ int SDL_UpdateWindowSurface(SDL_Window *window)
full_rect.x = 0; full_rect.x = 0;
full_rect.y = 0; full_rect.y = 0;
full_rect.w = window->w; SDL_GetWindowSizeInPixels(window, &full_rect.w, &full_rect.h);
full_rect.h = window->h;
return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1); return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
} }
+1 -1
View File
@@ -37,7 +37,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
SDL_DUMMY_DestroyWindowFramebuffer(_this, window); SDL_DUMMY_DestroyWindowFramebuffer(_this, window);
/* Create a new one */ /* Create a new one */
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) { if (surface == NULL) {
return -1; return -1;
@@ -43,7 +43,7 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format
/* Create a new one */ /* Create a new one */
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); 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); surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
if (surface == NULL) { if (surface == NULL) {
+1 -1
View File
@@ -71,7 +71,7 @@ CreateNewWindowFramebuffer(SDL_Window *window)
int w, h, bpp; int w, h, bpp;
Uint32 Rmask, Gmask, Bmask, Amask; Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(FRAMEBUFFER_FORMAT, &bpp, &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); return SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
} }
+1 -1
View File
@@ -55,7 +55,7 @@ int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
SDL_NGAGE_DestroyWindowFramebuffer(_this, window); SDL_NGAGE_DestroyWindowFramebuffer(_this, window);
/* Create a new one */ /* Create a new one */
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) { if (surface == NULL) {
return -1; return -1;
@@ -37,7 +37,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *for
SDL_OFFSCREEN_DestroyWindowFramebuffer(_this, window); SDL_OFFSCREEN_DestroyWindowFramebuffer(_this, window);
/* Create a new one */ /* Create a new one */
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (surface == NULL) { if (surface == NULL) {
return -1; return -1;
+7 -4
View File
@@ -39,6 +39,9 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo
_kernel_swi_regs regs; _kernel_swi_regs regs;
SDL_DisplayMode mode; SDL_DisplayMode mode;
int size; int size;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */ /* Free the old framebuffer surface */
RISCOS_DestroyWindowFramebuffer(_this, window); RISCOS_DestroyWindowFramebuffer(_this, window);
@@ -54,10 +57,10 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo
} }
/* Calculate pitch */ /* Calculate pitch */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3); *pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
/* Allocate the sprite area */ /* 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); driverdata->fb_area = SDL_malloc(size);
if (!driverdata->fb_area) { if (!driverdata->fb_area) {
return SDL_OutOfMemory(); 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[1] = (int)driverdata->fb_area;
regs.r[2] = (int)sprite_name; regs.r[2] = (int)sprite_name;
regs.r[3] = 0; regs.r[3] = 0;
regs.r[4] = window->w; regs.r[4] = w;
regs.r[5] = window->h; regs.r[5] = h;
regs.r[6] = sprite_mode; regs.r[6] = sprite_mode;
error = _kernel_swi(OS_SpriteOp, &regs, &regs); error = _kernel_swi(OS_SpriteOp, &regs, &regs);
if (error != NULL) { if (error != NULL) {
+7 -4
View File
@@ -31,6 +31,9 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void
size_t size; size_t size;
LPBITMAPINFO info; LPBITMAPINFO info;
HBITMAP hbm; HBITMAP hbm;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */ /* Free the old framebuffer surface */
if (data->mdc) { if (data->mdc) {
@@ -78,10 +81,10 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void
} }
/* Fill in the size information */ /* Fill in the size information */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3); *pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
info->bmiHeader.biWidth = window->w; info->bmiHeader.biWidth = w;
info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */ info->bmiHeader.biHeight = -h; /* negative for topdown bitmap */
info->bmiHeader.biSizeImage = (DWORD)window->h * (*pitch); info->bmiHeader.biSizeImage = (DWORD)h * (*pitch);
data->mdc = CreateCompatibleDC(data->hdc); data->mdc = CreateCompatibleDC(data->hdc);
data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0); data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
+20 -13
View File
@@ -54,6 +54,9 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
Display *display = data->videodata->display; Display *display = data->videodata->display;
XGCValues gcv; XGCValues gcv;
XVisualInfo vinfo; XVisualInfo vinfo;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
/* Free the old framebuffer surface */ /* Free the old framebuffer surface */
X11_DestroyWindowFramebuffer(_this, window); X11_DestroyWindowFramebuffer(_this, window);
@@ -76,14 +79,14 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
} }
/* Calculate pitch */ /* Calculate pitch */
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3); *pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
/* Create the actual image */ /* Create the actual image */
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
if (have_mitshm(display)) { if (have_mitshm(display)) {
XShmSegmentInfo *shminfo = &data->shminfo; 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) { if (shminfo->shmid >= 0) {
shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0); shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0);
shminfo->readOnly = False; shminfo->readOnly = False;
@@ -107,7 +110,7 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
data->ximage = X11_XShmCreateImage(display, data->visual, data->ximage = X11_XShmCreateImage(display, data->visual,
vinfo.depth, ZPixmap, vinfo.depth, ZPixmap,
shminfo->shmaddr, shminfo, shminfo->shmaddr, shminfo,
window->w, window->h); w, h);
if (!data->ximage) { if (!data->ximage) {
X11_XShmDetach(display, shminfo); X11_XShmDetach(display, shminfo);
X11_XSync(display, False); X11_XSync(display, False);
@@ -123,14 +126,14 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
} }
#endif /* not NO_SHARED_MEMORY */ #endif /* not NO_SHARED_MEMORY */
*pixels = SDL_malloc((size_t)window->h * (*pitch)); *pixels = SDL_malloc((size_t)h * (*pitch));
if (*pixels == NULL) { if (*pixels == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
data->ximage = X11_XCreateImage(display, data->visual, data->ximage = X11_XCreateImage(display, data->visual,
vinfo.depth, ZPixmap, 0, (char *)(*pixels), vinfo.depth, ZPixmap, 0, (char *)(*pixels),
window->w, window->h, 32, 0); w, h, 32, 0);
if (!data->ximage) { if (!data->ximage) {
SDL_free(*pixels); SDL_free(*pixels);
return SDL_SetError("Couldn't create XImage"); 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; Display *display = data->videodata->display;
int i; int i;
int x, y, w, h; int x, y, w, h;
int window_w, window_h;
SDL_GetWindowSizeInPixels(window, &window_w, &window_h);
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
if (data->use_mitshm) { if (data->use_mitshm) {
for (i = 0; i < numrects; ++i) { for (i = 0; i < numrects; ++i) {
@@ -166,11 +173,11 @@ int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects
y += h; y += h;
h += rects[i].y; h += rects[i].y;
} }
if (x + w > window->w) { if (x + w > window_w) {
w = window->w - x; w = window_w - x;
} }
if (y + h > window->h) { if (y + h > window_h) {
h = window->h - y; h = window_h - y;
} }
X11_XShmPutImage(display, data->xwindow, data->gc, data->ximage, 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; y += h;
h += rects[i].y; h += rects[i].y;
} }
if (x + w > window->w) { if (x + w > window_w) {
w = window->w - x; w = window_w - x;
} }
if (y + h > window->h) { if (y + h > window_h) {
h = window->h - y; h = window_h - y;
} }
X11_XPutImage(display, data->xwindow, data->gc, data->ximage, X11_XPutImage(display, data->xwindow, data->gc, data->ximage,