Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/SDL2' into dreamcastSDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
GPF committed Aug 14, 2024
2 parents 9c9e69f + dd6c663 commit 8f87a89
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 80 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:

- { name: Ubuntu 22.04 (CMake), os: ubuntu-22.04, shell: sh }
- { name: Ubuntu 22.04 (autotools), os: ubuntu-22.04, shell: sh, autotools: true }
- { name: iOS (CMake), os: macos-latest, shell: sh, cmake: '-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES="arm64"', cross: true, test-pkg-config: false }
- { name: tvOS (CMake), os: macos-latest, shell: sh, cmake: '-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_ARCHITECTURES="arm64"', cross: true, test-pkg-config: false }
- { name: MacOS (CMake), os: macos-latest, shell: sh, cmake: '-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"' }
- { name: MacOS (autotools), os: macos-latest, shell: sh, autotools: true }

Expand Down Expand Up @@ -107,7 +109,7 @@ jobs:
${{ matrix.platform.source_cmd }}
cmake --build build/ --config Release --verbose --parallel
- name: Run build-time tests (CMake)
if: "! matrix.platform.autotools"
if: ${{ ! matrix.platform.autotools && !matrix.platform.cross }}
run: |
${{ matrix.platform.source_cmd }}
set -eu
Expand Down Expand Up @@ -197,14 +199,17 @@ jobs:
${{ matrix.platform.source_cmd }}
cmake -S cmake/test -B cmake_config_build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
${{ matrix.platform.cmake }} \
-DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }}
cmake --build cmake_config_build --verbose
- name: Verify sdl2-config
if: ${{ !!matrix.platform.test-pkg-config }}
run: |
${{ matrix.platform.source_cmd }}
export PATH=${{ env.SDL2_DIR }}/bin:$PATH
cmake/test/test_sdlconfig.sh
- name: Verify sdl2.pc
if: ${{ !!matrix.platform.test-pkg-config }}
run: |
${{ matrix.platform.source_cmd }}
export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig
Expand Down
28 changes: 14 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ endif()
# so we'll just use libusb when it's available. libusb does not support iOS,
# so we default to yes on iOS.
# TODO: Windows can support libusb, the hid.c file just depends on Unix APIs
if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR ANDROID)
if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR VISIONOS OR WATCHOS OR ANDROID)
set(HIDAPI_SKIP_LIBUSB TRUE)
else()
set(HIDAPI_SKIP_LIBUSB FALSE)
Expand Down Expand Up @@ -244,7 +244,7 @@ endif()
if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS OR DREAMCAST OR SDL_CPU_ARM64EC)
set(OPT_DEF_LIBC ON)
endif()
if(WINDOWS OR DARWIN OR MACOSX OR IOS OR TVOS)
if(WINDOWS OR MACOS OR IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_SYSTEM_ICONV_DEFAULT OFF)
else()
set(SDL_SYSTEM_ICONV_DEFAULT ON)
Expand Down Expand Up @@ -2076,7 +2076,7 @@ elseif(APPLE)
# !!! FIXME: we need Carbon for some very old API calls in
# !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
# !!! FIXME: how to dump those.
if(DARWIN OR MACOSX)
if(MACOS)
set(SDL_FRAMEWORK_COCOA 1)
set(SDL_FRAMEWORK_CARBON 1)
endif()
Expand All @@ -2090,12 +2090,12 @@ elseif(APPLE)
set(HAVE_SDL_FILE TRUE)
endif()

if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/uikit/*.c)
endif()

if(SDL_MISC)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/ios/*.m)
else()
file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
Expand All @@ -2120,10 +2120,10 @@ elseif(APPLE)

if(SDL_JOYSTICK)
file(GLOB MFI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
set(SDL_JOYSTICK_MFI 1)
if(IOS)
if(IOS OR VISIONOS OR WATCHOS)
set(SDL_FRAMEWORK_COREMOTION 1)
endif()
set(SDL_FRAMEWORK_GAMECONTROLLER 1)
Expand Down Expand Up @@ -2164,7 +2164,7 @@ elseif(APPLE)
endif()

if(SDL_HAPTIC)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
set(SDL_HAPTIC_DUMMY 1)
else()
Expand All @@ -2178,7 +2178,7 @@ elseif(APPLE)
endif()

if(SDL_POWER)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
set(SDL_POWER_UIKIT 1)
else()
Expand Down Expand Up @@ -2211,7 +2211,7 @@ elseif(APPLE)
endif()

if(SDL_SENSOR)
if(IOS)
if(IOS OR VISIONOS OR WATCHOS)
set(SDL_SENSOR_COREMOTION 1)
set(HAVE_SDL_SENSORS TRUE)
file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
Expand All @@ -2221,7 +2221,7 @@ elseif(APPLE)

# iOS hack needed - http://code.google.com/p/ios-cmake/ ?
if(SDL_VIDEO)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_VIDEO_DRIVER_UIKIT 1)
set(SDL_FRAMEWORK_COREGRAPHICS 1)
set(SDL_FRAMEWORK_QUARTZCORE 1)
Expand All @@ -2242,7 +2242,7 @@ elseif(APPLE)
endif()

if(SDL_OPENGLES)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_FRAMEWORK_OPENGLES 1)
set(SDL_VIDEO_OPENGL_ES 1)
set(SDL_VIDEO_RENDER_OGL_ES 1)
Expand Down Expand Up @@ -2345,7 +2345,7 @@ elseif(APPLE)
endif()
endif()
if(SDL_FRAMEWORK_METAL)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
list(APPEND PKGCONFIG_LDFLAGS "-Wl,-framework,Metal")
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,Metal>")
else()
Expand All @@ -2358,7 +2358,7 @@ elseif(APPLE)
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,OpenGLES>")
endif()
if(SDL_FRAMEWORK_QUARTZCORE)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
list(APPEND PKGCONFIG_LDFLAGS "-Wl,-framework,QuartzCore")
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,QuartzCore>")
else()
Expand Down
2 changes: 1 addition & 1 deletion cmake/sdlchecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ macro(CheckPTHREAD)
elseif(BSDI)
set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
set(PTHREAD_LDFLAGS "")
elseif(DARWIN)
elseif(MACOS)
set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
# causes Carbon.p complaints?
# set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
Expand Down
10 changes: 6 additions & 4 deletions cmake/sdlplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ macro(SDL_DetectCMakePlatform)
set(SDL_CMAKE_PLATFORM QNX)
endif()
elseif(APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
set(SDL_CMAKE_PLATFORM DARWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
set(SDL_CMAKE_PLATFORM MACOSX)
if(CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
set(SDL_CMAKE_PLATFORM MACOS)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
set(SDL_CMAKE_PLATFORM TVOS)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
# !!! FIXME: remove the version check when we start requiring >= 3.14.0
if(CMAKE_VERSION VERSION_LESS 3.14)
set(SDL_CMAKE_PLATFORM IOS)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES ".*watchOS.*")
set(SDL_CMAKE_PLATFORM WATCHOS)
elseif (CMAKE_SYSTEM_NAME MATCHES "visionOS")
set(SDL_CMAKE_PLATFORM VISIONOS)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
message_error("BeOS support has been removed as of SDL 2.0.2.")
Expand Down
4 changes: 3 additions & 1 deletion cmake/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
option(TEST_STATIC "Test linking to static SDL2 library" ON)
add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")

if(APPLE)
# FIXME: how to target ios/tvos with Swift?
# https://gitlab.kitware.com/cmake/cmake/-/issues/20104
if(APPLE AND CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
# multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift
list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs)
if(count_osx_archs LESS_EQUAL 1)
Expand Down
3 changes: 2 additions & 1 deletion src/audio/coreaudio/SDL_coreaudio.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,13 @@ static BOOL update_audio_session(_THIS, SDL_bool open, SDL_bool allow_playandrec

if ((open_playback_devices || open_capture_devices) && !session_active) {
if (![session setActive:YES error:&err]) {
NSString *desc;
if ([err code] == AVAudioSessionErrorCodeResourceNotAvailable &&
category == AVAudioSessionCategoryPlayAndRecord) {
return update_audio_session(this, open, SDL_FALSE);
}

NSString *desc = err.description;
desc = err.description;
SDL_SetError("Could not activate Audio Session: %s", desc.UTF8String);
return NO;
}
Expand Down
24 changes: 16 additions & 8 deletions src/hidapi/ios/hid.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ - (int)updateConnectedSteamControllers:(BOOL) bForce
{
static uint64_t s_unLastUpdateTick = 0;
static mach_timebase_info_data_t s_timebase_info;
uint64_t ticksNow;
NSArray<CBPeripheral *> *peripherals;

if ( self.centralManager == nil )
{
Expand All @@ -301,7 +303,7 @@ - (int)updateConnectedSteamControllers:(BOOL) bForce
mach_timebase_info( &s_timebase_info );
}

uint64_t ticksNow = mach_approximate_time();
ticksNow = mach_approximate_time();
if ( !bForce && ( ( (ticksNow - s_unLastUpdateTick) * s_timebase_info.numer ) / s_timebase_info.denom ) < (5ull * NSEC_PER_SEC) )
return (int)self.deviceMap.count;

Expand All @@ -318,7 +320,7 @@ - (int)updateConnectedSteamControllers:(BOOL) bForce
if ( self.nPendingPairs > 0 )
return (int)self.deviceMap.count;

NSArray<CBPeripheral *> *peripherals = [self.centralManager retrieveConnectedPeripheralsWithServices: @[ [CBUUID UUIDWithString:@"180A"]]];
peripherals = [self.centralManager retrieveConnectedPeripheralsWithServices: @[ [CBUUID UUIDWithString:@"180A"]]];
for ( CBPeripheral *peripheral in peripherals )
{
// we already know this peripheral
Expand All @@ -328,8 +330,9 @@ - (int)updateConnectedSteamControllers:(BOOL) bForce
NSLog( @"connected peripheral: %@", peripheral );
if ( [peripheral.name isEqualToString:@"SteamController"] )
{
HIDBLEDevice *steamController;
self.nPendingPairs += 1;
HIDBLEDevice *steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
[self.deviceMap setObject:steamController forKey:peripheral];
[self.centralManager connectPeripheral:peripheral options:nil];
}
Expand Down Expand Up @@ -452,9 +455,10 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri

if ( [localName isEqualToString:@"SteamController"] )
{
HIDBLEDevice *steamController;
NSLog( @"%@ : %@ - %@", log, peripheral, advertisementData );
self.nPendingPairs += 1;
HIDBLEDevice *steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
[self.deviceMap setObject:steamController forKey:peripheral];
[self.centralManager connectPeripheral:peripheral options:nil];
}
Expand Down Expand Up @@ -851,11 +855,13 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
if ( ( vendor_id == 0 || vendor_id == VALVE_USB_VID ) &&
( product_id == 0 || product_id == D0G_BLE2_PID ) )
{
NSEnumerator<HIDBLEDevice *> *devices;
HIDBLEManager *bleManager = HIDBLEManager.sharedInstance;
[bleManager updateConnectedSteamControllers:false];
NSEnumerator<HIDBLEDevice *> *devices = [bleManager.deviceMap objectEnumerator];
devices = [bleManager.deviceMap objectEnumerator];
for ( HIDBLEDevice *device in devices )
{
struct hid_device_info *device_info;
// there are several brief windows in connecting to an already paired device and
// one long window waiting for users to confirm pairing where we don't want
// to consider a device ready - if we hand it back to SDL or another
Expand All @@ -873,7 +879,7 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
}
continue;
}
struct hid_device_info *device_info = (struct hid_device_info *)malloc( sizeof(struct hid_device_info) );
device_info = (struct hid_device_info *)malloc( sizeof(struct hid_device_info) );
memset( device_info, 0, sizeof(struct hid_device_info) );
device_info->next = root;
root = device_info;
Expand Down Expand Up @@ -947,12 +953,13 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char

int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
size_t written;
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;

if ( !device_handle.connected )
return -1;

size_t written = [device_handle get_feature_report:data[0] into:data];
written = [device_handle get_feature_report:data[0] into:data];

return written == length-1 ? (int)length : (int)written;
}
Expand All @@ -969,6 +976,7 @@ int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)

int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
{
int result;
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;

if ( !device_handle.connected )
Expand All @@ -978,7 +986,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
{
NSLog( @"hid_read_timeout with non-zero wait" );
}
int result = (int)[device_handle read_input_report:data];
result = (int)[device_handle read_input_report:data];
#if FEATURE_REPORT_LOGGING
NSLog( @"HIDBLE:hid_read_timeout (%d) [%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", result,
data[1], data[2], data[3], data[4], data[5], data[6],
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/iphoneos/SDL_mfijoystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
#if TARGET_OS_TV
else if (controller.microGamepad) {
Uint8 buttons[joystick->nbuttons];
int button_count = 0;
GCMicroGamepad *gamepad = controller.microGamepad;

Sint16 axes[] = {
Expand All @@ -1289,8 +1291,6 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
SDL_PrivateJoystickAxis(joystick, i, axes[i]);
}

Uint8 buttons[joystick->nbuttons];
int button_count = 0;
buttons[button_count++] = gamepad.buttonA.isPressed;
buttons[button_count++] = gamepad.buttonX.isPressed;
buttons[button_count++] = (device->pause_button_pressed > 0);
Expand Down
2 changes: 1 addition & 1 deletion src/power/uikit/SDL_syspower.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percen
#else /* TARGET_OS_TV */
@autoreleasepool {
UIDevice *uidev = [UIDevice currentDevice];
const float level = uidev.batteryLevel;

if (!SDL_UIKitLastPowerInfoQuery) {
SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
Expand Down Expand Up @@ -95,7 +96,6 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percen
break;
}

const float level = uidev.batteryLevel;
*percent = ((level < 0.0f) ? -1 : ((int)((level * 100) + 0.5f)));
}
#endif /* TARGET_OS_TV */
Expand Down
14 changes: 10 additions & 4 deletions src/video/uikit/SDL_uikitappdelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ - (instancetype)init

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSString *screenname;
NSBundle *bundle;
if (!(self = [super initWithNibName:nil bundle:nil])) {
return nil;
}

NSString *screenname = nibNameOrNil;
NSBundle *bundle = nibBundleOrNil;
screenname = nibNameOrNil;
bundle = nibBundleOrNil;

/* A launch screen may not exist. Fall back to launch images in that case. */
if (screenname) {
Expand Down Expand Up @@ -230,6 +232,10 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
/* Xcode 5 introduced a dictionary of launch images in Info.plist. */
if (launchimages) {
for (NSDictionary *dict in launchimages) {
#if !TARGET_OS_TV
UIInterfaceOrientationMask orientmask;
NSString *orientstring;
#endif
NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
NSString *sizestring = dict[@"UILaunchImageSize"];

Expand All @@ -247,8 +253,8 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
}

#if !TARGET_OS_TV
UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
NSString *orientstring = dict[@"UILaunchImageOrientation"];
orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
orientstring = dict[@"UILaunchImageOrientation"];

if (orientstring) {
if ([orientstring isEqualToString:@"PortraitUpsideDown"]) {
Expand Down
Loading

0 comments on commit 8f87a89

Please sign in to comment.