From afc1738ecb4a0c44a635bae42f51ce3cfbfc4e1c Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 7 Sep 2018 10:47:50 +0300 Subject: [PATCH 001/151] SDL_sensor.h, SDL_video.h: remove comma at end of enumerator lists. Avoids gcc -pedantic warnings, closes bug #4253. --- include/SDL_sensor.h | 2 +- include/SDL_video.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/SDL_sensor.h b/include/SDL_sensor.h index 7f566e1ccb679..fa19c41ff6772 100644 --- a/include/SDL_sensor.h +++ b/include/SDL_sensor.h @@ -71,7 +71,7 @@ typedef enum SDL_SENSOR_INVALID = -1, /**< Returned for an invalid sensor */ SDL_SENSOR_UNKNOWN, /**< Unknown sensor type */ SDL_SENSOR_ACCEL, /**< Accelerometer */ - SDL_SENSOR_GYRO, /**< Gyroscope */ + SDL_SENSOR_GYRO /**< Gyroscope */ } SDL_SensorType; /** diff --git a/include/SDL_video.h b/include/SDL_video.h index 41ca070135d9f..461f13805101c 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -175,7 +175,7 @@ typedef enum typedef enum { SDL_DISPLAYEVENT_NONE, /**< Never used */ - SDL_DISPLAYEVENT_ORIENTATION, /**< Display orientation has changed to data1 */ + SDL_DISPLAYEVENT_ORIENTATION /**< Display orientation has changed to data1 */ } SDL_DisplayEventID; typedef enum @@ -184,7 +184,7 @@ typedef enum SDL_ORIENTATION_LANDSCAPE, /**< The display is in landscape mode, with the right side up, relative to portrait mode */ SDL_ORIENTATION_LANDSCAPE_FLIPPED, /**< The display is in landscape mode, with the left side up, relative to portrait mode */ SDL_ORIENTATION_PORTRAIT, /**< The display is in portrait mode */ - SDL_ORIENTATION_PORTRAIT_FLIPPED, /**< The display is in portrait mode, upside down */ + SDL_ORIENTATION_PORTRAIT_FLIPPED /**< The display is in portrait mode, upside down */ } SDL_DisplayOrientation; /** From 33381d3d10852f9997251c7517c7805198dcf27c Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 7 Sep 2018 11:03:24 +0300 Subject: [PATCH 002/151] hidapi/SDL_hidapijoystick.c: fix build in C90 mode: src/joystick/hidapi/SDL_hidapijoystick.c: In function 'HIDAPI_InitializeDiscovery': src/joystick/hidapi/SDL_hidapijoystick.c:281: error: 'true' undeclared (first use in this function) src/joystick/hidapi/SDL_hidapijoystick.c:281: error: (Each undeclared identifier is reported only once src/joystick/hidapi/SDL_hidapijoystick.c:281: error: for each function it appears in.) src/joystick/hidapi/SDL_hidapijoystick.c: In function 'HIDAPI_UpdateDiscovery': src/joystick/hidapi/SDL_hidapijoystick.c:339: error: 'true' undeclared (first use in this function) src/joystick/hidapi/SDL_hidapijoystick.c:341: error: ISO C90 forbids mixed declarations and code --- src/joystick/hidapi/SDL_hidapijoystick.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 65168ae4c5f9b..7f45be8cdb5f0 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -278,7 +278,7 @@ HIDAPI_InitializeDiscovery() if (SDL_HIDAPI_discovery.m_pUdevMonitor) { udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor); SDL_HIDAPI_discovery.m_nUdevFd = udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor); - SDL_HIDAPI_discovery.m_bCanGetNotifications = true; + SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE; } } @@ -329,6 +329,7 @@ HIDAPI_UpdateDiscovery() */ for (;;) { struct pollfd PollUdev; + struct udev_device *pUdevDevice; PollUdev.fd = SDL_HIDAPI_discovery.m_nUdevFd; PollUdev.events = POLLIN; @@ -336,9 +337,9 @@ HIDAPI_UpdateDiscovery() break; } - SDL_HIDAPI_discovery.m_bHaveDevicesChanged = true; + SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE; - struct udev_device *pUdevDevice = udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor); + pUdevDevice = udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor); if (pUdevDevice) { udev_device_unref(pUdevDevice); } From 63848141c1a44bbe45d603b2df1f9f6f5b0286f5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 10 Sep 2018 22:59:49 -0700 Subject: [PATCH 003/151] Fixed building on tvOS without any sensor support --- Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj index df9f19b8bac01..f319c3b8c00d7 100644 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj @@ -208,6 +208,9 @@ F30D9CA7212CD0BF0047DF2E /* SDL_coremotionsensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F30D9CA4212CD0BF0047DF2E /* SDL_coremotionsensor.h */; }; F30D9CC6212CE92C0047DF2E /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = F30D9CC5212CE92C0047DF2E /* hid.m */; }; F30D9CC7212CE92C0047DF2E /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = F30D9CC5212CE92C0047DF2E /* hid.m */; }; + F36839CC214790950000F255 /* SDL_dummysensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F36839CA214790950000F255 /* SDL_dummysensor.h */; }; + F36839CD214790950000F255 /* SDL_dummysensor.c in Sources */ = {isa = PBXBuildFile; fileRef = F36839CB214790950000F255 /* SDL_dummysensor.c */; }; + F36839CE214790950000F255 /* SDL_dummysensor.c in Sources */ = {isa = PBXBuildFile; fileRef = F36839CB214790950000F255 /* SDL_dummysensor.c */; }; F3BDD79220F51CB8004ECBF3 /* SDL_hidapi_xbox360.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */; }; F3BDD79320F51CB8004ECBF3 /* SDL_hidapi_xbox360.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */; }; F3BDD79420F51CB8004ECBF3 /* SDL_hidapi_switch.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD78C20F51CB8004ECBF3 /* SDL_hidapi_switch.c */; }; @@ -542,6 +545,8 @@ F30D9CA3212CD0BF0047DF2E /* SDL_coremotionsensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_coremotionsensor.m; sourceTree = ""; }; F30D9CA4212CD0BF0047DF2E /* SDL_coremotionsensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_coremotionsensor.h; sourceTree = ""; }; F30D9CC5212CE92C0047DF2E /* hid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = hid.m; sourceTree = ""; }; + F36839CA214790950000F255 /* SDL_dummysensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_dummysensor.h; sourceTree = ""; }; + F36839CB214790950000F255 /* SDL_dummysensor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_dummysensor.c; sourceTree = ""; }; F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_xbox360.c; sourceTree = ""; }; F3BDD78C20F51CB8004ECBF3 /* SDL_hidapi_switch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_switch.c; sourceTree = ""; }; F3BDD78D20F51CB8004ECBF3 /* SDL_hidapi_xboxone.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_xboxone.c; sourceTree = ""; }; @@ -838,6 +843,7 @@ isa = PBXGroup; children = ( F30D9CA2212CD09E0047DF2E /* coremotion */, + F36839C9214790740000F255 /* dummy */, F30D9C9B212CD0980047DF2E /* SDL_sensor_c.h */, F30D9C9D212CD0990047DF2E /* SDL_sensor.c */, F30D9C9C212CD0990047DF2E /* SDL_syssensor.h */, @@ -862,6 +868,15 @@ path = hidapi; sourceTree = ""; }; + F36839C9214790740000F255 /* dummy */ = { + isa = PBXGroup; + children = ( + F36839CB214790950000F255 /* SDL_dummysensor.c */, + F36839CA214790950000F255 /* SDL_dummysensor.h */, + ); + path = dummy; + sourceTree = ""; + }; F3BDD77420F51C18004ECBF3 /* ios */ = { isa = PBXGroup; children = ( @@ -1370,6 +1385,7 @@ AA9FF9511637C6E5000DF050 /* SDL_messagebox.h in Headers */, AABCC3941640643D00AB8930 /* SDL_uikitmessagebox.h in Headers */, AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */, + F36839CC214790950000F255 /* SDL_dummysensor.h in Headers */, AADA5B8F16CCAB7C00107CF7 /* SDL_bits.h in Headers */, 56C181DF17C44D5E00406AE3 /* SDL_filesystem.h in Headers */, ); @@ -1565,6 +1581,7 @@ FAB598731BB5C31600BE72C5 /* SDL_iconv.c in Sources */, FAB598741BB5C31600BE72C5 /* SDL_malloc.c in Sources */, FAB598751BB5C31600BE72C5 /* SDL_qsort.c in Sources */, + F36839CE214790950000F255 /* SDL_dummysensor.c in Sources */, A7C19D2B212E552C00DF2152 /* SDL_displayevents.c in Sources */, FAB598761BB5C31600BE72C5 /* SDL_stdlib.c in Sources */, FAB598771BB5C31600BE72C5 /* SDL_string.c in Sources */, @@ -1720,6 +1737,7 @@ 0442EC5512FE1C3F004C9285 /* SDL_hints.c in Sources */, AA13B34A1FB8B27800D9FEE6 /* SDL_shape.c in Sources */, 0402A85812FE70C600CECEE3 /* SDL_render_gles2.c in Sources */, + F36839CD214790950000F255 /* SDL_dummysensor.c in Sources */, 0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */, 04BAC09D1300C1290055DE28 /* SDL_log.c in Sources */, 56EA86FB13E9EC2B002E47EB /* SDL_coreaudio.m in Sources */, From af823cc1d95704cf6b3f9f39a62c460041ef0886 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 10 Sep 2018 23:00:09 -0700 Subject: [PATCH 004/151] Fixed building on tvOS --- src/video/uikit/SDL_uikitmodes.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index e9224e1c15ee0..acf739b61bec8 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -324,6 +324,7 @@ @implementation SDL_DisplayModeData } } +#if !TARGET_OS_TV void SDL_OnApplicationDidChangeStatusBarOrientation() { BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation); @@ -372,6 +373,7 @@ void SDL_OnApplicationDidChangeStatusBarOrientation() SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation); } } +#endif /* !TARGET_OS_TV */ #endif /* SDL_VIDEO_DRIVER_UIKIT */ From 0b3a350c903c2bde462328642f03b4a0ab112b42 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 10 Sep 2018 23:01:33 -0700 Subject: [PATCH 005/151] Fixed Chinese IME support (thanks ???!) --- src/video/uikit/SDL_uikitviewcontroller.m | 109 +++++++++++++--------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 2962742356582..49a39b6bc07b6 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -74,6 +74,8 @@ @implementation SDL_uikitviewcontroller { #if SDL_IPHONE_KEYBOARD UITextField *textField; BOOL rotatingOrientation; + NSString *changeText; + NSString *obligateForBackspace; #endif } @@ -250,10 +252,12 @@ - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures /* Set ourselves up as a UITextFieldDelegate */ - (void)initKeyboard { + changeText = nil; + obligateForBackspace = @" "; /* 64 space */ textField = [[UITextField alloc] initWithFrame:CGRectZero]; textField.delegate = self; /* placeholder so there is something to delete! */ - textField.text = @" "; + textField.text = obligateForBackspace; /* set UITextInputTrait properties, mostly to defaults */ textField.autocapitalizationType = UITextAutocapitalizationTypeNone; @@ -267,11 +271,12 @@ - (void)initKeyboard textField.hidden = YES; keyboardVisible = NO; -#if !TARGET_OS_TV NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; +#if !TARGET_OS_TV [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; #endif + [center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil]; } - (void)setView:(UIView *)view @@ -310,11 +315,12 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO - (void)deinitKeyboard { -#if !TARGET_OS_TV NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; +#if !TARGET_OS_TV [center removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [center removeObserver:self name:UIKeyboardWillHideNotification object:nil]; #endif + [center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil]; } /* reveal onscreen virtual keyboard */ @@ -354,6 +360,50 @@ - (void)keyboardWillHide:(NSNotification *)notification [self setKeyboardHeight:0]; } +- (void)textFieldTextDidChange:(NSNotification *)notification +{ + if (changeText!=nil && textField.markedTextRange == nil) + { + NSUInteger len = changeText.length; + if (len > 0) { + /* Go through all the characters in the string we've been sent and + * convert them to key presses */ + int i; + for (i = 0; i < len; i++) { + unichar c = [changeText characterAtIndex:i]; + SDL_Scancode code; + Uint16 mod; + + if (c < 127) { + /* Figure out the SDL_Scancode and SDL_keymod for this unichar */ + code = unicharToUIKeyInfoTable[c].code; + mod = unicharToUIKeyInfoTable[c].mod; + } else { + /* We only deal with ASCII right now */ + code = SDL_SCANCODE_UNKNOWN; + mod = 0; + } + + if (mod & KMOD_SHIFT) { + /* If character uses shift, press shift down */ + SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT); + } + + /* send a keydown and keyup even for the character */ + SDL_SendKeyboardKey(SDL_PRESSED, code); + SDL_SendKeyboardKey(SDL_RELEASED, code); + + if (mod & KMOD_SHIFT) { + /* If character uses shift, press shift back up */ + SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); + } + } + SDL_SendKeyboardText([changeText UTF8String]); + } + changeText = nil; + } +} + - (void)updateKeyboard { CGAffineTransform t = self.view.transform; @@ -392,49 +442,20 @@ - (void)setKeyboardHeight:(int)height - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSUInteger len = string.length; - if (len == 0) { - /* it wants to replace text with nothing, ie a delete */ - SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE); - SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE); - } else { - /* go through all the characters in the string we've been sent and - * convert them to key presses */ - int i; - for (i = 0; i < len; i++) { - unichar c = [string characterAtIndex:i]; - Uint16 mod = 0; - SDL_Scancode code; - - if (c < 127) { - /* figure out the SDL_Scancode and SDL_keymod for this unichar */ - code = unicharToUIKeyInfoTable[c].code; - mod = unicharToUIKeyInfoTable[c].mod; - } else { - /* we only deal with ASCII right now */ - code = SDL_SCANCODE_UNKNOWN; - mod = 0; - } - - if (mod & KMOD_SHIFT) { - /* If character uses shift, press shift down */ - SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT); - } - - /* send a keydown and keyup even for the character */ - SDL_SendKeyboardKey(SDL_PRESSED, code); - SDL_SendKeyboardKey(SDL_RELEASED, code); - - if (mod & KMOD_SHIFT) { - /* If character uses shift, press shift back up */ - SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); - } + changeText = nil; + if (textField.markedTextRange == nil) { + /* it wants to replace text with nothing, ie a delete */ + SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE); + SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE); } - - SDL_SendKeyboardText([string UTF8String]); + if (textField.text.length < 16) { + textField.text = obligateForBackspace; + } + } else { + changeText = string; } - - return NO; /* don't allow the edit! (keep placeholder text there) */ + return YES; } /* Terminates the editing session */ @@ -498,7 +519,7 @@ - (BOOL)textFieldShouldReturn:(UITextField*)_textField @autoreleasepool { SDL_uikitviewcontroller *vc = GetWindowViewController(window); if (vc != nil) { - return vc.isKeyboardVisible; + return vc.keyboardVisible; } return SDL_FALSE; } From 6a7b0c27afd943313f4c0d4c2596d4fc5ee4e54f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 14 Sep 2018 12:41:29 -0700 Subject: [PATCH 006/151] Fixed crash launching under Steam on Mac OS X --- src/joystick/SDL_gamecontroller.c | 5 +++-- src/joystick/hidapi/SDL_hidapijoystick.c | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index fa647819c4147..8616950ed61c4 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -1462,6 +1462,7 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid) int i; Uint16 vendor; Uint16 product; + Uint16 version; Uint32 vidpid; if (SDL_allowed_controllers.num_entries == 0 && @@ -1469,7 +1470,7 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid) return SDL_FALSE; } - SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL); + SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version); if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) { /* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */ @@ -1477,7 +1478,7 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid) #if defined(__LINUX__) bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF); #elif defined(__MACOSX__) - bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0); + bSteamVirtualGamepad = (vendor == 0x045E && product == 0x028E && version == 1); #elif defined(__WIN32__) /* We can't tell on Windows, but Steam will block others in input hooks */ bSteamVirtualGamepad = SDL_TRUE; diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 7f45be8cdb5f0..e57caca159f31 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -736,15 +736,8 @@ HIDAPI_AddDevice(struct hid_device_info *info) device->guid.data[14] = 'h'; device->guid.data[15] = 0; } - device->driver = HIDAPI_GetDeviceDriver(device); - - if (device->driver) { - const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id); - if (name) { - device->name = SDL_strdup(name); - } - } + /* Need the device name before getting the driver to know whether to ignore this device */ if (!device->name && info->manufacturer_string && info->product_string) { char *manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t)); char *product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t)); @@ -781,6 +774,16 @@ HIDAPI_AddDevice(struct hid_device_info *info) SDL_snprintf(device->name, name_size, "0x%.4x/0x%.4x", info->vendor_id, info->product_id); } + device->driver = HIDAPI_GetDeviceDriver(device); + + if (device->driver) { + const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id); + if (name) { + SDL_free(device->name); + device->name = SDL_strdup(name); + } + } + device->path = SDL_strdup(info->path); if (!device->path) { SDL_free(device->name); @@ -789,7 +792,7 @@ HIDAPI_AddDevice(struct hid_device_info *info) } #ifdef DEBUG_HIDAPI - SDL_Log("Adding HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage); + SDL_Log("Adding HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x, driver = %s\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage, device->driver ? device->driver->hint : "NONE"); #endif /* Add it to the list */ From e8a0e35e24a4259e5d68a0f24f0994e20a81a457 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 14 Sep 2018 18:31:01 -0700 Subject: [PATCH 007/151] Use atomic reference counting for the HID device object --- Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 0 Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 src/hidapi/android/hid.cpp | 27 ++++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) mode change 100644 => 100755 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj mode change 100644 => 100755 Xcode/SDL/SDL.xcodeproj/project.pbxproj diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index 37b159b12a834..c9150d1e46332 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include // For ETIMEDOUT and ECONNRESET #include // For malloc() and free() @@ -27,6 +28,7 @@ #define HID_DEVICE_MANAGER_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, HIDDeviceManager, function) #include "../hidapi/hidapi.h" + typedef uint32_t uint32; typedef uint64_t uint64; @@ -364,12 +366,20 @@ class CHIDDevice int IncrementRefCount() { - return ++m_nRefCount; + int nValue; + pthread_mutex_lock( &m_refCountLock ); + nValue = ++m_nRefCount; + pthread_mutex_unlock( &m_refCountLock ); + return nValue; } int DecrementRefCount() { - return --m_nRefCount; + int nValue; + pthread_mutex_lock( &m_refCountLock ); + nValue = --m_nRefCount; + pthread_mutex_unlock( &m_refCountLock ); + return nValue; } int GetId() @@ -394,12 +404,20 @@ class CHIDDevice int IncrementDeviceRefCount() { - return ++m_nDeviceRefCount; + int nValue; + pthread_mutex_lock( &m_refCountLock ); + nValue = ++m_nDeviceRefCount; + pthread_mutex_unlock( &m_refCountLock ); + return nValue; } int DecrementDeviceRefCount() { - return --m_nDeviceRefCount; + int nValue; + pthread_mutex_lock( &m_refCountLock ); + nValue = --m_nDeviceRefCount; + pthread_mutex_unlock( &m_refCountLock ); + return nValue; } bool BOpen() @@ -644,6 +662,7 @@ class CHIDDevice } private: + pthread_mutex_t m_refCountLock = PTHREAD_MUTEX_INITIALIZER; int m_nRefCount = 0; int m_nId = 0; hid_device_info *m_pInfo = nullptr; From 66294d31dfc23bf621febc649081078669a2f2c5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 14 Sep 2018 18:31:03 -0700 Subject: [PATCH 008/151] Guard against Steam Controller input when we're shutting down. --- .../main/java/org/libsdl/app/HIDDeviceBLESteamController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java index b1ed5ac862937..bd9de19541991 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java @@ -479,7 +479,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris // Enable this for verbose logging of controller input reports //Log.v(TAG, "onCharacteristicChanged uuid=" + characteristic.getUuid() + " data=" + HexDump.dumpHexString(characteristic.getValue())); - if (characteristic.getUuid().equals(inputCharacteristic)) { + if (characteristic.getUuid().equals(inputCharacteristic) && !mFrozen) { mManager.HIDDeviceInputReport(getId(), characteristic.getValue()); } } From 6b3e893105e5775e3f0792d7d2d8921ee0144012 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 14 Sep 2018 19:26:26 -0700 Subject: [PATCH 009/151] Added hints SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to allow tuning double-click sensitivity. Also increased the default double-click radius to 32 pixels to be more forgiving for touch interfaces --- include/SDL_hints.h | 10 ++++++ src/events/SDL_mouse.c | 48 +++++++++++++++++++++------- src/events/SDL_mouse_c.h | 5 ++- src/video/windows/SDL_windowsmouse.c | 2 -- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 07a911338928c..3f6653bb98eea 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -262,6 +262,16 @@ extern "C" { */ #define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD" +/** + * \brief A variable setting the double click time, in milliseconds. + */ +#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME "SDL_MOUSE_DOUBLE_CLICK_TIME" + +/** + * \brief A variable setting the double click radius, in pixels. + */ +#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS "SDL_MOUSE_DOUBLE_CLICK_RADIUS" + /** * \brief A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode */ diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 55d248eed7ffd..ff23c5ea46e1b 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -33,12 +33,38 @@ /* The mouse state */ static SDL_Mouse SDL_mouse; -static Uint32 SDL_double_click_time = 500; -static int SDL_double_click_radius = 1; static int SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y); +static void SDLCALL +SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint) +{ + SDL_Mouse *mouse = (SDL_Mouse *)userdata; + + if (hint && *hint) { + mouse->double_click_time = SDL_atoi(hint); + } else { +#ifdef __WIN32__ + mouse->double_click_time = GetDoubleClickTime(); +#else + mouse->double_click_time = 500; +#endif + } +} + +static void SDLCALL +SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint) +{ + SDL_Mouse *mouse = (SDL_Mouse *)userdata; + + if (hint && *hint) { + mouse->double_click_radius = SDL_atoi(hint); + } else { + mouse->double_click_radius = 32; /* 32 pixels seems about right for touch interfaces */ + } +} + static void SDLCALL SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { @@ -83,6 +109,12 @@ SDL_MouseInit(void) SDL_zerop(mouse); + SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME, + SDL_MouseDoubleClickTimeChanged, mouse); + + SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS, + SDL_MouseDoubleClickRadiusChanged, mouse); + SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_MouseNormalSpeedScaleChanged, mouse); @@ -114,12 +146,6 @@ SDL_GetMouse(void) return &SDL_mouse; } -void -SDL_SetDoubleClickTime(Uint32 interval) -{ - SDL_double_click_time = interval; -} - SDL_Window * SDL_GetMouseFocus(void) { @@ -454,9 +480,9 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state if (state == SDL_PRESSED) { Uint32 now = SDL_GetTicks(); - if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) || - SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius || - SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) { + if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) || + SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius || + SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) { clickstate->click_count = 0; } clickstate->last_timestamp = now; diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 28089e0c43007..ad444922a4d92 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -90,6 +90,8 @@ typedef struct float relative_speed_scale; float scale_accum_x; float scale_accum_y; + Uint32 double_click_time; + int double_click_radius; SDL_bool touch_mouse_events; /* Data for double-click tracking */ @@ -112,9 +114,6 @@ extern int SDL_MouseInit(void); /* Get the mouse state structure */ SDL_Mouse *SDL_GetMouse(void); -/* Set the default double-click interval */ -extern void SDL_SetDoubleClickTime(Uint32 interval); - /* Set the default mouse cursor */ extern void SDL_SetDefaultCursor(SDL_Cursor * cursor); diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 1ddeae24beabd..eff31605b3b79 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -304,8 +304,6 @@ WIN_InitMouse(_THIS) mouse->GetGlobalMouseState = WIN_GetGlobalMouseState; SDL_SetDefaultCursor(WIN_CreateDefaultCursor()); - - SDL_SetDoubleClickTime(GetDoubleClickTime()); } void From bab5b0843730c6b479a4ba712f43767fc76ce3ba Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 15 Sep 2018 08:11:50 +0300 Subject: [PATCH 010/151] fix permissions --- Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 0 Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj mode change 100755 => 100644 Xcode/SDL/SDL.xcodeproj/project.pbxproj diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj old mode 100755 new mode 100644 diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100755 new mode 100644 From 5a34f1e3ee34fbc4b5668122655538953c2e2be6 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 15 Sep 2018 09:24:04 +0300 Subject: [PATCH 011/151] acinclude: rename ax_gcc_x86_cpuid.m4.htm to ax_gcc_x86_cpuid.m4 --- acinclude/{ax_gcc_x86_cpuid.m4.htm => ax_gcc_x86_cpuid.m4} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename acinclude/{ax_gcc_x86_cpuid.m4.htm => ax_gcc_x86_cpuid.m4} (100%) diff --git a/acinclude/ax_gcc_x86_cpuid.m4.htm b/acinclude/ax_gcc_x86_cpuid.m4 similarity index 100% rename from acinclude/ax_gcc_x86_cpuid.m4.htm rename to acinclude/ax_gcc_x86_cpuid.m4 From 305e5968aa6a39ab78c13383a43aa39857c7644a Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 15 Sep 2018 14:28:10 +0300 Subject: [PATCH 012/151] do not export hidapi symbols from SDL dlls (bug #4259). --- src/hidapi/hidapi/hidapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hidapi/hidapi/hidapi.h b/src/hidapi/hidapi/hidapi.h index 2057602807607..e9a74d559539b 100644 --- a/src/hidapi/hidapi/hidapi.h +++ b/src/hidapi/hidapi/hidapi.h @@ -29,7 +29,7 @@ #include -#if defined(_WIN32) && !defined(NAMESPACE) +#if defined(_WIN32) && !defined(NAMESPACE) && (0) /* SDL: don't export hidapi syms */ #define HID_API_EXPORT __declspec(dllexport) #define HID_API_CALL #else From 59a2d12cc34e912c7ed1bfa9a3019b2dd5f6f436 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 17 Sep 2018 11:35:22 -0700 Subject: [PATCH 013/151] Fixed creating an Android game controller mapping for HIDAPI devices on initialization --- src/joystick/SDL_gamecontroller.c | 8 ++++---- src/joystick/SDL_joystick.c | 14 +++++++++++++- src/joystick/SDL_joystick_c.h | 6 ++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 8616950ed61c4..baf85e58b83d6 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -432,12 +432,12 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG pSupportedController = pSupportedController->next; } if (!exact_match) { - if (guid->data[14] == 'h') { + if (SDL_IsJoystickHIDAPI(*guid)) { /* This is a HIDAPI device */ return s_pHIDAPIMapping; } #if SDL_JOYSTICK_XINPUT - if (guid->data[14] == 'x') { + if (SDL_IsJoystickXInput(*guid)) { /* This is an XInput device */ return s_pXInputMapping; } @@ -1026,8 +1026,8 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const } } #ifdef __ANDROID__ - if (!mapping) { - mapping = SDL_CreateMappingForAndroidController(name, guid); + if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) { + mapping = SDL_CreateMappingForAndroidController(name, guid); } #endif if (!mapping) { diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 72c5656d2655c..d274444fdc583 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1157,6 +1157,18 @@ SDL_IsJoystickXboxOne(Uint16 vendor, Uint16 product) return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController); } +SDL_bool +SDL_IsJoystickXInput(SDL_JoystickGUID guid) +{ + return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE; +} + +SDL_bool +SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid) +{ + return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE; +} + static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid) { static Uint32 wheel_joysticks[] = { @@ -1222,7 +1234,7 @@ static SDL_JoystickType SDL_GetJoystickGUIDType(SDL_JoystickGUID guid) Uint16 product; Uint32 vidpid; - if (guid.data[14] == 'x') { + if (SDL_IsJoystickXInput(guid)) { /* XInput GUID, get the type based on the XInput device subtype */ switch (guid.data[15]) { case 0x01: /* XINPUT_DEVSUBTYPE_GAMEPAD */ diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index b457617147e5b..1ede4a15964f4 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -62,6 +62,12 @@ extern SDL_bool SDL_IsJoystickXbox360(Uint16 vendor_id, Uint16 product_id); /* Function to return whether a joystick is an Xbox One controller */ extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id); +/* Function to return whether a joystick guid comes from the XInput driver */ +extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid); + +/* Function to return whether a joystick guid comes from the HIDAPI driver */ +extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid); + /* Function to return whether a joystick should be ignored */ extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid); From f6a537cbfa2cd01dce08e05b69a7f6281e6d0e68 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 17 Sep 2018 11:35:24 -0700 Subject: [PATCH 014/151] Store the API device refcount on the device itself, so if the device is disconnected and we have multiple application references to it, we only free it once. --- src/hidapi/android/hid.cpp | 89 ++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index c9150d1e46332..a8c6b1fdd3ccb 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -35,7 +35,8 @@ typedef uint64_t uint64; struct hid_device_ { - int nId; + int m_nId; + int m_nDeviceRefCount; }; static JavaVM *g_JVM; @@ -397,29 +398,6 @@ class CHIDDevice return m_pDevice; } - int GetDeviceRefCount() - { - return m_nDeviceRefCount; - } - - int IncrementDeviceRefCount() - { - int nValue; - pthread_mutex_lock( &m_refCountLock ); - nValue = ++m_nDeviceRefCount; - pthread_mutex_unlock( &m_refCountLock ); - return nValue; - } - - int DecrementDeviceRefCount() - { - int nValue; - pthread_mutex_lock( &m_refCountLock ); - nValue = --m_nDeviceRefCount; - pthread_mutex_unlock( &m_refCountLock ); - return nValue; - } - bool BOpen() { // Make sure thread is attached to JVM/env @@ -463,8 +441,9 @@ class CHIDDevice } m_pDevice = new hid_device; - m_pDevice->nId = m_nId; - m_nDeviceRefCount = 1; + m_pDevice->m_nId = m_nId; + m_pDevice->m_nDeviceRefCount = 1; + LOGD("Creating device %d (%p), refCount = 1\n", m_pDevice->m_nId, m_pDevice); return true; } @@ -668,7 +647,6 @@ class CHIDDevice hid_device_info *m_pInfo = nullptr; hid_device *m_pDevice = nullptr; bool m_bIsBLESteamController = false; - int m_nDeviceRefCount = 0; pthread_mutex_t m_dataLock = PTHREAD_MUTEX_INITIALIZER; // This lock has to be held to access m_vecData hid_buffer_pool m_vecData; @@ -688,6 +666,7 @@ class CHIDDevice class CHIDDevice; static pthread_mutex_t g_DevicesMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_DevicesRefCountMutex = PTHREAD_MUTEX_INITIALIZER; static hid_device_ref g_Devices; static hid_device_ref FindDevice( int nDeviceId ) @@ -943,14 +922,18 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx hid_device_ref< CHIDDevice > pDevice; { + hid_mutex_guard r( &g_DevicesRefCountMutex ); hid_mutex_guard l( &g_DevicesMutex ); for ( hid_device_ref pCurr = g_Devices; pCurr; pCurr = pCurr->next ) { if ( strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 ) { - if ( pCurr->GetDevice() ) { - pCurr->IncrementDeviceRefCount(); - return pCurr->GetDevice(); + hid_device *pValue = pCurr->GetDevice(); + if ( pValue ) + { + ++pValue->m_nDeviceRefCount; + LOGD("Incrementing device %d (%p), refCount = %d\n", pValue->m_nId, pValue, pValue->m_nDeviceRefCount); + return pValue; } // Hold a shared pointer to the controller for the duration @@ -968,8 +951,8 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length) { - LOGV( "hid_write id=%d length=%u", device->nId, length ); - hid_device_ref pDevice = FindDevice( device->nId ); + LOGV( "hid_write id=%d length=%u", device->m_nId, length ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { return pDevice->SendOutputReport( data, length ); @@ -980,8 +963,8 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned ch // TODO: Implement timeout? int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds) { -// LOGV( "hid_read_timeout id=%d length=%u timeout=%d", device->nId, length, milliseconds ); - hid_device_ref pDevice = FindDevice( device->nId ); +// LOGV( "hid_read_timeout id=%d length=%u timeout=%d", device->m_nId, length, milliseconds ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { return pDevice->GetInput( data, length ); @@ -993,7 +976,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned ch // TODO: Implement blocking int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length) { - LOGV( "hid_read id=%d length=%u", device->nId, length ); + LOGV( "hid_read id=%d length=%u", device->m_nId, length ); return hid_read_timeout( device, data, length, 0 ); } @@ -1005,8 +988,8 @@ int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int non int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length) { - LOGV( "hid_send_feature_report id=%d length=%u", device->nId, length ); - hid_device_ref pDevice = FindDevice( device->nId ); + LOGV( "hid_send_feature_report id=%d length=%u", device->m_nId, length ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { return pDevice->SendFeatureReport( data, length ); @@ -1018,8 +1001,8 @@ int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, cons // Synchronous operation. Will block until completed. int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length) { - LOGV( "hid_get_feature_report id=%d length=%u", device->nId, length ); - hid_device_ref pDevice = FindDevice( device->nId ); + LOGV( "hid_get_feature_report id=%d length=%u", device->m_nId, length ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { return pDevice->GetFeatureReport( data, length ); @@ -1030,26 +1013,28 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsig void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device) { - LOGV( "hid_close id=%d", device->nId ); - hid_device_ref pDevice = FindDevice( device->nId ); - if ( pDevice ) + LOGV( "hid_close id=%d", device->m_nId ); + hid_mutex_guard r( &g_DevicesRefCountMutex ); + LOGD("Decrementing device %d (%p), refCount = %d\n", device->m_nId, device, device->m_nDeviceRefCount - 1); + if ( --device->m_nDeviceRefCount == 0 ) { - pDevice->DecrementDeviceRefCount(); - if ( pDevice->GetDeviceRefCount() == 0 ) { + hid_device_ref pDevice = FindDevice( device->m_nId ); + if ( pDevice ) + { pDevice->Close( true ); } - } - else - { - // Couldn't find it, it's already closed - delete device; + else + { + delete device; + } + LOGD("Deleted device %p\n", device); } } int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen) { - hid_device_ref pDevice = FindDevice( device->nId ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { wcsncpy( string, pDevice->GetDeviceInfo()->manufacturer_string, maxlen ); @@ -1060,7 +1045,7 @@ int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen) { - hid_device_ref pDevice = FindDevice( device->nId ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { wcsncpy( string, pDevice->GetDeviceInfo()->product_string, maxlen ); @@ -1071,7 +1056,7 @@ int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *stri int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen) { - hid_device_ref pDevice = FindDevice( device->nId ); + hid_device_ref pDevice = FindDevice( device->m_nId ); if ( pDevice ) { wcsncpy( string, pDevice->GetDeviceInfo()->serial_number, maxlen ); From c179d3948aef44e163c3a5684ee64fa00c0964e4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 17 Sep 2018 12:08:05 -0700 Subject: [PATCH 015/151] Fixed NullPointerException if there's no singleton --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 839624f5e183a..b6c90d87107a7 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -520,7 +520,9 @@ public static void handleNativeState() { /* The native thread has finished */ public static void handleNativeExit() { SDLActivity.mSDLThread = null; - mSingleton.finish(); + if (mSingleton != null) { + mSingleton.finish(); + } } From c19516b50cda2e8db43f1e248798dfee49e90c7c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 18 Sep 2018 11:49:42 -0400 Subject: [PATCH 016/151] cmake: correctly report Vulkan support at configure time (thanks, Tiago!). Fixes Bugzilla #4262. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd0ac63a9ef70..1a7fe196d621b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1544,6 +1544,7 @@ endif() if(VIDEO_VULKAN) set(SDL_VIDEO_VULKAN 1) + set(HAVE_VIDEO_VULKAN TRUE) endif() # Dummies From 600126c90e8c4a1bd99c1557a7e37622f17d0b38 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 19 Sep 2018 10:03:40 -0700 Subject: [PATCH 017/151] Added experimental support for Windows.Gaming.Input --- src/joystick/hidapi/SDL_hidapi_xbox360.c | 269 ++++++++++++++++++++--- 1 file changed, 241 insertions(+), 28 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 43b2ff70d0bba..07b2b943f2ead 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -35,23 +35,41 @@ #ifdef SDL_JOYSTICK_HIDAPI_XBOX360 #ifdef __WIN32__ +#define SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT +/* This requires the Windows 10 SDK to build */ +/*#define SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT*/ +#endif + +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT #include "../../core/windows/SDL_xinput.h" #endif +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT +#include "../../core/windows/SDL_windows.h" +#define COBJMACROS +#include "windows.gaming.input.h" +#endif + #define USB_PACKET_LENGTH 64 typedef struct { Uint8 last_state[USB_PACKET_LENGTH]; Uint32 rumble_expiration; -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT SDL_bool xinput_enabled; Uint8 xinput_slot; #endif +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + SDL_bool coinitialized; + __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics *gamepad_statics; + __x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad; + struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration; +#endif } SDL_DriverXbox360_Context; -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT static Uint8 xinput_slots; static void @@ -104,7 +122,128 @@ HIDAPI_DriverXbox360_GuessXInputSlot(WORD wButtons) return XUSER_INDEX_ANY; } -#endif /* __WIN32__ */ +#endif /* SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT */ + +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + +static void +HIDAPI_DriverXbox360_InitWindowsGamingInput(SDL_DriverXbox360_Context *ctx) +{ + /* I think this takes care of RoInitialize() in a way that is compatible with the rest of SDL */ + if (FAILED(WIN_CoInitialize())) { + return; + } + ctx->coinitialized = SDL_TRUE; + + { + static const IID SDL_IID_IGamepadStatics = { 0x8BBCE529, 0xD49C, 0x39E9, { 0x95, 0x60, 0xE4, 0x7D, 0xDE, 0x96, 0xB7, 0xC8 } }; + HRESULT hr; + HMODULE hModule = LoadLibraryA("combase.dll"); + if (hModule != NULL) { + typedef HRESULT(WINAPI *WindowsCreateString_t)(PCNZWCH sourceString, UINT32 length, HSTRING* string); + typedef HRESULT(WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory); + + WindowsCreateString_t WindowsCreateStringFunc = (WindowsCreateString_t)GetProcAddress(hModule, "WindowsCreateString"); + RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory"); + if (WindowsCreateStringFunc && RoGetActivationFactoryFunc) { + LPTSTR pNamespace = L"Windows.Gaming.Input.Gamepad"; + HSTRING hNamespaceString; + + hr = WindowsCreateStringFunc(pNamespace, SDL_wcslen(pNamespace), &hNamespaceString); + if (SUCCEEDED(hr)) { + hr = RoGetActivationFactoryFunc(hNamespaceString, &SDL_IID_IGamepadStatics, &ctx->gamepad_statics); + if (SUCCEEDED(hr)) { + } + } + } + FreeLibrary(hModule); + } + } +} + +static Uint8 +HIDAPI_DriverXbox360_GetGamepadButtonsForMatch(__x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad) +{ + HRESULT hr; + struct __x_ABI_CWindows_CGaming_CInput_CGamepadReading state; + Uint8 buttons = 0; + + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_GetCurrentReading(gamepad, &state); + if (SUCCEEDED(hr)) { + if (state.Buttons & GamepadButtons_A) { + buttons |= (1 << SDL_CONTROLLER_BUTTON_A); + } + if (state.Buttons & GamepadButtons_B) { + buttons |= (1 << SDL_CONTROLLER_BUTTON_B); + } + if (state.Buttons & GamepadButtons_X) { + buttons |= (1 << SDL_CONTROLLER_BUTTON_X); + } + if (state.Buttons & GamepadButtons_Y) { + buttons |= (1 << SDL_CONTROLLER_BUTTON_Y); + } + } + return buttons; +} + +static void +HIDAPI_DriverXbox360_GuessGamepad(SDL_DriverXbox360_Context *ctx, Uint8 buttons) +{ + HRESULT hr; + __FIVectorView_1_Windows__CGaming__CInput__CGamepad *gamepads; + + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_get_Gamepads(ctx->gamepad_statics, &gamepads); + if (SUCCEEDED(hr)) { + unsigned int i, num_gamepads; + + hr = __FIVectorView_1_Windows__CGaming__CInput__CGamepad_get_Size(gamepads, &num_gamepads); + if (SUCCEEDED(hr)) { + int match_count; + unsigned int match_slot; + + match_count = 0; + for (i = 0; i < num_gamepads; ++i) { + __x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad; + + hr = __FIVectorView_1_Windows__CGaming__CInput__CGamepad_GetAt(gamepads, i, &gamepad); + if (SUCCEEDED(hr)) { + Uint8 gamepad_buttons = HIDAPI_DriverXbox360_GetGamepadButtonsForMatch(gamepad); + if (buttons == gamepad_buttons) { + ++match_count; + match_slot = i; + } + __x_ABI_CWindows_CGaming_CInput_CIGamepad_Release(gamepad); + } + } + if (match_count == 1) { + hr = __FIVectorView_1_Windows__CGaming__CInput__CGamepad_GetAt(gamepads, match_slot, &ctx->gamepad); + if (SUCCEEDED(hr)) { + } + } + } + __FIVectorView_1_Windows__CGaming__CInput__CGamepad_Release(gamepads); + } +} + +static void +HIDAPI_DriverXbox360_QuitWindowsGamingInput(SDL_DriverXbox360_Context *ctx) +{ + if (ctx->gamepad_statics) { + __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_Release(ctx->gamepad_statics); + ctx->gamepad_statics = NULL; + } + if (ctx->gamepad) { + __x_ABI_CWindows_CGaming_CInput_CIGamepad_Release(ctx->gamepad); + ctx->gamepad = NULL; + } + + if (ctx->coinitialized) { + WIN_CoUninitialize(); + ctx->coinitialized = SDL_FALSE; + } +} + +#endif /* SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT */ static SDL_bool HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number) @@ -146,12 +285,15 @@ HIDAPI_DriverXbox360_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor SDL_OutOfMemory(); return SDL_FALSE; } -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT ctx->xinput_enabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE); if (ctx->xinput_enabled && WIN_LoadXInputDLL() < 0) { ctx->xinput_enabled = SDL_FALSE; } ctx->xinput_slot = XUSER_INDEX_ANY; +#endif +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + HIDAPI_DriverXbox360_InitWindowsGamingInput(ctx); #endif *context = ctx; @@ -170,8 +312,25 @@ static int HIDAPI_DriverXbox360_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) { SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context; + #ifdef __WIN32__ - if (ctx->xinput_slot != XUSER_INDEX_ANY) { + SDL_bool rumbled = SDL_FALSE; + +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + if (!rumbled && ctx->gamepad) { + HRESULT hr; + + ctx->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16; + ctx->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16; + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(ctx->gamepad, ctx->vibration); + if (SUCCEEDED(hr)) { + rumbled = SDL_TRUE; + } + } +#endif + +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT + if (!rumbled && ctx->xinput_slot != XUSER_INDEX_ANY) { XINPUT_VIBRATION XVibration; if (!XINPUTSETSTATE) { @@ -180,11 +339,16 @@ HIDAPI_DriverXbox360_Rumble(SDL_Joystick *joystick, hid_device *dev, void *conte XVibration.wLeftMotorSpeed = low_frequency_rumble; XVibration.wRightMotorSpeed = high_frequency_rumble; - if (XINPUTSETSTATE(ctx->xinput_slot, &XVibration) != ERROR_SUCCESS) { + if (XINPUTSETSTATE(ctx->xinput_slot, &XVibration) == ERROR_SUCCESS) { + rumbled = SDL_TRUE; + } else { return SDL_SetError("XInputSetState() failed"); } } -#else +#endif /* SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT */ + +#else /* !__WIN32__ */ + #ifdef __MACOSX__ /* On Mac OS X the 360Controller driver uses this short report, and we need to prefix it with a magic token so hidapi passes it through untouched @@ -217,11 +381,14 @@ HIDAPI_DriverXbox360_Rumble(SDL_Joystick *joystick, hid_device *dev, void *conte /* This is the packet format for Xbox 360 and Xbox One controllers on Windows, however with this interface there is no rumble support, no guide button, and the left and right triggers are tied together as a single axis. + + We use XInput and Windows.Gaming.Input to make up for these shortcomings. */ static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size) { Sint16 axis; + SDL_bool has_trigger_data = SDL_FALSE; if (ctx->last_state[10] != data[10]) { SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A, (data[10] & 0x01) ? SDL_PRESSED : SDL_RELEASED); @@ -290,31 +457,82 @@ HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, axis = (int)*(Uint16*)(&data[6]) - 0x8000; SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis); - if (ctx->xinput_slot == XUSER_INDEX_ANY && HIDAPI_DriverXbox360_MissingXInputSlot()) { - WORD wButtons = 0; +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + if (ctx->gamepad_statics && !ctx->gamepad) { + Uint8 buttons = 0; if (data[10] & 0x01) { - wButtons |= XINPUT_GAMEPAD_A; + buttons |= (1 << SDL_CONTROLLER_BUTTON_A); } if (data[10] & 0x02) { - wButtons |= XINPUT_GAMEPAD_B; + buttons |= (1 << SDL_CONTROLLER_BUTTON_B); } if (data[10] & 0x04) { - wButtons |= XINPUT_GAMEPAD_X; + buttons |= (1 << SDL_CONTROLLER_BUTTON_X); } if (data[10] & 0x08) { - wButtons |= XINPUT_GAMEPAD_Y; + buttons |= (1 << SDL_CONTROLLER_BUTTON_Y); + } + if (buttons != 0) { + HIDAPI_DriverXbox360_GuessGamepad(ctx, buttons); } - if (wButtons != 0) { - Uint8 xinput_slot = HIDAPI_DriverXbox360_GuessXInputSlot(wButtons); - if (xinput_slot != XUSER_INDEX_ANY) { - HIDAPI_DriverXbox360_MarkXInputSlotUsed(xinput_slot); - ctx->xinput_slot = xinput_slot; + } + + if (ctx->gamepad) { + HRESULT hr; + struct __x_ABI_CWindows_CGaming_CInput_CGamepadReading state; + + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_GetCurrentReading(ctx->gamepad, &state); + if (SUCCEEDED(hr)) { + SDL_Log("Windows.Gaming.Input buttons: 0x%x\n", state.Buttons); + SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (state.Buttons & 0x40000000) ? SDL_PRESSED : SDL_RELEASED); + SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, ((int)(state.LeftTrigger * SDL_MAX_UINT16)) - 32768); + SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, ((int)(state.RightTrigger * SDL_MAX_UINT16)) - 32768); + has_trigger_data = SDL_TRUE; + } + } +#endif /* SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT */ + +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT + if (ctx->xinput_enabled) { + if (ctx->xinput_slot == XUSER_INDEX_ANY && HIDAPI_DriverXbox360_MissingXInputSlot()) { + WORD wButtons = 0; + + if (data[10] & 0x01) { + wButtons |= XINPUT_GAMEPAD_A; + } + if (data[10] & 0x02) { + wButtons |= XINPUT_GAMEPAD_B; + } + if (data[10] & 0x04) { + wButtons |= XINPUT_GAMEPAD_X; + } + if (data[10] & 0x08) { + wButtons |= XINPUT_GAMEPAD_Y; + } + if (wButtons != 0) { + Uint8 xinput_slot = HIDAPI_DriverXbox360_GuessXInputSlot(wButtons); + if (xinput_slot != XUSER_INDEX_ANY) { + HIDAPI_DriverXbox360_MarkXInputSlotUsed(xinput_slot); + ctx->xinput_slot = xinput_slot; + } + } + } + + if (!has_trigger_data && ctx->xinput_slot != XUSER_INDEX_ANY) { + XINPUT_STATE_EX xinput_state; + + if (XINPUTGETSTATE(ctx->xinput_slot, &xinput_state) == ERROR_SUCCESS) { + SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (xinput_state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) ? SDL_PRESSED : SDL_RELEASED); + SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, ((int)xinput_state.Gamepad.bLeftTrigger * 257) - 32768); + SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, ((int)xinput_state.Gamepad.bRightTrigger * 257) - 32768); + has_trigger_data = SDL_TRUE; } } } +#endif /* SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT */ - if (ctx->xinput_slot == XUSER_INDEX_ANY) { + if (!has_trigger_data) { axis = (data[9] * 257) - 32768; if (data[9] < 0x80) { axis = -axis * 2 - 32769; @@ -326,14 +544,6 @@ HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, SDL_MIN_SINT16); SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_MIN_SINT16); } - } else { - XINPUT_STATE_EX xinput_state; - - if (XINPUTGETSTATE(ctx->xinput_slot, &xinput_state) == ERROR_SUCCESS) { - SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (xinput_state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) ? SDL_PRESSED : SDL_RELEASED); - SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, ((int)xinput_state.Gamepad.bLeftTrigger * 257) - 32768); - SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, ((int)xinput_state.Gamepad.bRightTrigger * 257) - 32768); - } } SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state))); @@ -542,13 +752,16 @@ HIDAPI_DriverXbox360_Update(SDL_Joystick *joystick, hid_device *dev, void *conte static void HIDAPI_DriverXbox360_Quit(SDL_Joystick *joystick, hid_device *dev, void *context) { -#ifdef __WIN32__ SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context; +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT if (ctx->xinput_enabled) { HIDAPI_DriverXbox360_MarkXInputSlotFree(ctx->xinput_slot); WIN_UnloadXInputDLL(); } +#endif +#ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT + HIDAPI_DriverXbox360_InitWindowsGamingInput(ctx); #endif SDL_free(context); } From e8b0859f17b01ec501c7aa20b977c760f064ddac Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 20 Sep 2018 15:55:52 -0700 Subject: [PATCH 018/151] Added missing call to WindowsDeleteString() --- src/joystick/hidapi/SDL_hidapi_xbox360.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 07b2b943f2ead..906e1c95b8d0c 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -140,20 +140,21 @@ HIDAPI_DriverXbox360_InitWindowsGamingInput(SDL_DriverXbox360_Context *ctx) HRESULT hr; HMODULE hModule = LoadLibraryA("combase.dll"); if (hModule != NULL) { - typedef HRESULT(WINAPI *WindowsCreateString_t)(PCNZWCH sourceString, UINT32 length, HSTRING* string); - typedef HRESULT(WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory); + typedef HRESULT (WINAPI *WindowsCreateString_t)(PCNZWCH sourceString, UINT32 length, HSTRING* string); + typedef HRESULT (WINAPI *WindowsDeleteString_t)(HSTRING string); + typedef HRESULT (WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory); WindowsCreateString_t WindowsCreateStringFunc = (WindowsCreateString_t)GetProcAddress(hModule, "WindowsCreateString"); + WindowsDeleteString_t WindowsDeleteStringFunc = (WindowsDeleteString_t)GetProcAddress(hModule, "WindowsDeleteString"); RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory"); - if (WindowsCreateStringFunc && RoGetActivationFactoryFunc) { + if (WindowsCreateStringFunc && WindowsDeleteStringFunc && RoGetActivationFactoryFunc) { LPTSTR pNamespace = L"Windows.Gaming.Input.Gamepad"; HSTRING hNamespaceString; hr = WindowsCreateStringFunc(pNamespace, SDL_wcslen(pNamespace), &hNamespaceString); if (SUCCEEDED(hr)) { - hr = RoGetActivationFactoryFunc(hNamespaceString, &SDL_IID_IGamepadStatics, &ctx->gamepad_statics); - if (SUCCEEDED(hr)) { - } + RoGetActivationFactoryFunc(hNamespaceString, &SDL_IID_IGamepadStatics, &ctx->gamepad_statics); + WindowsDeleteStringFunc(hNamespaceString); } } FreeLibrary(hModule); From d07fe7ad95e431be9135e90d5e26d25a4099e3a3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 21 Sep 2018 09:41:21 -0700 Subject: [PATCH 019/151] Removed button logging message --- src/joystick/hidapi/SDL_hidapi_xbox360.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 906e1c95b8d0c..d8c5edb9ab788 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -485,7 +485,6 @@ HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_GetCurrentReading(ctx->gamepad, &state); if (SUCCEEDED(hr)) { - SDL_Log("Windows.Gaming.Input buttons: 0x%x\n", state.Buttons); SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (state.Buttons & 0x40000000) ? SDL_PRESSED : SDL_RELEASED); SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, ((int)(state.LeftTrigger * SDL_MAX_UINT16)) - 32768); SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, ((int)(state.RightTrigger * SDL_MAX_UINT16)) - 32768); From 8aaef4b914f6ca68cc9e963dd8c8cc066da1603e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 08:41:59 -0700 Subject: [PATCH 020/151] Fixed bug 3166 - It would be nice, if SDL would support including SDL project as a subdirectory into another CMake project Wayde Reitsma After attempting to use SDL2 in the way described in this bug, I found the main issue was the includes not being added to the compiler command. I found the issue was that the target_include_directories commands for the SDL2, SDL2-static and SDL2main targets only sets the public includes for installations using the INSTALL_INTERFACE generator expression. I have written a patch to CMakeLists.txt that fixes this issue by adding another item to the target_include_directories commands, utilizing the BUILD_INTERFACE generator expression to correctly add the include directory during builds. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a7fe196d621b..91672536380f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1718,7 +1718,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") # Always build SDLmain add_library(SDL2main STATIC ${SDLMAIN_SOURCES}) -target_include_directories(SDL2main PUBLIC $) +target_include_directories(SDL2main PUBLIC "$" $) set(_INSTALL_LIBS "SDL2main") if (NOT ANDROID) set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) @@ -1747,7 +1747,7 @@ if(SDL_SHARED) endif() set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS}) target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) - target_include_directories(SDL2 PUBLIC $) + target_include_directories(SDL2 PUBLIC "$" $) if (NOT ANDROID) set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) endif() @@ -1773,7 +1773,7 @@ if(SDL_STATIC) # libraries - do we need to consider this? set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS}) target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) - target_include_directories(SDL2-static PUBLIC $) + target_include_directories(SDL2-static PUBLIC "$" $) if (NOT ANDROID) set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) endif() From 58021b3834fcb32b0ece202753a6163d4c80d767 Mon Sep 17 00:00:00 2001 From: Drew Pirrone-Brusse Date: Sat, 18 Aug 2018 17:23:40 -0400 Subject: [PATCH 021/151] Correct the name of the SDL shared library in CMake for Mac OS --- CMakeLists.txt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91672536380f0..659a61b7d8048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1727,7 +1727,9 @@ endif() if(SDL_SHARED) add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES}) if(APPLE) - set_target_properties(SDL2 PROPERTIES MACOSX_RPATH 1) + set_target_properties(SDL2 PROPERTIES + MACOSX_RPATH 1 + OUTPUT_NAME "SDL2-${LT_RELEASE}") elseif(UNIX AND NOT ANDROID) set_target_properties(SDL2 PROPERTIES VERSION ${LT_VERSION} @@ -1840,17 +1842,14 @@ endif() if(NOT (WINDOWS OR CYGWIN)) if(SDL_SHARED) - if (APPLE) - set(SOEXT "dylib") - else() - set(SOEXT "so") - endif() + set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc. + get_target_property(SONAME SDL2 OUTPUT_NAME) if(NOT ANDROID) install(CODE " execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink - \"libSDL2-2.0${SOPOSTFIX}.${SOEXT}\" \"libSDL2.${SOEXT}\")" + \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\")" WORKING_DIR "${SDL2_BINARY_DIR}") - install(FILES ${SDL2_BINARY_DIR}/libSDL2.${SOEXT} DESTINATION "lib${LIB_SUFFIX}") + install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "lib${LIB_SUFFIX}") endif() endif() if(FREEBSD) From 5febdfcece40145f8394e6fe676db9436c6394df Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 11:49:25 -0700 Subject: [PATCH 022/151] Fixed whitespace --- src/SDL.c | 14 +- src/audio/alsa/SDL_alsa_audio.c | 2 +- src/audio/arts/SDL_artsaudio.c | 2 +- src/audio/directsound/SDL_directsound.c | 6 +- src/audio/pulseaudio/SDL_pulseaudio.c | 2 +- src/audio/winmm/SDL_winmm.c | 5 +- src/core/android/SDL_android.c | 4 +- src/core/linux/SDL_dbus.h | 9 +- src/core/linux/SDL_udev.h | 4 +- src/core/winrt/SDL_winrtapp_xaml.cpp | 2 +- src/joystick/SDL_gamecontroller.c | 2 +- src/joystick/SDL_joystick.c | 14 +- src/joystick/controller_type.h | 77 +- src/joystick/haiku/SDL_haikujoystick.cc | 2 +- src/joystick/windows/SDL_windowsjoystick.c | 2 +- src/main/haiku/SDL_BApp.h | 2 +- src/main/haiku/SDL_BeApp.cc | 50 +- src/stdlib/SDL_iconv.c | 16 +- src/video/SDL_blit_1.c | 220 ++-- src/video/SDL_blit_A.c | 1070 ++++++++++---------- src/video/SDL_egl.c | 4 +- src/video/SDL_pixels.c | 2 +- src/video/SDL_shape_internals.h | 12 +- src/video/SDL_video.c | 9 +- src/video/SDL_vulkan_utils.c | 8 +- src/video/SDL_yuv.c | 26 +- src/video/android/SDL_androidvideo.c | 8 +- src/video/cocoa/SDL_cocoaevents.m | 4 +- src/video/cocoa/SDL_cocoametalview.m | 6 +- src/video/cocoa/SDL_cocoamousetap.m | 2 +- src/video/cocoa/SDL_cocoawindow.m | 4 +- src/video/directfb/SDL_DirectFB_video.c | 2 +- src/video/haiku/SDL_BWin.h | 2 +- src/video/haiku/SDL_bclipboard.cc | 84 +- src/video/haiku/SDL_bevents.cc | 2 +- src/video/haiku/SDL_bframebuffer.cc | 340 +++---- src/video/haiku/SDL_bkeyboard.cc | 256 ++--- src/video/haiku/SDL_bmodes.cc | 408 ++++---- src/video/haiku/SDL_bvideo.cc | 35 +- src/video/haiku/SDL_bwindow.cc | 156 +-- src/video/kmsdrm/SDL_kmsdrmmouse.c | 10 +- src/video/kmsdrm/SDL_kmsdrmopengles.c | 18 +- src/video/raspberry/SDL_rpivideo.c | 18 +- src/video/uikit/SDL_uikitappdelegate.m | 2 +- src/video/uikit/SDL_uikitmodes.m | 2 +- src/video/uikit/SDL_uikitview.m | 36 +- src/video/wayland/SDL_waylandevents.c | 8 +- src/video/wayland/SDL_waylandtouch.c | 6 +- src/video/wayland/SDL_waylandvideo.c | 8 +- src/video/wayland/SDL_waylandwindow.c | 16 +- src/video/windows/SDL_windowsopengl.h | 48 +- src/video/windows/SDL_windowsvulkan.c | 2 +- src/video/x11/SDL_x11opengl.h | 16 +- src/video/x11/SDL_x11sym.h | 4 +- 54 files changed, 1519 insertions(+), 1550 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 5a1e0febeae60..6d7e166629b5a 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -124,11 +124,11 @@ SDL_InitSubSystem(Uint32 flags) } #if SDL_VIDEO_DRIVER_WINDOWS - if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) { - if (SDL_HelperWindowCreate() < 0) { - return -1; - } - } + if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) { + if (SDL_HelperWindowCreate() < 0) { + return -1; + } + } #endif #if !SDL_TIMERS_DISABLED @@ -263,8 +263,8 @@ SDL_QuitSubSystem(Uint32 flags) #if !SDL_SENSOR_DISABLED if ((flags & SDL_INIT_SENSOR)) { if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) { - SDL_SensorQuit(); - } + SDL_SensorQuit(); + } SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR); } #endif diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 48b9c0caed7d5..eff192b7e8d31 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -445,7 +445,7 @@ static void ALSA_CloseDevice(_THIS) { if (this->hidden->pcm_handle) { - /* Wait for the submitted audio to drain + /* Wait for the submitted audio to drain ALSA_snd_pcm_drop() can hang, so don't use that. */ Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2; diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index 4e3ebf2ce67e8..47bad4bd4ca27 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/src/audio/arts/SDL_artsaudio.c @@ -39,7 +39,7 @@ #include "SDL_name.h" #include "SDL_loadso.h" #else -#define SDL_NAME(X) X +#define SDL_NAME(X) X #endif #ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index 09b83aedf43e5..a943ba29e30fd 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -477,8 +477,8 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) SDL_bool tried_format = SDL_FALSE; SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); LPGUID guid = (LPGUID) handle; - DWORD bufsize; - + DWORD bufsize; + /* Initialize all variables that we clean on shutdown */ this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); @@ -526,7 +526,7 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) (int) (DSBSIZE_MAX / numchunks)); } else { int rc; - WAVEFORMATEX wfmt; + WAVEFORMATEX wfmt; SDL_zero(wfmt); if (SDL_AUDIO_ISFLOAT(this->spec.format)) { wfmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 1e985806368fa..053a1c34af900 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -109,7 +109,7 @@ static pa_operation * (*PULSEAUDIO_pa_stream_drain) (pa_stream *, pa_stream_success_cb_t, void *); static int (*PULSEAUDIO_pa_stream_peek) (pa_stream *, const void **, size_t *); static int (*PULSEAUDIO_pa_stream_drop) (pa_stream *); -static pa_operation * (*PULSEAUDIO_pa_stream_flush) (pa_stream *, +static pa_operation * (*PULSEAUDIO_pa_stream_flush) (pa_stream *, pa_stream_success_cb_t, void *); static int (*PULSEAUDIO_pa_stream_disconnect) (pa_stream *); static void (*PULSEAUDIO_pa_stream_unref) (pa_stream *); diff --git a/src/audio/winmm/SDL_winmm.c b/src/audio/winmm/SDL_winmm.c index 8e5c17ba1a950..20426f13ac7a0 100644 --- a/src/audio/winmm/SDL_winmm.c +++ b/src/audio/winmm/SDL_winmm.c @@ -78,7 +78,7 @@ static void DetectWave##typ##Devs(void) { \ capstyp##2W caps; \ UINT i; \ for (i = 0; i < devcount; i++) { \ - if (wave##typ##GetDevCaps(i,(LP##capstyp##W)&caps,sizeof(caps))==MMSYSERR_NOERROR) { \ + if (wave##typ##GetDevCaps(i,(LP##capstyp##W)&caps,sizeof(caps))==MMSYSERR_NOERROR) { \ char *name = WIN_LookupAudioDeviceName(caps.szPname,&caps.NameGuid); \ if (name != NULL) { \ SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i+1)); \ @@ -375,8 +375,7 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) #endif /* Create the audio buffer semaphore */ - this->hidden->audio_sem = - CreateSemaphore(NULL, iscapture ? 0 : NUM_BUFFERS - 1, NUM_BUFFERS, NULL); + this->hidden->audio_sem = CreateSemaphore(NULL, iscapture ? 0 : NUM_BUFFERS - 1, NUM_BUFFERS, NULL); if (this->hidden->audio_sem == NULL) { return SDL_SetError("Couldn't create semaphore"); } diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 91786042de321..15a1a74f2aa7b 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -77,7 +77,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)( JNIEnv* env, jclass jcls, jint surfaceWidth, jint surfaceHeight, - jint deviceWidth, jint deviceHeight, jint format, jfloat rate); + jint deviceWidth, jint deviceHeight, jint format, jfloat rate); JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)( JNIEnv* env, jclass jcls); @@ -537,7 +537,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)( JNIEnv* env, jclass jcls, jint surfaceWidth, jint surfaceHeight, - jint deviceWidth, jint deviceHeight, jint format, jfloat rate) + jint deviceWidth, jint deviceHeight, jint format, jfloat rate) { Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate); } diff --git a/src/core/linux/SDL_dbus.h b/src/core/linux/SDL_dbus.h index 062543d4626ab..aa787f223c828 100644 --- a/src/core/linux/SDL_dbus.h +++ b/src/core/linux/SDL_dbus.h @@ -39,9 +39,8 @@ typedef struct SDL_DBusContext { void (*bus_add_match)(DBusConnection *, const char *, DBusError *); DBusConnection * (*connection_open_private)(const char *, DBusError *); void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t); - dbus_bool_t (*connection_get_is_connected)(DBusConnection *); - dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction, - void *, DBusFreeFunction); + dbus_bool_t (*connection_get_is_connected)(DBusConnection *); + dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction, void *, DBusFreeFunction); dbus_bool_t (*connection_try_register_object_path)(DBusConnection *, const char *, const DBusObjectPathVTable *, void *, DBusError *); dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *); @@ -51,7 +50,7 @@ typedef struct SDL_DBusContext { void (*connection_flush)(DBusConnection *); dbus_bool_t (*connection_read_write)(DBusConnection *, int); DBusDispatchStatus (*connection_dispatch)(DBusConnection *); - dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *); + dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *); DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *); dbus_bool_t (*message_append_args)(DBusMessage *, int, ...); dbus_bool_t (*message_append_args_valist)(DBusMessage *, int, va_list); @@ -61,7 +60,7 @@ typedef struct SDL_DBusContext { dbus_bool_t (*message_iter_next)(DBusMessageIter *); void (*message_iter_get_basic)(DBusMessageIter *, void *); int (*message_iter_get_arg_type)(DBusMessageIter *); - void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *); + void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *); void (*message_unref)(DBusMessage *); void (*error_init)(DBusError *); dbus_bool_t (*error_is_set)(const DBusError *); diff --git a/src/core/linux/SDL_udev.h b/src/core/linux/SDL_udev.h index edf51870b0c04..033a2998b509b 100644 --- a/src/core/linux/SDL_udev.h +++ b/src/core/linux/SDL_udev.h @@ -77,9 +77,9 @@ typedef struct SDL_UDEV_PrivateData const char *(*udev_device_get_action)(struct udev_device *); const char *(*udev_device_get_devnode)(struct udev_device *); const char *(*udev_device_get_subsystem)(struct udev_device *); - struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype); + struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype); const char *(*udev_device_get_property_value)(struct udev_device *, const char *); - const char *(*udev_device_get_sysattr_value)(struct udev_device *udev_device, const char *sysattr); + const char *(*udev_device_get_sysattr_value)(struct udev_device *udev_device, const char *sysattr); struct udev_device *(*udev_device_new_from_syspath)(struct udev *, const char *); void (*udev_device_unref)(struct udev_device *); int (*udev_enumerate_add_match_property)(struct udev_enumerate *, const char *, const char *); diff --git a/src/core/winrt/SDL_winrtapp_xaml.cpp b/src/core/winrt/SDL_winrtapp_xaml.cpp index 9789d036fa503..7e2aac8a7bdd1 100644 --- a/src/core/winrt/SDL_winrtapp_xaml.cpp +++ b/src/core/winrt/SDL_winrtapp_xaml.cpp @@ -44,7 +44,7 @@ SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE; #if WINAPI_FAMILY == WINAPI_FAMILY_APP extern "C" ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL; -static Windows::Foundation::EventRegistrationToken WINRT_XAMLAppEventToken; +static Windows::Foundation::EventRegistrationToken WINRT_XAMLAppEventToken; #endif diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index baf85e58b83d6..15a44a84347e1 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -1027,7 +1027,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const } #ifdef __ANDROID__ if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) { - mapping = SDL_CreateMappingForAndroidController(name, guid); + mapping = SDL_CreateMappingForAndroidController(name, guid); } #endif if (!mapping) { diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index d274444fdc583..5dece76fcc863 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1141,13 +1141,13 @@ SDL_IsJoystickSteamController(Uint16 vendor, Uint16 product) SDL_bool SDL_IsJoystickXbox360(Uint16 vendor, Uint16 product) { - /* Filter out some bogus values here */ - if (vendor == 0x0000 && product == 0x0000) { - return SDL_FALSE; - } - if (vendor == 0x0001 && product == 0x0001) { - return SDL_FALSE; - } + /* Filter out some bogus values here */ + if (vendor == 0x0000 && product == 0x0000) { + return SDL_FALSE; + } + if (vendor == 0x0001 && product == 0x0001) { + return SDL_FALSE; + } return (GuessControllerType(vendor, product) == k_eControllerType_XBox360Controller); } diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h index b5a5193b9e144..26054edfa0b1f 100644 --- a/src/joystick/controller_type.h +++ b/src/joystick/controller_type.h @@ -43,9 +43,6 @@ typedef enum k_eControllerType_SteamController = 2, k_eControllerType_SteamControllerV2 = 3, - // IR Remote controls on Steambox - k_eControllerType_FrontPanelBoard = 20, - // Other Controllers k_eControllerType_UnknownNonSteamController = 30, k_eControllerType_XBox360Controller = 31, @@ -73,49 +70,6 @@ static inline bool BIsSteamController( EControllerType eType ) return ( eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2 ); } -#if 0 /* these are currently unused, so #if 0'd out to prevent compiler warnings for now */ -static inline bool BIsSteamHardwareDevice( EControllerType eType ) -{ - return ( eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2 || eType == k_eControllerType_FrontPanelBoard ); -} - -static inline bool BIsXInputController( EControllerType eType ) -{ - return ( eType == k_eControllerType_XBox360Controller || eType == k_eControllerType_XBoxOneController || eType == k_eControllerType_UnknownNonSteamController ); -} - -static inline bool BIsSwitchController( EControllerType eType ) -{ - return ( eType == k_eControllerType_SwitchJoyConLeft || eType == k_eControllerType_SwitchJoyConRight || - eType == k_eControllerType_SwitchJoyConPair || eType == k_eControllerType_SwitchProController || - eType == k_eControllerType_SwitchInputOnlyController ); -} - -/* XXX: this should be updated when we ship nintentdo switch controller support */ -static inline bool BIsRawHIDDevice( EControllerType eType ) -{ - return BIsSteamHardwareDevice( eType) || eType == k_eControllerType_PS4Controller || BIsSwitchController( eType ); -} - -// 'Full' here means that the controller has a full complement of buttons, joysticks, etc, as compared to -// the single Joy-Con's that only have around half of the controls that a normal controller has -static inline bool BIsFullSwitchController( EControllerType eType ) -{ - return ( eType == k_eControllerType_SwitchJoyConPair || eType == k_eControllerType_SwitchProController ); -} - -static inline bool BIsCompatibleType( EControllerType eTypeA, EControllerType eTypeB ) -{ - if ( BIsSteamController( eTypeA ) && BIsSteamController( eTypeB ) ) - return true; - if ( BIsXInputController( eTypeA ) && BIsXInputController( eTypeB ) ) - return true; - if ( eTypeA == eTypeB ) - return true; - return false; -} -#endif - #define MAKE_CONTROLLER_ID( nVID, nPID ) (unsigned int)( nVID << 16 | nPID ) typedef struct { @@ -168,7 +122,6 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x146b, 0x0603 ), k_eControllerType_PS3Controller }, // From SDL { MAKE_CONTROLLER_ID( 0x044f, 0xb315 ), k_eControllerType_PS3Controller }, // Firestorm Dual Analog 3 { MAKE_CONTROLLER_ID( 0x0925, 0x8888 ), k_eControllerType_PS3Controller }, // Actually ps2 -maybe break out later Lakeview Research WiseGroup Ltd, MP-8866 Dual Joypad - { MAKE_CONTROLLER_ID( 0x146b, 0x0602 ), k_eControllerType_PS3Controller }, // From SDL { MAKE_CONTROLLER_ID( 0x0f0d, 0x004d ), k_eControllerType_PS3Controller }, // Horipad 3 { MAKE_CONTROLLER_ID( 0x0f0d, 0x0009 ), k_eControllerType_PS3Controller }, // HORI BDA GP1 { MAKE_CONTROLLER_ID( 0x0e8f, 0x0008 ), k_eControllerType_PS3Controller }, // Green Asia @@ -214,8 +167,8 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x1532, 0x1000 ), k_eControllerType_PS4Controller }, // Razer Raiju PS4 Controller { MAKE_CONTROLLER_ID( 0x1532, 0X0401 ), k_eControllerType_PS4Controller }, // Razer Panthera PS4 Controller { MAKE_CONTROLLER_ID( 0x054c, 0x05c5 ), k_eControllerType_PS4Controller }, // STRIKEPAD PS4 Grip Add-on - { MAKE_CONTROLLER_ID( 0x146b, 0x0d01 ), k_eControllerType_PS4Controller }, // Nacon Revolution Pro Controller - { MAKE_CONTROLLER_ID( 0x146b, 0x0d02 ), k_eControllerType_PS4Controller }, // Nacon Revolution Pro Controller v2 + { MAKE_CONTROLLER_ID( 0x146b, 0x0d01 ), k_eControllerType_PS4Controller }, // Nacon Revolution Pro Controller - has gyro + { MAKE_CONTROLLER_ID( 0x146b, 0x0d02 ), k_eControllerType_PS4Controller }, // Nacon Revolution Pro Controller v2 - has gyro { MAKE_CONTROLLER_ID( 0x0f0d, 0x00a0 ), k_eControllerType_PS4Controller }, // HORI TAC4 mousething { MAKE_CONTROLLER_ID( 0x0f0d, 0x009c ), k_eControllerType_PS4Controller }, // HORI TAC PRO mousething { MAKE_CONTROLLER_ID( 0x0c12, 0x0ef6 ), k_eControllerType_PS4Controller }, // Hitbox Arcade Stick @@ -224,7 +177,15 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x0f0d, 0x00ee ), k_eControllerType_PS4Controller }, // Hori mini wired https://www.playstation.com/en-us/explore/accessories/gaming-controllers/mini-wired-gamepad/ { MAKE_CONTROLLER_ID( 0x0738, 0x8481 ), k_eControllerType_PS4Controller }, // Mad Catz FightStick TE 2+ PS4 { MAKE_CONTROLLER_ID( 0x0738, 0x8480 ), k_eControllerType_PS4Controller }, // Mad Catz FightStick TE 2 PS4 - { MAKE_CONTROLLER_ID( 0x7545, 0x0104 ), k_eControllerType_PS4Controller }, // Armor 3 or Level Up Cobra + { MAKE_CONTROLLER_ID( 0x7545, 0x0104 ), k_eControllerType_PS4Controller }, // Armor 3 or Level Up Cobra - At least one variant has gyro + { MAKE_CONTROLLER_ID( 0x0c12, 0x0e15 ), k_eControllerType_PS4Controller }, // Game:Pad 4 + { MAKE_CONTROLLER_ID( 0x11c0, 0x4001 ), k_eControllerType_PS4Controller }, // "PS4 Fun Controller" added from user log + + { MAKE_CONTROLLER_ID( 0x1532, 0x1007 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition USB- untested and added for razer + { MAKE_CONTROLLER_ID( 0x1532, 0x100A ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition BT - untested and added for razer + { MAKE_CONTROLLER_ID( 0x1532, 0x1004 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Ultimate USB - untested and added for razer + { MAKE_CONTROLLER_ID( 0x1532, 0x1009 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Ultimate BT - untested and added for razer + { MAKE_CONTROLLER_ID( 0x1532, 0x1008 ), k_eControllerType_PS4Controller }, // Razer Panthera Evo Fightstick - untested and added for razer { MAKE_CONTROLLER_ID( 0x056e, 0x2004 ), k_eControllerType_XBox360Controller }, // Elecom JC-U3613M { MAKE_CONTROLLER_ID( 0x06a3, 0xf51a ), k_eControllerType_XBox360Controller }, // Saitek P3600 @@ -400,32 +361,42 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x0079, 0x187c ), k_eControllerType_XBox360Controller }, // Unknown Controller { MAKE_CONTROLLER_ID( 0x0079, 0x189c ), k_eControllerType_XBox360Controller }, // Unknown Controller { MAKE_CONTROLLER_ID( 0x0079, 0x1874 ), k_eControllerType_XBox360Controller }, // Unknown Controller + + { MAKE_CONTROLLER_ID( 0x1038, 0xb360 ), k_eControllerType_XBox360Controller }, // SteelSeries Nimbus/Stratus XL + //{ MAKE_CONTROLLER_ID( 0x1949, 0x0402 ), /*android*/ }, // Unknown Controller { MAKE_CONTROLLER_ID( 0x05ac, 0x0001 ), k_eControllerType_AppleController }, // MFI Extended Gamepad (generic entry for iOS/tvOS) { MAKE_CONTROLLER_ID( 0x05ac, 0x0002 ), k_eControllerType_AppleController }, // MFI Standard Gamepad (generic entry for iOS/tvOS) - { MAKE_CONTROLLER_ID( 0x1038, 0xb360 ), k_eControllerType_AppleController }, // SteelSeries Nimbus // We currently don't support using a pair of Switch Joy-Con's as a single // controller and we don't want to support using them individually for the // time being, so these should be disabled until one of the above is true // { MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft }, // Nintendo Switch Joy-Con (Left) // { MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight }, // Nintendo Switch Joy-Con (Right) + + // This same controller ID is spoofed by many 3rd-party Switch controllers. + // The ones we currently know of are: + // * Any 8bitdo controller with Switch support + // * ORTZ Gaming Wireless Pro Controller + // * ZhiXu Gamepad Wireless + // * Sunwaytek Wireless Motion Controller for Nintendo Switch { MAKE_CONTROLLER_ID( 0x057e, 0x2009 ), k_eControllerType_SwitchProController }, // Nintendo Switch Pro Controller + { MAKE_CONTROLLER_ID( 0x0f0d, 0x00c1 ), k_eControllerType_SwitchInputOnlyController }, // HORIPAD for Nintendo Switch { MAKE_CONTROLLER_ID( 0x20d6, 0xa711 ), k_eControllerType_SwitchInputOnlyController }, // PowerA Wired Controller Plus + { MAKE_CONTROLLER_ID( 0x0f0d, 0x0092 ), k_eControllerType_SwitchInputOnlyController }, // HORI Pokken Tournament DX Pro Pad // Valve products - don't add to public list - { MAKE_CONTROLLER_ID( 0x0000, 0x11fa ), k_eControllerType_MobileTouch }, // Streaming mobile touch virtual controls + { MAKE_CONTROLLER_ID( 0x0000, 0x11fb ), k_eControllerType_MobileTouch }, // Streaming mobile touch virtual controls { MAKE_CONTROLLER_ID( 0x28de, 0x1101 ), k_eControllerType_SteamController }, // Valve Legacy Steam Controller (CHELL) { MAKE_CONTROLLER_ID( 0x28de, 0x1102 ), k_eControllerType_SteamController }, // Valve wired Steam Controller (D0G) { MAKE_CONTROLLER_ID( 0x28de, 0x1105 ), k_eControllerType_SteamControllerV2 }, // Valve Bluetooth Steam Controller (D0G) { MAKE_CONTROLLER_ID( 0x28de, 0x1106 ), k_eControllerType_SteamControllerV2 }, // Valve Bluetooth Steam Controller (D0G) { MAKE_CONTROLLER_ID( 0x28de, 0x1142 ), k_eControllerType_SteamController }, // Valve wireless Steam Controller { MAKE_CONTROLLER_ID( 0x28de, 0x1201 ), k_eControllerType_SteamController }, // Valve wired Steam Controller (HEADCRAB) - { MAKE_CONTROLLER_ID( 0x28de, 0x1202 ), k_eControllerType_SteamControllerV2 }, // Valve Bluetooth Steam Controller (HEADCRAB) }; diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc index 30f919ca83642..b3b0467f153b3 100644 --- a/src/joystick/haiku/SDL_haikujoystick.cc +++ b/src/joystick/haiku/SDL_haikujoystick.cc @@ -36,7 +36,7 @@ extern "C" /* The maximum number of joysticks we'll detect */ -#define MAX_JOYSTICKS 16 +#define MAX_JOYSTICKS 16 /* A list of available joysticks */ static char *SDL_joyport[MAX_JOYSTICKS]; diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index 4ae17cc8e4f50..ebd15a81046d3 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -255,7 +255,7 @@ SDL_JoystickThread(void *_data) /* WM_DEVICECHANGE not working, no XINPUT, no point in keeping thread alive */ break; #endif /* SDL_JOYSTICK_XINPUT */ - } + } if (s_bWindowsDeviceChanged || bXInputChanged) { s_bDeviceRemoved = SDL_TRUE; diff --git a/src/main/haiku/SDL_BApp.h b/src/main/haiku/SDL_BApp.h index 3c416753524b4..7adbd007d37e6 100644 --- a/src/main/haiku/SDL_BApp.h +++ b/src/main/haiku/SDL_BApp.h @@ -198,7 +198,7 @@ class SDL_BApp : public BApplication { _current_context->UnlockGL(); _current_context = newContext; if (_current_context) - _current_context->LockGL(); + _current_context->LockGL(); } #endif diff --git a/src/main/haiku/SDL_BeApp.cc b/src/main/haiku/SDL_BeApp.cc index f4ee17951969d..cbd21293b7218 100644 --- a/src/main/haiku/SDL_BeApp.cc +++ b/src/main/haiku/SDL_BeApp.cc @@ -31,7 +31,7 @@ #include #include -#include "SDL_BApp.h" /* SDL_BApp class definition */ +#include "SDL_BApp.h" /* SDL_BApp class definition */ #include "SDL_BeApp.h" #include "SDL_timer.h" #include "SDL_error.h" @@ -53,24 +53,24 @@ StartBeApp(void *unused) { BApplication *App; - // default application signature - const char *signature = "application/x-SDL-executable"; - // dig resources for correct signature - image_info info; - int32 cookie = 0; - if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { - BFile f(info.name, O_RDONLY); - if (f.InitCheck() == B_OK) { - BAppFileInfo app_info(&f); - if (app_info.InitCheck() == B_OK) { - char sig[B_MIME_TYPE_LENGTH]; - if (app_info.GetSignature(sig) == B_OK) - signature = strndup(sig, B_MIME_TYPE_LENGTH); - } - } - } - - App = new SDL_BApp(signature); + // default application signature + const char *signature = "application/x-SDL-executable"; + // dig resources for correct signature + image_info info; + int32 cookie = 0; + if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { + BFile f(info.name, O_RDONLY); + if (f.InitCheck() == B_OK) { + BAppFileInfo app_info(&f); + if (app_info.InitCheck() == B_OK) { + char sig[B_MIME_TYPE_LENGTH]; + if (app_info.GetSignature(sig) == B_OK) + signature = strndup(sig, B_MIME_TYPE_LENGTH); + } + } + } + + App = new SDL_BApp(signature); App->Run(); delete App; @@ -144,12 +144,12 @@ SDL_QuitBeApp(void) /* SDL_BApp functions */ void SDL_BApp::ClearID(SDL_BWin *bwin) { - _SetSDLWindow(NULL, bwin->GetID()); - int32 i = _GetNumWindowSlots() - 1; - while(i >= 0 && GetSDLWindow(i) == NULL) { - _PopBackWindow(); - --i; - } + _SetSDLWindow(NULL, bwin->GetID()); + int32 i = _GetNumWindowSlots() - 1; + while(i >= 0 && GetSDLWindow(i) == NULL) { + _PopBackWindow(); + --i; + } } #endif /* __HAIKU__ */ diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index f8dbc9fa71e48..e2e3a3f866425 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -89,13 +89,13 @@ SDL_iconv(SDL_iconv_t cd, #else /* Lots of useful information on Unicode at: - http://www.cl.cam.ac.uk/~mgk25/unicode.html + http://www.cl.cam.ac.uk/~mgk25/unicode.html */ -#define UNICODE_BOM 0xFEFF +#define UNICODE_BOM 0xFEFF -#define UNKNOWN_ASCII '?' -#define UNKNOWN_UNICODE 0xFFFD +#define UNKNOWN_ASCII '?' +#define UNKNOWN_UNICODE 0xFFFD enum { @@ -115,13 +115,13 @@ enum ENCODING_UCS4LE, }; #if SDL_BYTEORDER == SDL_BIG_ENDIAN -#define ENCODING_UTF16NATIVE ENCODING_UTF16BE -#define ENCODING_UTF32NATIVE ENCODING_UTF32BE +#define ENCODING_UTF16NATIVE ENCODING_UTF16BE +#define ENCODING_UTF32NATIVE ENCODING_UTF32BE #define ENCODING_UCS2NATIVE ENCODING_UCS2BE #define ENCODING_UCS4NATIVE ENCODING_UCS4BE #else -#define ENCODING_UTF16NATIVE ENCODING_UTF16LE -#define ENCODING_UTF32NATIVE ENCODING_UTF32LE +#define ENCODING_UTF16NATIVE ENCODING_UTF16LE +#define ENCODING_UTF32NATIVE ENCODING_UTF32LE #define ENCODING_UCS2NATIVE ENCODING_UCS2LE #define ENCODING_UCS4NATIVE ENCODING_UCS4LE #endif diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index b7c5412eea076..56ccf15fc9fcf 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -49,13 +49,13 @@ Blit1to1(SDL_BlitInfo * info) while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *dst = map[*src]; - } - dst++; - src++; - , width); + DUFFS_LOOP( + { + *dst = map[*src]; + } + dst++; + src++; + , width); /* *INDENT-ON* */ #else for (c = width; c; --c) { @@ -72,11 +72,11 @@ Blit1to1(SDL_BlitInfo * info) /* This is now endian dependent */ #ifndef USE_DUFFS_LOOP # if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) -# define HI 1 -# define LO 0 +# define HI 1 +# define LO 0 # else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */ -# define HI 0 -# define LO 1 +# define HI 0 +# define LO 1 # endif #endif static void @@ -101,14 +101,14 @@ Blit1to2(SDL_BlitInfo * info) #ifdef USE_DUFFS_LOOP while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *(Uint16 *)dst = map[*src++]; - dst += 2; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + *(Uint16 *)dst = map[*src++]; + dst += 2; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -208,18 +208,18 @@ Blit1to3(SDL_BlitInfo * info) while (height--) { #ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - o = *src * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - } - src++; - dst += 3; - , width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + o = *src * 4; + dst[0] = map[o++]; + dst[1] = map[o++]; + dst[2] = map[o++]; + } + src++; + dst += 3; + , width); + /* *INDENT-ON* */ #else for (c = width; c; --c) { o = *src * 4; @@ -257,11 +257,11 @@ Blit1to4(SDL_BlitInfo * info) while (height--) { #ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - *dst++ = map[*src++]; - , width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + *dst++ = map[*src++]; + , width); + /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { *dst++ = map[*src++]; @@ -297,33 +297,33 @@ Blit1to1Key(SDL_BlitInfo * info) if (palmap) { while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dst = palmap[*src]; - } - dst++; - src++; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + *dst = palmap[*src]; + } + dst++; + src++; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } else { while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dst = *src; - } - dst++; - src++; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + *dst = *src; + } + dst++; + src++; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -346,17 +346,17 @@ Blit1to2Key(SDL_BlitInfo * info) dstskip /= 2; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dstp=palmap[*src]; - } - src++; - dstp++; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + *dstp=palmap[*src]; + } + src++; + dstp++; + }, + width); + /* *INDENT-ON* */ src += srcskip; dstp += dstskip; } @@ -376,20 +376,20 @@ Blit1to3Key(SDL_BlitInfo * info) int o; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - o = *src * 4; - dst[0] = palmap[o++]; - dst[1] = palmap[o++]; - dst[2] = palmap[o++]; - } - src++; - dst += 3; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + o = *src * 4; + dst[0] = palmap[o++]; + dst[1] = palmap[o++]; + dst[2] = palmap[o++]; + } + src++; + dst += 3; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -411,17 +411,17 @@ Blit1to4Key(SDL_BlitInfo * info) dstskip /= 4; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dstp = palmap[*src]; - } - src++; - dstp++; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + *dstp = palmap[*src]; + } + src++; + dstp++; + }, + width); + /* *INDENT-ON* */ src += srcskip; dstp += dstskip; } @@ -489,22 +489,22 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) dstbpp = dstfmt->BytesPerPixel; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - sR = srcpal[*src].r; - sG = srcpal[*src].g; - sB = srcpal[*src].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); - } - src++; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + if ( *src != ckey ) { + sR = srcpal[*src].r; + sG = srcpal[*src].g; + sB = srcpal[*src].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); + } + src++; + dst += dstbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c index 1e9c9d89ba6d9..35079329412be 100644 --- a/src/video/SDL_blit_A.c +++ b/src/video/SDL_blit_A.c @@ -45,28 +45,28 @@ BlitNto1SurfaceAlpha(SDL_BlitInfo * info) const unsigned A = info->a; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { - *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); - } else { - *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4( + { + DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); + dR = dstfmt->palette->colors[*dst].r; + dG = dstfmt->palette->colors[*dst].g; + dB = dstfmt->palette->colors[*dst].b; + ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); + dR &= 0xff; + dG &= 0xff; + dB &= 0xff; + /* Pack RGB into 8bit pixel */ + if ( palmap == NULL ) { + *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); + } else { + *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; + } + dst++; + src += srcbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -91,28 +91,28 @@ BlitNto1PixelAlpha(SDL_BlitInfo * info) unsigned dR, dG, dB; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA); - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { - *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); - } else { - *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4( + { + DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA); + dR = dstfmt->palette->colors[*dst].r; + dG = dstfmt->palette->colors[*dst].g; + dB = dstfmt->palette->colors[*dst].b; + ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB); + dR &= 0xff; + dG &= 0xff; + dB &= 0xff; + /* Pack RGB into 8bit pixel */ + if ( palmap == NULL ) { + *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); + } else { + *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; + } + dst++; + src += srcbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -139,30 +139,30 @@ BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info) const unsigned A = info->a; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - if ( Pixel != ckey ) { - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); + if ( Pixel != ckey ) { + dR = dstfmt->palette->colors[*dst].r; + dG = dstfmt->palette->colors[*dst].g; + dB = dstfmt->palette->colors[*dst].b; + ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); + dR &= 0xff; + dG &= 0xff; + dB &= 0xff; + /* Pack RGB into 8bit pixel */ + if ( palmap == NULL ) { *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); - } else { + } else { *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; - } - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ + } + } + dst++; + src += srcbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -342,45 +342,45 @@ BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info) mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ multmask = 0x00FF; - multmask <<= (ashift * 2); - multmask2 = 0x00FF00FF00FF00FFULL; + multmask <<= (ashift * 2); + multmask2 = 0x00FF00FF00FF00FFULL; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 alpha = *srcp & amask; - if (alpha == 0) { - /* do nothing */ - } else if (alpha == amask) { - *dstp = *srcp; - } else { - src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ - - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ - - mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ - mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ - mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ - mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ - - /* blend */ - src1 = _mm_mullo_pi16(src1, mm_alpha); - src1 = _mm_srli_pi16(src1, 8); - dst1 = _mm_mullo_pi16(dst1, mm_alpha2); - dst1 = _mm_srli_pi16(dst1, 8); - dst1 = _mm_add_pi16(src1, dst1); - dst1 = _mm_packs_pu16(dst1, mm_zero); - - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 alpha = *srcp & amask; + if (alpha == 0) { + /* do nothing */ + } else if (alpha == amask) { + *dstp = *srcp; + } else { + src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ + src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ + + dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ + dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ + + mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ + mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ + mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ + mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ + mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ + mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ + + /* blend */ + src1 = _mm_mullo_pi16(src1, mm_alpha); + src1 = _mm_srli_pi16(src1, 8); + dst1 = _mm_mullo_pi16(dst1, mm_alpha2); + dst1 = _mm_srli_pi16(dst1, 8); + dst1 = _mm_add_pi16(src1, dst1); + dst1 = _mm_packs_pu16(dst1, mm_zero); + + *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ + } + ++srcp; + ++dstp; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -401,14 +401,14 @@ BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info) int dstskip = info->dst_skip >> 2; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) - + (s & d & 0x00010101)) | 0xff000000; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 s = *srcp++; + Uint32 d = *dstp; + *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + + (s & d & 0x00010101)) | 0xff000000; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -434,22 +434,22 @@ BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info) Uint32 d1; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - s = *srcp; - d = *dstp; - s1 = s & 0xff00ff; - d1 = d & 0xff00ff; - d1 = (d1 + ((s1 - d1) * alpha >> 8)) - & 0xff00ff; - s &= 0xff00; - d &= 0xff00; - d = (d + ((s - d) * alpha >> 8)) & 0xff00; - *dstp = d1 | d | 0xff000000; - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + s = *srcp; + d = *dstp; + s1 = s & 0xff00ff; + d1 = d & 0xff00ff; + d1 = (d1 + ((s1 - d1) * alpha >> 8)) + & 0xff00ff; + s &= 0xff00; + d &= 0xff00; + d = (d + ((s - d) * alpha >> 8)) & 0xff00; + *dstp = d1 | d | 0xff000000; + ++srcp; + ++dstp; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -468,42 +468,42 @@ BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info) int dstskip = info->dst_skip >> 2; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 dalpha; - Uint32 d; - Uint32 s1; - Uint32 d1; - Uint32 s = *srcp; - Uint32 alpha = s >> 24; - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if (alpha) { - if (alpha == SDL_ALPHA_OPAQUE) { - *dstp = *srcp; - } else { - /* - * take out the middle component (green), and process - * the other two in parallel. One multiply less. - */ - d = *dstp; - dalpha = d >> 24; - s1 = s & 0xff00ff; - d1 = d & 0xff00ff; - d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; - s &= 0xff00; - d &= 0xff00; - d = (d + ((s - d) * alpha >> 8)) & 0xff00; - dalpha = alpha + (dalpha * (alpha ^ 0xFF) >> 8); - *dstp = d1 | d | (dalpha << 24); - } - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 dalpha; + Uint32 d; + Uint32 s1; + Uint32 d1; + Uint32 s = *srcp; + Uint32 alpha = s >> 24; + /* FIXME: Here we special-case opaque alpha since the + compositioning used (>>8 instead of /255) doesn't handle + it correctly. Also special-case alpha=0 for speed? + Benchmark this! */ + if (alpha) { + if (alpha == SDL_ALPHA_OPAQUE) { + *dstp = *srcp; + } else { + /* + * take out the middle component (green), and process + * the other two in parallel. One multiply less. + */ + d = *dstp; + dalpha = d >> 24; + s1 = s & 0xff00ff; + d1 = d & 0xff00ff; + d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; + s &= 0xff00; + d &= 0xff00; + d = (d + ((s - d) * alpha >> 8)) & 0xff00; + dalpha = alpha + (dalpha * (alpha ^ 0xFF) >> 8); + *dstp = d1 | d | (dalpha << 24); + } + } + ++srcp; + ++dstp; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -533,47 +533,47 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info) multmask2 = 0x00FF00FF00FF00FFULL; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 alpha; - - _m_prefetch(srcp + 16); - _m_prefetch(dstp + 16); - - alpha = *srcp & amask; - if (alpha == 0) { - /* do nothing */ - } else if (alpha == amask) { - *dstp = *srcp; - } else { - src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ - - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ - - mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ - mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ - mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ - mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ - - - /* blend */ - src1 = _mm_mullo_pi16(src1, mm_alpha); - src1 = _mm_srli_pi16(src1, 8); - dst1 = _mm_mullo_pi16(dst1, mm_alpha2); - dst1 = _mm_srli_pi16(dst1, 8); - dst1 = _mm_add_pi16(src1, dst1); - dst1 = _mm_packs_pu16(dst1, mm_zero); - - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 alpha; + + _m_prefetch(srcp + 16); + _m_prefetch(dstp + 16); + + alpha = *srcp & amask; + if (alpha == 0) { + /* do nothing */ + } else if (alpha == amask) { + *dstp = *srcp; + } else { + src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ + src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ + + dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ + dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ + + mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ + mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ + mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ + mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ + mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ + mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ + + + /* blend */ + src1 = _mm_mullo_pi16(src1, mm_alpha); + src1 = _mm_srli_pi16(src1, 8); + dst1 = _mm_mullo_pi16(dst1, mm_alpha2); + dst1 = _mm_srli_pi16(dst1, 8); + dst1 = _mm_add_pi16(src1, dst1); + dst1 = _mm_packs_pu16(dst1, mm_zero); + + *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ + } + ++srcp; + ++dstp; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -585,13 +585,13 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info) /* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */ /* blend a single 16 bit pixel at 50% */ -#define BLEND16_50(d, s, mask) \ - ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff))) +#define BLEND16_50(d, s, mask) \ + ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff))) /* blend two 16 bit pixels at 50% */ -#define BLEND2x16_50(d, s, mask) \ - (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \ - + (s & d & (~(mask | mask << 16)))) +#define BLEND2x16_50(d, s, mask) \ + (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \ + + (s & d & (~(mask | mask << 16)))) static void Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask) @@ -727,103 +727,103 @@ Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info) bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP_124( - { - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ - dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ - - /* red */ - src2 = src1; - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */ - - dst2 = dst1; - dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */ - - mm_res = dst2; /* RED -> mm_res */ - - /* green -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ - - /* blue */ - src2 = src1; - src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ - - *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ - - srcp += 4; - dstp += 4; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP_124( + { + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x07e0f81f; + d = (d | d << 16) & 0x07e0f81f; + d += (s - d) * alpha >> 5; + d &= 0x07e0f81f; + *dstp++ = (Uint16)(d | d >> 16); + },{ + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x07e0f81f; + d = (d | d << 16) & 0x07e0f81f; + d += (s - d) * alpha >> 5; + d &= 0x07e0f81f; + *dstp++ = (Uint16)(d | d >> 16); + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x07e0f81f; + d = (d | d << 16) & 0x07e0f81f; + d += (s - d) * alpha >> 5; + d &= 0x07e0f81f; + *dstp++ = (Uint16)(d | d >> 16); + },{ + src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ + dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ + + /* red */ + src2 = src1; + src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */ + + dst2 = dst1; + dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */ + + mm_res = dst2; /* RED -> mm_res */ + + /* green -- process the bits in place */ + src2 = src1; + src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ + + dst2 = dst1; + dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + + mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ + + /* blue */ + src2 = src1; + src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ + + dst2 = dst1; + dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ + + mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ + + *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ + + srcp += 4; + dstp += 4; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -865,103 +865,103 @@ Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info) bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP_124( - { - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ - dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ - - /* red -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */ - - mm_res = dst2; /* RED -> mm_res */ - - /* green -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ - - /* blue */ - src2 = src1; /* src -> src2 */ - src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ - - dst2 = dst1; /* dst -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ - - *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ - - srcp += 4; - dstp += 4; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP_124( + { + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x03e07c1f; + d = (d | d << 16) & 0x03e07c1f; + d += (s - d) * alpha >> 5; + d &= 0x03e07c1f; + *dstp++ = (Uint16)(d | d >> 16); + },{ + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x03e07c1f; + d = (d | d << 16) & 0x03e07c1f; + d += (s - d) * alpha >> 5; + d &= 0x03e07c1f; + *dstp++ = (Uint16)(d | d >> 16); + s = *srcp++; + d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x03e07c1f; + d = (d | d << 16) & 0x03e07c1f; + d += (s - d) * alpha >> 5; + d &= 0x03e07c1f; + *dstp++ = (Uint16)(d | d >> 16); + },{ + src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ + dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ + + /* red -- process the bits in place */ + src2 = src1; + src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */ + + dst2 = dst1; + dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */ + + mm_res = dst2; /* RED -> mm_res */ + + /* green -- process the bits in place */ + src2 = src1; + src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ + + dst2 = dst1; + dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + + mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ + + /* blue */ + src2 = src1; /* src -> src2 */ + src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ + + dst2 = dst1; /* dst -> dst2 */ + dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ + + /* blend */ + src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ + src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ + dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ + dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ + + mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ + + *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ + + srcp += 4; + dstp += 4; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -988,22 +988,22 @@ Blit565to565SurfaceAlpha(SDL_BlitInfo * info) alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 s = *srcp++; + Uint32 d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x07e0f81f; + d = (d | d << 16) & 0x07e0f81f; + d += (s - d) * alpha >> 5; + d &= 0x07e0f81f; + *dstp++ = (Uint16)(d | d >> 16); + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -1027,22 +1027,22 @@ Blit555to555SurfaceAlpha(SDL_BlitInfo * info) alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 s = *srcp++; + Uint32 d = *dstp; + /* + * shift out the middle component (green) to + * the high 16 bits, and process all three RGB + * components at the same time. + */ + s = (s | s << 16) & 0x03e07c1f; + d = (d | d << 16) & 0x03e07c1f; + d += (s - d) * alpha >> 5; + d &= 0x03e07c1f; + *dstp++ = (Uint16)(d | d >> 16); + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -1061,35 +1061,35 @@ BlitARGBto565PixelAlpha(SDL_BlitInfo * info) int dstskip = info->dst_skip >> 1; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp; - unsigned alpha = s >> 27; /* downscale alpha to 5 bits */ - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { - *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f)); - } else { - Uint32 d = *dstp; - /* - * convert source and destination to G0RAB65565 - * and blend all components at the same time - */ - s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800) - + (s >> 3 & 0x1f); - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp = (Uint16)(d | d >> 16); - } - } - srcp++; - dstp++; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + Uint32 s = *srcp; + unsigned alpha = s >> 27; /* downscale alpha to 5 bits */ + /* FIXME: Here we special-case opaque alpha since the + compositioning used (>>8 instead of /255) doesn't handle + it correctly. Also special-case alpha=0 for speed? + Benchmark this! */ + if(alpha) { + if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { + *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f)); + } else { + Uint32 d = *dstp; + /* + * convert source and destination to G0RAB65565 + * and blend all components at the same time + */ + s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800) + + (s >> 3 & 0x1f); + d = (d | d << 16) & 0x07e0f81f; + d += (s - d) * alpha >> 5; + d &= 0x07e0f81f; + *dstp = (Uint16)(d | d >> 16); + } + } + srcp++; + dstp++; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -1107,36 +1107,36 @@ BlitARGBto555PixelAlpha(SDL_BlitInfo * info) int dstskip = info->dst_skip >> 1; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - unsigned alpha; - Uint32 s = *srcp; - alpha = s >> 27; /* downscale alpha to 5 bits */ - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { - *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f)); - } else { - Uint32 d = *dstp; - /* - * convert source and destination to G0RAB65565 - * and blend all components at the same time - */ - s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00) - + (s >> 3 & 0x1f); - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp = (Uint16)(d | d >> 16); - } - } - srcp++; - dstp++; - }, width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4({ + unsigned alpha; + Uint32 s = *srcp; + alpha = s >> 27; /* downscale alpha to 5 bits */ + /* FIXME: Here we special-case opaque alpha since the + compositioning used (>>8 instead of /255) doesn't handle + it correctly. Also special-case alpha=0 for speed? + Benchmark this! */ + if(alpha) { + if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { + *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f)); + } else { + Uint32 d = *dstp; + /* + * convert source and destination to G0RAB65565 + * and blend all components at the same time + */ + s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00) + + (s >> 3 & 0x1f); + d = (d | d << 16) & 0x03e07c1f; + d += (s - d) * alpha >> 5; + d &= 0x03e07c1f; + *dstp = (Uint16)(d | d >> 16); + } + } + srcp++; + dstp++; + }, width); + /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } @@ -1163,18 +1163,18 @@ BlitNtoNSurfaceAlpha(SDL_BlitInfo * info) if (sA) { while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); - ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4( + { + DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); + DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); + ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); + ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); + src += srcbpp; + dst += dstbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -1202,21 +1202,21 @@ BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info) const unsigned sA = info->a; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); - if(sA && Pixel != ckey) { - RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); - DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); - ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - } - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4( + { + RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); + if(sA && Pixel != ckey) { + RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); + DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); + ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); + ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); + } + src += srcbpp; + dst += dstbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } @@ -1245,20 +1245,20 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info) dstbpp = dstfmt->BytesPerPixel; while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); - if(sA) { - DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); - ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - } - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ + /* *INDENT-OFF* */ + DUFFS_LOOP4( + { + DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); + if(sA) { + DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); + ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); + ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); + } + src += srcbpp; + dst += dstbpp; + }, + width); + /* *INDENT-ON* */ src += srcskip; dst += dstskip; } diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 96f02cd1cbdb8..c3b43760800f0 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -836,7 +836,7 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) /* max 2 values plus terminator. */ EGLint attribs[3]; int attr = 0; - + EGLSurface * surface; if (SDL_EGL_ChooseConfig(_this) != 0) { @@ -868,7 +868,7 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) return EGL_NO_SURFACE; } } - + attribs[attr++] = EGL_NONE; surface = _this->egl_data->eglCreateWindowSurface( diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 2e263955c062e..c2e41632ff1a4 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -326,7 +326,7 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, if (Rmask == 0) { return SDL_PIXELFORMAT_RGB555; } - /* fallthrough */ + /* fallthrough */ case 16: if (Rmask == 0) { return SDL_PIXELFORMAT_RGB565; diff --git a/src/video/SDL_shape_internals.h b/src/video/SDL_shape_internals.h index 3af175cdf2ac6..49a8786a1930f 100644 --- a/src/video/SDL_shape_internals.h +++ b/src/video/SDL_shape_internals.h @@ -36,21 +36,21 @@ extern "C" { #endif typedef struct { - struct SDL_ShapeTree *upleft,*upright,*downleft,*downright; + struct SDL_ShapeTree *upleft,*upright,*downleft,*downright; } SDL_QuadTreeChildren; typedef union { - SDL_QuadTreeChildren children; - SDL_Rect shape; + SDL_QuadTreeChildren children; + SDL_Rect shape; } SDL_ShapeUnion; typedef enum { QuadShape,TransparentShape,OpaqueShape } SDL_ShapeKind; typedef struct { - SDL_ShapeKind kind; - SDL_ShapeUnion data; + SDL_ShapeKind kind; + SDL_ShapeUnion data; } SDL_ShapeTree; - + typedef void(*SDL_TraversalFunction)(SDL_ShapeTree*,void*); extern void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index ae6fee9c782ad..336fdaa509538 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1540,11 +1540,12 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) return NULL; } - // Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation, - // but it's important or window focus will get broken on windows! + /* Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation, + * but it's important or window focus will get broken on windows! + */ #if !defined(__WIN32__) - if (window->flags & SDL_WINDOW_MINIMIZED) { - window->flags &= ~SDL_WINDOW_MINIMIZED; + if (window->flags & SDL_WINDOW_MINIMIZED) { + window->flags &= ~SDL_WINDOW_MINIMIZED; } #endif diff --git a/src/video/SDL_vulkan_utils.c b/src/video/SDL_vulkan_utils.c index d4cbed4d9f58d..1b242f1329ed6 100644 --- a/src/video/SDL_vulkan_utils.c +++ b/src/video/SDL_vulkan_utils.c @@ -123,10 +123,10 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList( { retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null } - else - { - retval = SDL_calloc(count, sizeof(VkExtensionProperties)); - } + else + { + retval = SDL_calloc(count, sizeof(VkExtensionProperties)); + } if(!retval) { SDL_OutOfMemory(); diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 50910a5f74f7f..7c1e6b4673d2c 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -89,10 +89,10 @@ static SDL_bool IsPacked4Format(Uint32 format) } static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch, - const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride) + const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride) { - const Uint8 *planes[3] = { NULL, NULL, NULL }; - int pitches[3] = { 0, 0, 0 }; + const Uint8 *planes[3] = { NULL, NULL, NULL }; + int pitches[3] = { 0, 0, 0 }; switch (format) { case SDL_PIXELFORMAT_YV12: @@ -180,10 +180,10 @@ static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, i static SDL_bool yuv_rgb_sse( Uint32 src_format, Uint32 dst_format, - Uint32 width, Uint32 height, - const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, - Uint8 *rgb, Uint32 rgb_stride, - YCbCrType yuv_type) + Uint32 width, Uint32 height, + const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, + Uint8 *rgb, Uint32 rgb_stride, + YCbCrType yuv_type) { #ifdef __SSE2__ if (!SDL_HasSSE2()) { @@ -289,10 +289,10 @@ static SDL_bool yuv_rgb_sse( static SDL_bool yuv_rgb_std( Uint32 src_format, Uint32 dst_format, - Uint32 width, Uint32 height, - const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, - Uint8 *rgb, Uint32 rgb_stride, - YCbCrType yuv_type) + Uint32 width, Uint32 height, + const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, + Uint8 *rgb, Uint32 rgb_stride, + YCbCrType yuv_type) { if (src_format == SDL_PIXELFORMAT_YV12 || src_format == SDL_PIXELFORMAT_IYUV) { @@ -395,7 +395,7 @@ SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch) { - const Uint8 *y = NULL; + const Uint8 *y = NULL; const Uint8 *u = NULL; const Uint8 *v = NULL; Uint32 y_stride = 0; @@ -553,7 +553,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr Uint32 y_stride, uv_stride, y_skip, uv_skip; GetYUVPlanes(width, height, dst_format, dst, dst_pitch, - (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, + (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, &y_stride, &uv_stride); plane_interleaved_uv = (plane_y + height * y_stride); y_skip = (y_stride - width); diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 3cf5040b8aeda..589461afbe07c 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -214,12 +214,12 @@ Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * h void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate) { - SDL_VideoDevice* device; - SDL_VideoDisplay *display; + SDL_VideoDevice* device; + SDL_VideoDisplay *display; Android_SurfaceWidth = surfaceWidth; Android_SurfaceHeight = surfaceHeight; - Android_DeviceWidth = deviceWidth; - Android_DeviceHeight = deviceHeight; + Android_DeviceWidth = deviceWidth; + Android_DeviceHeight = deviceHeight; Android_ScreenFormat = format; Android_ScreenRate = rate; diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 38f4ba6760670..76d235e3bb909 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -390,8 +390,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) { [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - } - + } + if ([NSApp mainMenu] == nil) { CreateApplicationMenus(); } diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index f28b743623139..8b7a697a4a131 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -39,7 +39,7 @@ @implementation SDL_cocoametalview /* Return a Metal-compatible layer. */ + (Class)layerClass { - return NSClassFromString(@"CAMetalLayer"); + return NSClassFromString(@"CAMetalLayer"); } /* Indicate the view wants to draw using a backing layer instead of drawRect. */ @@ -59,7 +59,7 @@ - (CALayer*)makeBackingLayer - (instancetype)initWithFrame:(NSRect)frame scale:(CGFloat)scale { - if ((self = [super initWithFrame:frame])) { + if ((self = [super initWithFrame:frame])) { _tag = METALVIEW_TAG; self.wantsLayer = YES; @@ -71,7 +71,7 @@ - (instancetype)initWithFrame:(NSRect)frame self.layer.contentsScale = scale; } - return self; + return self; } /* Set the size of the metal drawables when the view is resized. */ diff --git a/src/video/cocoa/SDL_cocoamousetap.m b/src/video/cocoa/SDL_cocoamousetap.m index 3c4fcf23e0e6a..05a7d77d8afbf 100644 --- a/src/video/cocoa/SDL_cocoamousetap.m +++ b/src/video/cocoa/SDL_cocoamousetap.m @@ -211,7 +211,7 @@ tapdata->thread = SDL_CreateThreadInternal(&Cocoa_MouseTapThread, "Event Tap Loop", 512 * 1024, tapdata); if (tapdata->thread) { /* Success - early out. Ownership transferred to thread. */ - return; + return; } CFRelease(tapdata->tap); } diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 0cf7ec335c0fe..71ff8db1ba0a6 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -241,7 +241,7 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) static int GetHintCtrlClickEmulateRightClick() { - return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE); + return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE); } static NSUInteger @@ -908,7 +908,7 @@ - (void)mouseDown:(NSEvent *)theEvent switch ([theEvent buttonNumber]) { case 0: if (([theEvent modifierFlags] & NSEventModifierFlagControl) && - GetHintCtrlClickEmulateRightClick()) { + GetHintCtrlClickEmulateRightClick()) { wasCtrlLeft = YES; button = SDL_BUTTON_RIGHT; } else { diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index e253c584b314e..8740ce111e06e 100644 --- a/src/video/directfb/SDL_DirectFB_video.c +++ b/src/video/directfb/SDL_DirectFB_video.c @@ -324,7 +324,7 @@ static const struct { { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */ { DSPF_UYVY, SDL_PIXELFORMAT_UYVY }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */ { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 }, /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */ - { DSPF_ABGR, SDL_PIXELFORMAT_ABGR8888 }, /* 32 bit ABGR (4 byte, alpha 8@24, blue 8@16, green 8@8, red 8@0) */ + { DSPF_ABGR, SDL_PIXELFORMAT_ABGR8888 }, /* 32 bit ABGR (4 byte, alpha 8@24, blue 8@16, green 8@8, red 8@0) */ #if (ENABLE_LUT8) { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 }, /* 8 bit LUT (8 bit color and alpha lookup from palette) */ #endif diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h index b3855401151ce..b22f74b253070 100644 --- a/src/video/haiku/SDL_BWin.h +++ b/src/video/haiku/SDL_BWin.h @@ -538,7 +538,7 @@ class SDL_BWin:public BDirectWindow msg.AddInt32("key-state", keyState); msg.AddInt32("key-scancode", keyCode); if (keyUtf8 != NULL) { - msg.AddData("key-utf8", B_INT8_TYPE, (const void*)keyUtf8, len); + msg.AddData("key-utf8", B_INT8_TYPE, (const void*)keyUtf8, len); } be_app->PostMessage(&msg); } diff --git a/src/video/haiku/SDL_bclipboard.cc b/src/video/haiku/SDL_bclipboard.cc index 0727fd177551f..3138603d8112c 100644 --- a/src/video/haiku/SDL_bclipboard.cc +++ b/src/video/haiku/SDL_bclipboard.cc @@ -36,54 +36,54 @@ extern "C" { #endif int HAIKU_SetClipboardText(_THIS, const char *text) { - BMessage *clip = NULL; - if(be_clipboard->Lock()) { - be_clipboard->Clear(); - if((clip = be_clipboard->Data())) { - /* Presumably the string of characters is ascii-format */ - ssize_t asciiLength = 0; - for(; text[asciiLength] != 0; ++asciiLength) {} - clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength); - be_clipboard->Commit(); - } - be_clipboard->Unlock(); - } - return 0; + BMessage *clip = NULL; + if(be_clipboard->Lock()) { + be_clipboard->Clear(); + if((clip = be_clipboard->Data())) { + /* Presumably the string of characters is ascii-format */ + ssize_t asciiLength = 0; + for(; text[asciiLength] != 0; ++asciiLength) {} + clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength); + be_clipboard->Commit(); + } + be_clipboard->Unlock(); + } + return 0; } char *HAIKU_GetClipboardText(_THIS) { - BMessage *clip = NULL; - const char *text = NULL; - ssize_t length; - char *result; - if(be_clipboard->Lock()) { - if((clip = be_clipboard->Data())) { - /* Presumably the string of characters is ascii-format */ - clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, - &length); - } - be_clipboard->Unlock(); - } - - if (!text) { - result = SDL_strdup(""); - } else { - /* Copy the data and pass on to SDL */ - result = (char *)SDL_malloc((length + 1) * sizeof(char)); - SDL_strlcpy(result, text, length + 1); - } - - return result; + BMessage *clip = NULL; + const char *text = NULL; + ssize_t length; + char *result; + if(be_clipboard->Lock()) { + if((clip = be_clipboard->Data())) { + /* Presumably the string of characters is ascii-format */ + clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, + &length); + } + be_clipboard->Unlock(); + } + + if (!text) { + result = SDL_strdup(""); + } else { + /* Copy the data and pass on to SDL */ + result = (char *)SDL_malloc((length + 1) * sizeof(char)); + SDL_strlcpy(result, text, length + 1); + } + + return result; } SDL_bool HAIKU_HasClipboardText(_THIS) { - SDL_bool result = SDL_FALSE; - char *text = HAIKU_GetClipboardText(_this); - if (text) { - result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE; - SDL_free(text); - } - return result; + SDL_bool result = SDL_FALSE; + char *text = HAIKU_GetClipboardText(_this); + if (text) { + result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE; + SDL_free(text); + } + return result; } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bevents.cc b/src/video/haiku/SDL_bevents.cc index e3884d3da6a7f..c918ab2439c03 100644 --- a/src/video/haiku/SDL_bevents.cc +++ b/src/video/haiku/SDL_bevents.cc @@ -29,7 +29,7 @@ extern "C" { #endif void HAIKU_PumpEvents(_THIS) { - /* Since the event thread is its own thread, this isn't really necessary */ + /* Since the event thread is its own thread, this isn't really necessary */ } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc index 848d7352efacb..967570612bc4a 100644 --- a/src/video/haiku/SDL_bframebuffer.cc +++ b/src/video/haiku/SDL_bframebuffer.cc @@ -40,158 +40,158 @@ static int32 HAIKU_UpdateOnce(SDL_Window *window); #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return ((SDL_BWin*)(window->driverdata)); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return ((SDL_BApp*)be_app); } int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) { - SDL_BWin *bwin = _ToBeWin(window); - BScreen bscreen; - if(!bscreen.IsValid()) { - return -1; - } - - while(!bwin->Connected()) { snooze(100); } - - /* Make sure we have exclusive access to frame buffer data */ - bwin->LockBuffer(); - - /* format */ - display_mode bmode; - bscreen.GetMode(&bmode); - int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space); - *format = HAIKU_BPPToSDLPxFormat(bpp); - - /* Create the new bitmap object */ - BBitmap *bitmap = bwin->GetBitmap(); - - if(bitmap) { - delete bitmap; - } - bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, - false, /* Views not accepted */ - true); /* Contiguous memory required */ - - if(bitmap->InitCheck() != B_OK) { - delete bitmap; - return SDL_SetError("Could not initialize back buffer!"); - } - - - bwin->SetBitmap(bitmap); - - /* Set the pixel pointer */ - *pixels = bitmap->Bits(); - - /* pitch = width of window, in bytes */ - *pitch = bitmap->BytesPerRow(); - - bwin->SetBufferExists(true); - bwin->SetTrashBuffer(false); - bwin->UnlockBuffer(); - return 0; + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + while(!bwin->Connected()) { snooze(100); } + + /* Make sure we have exclusive access to frame buffer data */ + bwin->LockBuffer(); + + /* format */ + display_mode bmode; + bscreen.GetMode(&bmode); + int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space); + *format = HAIKU_BPPToSDLPxFormat(bpp); + + /* Create the new bitmap object */ + BBitmap *bitmap = bwin->GetBitmap(); + + if(bitmap) { + delete bitmap; + } + bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, + false, /* Views not accepted */ + true); /* Contiguous memory required */ + + if(bitmap->InitCheck() != B_OK) { + delete bitmap; + return SDL_SetError("Could not initialize back buffer!"); + } + + + bwin->SetBitmap(bitmap); + + /* Set the pixel pointer */ + *pixels = bitmap->Bits(); + + /* pitch = width of window, in bytes */ + *pitch = bitmap->BytesPerRow(); + + bwin->SetBufferExists(true); + bwin->SetTrashBuffer(false); + bwin->UnlockBuffer(); + return 0; } int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { - if(!window) - return 0; + if(!window) + return 0; - SDL_BWin *bwin = _ToBeWin(window); + SDL_BWin *bwin = _ToBeWin(window); -#ifdef DRAWTHREAD - bwin->LockBuffer(); - bwin->SetBufferDirty(true); - bwin->UnlockBuffer(); +#ifdef DRAWTHREAD + bwin->LockBuffer(); + bwin->SetBufferDirty(true); + bwin->UnlockBuffer(); #else - bwin->SetBufferDirty(true); - HAIKU_UpdateOnce(window); + bwin->SetBufferDirty(true); + HAIKU_UpdateOnce(window); #endif - return 0; + return 0; } int32 HAIKU_DrawThread(void *data) { - SDL_BWin *bwin = (SDL_BWin*)data; - - BScreen bscreen; - if(!bscreen.IsValid()) { - return -1; - } - - while(bwin->ConnectionEnabled()) { - if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { - bwin->LockBuffer(); - BBitmap *bitmap = NULL; - bitmap = bwin->GetBitmap(); - int32 windowPitch = bitmap->BytesPerRow(); - int32 bufferPitch = bwin->GetRowBytes(); - uint8 *windowpx; - uint8 *bufferpx; - - int32 BPP = bwin->GetBytesPerPx(); - int32 windowSub = bwin->GetFbX() * BPP + - bwin->GetFbY() * windowPitch; - clipping_rect *clips = bwin->GetClips(); - int32 numClips = bwin->GetNumClips(); - int i, y; - - /* Blit each clipping rectangle */ - bscreen.WaitForRetrace(); - for(i = 0; i < numClips; ++i) { - /* Get addresses of the start of each clipping rectangle */ - int32 width = clips[i].right - clips[i].left + 1; - int32 height = clips[i].bottom - clips[i].top + 1; - bufferpx = bwin->GetBufferPx() + - clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = (uint8*)bitmap->Bits() + - clips[i].top * windowPitch + clips[i].left * BPP - - windowSub; - - /* Copy each row of pixels from the window buffer into the frame - buffer */ - for(y = 0; y < height; ++y) - { - - if(bwin->CanTrashWindowBuffer()) { - goto escape; /* Break out before the buffer is killed */ - } - - memcpy(bufferpx, windowpx, width * BPP); - bufferpx += bufferPitch; - windowpx += windowPitch; - } - } - - bwin->SetBufferDirty(false); + SDL_BWin *bwin = (SDL_BWin*)data; + + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + while(bwin->ConnectionEnabled()) { + if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { + bwin->LockBuffer(); + BBitmap *bitmap = NULL; + bitmap = bwin->GetBitmap(); + int32 windowPitch = bitmap->BytesPerRow(); + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; + + int32 BPP = bwin->GetBytesPerPx(); + int32 windowSub = bwin->GetFbX() * BPP + + bwin->GetFbY() * windowPitch; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; + + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * BPP; + windowpx = (uint8*)bitmap->Bits() + + clips[i].top * windowPitch + clips[i].left * BPP - + windowSub; + + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + + if(bwin->CanTrashWindowBuffer()) { + goto escape; /* Break out before the buffer is killed */ + } + + memcpy(bufferpx, windowpx, width * BPP); + bufferpx += bufferPitch; + windowpx += windowPitch; + } + } + + bwin->SetBufferDirty(false); escape: - bwin->UnlockBuffer(); - } else { - snooze(16000); - } - } - - return B_OK; + bwin->UnlockBuffer(); + } else { + snooze(16000); + } + } + + return B_OK; } void HAIKU_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { - SDL_BWin *bwin = _ToBeWin(window); - - bwin->LockBuffer(); - - /* Free and clear the window buffer */ - BBitmap *bitmap = bwin->GetBitmap(); - delete bitmap; - bwin->SetBitmap(NULL); - bwin->SetBufferExists(false); - bwin->UnlockBuffer(); + SDL_BWin *bwin = _ToBeWin(window); + + bwin->LockBuffer(); + + /* Free and clear the window buffer */ + BBitmap *bitmap = bwin->GetBitmap(); + delete bitmap; + bwin->SetBitmap(NULL); + bwin->SetBufferExists(false); + bwin->UnlockBuffer(); } @@ -203,50 +203,50 @@ void HAIKU_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { */ #ifndef DRAWTHREAD static int32 HAIKU_UpdateOnce(SDL_Window *window) { - SDL_BWin *bwin = _ToBeWin(window); - BScreen bscreen; - if(!bscreen.IsValid()) { - return -1; - } - - if(bwin->ConnectionEnabled() && bwin->Connected()) { - bwin->LockBuffer(); - int32 windowPitch = window->surface->pitch; - int32 bufferPitch = bwin->GetRowBytes(); - uint8 *windowpx; - uint8 *bufferpx; - - int32 BPP = bwin->GetBytesPerPx(); - uint8 *windowBaseAddress = (uint8*)window->surface->pixels; - int32 windowSub = bwin->GetFbX() * BPP + - bwin->GetFbY() * windowPitch; - clipping_rect *clips = bwin->GetClips(); - int32 numClips = bwin->GetNumClips(); - int i, y; - - /* Blit each clipping rectangle */ - bscreen.WaitForRetrace(); - for(i = 0; i < numClips; ++i) { - /* Get addresses of the start of each clipping rectangle */ - int32 width = clips[i].right - clips[i].left + 1; - int32 height = clips[i].bottom - clips[i].top + 1; - bufferpx = bwin->GetBufferPx() + - clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * BPP - windowSub; - - /* Copy each row of pixels from the window buffer into the frame - buffer */ - for(y = 0; y < height; ++y) - { - memcpy(bufferpx, windowpx, width * BPP); - bufferpx += bufferPitch; - windowpx += windowPitch; - } - } - bwin->UnlockBuffer(); - } - return 0; + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + if(bwin->ConnectionEnabled() && bwin->Connected()) { + bwin->LockBuffer(); + int32 windowPitch = window->surface->pitch; + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; + + int32 BPP = bwin->GetBytesPerPx(); + uint8 *windowBaseAddress = (uint8*)window->surface->pixels; + int32 windowSub = bwin->GetFbX() * BPP + + bwin->GetFbY() * windowPitch; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; + + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * BPP; + windowpx = windowBaseAddress + + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + memcpy(bufferpx, windowpx, width * BPP); + bufferpx += bufferPitch; + windowpx += windowPitch; + } + } + bwin->UnlockBuffer(); + } + return 0; } #endif diff --git a/src/video/haiku/SDL_bkeyboard.cc b/src/video/haiku/SDL_bkeyboard.cc index d12d238cde4ba..9a8b9a4a98d01 100644 --- a/src/video/haiku/SDL_bkeyboard.cc +++ b/src/video/haiku/SDL_bkeyboard.cc @@ -42,143 +42,143 @@ static SDL_Scancode keymap[KEYMAP_SIZE]; static int8 keystate[KEYMAP_SIZE]; void HAIKU_InitOSKeymap(void) { - for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) { - keymap[i] = SDL_SCANCODE_UNKNOWN; - } - - for( uint i = 0; i < KEYMAP_SIZE; ++i ) { - keystate[i] = SDL_RELEASED; - } - - keymap[0x01] = SDL_GetScancodeFromKey(SDLK_ESCAPE); - keymap[B_F1_KEY] = SDL_GetScancodeFromKey(SDLK_F1); - keymap[B_F2_KEY] = SDL_GetScancodeFromKey(SDLK_F2); - keymap[B_F3_KEY] = SDL_GetScancodeFromKey(SDLK_F3); - keymap[B_F4_KEY] = SDL_GetScancodeFromKey(SDLK_F4); - keymap[B_F5_KEY] = SDL_GetScancodeFromKey(SDLK_F5); - keymap[B_F6_KEY] = SDL_GetScancodeFromKey(SDLK_F6); - keymap[B_F7_KEY] = SDL_GetScancodeFromKey(SDLK_F7); - keymap[B_F8_KEY] = SDL_GetScancodeFromKey(SDLK_F8); - keymap[B_F9_KEY] = SDL_GetScancodeFromKey(SDLK_F9); - keymap[B_F10_KEY] = SDL_GetScancodeFromKey(SDLK_F10); - keymap[B_F11_KEY] = SDL_GetScancodeFromKey(SDLK_F11); - keymap[B_F12_KEY] = SDL_GetScancodeFromKey(SDLK_F12); - keymap[B_PRINT_KEY] = SDL_GetScancodeFromKey(SDLK_PRINTSCREEN); - keymap[B_SCROLL_KEY] = SDL_GetScancodeFromKey(SDLK_SCROLLLOCK); - keymap[B_PAUSE_KEY] = SDL_GetScancodeFromKey(SDLK_PAUSE); - keymap[0x11] = SDL_GetScancodeFromKey(SDLK_BACKQUOTE); - keymap[0x12] = SDL_GetScancodeFromKey(SDLK_1); - keymap[0x13] = SDL_GetScancodeFromKey(SDLK_2); - keymap[0x14] = SDL_GetScancodeFromKey(SDLK_3); - keymap[0x15] = SDL_GetScancodeFromKey(SDLK_4); - keymap[0x16] = SDL_GetScancodeFromKey(SDLK_5); - keymap[0x17] = SDL_GetScancodeFromKey(SDLK_6); - keymap[0x18] = SDL_GetScancodeFromKey(SDLK_7); - keymap[0x19] = SDL_GetScancodeFromKey(SDLK_8); - keymap[0x1a] = SDL_GetScancodeFromKey(SDLK_9); - keymap[0x1b] = SDL_GetScancodeFromKey(SDLK_0); - keymap[0x1c] = SDL_GetScancodeFromKey(SDLK_MINUS); - keymap[0x1d] = SDL_GetScancodeFromKey(SDLK_EQUALS); - keymap[0x1e] = SDL_GetScancodeFromKey(SDLK_BACKSPACE); - keymap[0x1f] = SDL_GetScancodeFromKey(SDLK_INSERT); - keymap[0x20] = SDL_GetScancodeFromKey(SDLK_HOME); - keymap[0x21] = SDL_GetScancodeFromKey(SDLK_PAGEUP); - keymap[0x22] = SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR); - keymap[0x23] = SDL_GetScancodeFromKey(SDLK_KP_DIVIDE); - keymap[0x24] = SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY); - keymap[0x25] = SDL_GetScancodeFromKey(SDLK_KP_MINUS); - keymap[0x26] = SDL_GetScancodeFromKey(SDLK_TAB); - keymap[0x27] = SDL_GetScancodeFromKey(SDLK_q); - keymap[0x28] = SDL_GetScancodeFromKey(SDLK_w); - keymap[0x29] = SDL_GetScancodeFromKey(SDLK_e); - keymap[0x2a] = SDL_GetScancodeFromKey(SDLK_r); - keymap[0x2b] = SDL_GetScancodeFromKey(SDLK_t); - keymap[0x2c] = SDL_GetScancodeFromKey(SDLK_y); - keymap[0x2d] = SDL_GetScancodeFromKey(SDLK_u); - keymap[0x2e] = SDL_GetScancodeFromKey(SDLK_i); - keymap[0x2f] = SDL_GetScancodeFromKey(SDLK_o); - keymap[0x30] = SDL_GetScancodeFromKey(SDLK_p); - keymap[0x31] = SDL_GetScancodeFromKey(SDLK_LEFTBRACKET); - keymap[0x32] = SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET); - keymap[0x33] = SDL_GetScancodeFromKey(SDLK_BACKSLASH); - keymap[0x34] = SDL_GetScancodeFromKey(SDLK_DELETE); - keymap[0x35] = SDL_GetScancodeFromKey(SDLK_END); - keymap[0x36] = SDL_GetScancodeFromKey(SDLK_PAGEDOWN); - keymap[0x37] = SDL_GetScancodeFromKey(SDLK_KP_7); - keymap[0x38] = SDL_GetScancodeFromKey(SDLK_KP_8); - keymap[0x39] = SDL_GetScancodeFromKey(SDLK_KP_9); - keymap[0x3a] = SDL_GetScancodeFromKey(SDLK_KP_PLUS); - keymap[0x3b] = SDL_GetScancodeFromKey(SDLK_CAPSLOCK); - keymap[0x3c] = SDL_GetScancodeFromKey(SDLK_a); - keymap[0x3d] = SDL_GetScancodeFromKey(SDLK_s); - keymap[0x3e] = SDL_GetScancodeFromKey(SDLK_d); - keymap[0x3f] = SDL_GetScancodeFromKey(SDLK_f); - keymap[0x40] = SDL_GetScancodeFromKey(SDLK_g); - keymap[0x41] = SDL_GetScancodeFromKey(SDLK_h); - keymap[0x42] = SDL_GetScancodeFromKey(SDLK_j); - keymap[0x43] = SDL_GetScancodeFromKey(SDLK_k); - keymap[0x44] = SDL_GetScancodeFromKey(SDLK_l); - keymap[0x45] = SDL_GetScancodeFromKey(SDLK_SEMICOLON); - keymap[0x46] = SDL_GetScancodeFromKey(SDLK_QUOTE); - keymap[0x47] = SDL_GetScancodeFromKey(SDLK_RETURN); - keymap[0x48] = SDL_GetScancodeFromKey(SDLK_KP_4); - keymap[0x49] = SDL_GetScancodeFromKey(SDLK_KP_5); - keymap[0x4a] = SDL_GetScancodeFromKey(SDLK_KP_6); - keymap[0x4b] = SDL_GetScancodeFromKey(SDLK_LSHIFT); - keymap[0x4c] = SDL_GetScancodeFromKey(SDLK_z); - keymap[0x4d] = SDL_GetScancodeFromKey(SDLK_x); - keymap[0x4e] = SDL_GetScancodeFromKey(SDLK_c); - keymap[0x4f] = SDL_GetScancodeFromKey(SDLK_v); - keymap[0x50] = SDL_GetScancodeFromKey(SDLK_b); - keymap[0x51] = SDL_GetScancodeFromKey(SDLK_n); - keymap[0x52] = SDL_GetScancodeFromKey(SDLK_m); - keymap[0x53] = SDL_GetScancodeFromKey(SDLK_COMMA); - keymap[0x54] = SDL_GetScancodeFromKey(SDLK_PERIOD); - keymap[0x55] = SDL_GetScancodeFromKey(SDLK_SLASH); - keymap[0x56] = SDL_GetScancodeFromKey(SDLK_RSHIFT); - keymap[0x57] = SDL_GetScancodeFromKey(SDLK_UP); - keymap[0x58] = SDL_GetScancodeFromKey(SDLK_KP_1); - keymap[0x59] = SDL_GetScancodeFromKey(SDLK_KP_2); - keymap[0x5a] = SDL_GetScancodeFromKey(SDLK_KP_3); - keymap[0x5b] = SDL_GetScancodeFromKey(SDLK_KP_ENTER); - keymap[0x5c] = SDL_GetScancodeFromKey(SDLK_LCTRL); - keymap[0x5d] = SDL_GetScancodeFromKey(SDLK_LALT); - keymap[0x5e] = SDL_GetScancodeFromKey(SDLK_SPACE); - keymap[0x5f] = SDL_GetScancodeFromKey(SDLK_RALT); - keymap[0x60] = SDL_GetScancodeFromKey(SDLK_RCTRL); - keymap[0x61] = SDL_GetScancodeFromKey(SDLK_LEFT); - keymap[0x62] = SDL_GetScancodeFromKey(SDLK_DOWN); - keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT); - keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0); - keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD); - keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); - keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); - keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU); - keymap[0x69] = SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */ - keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS); - keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER); + for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) { + keymap[i] = SDL_SCANCODE_UNKNOWN; + } + + for( uint i = 0; i < KEYMAP_SIZE; ++i ) { + keystate[i] = SDL_RELEASED; + } + + keymap[0x01] = SDL_GetScancodeFromKey(SDLK_ESCAPE); + keymap[B_F1_KEY] = SDL_GetScancodeFromKey(SDLK_F1); + keymap[B_F2_KEY] = SDL_GetScancodeFromKey(SDLK_F2); + keymap[B_F3_KEY] = SDL_GetScancodeFromKey(SDLK_F3); + keymap[B_F4_KEY] = SDL_GetScancodeFromKey(SDLK_F4); + keymap[B_F5_KEY] = SDL_GetScancodeFromKey(SDLK_F5); + keymap[B_F6_KEY] = SDL_GetScancodeFromKey(SDLK_F6); + keymap[B_F7_KEY] = SDL_GetScancodeFromKey(SDLK_F7); + keymap[B_F8_KEY] = SDL_GetScancodeFromKey(SDLK_F8); + keymap[B_F9_KEY] = SDL_GetScancodeFromKey(SDLK_F9); + keymap[B_F10_KEY] = SDL_GetScancodeFromKey(SDLK_F10); + keymap[B_F11_KEY] = SDL_GetScancodeFromKey(SDLK_F11); + keymap[B_F12_KEY] = SDL_GetScancodeFromKey(SDLK_F12); + keymap[B_PRINT_KEY] = SDL_GetScancodeFromKey(SDLK_PRINTSCREEN); + keymap[B_SCROLL_KEY] = SDL_GetScancodeFromKey(SDLK_SCROLLLOCK); + keymap[B_PAUSE_KEY] = SDL_GetScancodeFromKey(SDLK_PAUSE); + keymap[0x11] = SDL_GetScancodeFromKey(SDLK_BACKQUOTE); + keymap[0x12] = SDL_GetScancodeFromKey(SDLK_1); + keymap[0x13] = SDL_GetScancodeFromKey(SDLK_2); + keymap[0x14] = SDL_GetScancodeFromKey(SDLK_3); + keymap[0x15] = SDL_GetScancodeFromKey(SDLK_4); + keymap[0x16] = SDL_GetScancodeFromKey(SDLK_5); + keymap[0x17] = SDL_GetScancodeFromKey(SDLK_6); + keymap[0x18] = SDL_GetScancodeFromKey(SDLK_7); + keymap[0x19] = SDL_GetScancodeFromKey(SDLK_8); + keymap[0x1a] = SDL_GetScancodeFromKey(SDLK_9); + keymap[0x1b] = SDL_GetScancodeFromKey(SDLK_0); + keymap[0x1c] = SDL_GetScancodeFromKey(SDLK_MINUS); + keymap[0x1d] = SDL_GetScancodeFromKey(SDLK_EQUALS); + keymap[0x1e] = SDL_GetScancodeFromKey(SDLK_BACKSPACE); + keymap[0x1f] = SDL_GetScancodeFromKey(SDLK_INSERT); + keymap[0x20] = SDL_GetScancodeFromKey(SDLK_HOME); + keymap[0x21] = SDL_GetScancodeFromKey(SDLK_PAGEUP); + keymap[0x22] = SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR); + keymap[0x23] = SDL_GetScancodeFromKey(SDLK_KP_DIVIDE); + keymap[0x24] = SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY); + keymap[0x25] = SDL_GetScancodeFromKey(SDLK_KP_MINUS); + keymap[0x26] = SDL_GetScancodeFromKey(SDLK_TAB); + keymap[0x27] = SDL_GetScancodeFromKey(SDLK_q); + keymap[0x28] = SDL_GetScancodeFromKey(SDLK_w); + keymap[0x29] = SDL_GetScancodeFromKey(SDLK_e); + keymap[0x2a] = SDL_GetScancodeFromKey(SDLK_r); + keymap[0x2b] = SDL_GetScancodeFromKey(SDLK_t); + keymap[0x2c] = SDL_GetScancodeFromKey(SDLK_y); + keymap[0x2d] = SDL_GetScancodeFromKey(SDLK_u); + keymap[0x2e] = SDL_GetScancodeFromKey(SDLK_i); + keymap[0x2f] = SDL_GetScancodeFromKey(SDLK_o); + keymap[0x30] = SDL_GetScancodeFromKey(SDLK_p); + keymap[0x31] = SDL_GetScancodeFromKey(SDLK_LEFTBRACKET); + keymap[0x32] = SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET); + keymap[0x33] = SDL_GetScancodeFromKey(SDLK_BACKSLASH); + keymap[0x34] = SDL_GetScancodeFromKey(SDLK_DELETE); + keymap[0x35] = SDL_GetScancodeFromKey(SDLK_END); + keymap[0x36] = SDL_GetScancodeFromKey(SDLK_PAGEDOWN); + keymap[0x37] = SDL_GetScancodeFromKey(SDLK_KP_7); + keymap[0x38] = SDL_GetScancodeFromKey(SDLK_KP_8); + keymap[0x39] = SDL_GetScancodeFromKey(SDLK_KP_9); + keymap[0x3a] = SDL_GetScancodeFromKey(SDLK_KP_PLUS); + keymap[0x3b] = SDL_GetScancodeFromKey(SDLK_CAPSLOCK); + keymap[0x3c] = SDL_GetScancodeFromKey(SDLK_a); + keymap[0x3d] = SDL_GetScancodeFromKey(SDLK_s); + keymap[0x3e] = SDL_GetScancodeFromKey(SDLK_d); + keymap[0x3f] = SDL_GetScancodeFromKey(SDLK_f); + keymap[0x40] = SDL_GetScancodeFromKey(SDLK_g); + keymap[0x41] = SDL_GetScancodeFromKey(SDLK_h); + keymap[0x42] = SDL_GetScancodeFromKey(SDLK_j); + keymap[0x43] = SDL_GetScancodeFromKey(SDLK_k); + keymap[0x44] = SDL_GetScancodeFromKey(SDLK_l); + keymap[0x45] = SDL_GetScancodeFromKey(SDLK_SEMICOLON); + keymap[0x46] = SDL_GetScancodeFromKey(SDLK_QUOTE); + keymap[0x47] = SDL_GetScancodeFromKey(SDLK_RETURN); + keymap[0x48] = SDL_GetScancodeFromKey(SDLK_KP_4); + keymap[0x49] = SDL_GetScancodeFromKey(SDLK_KP_5); + keymap[0x4a] = SDL_GetScancodeFromKey(SDLK_KP_6); + keymap[0x4b] = SDL_GetScancodeFromKey(SDLK_LSHIFT); + keymap[0x4c] = SDL_GetScancodeFromKey(SDLK_z); + keymap[0x4d] = SDL_GetScancodeFromKey(SDLK_x); + keymap[0x4e] = SDL_GetScancodeFromKey(SDLK_c); + keymap[0x4f] = SDL_GetScancodeFromKey(SDLK_v); + keymap[0x50] = SDL_GetScancodeFromKey(SDLK_b); + keymap[0x51] = SDL_GetScancodeFromKey(SDLK_n); + keymap[0x52] = SDL_GetScancodeFromKey(SDLK_m); + keymap[0x53] = SDL_GetScancodeFromKey(SDLK_COMMA); + keymap[0x54] = SDL_GetScancodeFromKey(SDLK_PERIOD); + keymap[0x55] = SDL_GetScancodeFromKey(SDLK_SLASH); + keymap[0x56] = SDL_GetScancodeFromKey(SDLK_RSHIFT); + keymap[0x57] = SDL_GetScancodeFromKey(SDLK_UP); + keymap[0x58] = SDL_GetScancodeFromKey(SDLK_KP_1); + keymap[0x59] = SDL_GetScancodeFromKey(SDLK_KP_2); + keymap[0x5a] = SDL_GetScancodeFromKey(SDLK_KP_3); + keymap[0x5b] = SDL_GetScancodeFromKey(SDLK_KP_ENTER); + keymap[0x5c] = SDL_GetScancodeFromKey(SDLK_LCTRL); + keymap[0x5d] = SDL_GetScancodeFromKey(SDLK_LALT); + keymap[0x5e] = SDL_GetScancodeFromKey(SDLK_SPACE); + keymap[0x5f] = SDL_GetScancodeFromKey(SDLK_RALT); + keymap[0x60] = SDL_GetScancodeFromKey(SDLK_RCTRL); + keymap[0x61] = SDL_GetScancodeFromKey(SDLK_LEFT); + keymap[0x62] = SDL_GetScancodeFromKey(SDLK_DOWN); + keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT); + keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0); + keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD); + keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); + keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); + keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU); + keymap[0x69] = SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */ + keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS); + keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER); } SDL_Scancode HAIKU_GetScancodeFromBeKey(int32 bkey) { - if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) { - return keymap[bkey]; - } else { - return SDL_SCANCODE_UNKNOWN; - } + if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) { + return keymap[bkey]; + } else { + return SDL_SCANCODE_UNKNOWN; + } } int8 HAIKU_GetKeyState(int32 bkey) { - if(bkey > 0 && bkey < KEYMAP_SIZE) { - return keystate[bkey]; - } else { - return SDL_RELEASED; - } + if(bkey > 0 && bkey < KEYMAP_SIZE) { + return keystate[bkey]; + } else { + return SDL_RELEASED; + } } void HAIKU_SetKeyState(int32 bkey, int8 state) { - if(bkey > 0 && bkey < KEYMAP_SIZE) { - keystate[bkey] = state; - } + if(bkey > 0 && bkey < KEYMAP_SIZE) { + keystate[bkey] = state; + } } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc index 1d86821156fe7..9d719967381b1 100644 --- a/src/video/haiku/SDL_bmodes.cc +++ b/src/video/haiku/SDL_bmodes.cc @@ -44,30 +44,30 @@ extern "C" { /* This wrapper is here so that the driverdata can be freed without freeing the display_mode structure */ struct SDL_DisplayModeData { - display_mode *bmode; + display_mode *bmode; }; #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return ((SDL_BWin*)(window->driverdata)); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return ((SDL_BApp*)be_app); } static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) { #if WRAP_BMODE - return ((SDL_DisplayModeData*)mode->driverdata)->bmode; + return ((SDL_DisplayModeData*)mode->driverdata)->bmode; #else - return (display_mode*)(mode->driverdata); + return (display_mode*)(mode->driverdata); #endif } /* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */ static float get_refresh_rate(display_mode &mode) { - return float(mode.timing.pixel_clock * 1000) - / float(mode.timing.h_total * mode.timing.v_total); + return float(mode.timing.pixel_clock * 1000) + / float(mode.timing.h_total * mode.timing.v_total); } @@ -76,57 +76,57 @@ static float get_refresh_rate(display_mode &mode) { * This is a useful debugging tool. Uncomment and insert into code as needed. */ void _SpoutModeData(display_mode *bmode) { - printf("BMode:\n"); - printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); - printf("\th,v = (%i,%i)\n", bmode->h_display_start, - bmode->v_display_start); - if(bmode->flags) { - printf("\tFlags:\n"); - if(bmode->flags & B_SCROLL) { - printf("\t\tB_SCROLL\n"); - } - if(bmode->flags & B_8_BIT_DAC) { - printf("\t\tB_8_BIT_DAC\n"); - } - if(bmode->flags & B_HARDWARE_CURSOR) { - printf("\t\tB_HARDWARE_CURSOR\n"); - } - if(bmode->flags & B_PARALLEL_ACCESS) { - printf("\t\tB_PARALLEL_ACCESS\n"); - } - if(bmode->flags & B_DPMS) { - printf("\t\tB_DPMS\n"); - } - if(bmode->flags & B_IO_FB_NA) { - printf("\t\tB_IO_FB_NA\n"); - } - } - printf("\tTiming:\n"); - printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); - printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", - bmode->timing.h_display, bmode->timing.h_sync_start, - bmode->timing.h_sync_end, bmode->timing.h_total); - printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", - bmode->timing.v_display, bmode->timing.v_sync_start, - bmode->timing.v_sync_end, bmode->timing.v_total); - if(bmode->timing.flags) { - printf("\t\tFlags:\n"); - if(bmode->timing.flags & B_BLANK_PEDESTAL) { - printf("\t\t\tB_BLANK_PEDESTAL\n"); - } - if(bmode->timing.flags & B_TIMING_INTERLACED) { - printf("\t\t\tB_TIMING_INTERLACED\n"); - } - if(bmode->timing.flags & B_POSITIVE_HSYNC) { - printf("\t\t\tB_POSITIVE_HSYNC\n"); - } - if(bmode->timing.flags & B_POSITIVE_VSYNC) { - printf("\t\t\tB_POSITIVE_VSYNC\n"); - } - if(bmode->timing.flags & B_SYNC_ON_GREEN) { - printf("\t\t\tB_SYNC_ON_GREEN\n"); - } - } + printf("BMode:\n"); + printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); + printf("\th,v = (%i,%i)\n", bmode->h_display_start, + bmode->v_display_start); + if(bmode->flags) { + printf("\tFlags:\n"); + if(bmode->flags & B_SCROLL) { + printf("\t\tB_SCROLL\n"); + } + if(bmode->flags & B_8_BIT_DAC) { + printf("\t\tB_8_BIT_DAC\n"); + } + if(bmode->flags & B_HARDWARE_CURSOR) { + printf("\t\tB_HARDWARE_CURSOR\n"); + } + if(bmode->flags & B_PARALLEL_ACCESS) { + printf("\t\tB_PARALLEL_ACCESS\n"); + } + if(bmode->flags & B_DPMS) { + printf("\t\tB_DPMS\n"); + } + if(bmode->flags & B_IO_FB_NA) { + printf("\t\tB_IO_FB_NA\n"); + } + } + printf("\tTiming:\n"); + printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); + printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.h_display, bmode->timing.h_sync_start, + bmode->timing.h_sync_end, bmode->timing.h_total); + printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.v_display, bmode->timing.v_sync_start, + bmode->timing.v_sync_end, bmode->timing.v_total); + if(bmode->timing.flags) { + printf("\t\tFlags:\n"); + if(bmode->timing.flags & B_BLANK_PEDESTAL) { + printf("\t\t\tB_BLANK_PEDESTAL\n"); + } + if(bmode->timing.flags & B_TIMING_INTERLACED) { + printf("\t\t\tB_TIMING_INTERLACED\n"); + } + if(bmode->timing.flags & B_POSITIVE_HSYNC) { + printf("\t\t\tB_POSITIVE_HSYNC\n"); + } + if(bmode->timing.flags & B_POSITIVE_VSYNC) { + printf("\t\t\tB_POSITIVE_VSYNC\n"); + } + if(bmode->timing.flags & B_SYNC_ON_GREEN) { + printf("\t\t\tB_SYNC_ON_GREEN\n"); + } + } } #endif @@ -134,101 +134,101 @@ void _SpoutModeData(display_mode *bmode) { int32 HAIKU_ColorSpaceToBitsPerPixel(uint32 colorspace) { - int bitsperpixel; - - bitsperpixel = 0; - switch (colorspace) { - case B_CMAP8: - bitsperpixel = 8; - break; - case B_RGB15: - case B_RGBA15: - case B_RGB15_BIG: - case B_RGBA15_BIG: - bitsperpixel = 15; - break; - case B_RGB16: - case B_RGB16_BIG: - bitsperpixel = 16; - break; - case B_RGB32: - case B_RGBA32: - case B_RGB32_BIG: - case B_RGBA32_BIG: - bitsperpixel = 32; - break; - default: - break; - } - return(bitsperpixel); + int bitsperpixel; + + bitsperpixel = 0; + switch (colorspace) { + case B_CMAP8: + bitsperpixel = 8; + break; + case B_RGB15: + case B_RGBA15: + case B_RGB15_BIG: + case B_RGBA15_BIG: + bitsperpixel = 15; + break; + case B_RGB16: + case B_RGB16_BIG: + bitsperpixel = 16; + break; + case B_RGB32: + case B_RGBA32: + case B_RGB32_BIG: + case B_RGBA32_BIG: + bitsperpixel = 32; + break; + default: + break; + } + return(bitsperpixel); } int32 HAIKU_BPPToSDLPxFormat(int32 bpp) { - /* Translation taken from SDL_windowsmodes.c */ - switch (bpp) { - case 32: - return SDL_PIXELFORMAT_RGB888; - break; - case 24: /* May not be supported by Haiku */ - return SDL_PIXELFORMAT_RGB24; - break; - case 16: - return SDL_PIXELFORMAT_RGB565; - break; - case 15: - return SDL_PIXELFORMAT_RGB555; - break; - case 8: - return SDL_PIXELFORMAT_INDEX8; - break; - case 4: /* May not be supported by Haiku */ - return SDL_PIXELFORMAT_INDEX4LSB; - break; - } - - /* May never get here, but safer and needed to shut up compiler */ - SDL_SetError("Invalid bpp value"); - return 0; + /* Translation taken from SDL_windowsmodes.c */ + switch (bpp) { + case 32: + return SDL_PIXELFORMAT_RGB888; + break; + case 24: /* May not be supported by Haiku */ + return SDL_PIXELFORMAT_RGB24; + break; + case 16: + return SDL_PIXELFORMAT_RGB565; + break; + case 15: + return SDL_PIXELFORMAT_RGB555; + break; + case 8: + return SDL_PIXELFORMAT_INDEX8; + break; + case 4: /* May not be supported by Haiku */ + return SDL_PIXELFORMAT_INDEX4LSB; + break; + } + + /* May never get here, but safer and needed to shut up compiler */ + SDL_SetError("Invalid bpp value"); + return 0; } static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, - SDL_DisplayMode *mode) { - mode->w = bmode->virtual_width; - mode->h = bmode->virtual_height; - mode->refresh_rate = (int)get_refresh_rate(*bmode); + SDL_DisplayMode *mode) { + mode->w = bmode->virtual_width; + mode->h = bmode->virtual_height; + mode->refresh_rate = (int)get_refresh_rate(*bmode); #if WRAP_BMODE - SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, - sizeof(SDL_DisplayModeData)); - data->bmode = bmode; - - mode->driverdata = data; + SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, + sizeof(SDL_DisplayModeData)); + data->bmode = bmode; + + mode->driverdata = data; #else - mode->driverdata = bmode; + mode->driverdata = bmode; #endif - /* Set the format */ - int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode->space); - mode->format = HAIKU_BPPToSDLPxFormat(bpp); + /* Set the format */ + int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode->space); + mode->format = HAIKU_BPPToSDLPxFormat(bpp); } /* Later, there may be more than one monitor available */ static void _AddDisplay(BScreen *screen) { - SDL_VideoDisplay display; - SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, - sizeof(SDL_DisplayMode)); - display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode)); - screen->GetMode(bmode); - - _BDisplayModeToSdlDisplayMode(bmode, mode); - - SDL_zero(display); - display.desktop_mode = *mode; - display.current_mode = *mode; - - SDL_AddVideoDisplay(&display); + SDL_VideoDisplay display; + SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, + sizeof(SDL_DisplayMode)); + display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode)); + screen->GetMode(bmode); + + _BDisplayModeToSdlDisplayMode(bmode, mode); + + SDL_zero(display); + display.desktop_mode = *mode; + display.current_mode = *mode; + + SDL_AddVideoDisplay(&display); } /* @@ -236,92 +236,92 @@ static void _AddDisplay(BScreen *screen) { */ int HAIKU_InitModes(_THIS) { - BScreen screen; + BScreen screen; - /* TODO: When Haiku supports multiple display screens, call - _AddDisplayScreen() for each of them. */ - _AddDisplay(&screen); - return 0; + /* TODO: When Haiku supports multiple display screens, call + _AddDisplayScreen() for each of them. */ + _AddDisplay(&screen); + return 0; } int HAIKU_QuitModes(_THIS) { - /* FIXME: Nothing really needs to be done here at the moment? */ - return 0; + /* FIXME: Nothing really needs to be done here at the moment? */ + return 0; } int HAIKU_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - BScreen bscreen; - BRect rc = bscreen.Frame(); - rect->x = (int)rc.left; - rect->y = (int)rc.top; - rect->w = (int)rc.Width() + 1; - rect->h = (int)rc.Height() + 1; - return 0; + BScreen bscreen; + BRect rc = bscreen.Frame(); + rect->x = (int)rc.left; + rect->y = (int)rc.top; + rect->w = (int)rc.Width() + 1; + rect->h = (int)rc.Height() + 1; + return 0; } void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { - /* Get the current screen */ - BScreen bscreen; - - /* Iterate through all of the modes */ - SDL_DisplayMode mode; - display_mode this_bmode; - display_mode *bmodes; - uint32 count, i; - - /* Get graphics-hardware supported modes */ - bscreen.GetModeList(&bmodes, &count); - bscreen.GetMode(&this_bmode); - - for(i = 0; i < count; ++i) { - // FIXME: Apparently there are errors with colorspace changes - if (bmodes[i].space == this_bmode.space) { - _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); - SDL_AddDisplayMode(display, &mode); - } - } - free(bmodes); + /* Get the current screen */ + BScreen bscreen; + + /* Iterate through all of the modes */ + SDL_DisplayMode mode; + display_mode this_bmode; + display_mode *bmodes; + uint32 count, i; + + /* Get graphics-hardware supported modes */ + bscreen.GetModeList(&bmodes, &count); + bscreen.GetMode(&this_bmode); + + for(i = 0; i < count; ++i) { + // FIXME: Apparently there are errors with colorspace changes + if (bmodes[i].space == this_bmode.space) { + _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); + SDL_AddDisplayMode(display, &mode); + } + } + free(bmodes); } int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ - /* Get the current screen */ - BScreen bscreen; - if(!bscreen.IsValid()) { - printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); - } - - /* Set the mode using the driver data */ - display_mode *bmode = _ExtractBMode(mode); - - - /* FIXME: Is the first option always going to be the right one? */ - uint32 c = 0, i; - display_mode *bmode_list; - bscreen.GetModeList(&bmode_list, &c); - for(i = 0; i < c; ++i) { - if( bmode_list[i].space == bmode->space && - bmode_list[i].virtual_width == bmode->virtual_width && - bmode_list[i].virtual_height == bmode->virtual_height ) { - bmode = &bmode_list[i]; - break; - } - } - - if(bscreen.SetMode(bmode) != B_OK) { - return SDL_SetError("Bad video mode"); - } - - free(bmode_list); - + /* Get the current screen */ + BScreen bscreen; + if(!bscreen.IsValid()) { + printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); + } + + /* Set the mode using the driver data */ + display_mode *bmode = _ExtractBMode(mode); + + + /* FIXME: Is the first option always going to be the right one? */ + uint32 c = 0, i; + display_mode *bmode_list; + bscreen.GetModeList(&bmode_list, &c); + for(i = 0; i < c; ++i) { + if( bmode_list[i].space == bmode->space && + bmode_list[i].virtual_width == bmode->virtual_width && + bmode_list[i].virtual_height == bmode->virtual_height ) { + bmode = &bmode_list[i]; + break; + } + } + + if(bscreen.SetMode(bmode) != B_OK) { + return SDL_SetError("Bad video mode"); + } + + free(bmode_list); + #if SDL_VIDEO_OPENGL - /* FIXME: Is there some way to reboot the OpenGL context? This doesn't - help */ -// HAIKU_GL_RebootContexts(_this); + /* FIXME: Is there some way to reboot the OpenGL context? This doesn't + help */ +// HAIKU_GL_RebootContexts(_this); #endif - return 0; + return 0; } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index e6a9736d08a2d..e7b4b6e30034b 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -56,7 +56,7 @@ HAIKU_CreateDevice(int devindex) device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); device->driverdata = NULL; /* FIXME: Is this the cause of some of the - SDL_Quit() errors? */ + SDL_Quit() errors? */ /* TODO: Figure out if any initialization needs to go here */ @@ -122,37 +122,36 @@ HAIKU_CreateDevice(int devindex) } VideoBootStrap HAIKU_bootstrap = { - "haiku", "Haiku graphics", - HAIKU_Available, HAIKU_CreateDevice + "haiku", "Haiku graphics", + HAIKU_Available, HAIKU_CreateDevice }; void HAIKU_DeleteDevice(SDL_VideoDevice * device) { - SDL_free(device->driverdata); - SDL_free(device); + SDL_free(device->driverdata); + SDL_free(device); } int HAIKU_VideoInit(_THIS) { - /* Initialize the Be Application for appserver interaction */ - if (SDL_InitBeApp() < 0) { - return -1; - } - - /* Initialize video modes */ - HAIKU_InitModes(_this); - - /* Init the keymap */ - HAIKU_InitOSKeymap(); - - + /* Initialize the Be Application for appserver interaction */ + if (SDL_InitBeApp() < 0) { + return -1; + } + + /* Initialize video modes */ + HAIKU_InitModes(_this); + + /* Init the keymap */ + HAIKU_InitOSKeymap(); + #if SDL_VIDEO_OPENGL /* testgl application doesn't load library, just tries to load symbols */ /* is it correct? if so we have to load library here */ HAIKU_GL_LoadLibrary(_this, NULL); #endif - /* We're done! */ + /* We're done! */ return (0); } diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc index e89be1eb68fdd..142a3fa18c817 100644 --- a/src/video/haiku/SDL_bwindow.cc +++ b/src/video/haiku/SDL_bwindow.cc @@ -32,36 +32,36 @@ extern "C" { #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return ((SDL_BWin*)(window->driverdata)); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return ((SDL_BApp*)be_app); } static int _InitWindow(_THIS, SDL_Window *window) { - uint32 flags = 0; - window_look look = B_TITLED_WINDOW_LOOK; + uint32 flags = 0; + window_look look = B_TITLED_WINDOW_LOOK; - BRect bounds( + BRect bounds( window->x, window->y, - window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing + window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing window->y + window->h - 1 ); if(window->flags & SDL_WINDOW_FULLSCREEN) { - /* TODO: Add support for this flag */ - printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__); + /* TODO: Add support for this flag */ + printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__); } if(window->flags & SDL_WINDOW_OPENGL) { - /* TODO: Add support for this flag */ + /* TODO: Add support for this flag */ } if(!(window->flags & SDL_WINDOW_RESIZABLE)) { - flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; + flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; } if(window->flags & SDL_WINDOW_BORDERLESS) { - look = B_NO_BORDER_WINDOW_LOOK; + look = B_NO_BORDER_WINDOW_LOOK; } SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags); @@ -79,35 +79,35 @@ int HAIKU_CreateWindow(_THIS, SDL_Window *window) { if (_InitWindow(_this, window) < 0) { return -1; } - - /* Start window loop */ + + /* Start window loop */ _ToBeWin(window)->Show(); return 0; } int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { - SDL_BWin *otherBWin = (SDL_BWin*)data; - if(!otherBWin->LockLooper()) - return -1; - - /* Create the new window and initialize its members */ - window->x = (int)otherBWin->Frame().left; - window->y = (int)otherBWin->Frame().top; - window->w = (int)otherBWin->Frame().Width(); - window->h = (int)otherBWin->Frame().Height(); - - /* Set SDL flags */ - if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) { - window->flags |= SDL_WINDOW_RESIZABLE; - } - - /* If we are out of memory, return the error code */ + SDL_BWin *otherBWin = (SDL_BWin*)data; + if(!otherBWin->LockLooper()) + return -1; + + /* Create the new window and initialize its members */ + window->x = (int)otherBWin->Frame().left; + window->y = (int)otherBWin->Frame().top; + window->w = (int)otherBWin->Frame().Width(); + window->h = (int)otherBWin->Frame().Height(); + + /* Set SDL flags */ + if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) { + window->flags |= SDL_WINDOW_RESIZABLE; + } + + /* If we are out of memory, return the error code */ if (_InitWindow(_this, window) < 0) { return -1; } - - /* TODO: Add any other SDL-supported window attributes here */ + + /* TODO: Add any other SDL-supported window attributes here */ _ToBeWin(window)->SetTitle(otherBWin->Title()); /* Start window loop and unlock the other window */ @@ -118,106 +118,106 @@ int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { } void HAIKU_SetWindowTitle(_THIS, SDL_Window * window) { - BMessage msg(BWIN_SET_TITLE); - msg.AddString("window-title", window->title); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_SET_TITLE); + msg.AddString("window-title", window->title); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) { - /* FIXME: Icons not supported by Haiku */ + /* FIXME: Icons not supported by Haiku */ } void HAIKU_SetWindowPosition(_THIS, SDL_Window * window) { - BMessage msg(BWIN_MOVE_WINDOW); - msg.AddInt32("window-x", window->x); - msg.AddInt32("window-y", window->y); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_MOVE_WINDOW); + msg.AddInt32("window-x", window->x); + msg.AddInt32("window-y", window->y); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_SetWindowSize(_THIS, SDL_Window * window) { - BMessage msg(BWIN_RESIZE_WINDOW); - msg.AddInt32("window-w", window->w - 1); - msg.AddInt32("window-h", window->h - 1); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_RESIZE_WINDOW); + msg.AddInt32("window-w", window->w - 1); + msg.AddInt32("window-h", window->h - 1); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) { - BMessage msg(BWIN_SET_BORDERED); - msg.AddBool("window-border", bordered != SDL_FALSE); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_SET_BORDERED); + msg.AddBool("window-border", bordered != SDL_FALSE); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) { - BMessage msg(BWIN_SET_RESIZABLE); - msg.AddBool("window-resizable", resizable != SDL_FALSE); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_SET_RESIZABLE); + msg.AddBool("window-resizable", resizable != SDL_FALSE); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_ShowWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_SHOW_WINDOW); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_SHOW_WINDOW); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_HideWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_HIDE_WINDOW); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_HIDE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_RaiseWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */ - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */ + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_MaximizeWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_MAXIMIZE_WINDOW); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_MAXIMIZE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_MinimizeWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_MINIMIZE_WINDOW); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_MINIMIZE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_RestoreWindow(_THIS, SDL_Window * window) { - BMessage msg(BWIN_RESTORE_WINDOW); - _ToBeWin(window)->PostMessage(&msg); + BMessage msg(BWIN_RESTORE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); } void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window, - SDL_VideoDisplay * display, SDL_bool fullscreen) { - /* Haiku tracks all video display information */ - BMessage msg(BWIN_FULLSCREEN); - msg.AddBool("fullscreen", fullscreen); - _ToBeWin(window)->PostMessage(&msg); - + SDL_VideoDisplay * display, SDL_bool fullscreen) { + /* Haiku tracks all video display information */ + BMessage msg(BWIN_FULLSCREEN); + msg.AddBool("fullscreen", fullscreen); + _ToBeWin(window)->PostMessage(&msg); + } int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) { - /* FIXME: Not Haiku supported */ - return -1; + /* FIXME: Not Haiku supported */ + return -1; } int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) { - /* FIXME: Not Haiku supported */ - return -1; + /* FIXME: Not Haiku supported */ + return -1; } void HAIKU_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) { - /* TODO: Implement this! */ + /* TODO: Implement this! */ } void HAIKU_DestroyWindow(_THIS, SDL_Window * window) { - _ToBeWin(window)->LockLooper(); /* This MUST be locked */ - _GetBeApp()->ClearID(_ToBeWin(window)); - _ToBeWin(window)->Quit(); - window->driverdata = NULL; + _ToBeWin(window)->LockLooper(); /* This MUST be locked */ + _GetBeApp()->ClearID(_ToBeWin(window)); + _ToBeWin(window)->Quit(); + window->driverdata = NULL; } SDL_bool HAIKU_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) { - /* FIXME: What is the point of this? What information should be included? */ - return SDL_FALSE; + /* FIXME: What is the point of this? What information should be included? */ + return SDL_FALSE; } diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index e23dd1310ee60..04740899fdbf1 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -487,12 +487,12 @@ KMSDRM_MoveCursor(SDL_Cursor * cursor) That's why we move the cursor graphic ONLY. */ if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) { curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata; - drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo)); - ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y); + drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo)); + ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y); - if (ret) { - SDL_SetError("drmModeMoveCursor() failed."); - } + if (ret) { + SDL_SetError("drmModeMoveCursor() failed."); + } } } diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index 7a0b079ffd4f6..7e8fae725d2b2 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -50,23 +50,23 @@ KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) { KMSDRM_FBInfo *fb_info; if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup"); - return SDL_FALSE; + SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup"); + return SDL_FALSE; } wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs); if (wdata->next_bo == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup"); - return SDL_FALSE; + SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup"); + return SDL_FALSE; } fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo); if (fb_info == NULL) { - return SDL_FALSE; + return SDL_FALSE; } if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id, - 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) { + 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) { SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC to a GBM buffer"); return SDL_FALSE; @@ -153,14 +153,14 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) { } else { /* Queue page flip at vsync */ - /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not, + /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not, or FlipPage won't work in some cases. */ - if (!wdata->crtc_ready) { + if (!wdata->crtc_ready) { if(!KMSDRM_GLES_SetupCrtc(_this, window)) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips"); return 0; } - } + } /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)", vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */ diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index e3863803a3bf9..c4f4a6069bf76 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -343,17 +343,17 @@ RPI_DestroyWindow(_THIS, SDL_Window * window) SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; if(data) { - if (data->double_buffer) { - /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */ - SDL_LockMutex(data->vsync_cond_mutex); - SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex); - SDL_UnlockMutex(data->vsync_cond_mutex); + if (data->double_buffer) { + /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */ + SDL_LockMutex(data->vsync_cond_mutex); + SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex); + SDL_UnlockMutex(data->vsync_cond_mutex); - vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL); + vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL); - SDL_DestroyCond(data->vsync_cond); - SDL_DestroyMutex(data->vsync_cond_mutex); - } + SDL_DestroyCond(data->vsync_cond); + SDL_DestroyMutex(data->vsync_cond_mutex); + } #if SDL_VIDEO_OPENGL_EGL if (data->egl_surface != EGL_NO_SURFACE) { diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index e8ecebe11eabd..15762d2bf4297 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -445,7 +445,7 @@ - (void)setWindow:(UIWindow *)window #if !TARGET_OS_TV - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation { - SDL_OnApplicationDidChangeStatusBarOrientation(); + SDL_OnApplicationDidChangeStatusBarOrientation(); } #endif diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index acf739b61bec8..7ddf1078af976 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -191,7 +191,7 @@ @implementation SDL_DisplayModeData } } #if !TARGET_OS_TV - SDL_OnApplicationDidChangeStatusBarOrientation(); + SDL_OnApplicationDidChangeStatusBarOrientation(); #endif } diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index bd60c552fd7d5..caabfac072478 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -252,34 +252,34 @@ - (SDL_Scancode)scancodeFromPressType:(UIPressType)presstype - (void)pressesBegan:(NSSet *)presses withEvent:(UIPressesEvent *)event { - if (!SDL_AppleTVRemoteOpenedAsJoystick) { - for (UIPress *press in presses) { - SDL_Scancode scancode = [self scancodeFromPressType:press.type]; - SDL_SendKeyboardKey(SDL_PRESSED, scancode); - } - } + if (!SDL_AppleTVRemoteOpenedAsJoystick) { + for (UIPress *press in presses) { + SDL_Scancode scancode = [self scancodeFromPressType:press.type]; + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } + } [super pressesBegan:presses withEvent:event]; } - (void)pressesEnded:(NSSet *)presses withEvent:(UIPressesEvent *)event { - if (!SDL_AppleTVRemoteOpenedAsJoystick) { - for (UIPress *press in presses) { - SDL_Scancode scancode = [self scancodeFromPressType:press.type]; - SDL_SendKeyboardKey(SDL_RELEASED, scancode); - } - } + if (!SDL_AppleTVRemoteOpenedAsJoystick) { + for (UIPress *press in presses) { + SDL_Scancode scancode = [self scancodeFromPressType:press.type]; + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + } [super pressesEnded:presses withEvent:event]; } - (void)pressesCancelled:(NSSet *)presses withEvent:(UIPressesEvent *)event { - if (!SDL_AppleTVRemoteOpenedAsJoystick) { - for (UIPress *press in presses) { - SDL_Scancode scancode = [self scancodeFromPressType:press.type]; - SDL_SendKeyboardKey(SDL_RELEASED, scancode); - } - } + if (!SDL_AppleTVRemoteOpenedAsJoystick) { + for (UIPress *press in presses) { + SDL_Scancode scancode = [self scancodeFromPressType:press.type]; + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + } [super pressesCancelled:presses withEvent:event]; } diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index b8be6087fac6b..5ee76afea5582 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -747,7 +747,7 @@ static const struct wl_data_offer_listener data_offer_listener = { static void data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, - struct wl_data_offer *id) + struct wl_data_offer *id) { SDL_WaylandDataOffer *data_offer = NULL; @@ -765,7 +765,7 @@ data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, static void data_device_handle_enter(void *data, struct wl_data_device *wl_data_device, - uint32_t serial, struct wl_surface *surface, + uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id) { SDL_WaylandDataDevice *data_device = data; @@ -808,7 +808,7 @@ data_device_handle_leave(void *data, struct wl_data_device *wl_data_device) static void data_device_handle_motion(void *data, struct wl_data_device *wl_data_device, - uint32_t time, wl_fixed_t x, wl_fixed_t y) + uint32_t time, wl_fixed_t x, wl_fixed_t y) { } @@ -847,7 +847,7 @@ data_device_handle_drop(void *data, struct wl_data_device *wl_data_device) static void data_device_handle_selection(void *data, struct wl_data_device *wl_data_device, - struct wl_data_offer *id) + struct wl_data_offer *id) { SDL_WaylandDataDevice *data_device = data; SDL_WaylandDataOffer *offer = NULL; diff --git a/src/video/wayland/SDL_waylandtouch.c b/src/video/wayland/SDL_waylandtouch.c index 005b47f587acf..1cf37c1a28902 100644 --- a/src/video/wayland/SDL_waylandtouch.c +++ b/src/video/wayland/SDL_waylandtouch.c @@ -89,9 +89,9 @@ touch_handle_touch(void *data, */ SDL_TouchID deviceId = 1; - if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { - SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); - } + if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); + } switch (touchState) { case QtWaylandTouchPointPressed: diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 06230277f7963..b6155e76d9ef2 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -68,10 +68,10 @@ static char * get_classname() { /* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec: - "The surface class identifies the general class of applications - to which the surface belongs. A common convention is to use the - file name (or the full path if it is a non-standard location) of - the application's .desktop file as the class." */ + "The surface class identifies the general class of applications + to which the surface belongs. A common convention is to use the + file name (or the full path if it is a non-standard location) of + the application's .desktop file as the class." */ char *spot; #if defined(__LINUX__) || defined(__FREEBSD__) diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index 7055336d6a4a4..aaebea9acb075 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -134,10 +134,10 @@ static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = { static void handle_configure_zxdg_toplevel(void *data, - struct zxdg_toplevel_v6 *zxdg_toplevel_v6, - int32_t width, - int32_t height, - struct wl_array *states) + struct zxdg_toplevel_v6 *zxdg_toplevel_v6, + int32_t width, + int32_t height, + struct wl_array *states) { SDL_WindowData *wind = (SDL_WindowData *)data; SDL_Window *window = wind->sdlwindow; @@ -213,10 +213,10 @@ static const struct xdg_surface_listener shell_surface_listener_xdg = { static void handle_configure_xdg_toplevel(void *data, - struct xdg_toplevel *xdg_toplevel, - int32_t width, - int32_t height, - struct wl_array *states) + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *states) { SDL_WindowData *wind = (SDL_WindowData *)data; SDL_Window *window = wind->sdlwindow; diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h index 75b4898c3a219..87044117c55fa 100644 --- a/src/video/windows/SDL_windowsopengl.h +++ b/src/video/windows/SDL_windowsopengl.h @@ -33,31 +33,31 @@ struct SDL_GLDriverData SDL_bool HAS_WGL_ARB_create_context_robustness; SDL_bool HAS_WGL_ARB_create_context_no_error; - /* Max version of OpenGL ES context that can be created if the - implementation supports WGL_EXT_create_context_es2_profile. - major = minor = 0 when unsupported. - */ - struct { - int major; - int minor; - } es_profile_max_supported_version; + /* Max version of OpenGL ES context that can be created if the + implementation supports WGL_EXT_create_context_es2_profile. + major = minor = 0 when unsupported. + */ + struct { + int major; + int minor; + } es_profile_max_supported_version; - void *(WINAPI * wglGetProcAddress) (const char *proc); - HGLRC(WINAPI * wglCreateContext) (HDC hdc); - BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc); - BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc); - BOOL(WINAPI * wglShareLists) (HGLRC hglrc1, HGLRC hglrc2); - BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc, - const int *piAttribIList, - const FLOAT * pfAttribFList, - UINT nMaxFormats, - int *piFormats, - UINT * nNumFormats); - BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat, - int iLayerPlane, - UINT nAttributes, - const int *piAttributes, - int *piValues); + void *(WINAPI * wglGetProcAddress) (const char *proc); + HGLRC(WINAPI * wglCreateContext) (HDC hdc); + BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc); + BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc); + BOOL(WINAPI * wglShareLists) (HGLRC hglrc1, HGLRC hglrc2); + BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc, + const int *piAttribIList, + const FLOAT * pfAttribFList, + UINT nMaxFormats, + int *piFormats, + UINT * nNumFormats); + BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat, + int iLayerPlane, + UINT nAttributes, + const int *piAttributes, + int *piValues); BOOL (WINAPI * wglSwapIntervalEXT) (int interval); int (WINAPI * wglGetSwapIntervalEXT) (void); }; diff --git a/src/video/windows/SDL_windowsvulkan.c b/src/video/windows/SDL_windowsvulkan.c index c4b34f0db2e8a..6bb8f2a428cd0 100644 --- a/src/video/windows/SDL_windowsvulkan.c +++ b/src/video/windows/SDL_windowsvulkan.c @@ -40,7 +40,7 @@ int WIN_Vulkan_LoadLibrary(_THIS, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; - Uint32 i; + Uint32 i; SDL_bool hasSurfaceExtension = SDL_FALSE; SDL_bool hasWin32SurfaceExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h index 1a26ea0994ce1..7331b71ff03a2 100644 --- a/src/video/x11/SDL_x11opengl.h +++ b/src/video/x11/SDL_x11opengl.h @@ -38,14 +38,14 @@ struct SDL_GLDriverData SDL_bool HAS_GLX_ARB_create_context_robustness; SDL_bool HAS_GLX_ARB_create_context_no_error; - /* Max version of OpenGL ES context that can be created if the - implementation supports GLX_EXT_create_context_es2_profile. - major = minor = 0 when unsupported. - */ - struct { - int major; - int minor; - } es_profile_max_supported_version; + /* Max version of OpenGL ES context that can be created if the + implementation supports GLX_EXT_create_context_es2_profile. + major = minor = 0 when unsupported. + */ + struct { + int major; + int minor; + } es_profile_max_supported_version; Bool (*glXQueryExtension) (Display*,int*,int*); void *(*glXGetProcAddress) (const GLubyte*); diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h index a07a0309ce10e..a4c6d1db0f390 100644 --- a/src/video/x11/SDL_x11sym.h +++ b/src/video/x11/SDL_x11sym.h @@ -45,7 +45,7 @@ SDL_X11_SYM(Pixmap,XCreateBitmapFromData,(Display *dpy,Drawable d,_Xconst char * SDL_X11_SYM(Colormap,XCreateColormap,(Display* a,Window b,Visual* c,int d),(a,b,c,d),return) SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display* a,Pixmap b,Pixmap c,XColor* d,XColor* e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return) SDL_X11_SYM(Cursor,XCreateFontCursor,(Display* a,unsigned int b),(a,b),return) -SDL_X11_SYM(XFontSet,XCreateFontSet,(Display* a, _Xconst char* b, char*** c, int* d, char** e),(a,b,c,d,e),return) +SDL_X11_SYM(XFontSet,XCreateFontSet,(Display* a, _Xconst char* b, char*** c, int* d, char** e),(a,b,c,d,e),return) SDL_X11_SYM(GC,XCreateGC,(Display* a,Drawable b,unsigned long c,XGCValues* d),(a,b,c,d),return) SDL_X11_SYM(XImage*,XCreateImage,(Display* a,Visual* b,unsigned int c,int d,int e,char* f,unsigned int g,unsigned int h,int i,int j),(a,b,c,d,e,f,g,h,i,j),return) SDL_X11_SYM(Window,XCreateWindow,(Display* a,Window b,int c,int d,unsigned int e,unsigned int f,unsigned int g,int h,unsigned int i,Visual* j,unsigned long k,XSetWindowAttributes* l),(a,b,c,d,e,f,g,h,i,j,k,l),return) @@ -201,7 +201,7 @@ SDL_X11_SYM(void,XUnsetICFocus,(XIC a),(a),) SDL_X11_SYM(XIM,XOpenIM,(Display* a,struct _XrmHashBucketRec* b,char* c,char* d),(a,b,c,d),return) SDL_X11_SYM(Status,XCloseIM,(XIM a),(a),return) SDL_X11_SYM(void,Xutf8DrawString,(Display *a, Drawable b, XFontSet c, GC d, int e, int f, _Xconst char *g, int h),(a,b,c,d,e,f,g,h),) -SDL_X11_SYM(int,Xutf8TextExtents,(XFontSet a, _Xconst char* b, int c, XRectangle* d, XRectangle* e),(a,b,c,d,e),return) +SDL_X11_SYM(int,Xutf8TextExtents,(XFontSet a, _Xconst char* b, int c, XRectangle* d, XRectangle* e),(a,b,c,d,e),return) SDL_X11_SYM(char*,XSetLocaleModifiers,(const char *a),(a),return) SDL_X11_SYM(char*,Xutf8ResetIC,(XIC a),(a),return) #endif From e0fe8f3cb3864de60273535431e8276df00fdaf4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 11:53:04 -0700 Subject: [PATCH 023/151] Support relative mouse for Samsung DeX on Samsung Experience 9.5 or later (Android 8.1 or later) --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 11 ++++++++--- .../java/org/libsdl/app/SDLControllerManager.java | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index b6c90d87107a7..a624fb547feba 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -766,9 +766,14 @@ public static boolean supportsRelativeMouse() return false; } - // Samsung DeX mode doesn't support relative mice properly under Android 7 APIs, - // and simply returns no data under Android 8 APIs. - if (isDeXMode()) { + // DeX mode in Samsung Experience 9.0 and earlier doesn't support relative mice properly under + // Android 7 APIs, and simply returns no data under Android 8 APIs. + // + // This is fixed in Samsung Experience 9.5, which corresponds to Android 8.1.0, and + // thus SDK version 27. If we are in DeX mode and not API 27 or higher, as a result, + // we should stick to relative mode. + // + if ((Build.VERSION.SDK_INT < 27) && isDeXMode()) { return false; } diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 342610fe7cf2e..a631c3ed0a6a0 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -764,7 +764,7 @@ public boolean onGenericMotion(View v, MotionEvent event) { @Override public boolean supportsRelativeMouse() { - return !SDLActivity.isDeXMode(); + return (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)); } @Override @@ -774,7 +774,7 @@ public boolean inRelativeMode() { @Override public boolean setRelativeMouseEnabled(boolean enabled) { - if (!SDLActivity.isDeXMode()) { + if (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)) { if (enabled) { SDLActivity.getContentView().requestPointerCapture(); } From cd90e2ca58fa485d456532ab420e25120296c462 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 16:33:14 -0700 Subject: [PATCH 024/151] Fixed bug 4267 - linkage failure with --enable-hidapi because of missing libudev symbols Ozkan Sezer hidapi dynamic udev initial patch --- src/core/linux/SDL_udev.c | 80 ++++++++++++++---------- src/core/linux/SDL_udev.h | 28 +++++---- src/joystick/hidapi/SDL_hidapijoystick.c | 27 +++++--- 3 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index dfbeb790aee74..751e2cabbba75 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -63,7 +63,7 @@ SDL_UDEV_load_syms(void) { /* cast funcs to char* first, to please GCC's strict aliasing rules. */ #define SDL_UDEV_SYM(x) \ - if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1 + if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->syms.x)) return -1 SDL_UDEV_SYM(udev_device_get_action); SDL_UDEV_SYM(udev_device_get_devnode); @@ -100,7 +100,7 @@ static SDL_bool SDL_UDEV_hotplug_update_available(void) { if (_this->udev_mon != NULL) { - const int fd = _this->udev_monitor_get_fd(_this->udev_mon); + const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon); if (SDL_IOReady(fd, SDL_FALSE, 0)) { return SDL_TRUE; } @@ -130,21 +130,21 @@ SDL_UDEV_Init(void) * Listen for input devices (mouse, keyboard, joystick, etc) and sound devices */ - _this->udev = _this->udev_new(); + _this->udev = _this->syms.udev_new(); if (_this->udev == NULL) { SDL_UDEV_Quit(); return SDL_SetError("udev_new() failed"); } - _this->udev_mon = _this->udev_monitor_new_from_netlink(_this->udev, "udev"); + _this->udev_mon = _this->syms.udev_monitor_new_from_netlink(_this->udev, "udev"); if (_this->udev_mon == NULL) { SDL_UDEV_Quit(); return SDL_SetError("udev_monitor_new_from_netlink() failed"); } - _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL); - _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL); - _this->udev_monitor_enable_receiving(_this->udev_mon); + _this->syms.udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL); + _this->syms.udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL); + _this->syms.udev_monitor_enable_receiving(_this->udev_mon); /* Do an initial scan of existing devices */ SDL_UDEV_Scan(); @@ -170,11 +170,11 @@ SDL_UDEV_Quit(void) if (_this->ref_count < 1) { if (_this->udev_mon != NULL) { - _this->udev_monitor_unref(_this->udev_mon); + _this->syms.udev_monitor_unref(_this->udev_mon); _this->udev_mon = NULL; } if (_this->udev != NULL) { - _this->udev_unref(_this->udev); + _this->syms.udev_unref(_this->udev); _this->udev = NULL; } @@ -202,28 +202,28 @@ SDL_UDEV_Scan(void) return; } - enumerate = _this->udev_enumerate_new(_this->udev); + enumerate = _this->syms.udev_enumerate_new(_this->udev); if (enumerate == NULL) { SDL_UDEV_Quit(); SDL_SetError("udev_enumerate_new() failed"); return; } - _this->udev_enumerate_add_match_subsystem(enumerate, "input"); - _this->udev_enumerate_add_match_subsystem(enumerate, "sound"); + _this->syms.udev_enumerate_add_match_subsystem(enumerate, "input"); + _this->syms.udev_enumerate_add_match_subsystem(enumerate, "sound"); - _this->udev_enumerate_scan_devices(enumerate); - devs = _this->udev_enumerate_get_list_entry(enumerate); - for (item = devs; item; item = _this->udev_list_entry_get_next(item)) { - const char *path = _this->udev_list_entry_get_name(item); - struct udev_device *dev = _this->udev_device_new_from_syspath(_this->udev, path); + _this->syms.udev_enumerate_scan_devices(enumerate); + devs = _this->syms.udev_enumerate_get_list_entry(enumerate); + for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) { + const char *path = _this->syms.udev_list_entry_get_name(item); + struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path); if (dev != NULL) { device_event(SDL_UDEV_DEVICEADDED, dev); - _this->udev_device_unref(dev); + _this->syms.udev_device_unref(dev); } } - _this->udev_enumerate_unref(enumerate); + _this->syms.udev_enumerate_unref(enumerate); } @@ -305,7 +305,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch unsigned long v; SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask)); - value = _this->udev_device_get_sysattr_value(pdev, attr); + value = _this->syms.udev_device_get_sysattr_value(pdev, attr); if (!value) { return; } @@ -340,8 +340,8 @@ guess_device_class(struct udev_device *dev) /* walk up the parental chain until we find the real input device; the * argument is very likely a subdevice of this, like eventN */ pdev = dev; - while (pdev && !_this->udev_device_get_sysattr_value(pdev, "capabilities/ev")) { - pdev = _this->udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); + while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) { + pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); } if (!pdev) { return 0; @@ -405,28 +405,28 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev) const char *path; SDL_UDEV_CallbackList *item; - path = _this->udev_device_get_devnode(dev); + path = _this->syms.udev_device_get_devnode(dev); if (path == NULL) { return; } - subsystem = _this->udev_device_get_subsystem(dev); + subsystem = _this->syms.udev_device_get_subsystem(dev); if (SDL_strcmp(subsystem, "sound") == 0) { devclass = SDL_UDEV_DEVICE_SOUND; } else if (SDL_strcmp(subsystem, "input") == 0) { /* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */ - val = _this->udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"); + val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"); if (val != NULL && SDL_strcmp(val, "1") == 0 ) { devclass |= SDL_UDEV_DEVICE_JOYSTICK; } - val = _this->udev_device_get_property_value(dev, "ID_INPUT_MOUSE"); + val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE"); if (val != NULL && SDL_strcmp(val, "1") == 0 ) { devclass |= SDL_UDEV_DEVICE_MOUSE; } - val = _this->udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"); + val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"); if (val != NULL && SDL_strcmp(val, "1") == 0 ) { devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; } @@ -437,14 +437,14 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev) Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183 */ - val = _this->udev_device_get_property_value(dev, "ID_INPUT_KEY"); + val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY"); if (val != NULL && SDL_strcmp(val, "1") == 0 ) { devclass |= SDL_UDEV_DEVICE_KEYBOARD; } if (devclass == 0) { /* Fall back to old style input classes */ - val = _this->udev_device_get_property_value(dev, "ID_CLASS"); + val = _this->syms.udev_device_get_property_value(dev, "ID_CLASS"); if (val != NULL) { if (SDL_strcmp(val, "joystick") == 0) { devclass = SDL_UDEV_DEVICE_JOYSTICK; @@ -481,11 +481,11 @@ SDL_UDEV_Poll(void) } while (SDL_UDEV_hotplug_update_available()) { - dev = _this->udev_monitor_receive_device(_this->udev_mon); + dev = _this->syms.udev_monitor_receive_device(_this->udev_mon); if (dev == NULL) { break; } - action = _this->udev_device_get_action(dev); + action = _this->syms.udev_device_get_action(dev); if (SDL_strcmp(action, "add") == 0) { /* Wait for the device to finish initialization */ @@ -496,7 +496,7 @@ SDL_UDEV_Poll(void) device_event(SDL_UDEV_DEVICEREMOVED, dev); } - _this->udev_device_unref(dev); + _this->syms.udev_device_unref(dev); } } @@ -547,6 +547,22 @@ SDL_UDEV_DelCallback(SDL_UDEV_Callback cb) } +const SDL_UDEV_Symbols * +SDL_UDEV_GetUdevSyms(void) +{ + if (SDL_UDEV_Init() < 0) { + SDL_SetError("Could not initialize UDEV"); + return NULL; + } + + return &_this->syms; +} + +void +SDL_UDEV_ReleaseUdevSyms(void) +{ + SDL_UDEV_Quit(); +} #endif /* SDL_USE_LIBUDEV */ diff --git a/src/core/linux/SDL_udev.h b/src/core/linux/SDL_udev.h index 033a2998b509b..8be74340a862b 100644 --- a/src/core/linux/SDL_udev.h +++ b/src/core/linux/SDL_udev.h @@ -64,16 +64,7 @@ typedef struct SDL_UDEV_CallbackList { struct SDL_UDEV_CallbackList *next; } SDL_UDEV_CallbackList; -typedef struct SDL_UDEV_PrivateData -{ - const char *udev_library; - void *udev_handle; - struct udev *udev; - struct udev_monitor *udev_mon; - int ref_count; - SDL_UDEV_CallbackList *first, *last; - - /* Function pointers */ +typedef struct SDL_UDEV_Symbols { const char *(*udev_device_get_action)(struct udev_device *); const char *(*udev_device_get_devnode)(struct udev_device *); const char *(*udev_device_get_subsystem)(struct udev_device *); @@ -100,6 +91,19 @@ typedef struct SDL_UDEV_PrivateData void (*udev_unref)(struct udev *); struct udev_device * (*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum); dev_t (*udev_device_get_devnum) (struct udev_device *udev_device); +} SDL_UDEV_Symbols; + +typedef struct SDL_UDEV_PrivateData +{ + const char *udev_library; + void *udev_handle; + struct udev *udev; + struct udev_monitor *udev_mon; + int ref_count; + SDL_UDEV_CallbackList *first, *last; + + /* Function pointers */ + SDL_UDEV_Symbols syms; } SDL_UDEV_PrivateData; extern int SDL_UDEV_Init(void); @@ -110,8 +114,8 @@ extern void SDL_UDEV_Poll(void); extern void SDL_UDEV_Scan(void); extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb); extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb); - - +extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void); +extern void SDL_UDEV_ReleaseUdevSyms(void); #endif /* HAVE_LIBUDEV_H */ diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index e57caca159f31..d238fc2981337 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -97,6 +97,10 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = { static SDL_HIDAPI_Device *SDL_HIDAPI_devices; static int SDL_HIDAPI_numjoysticks = 0; +#if defined(SDL_USE_LIBUDEV) +static const SDL_UDEV_Symbols * usyms = NULL; +#endif + static struct { SDL_bool m_bHaveDevicesChanged; @@ -272,12 +276,15 @@ HIDAPI_InitializeDiscovery() SDL_HIDAPI_discovery.m_pUdevMonitor = NULL; SDL_HIDAPI_discovery.m_nUdevFd = -1; - SDL_HIDAPI_discovery.m_pUdev = udev_new(); + usyms = SDL_UDEV_GetUdevSyms(); + if (usyms) { + SDL_HIDAPI_discovery.m_pUdev = usyms->udev_new(); + } if (SDL_HIDAPI_discovery.m_pUdev) { - SDL_HIDAPI_discovery.m_pUdevMonitor = udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev"); + SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev"); if (SDL_HIDAPI_discovery.m_pUdevMonitor) { - udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor); - SDL_HIDAPI_discovery.m_nUdevFd = udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor); + usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor); + SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor); SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE; } } @@ -339,9 +346,9 @@ HIDAPI_UpdateDiscovery() SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE; - pUdevDevice = udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor); + pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor); if (pUdevDevice) { - udev_device_unref(pUdevDevice); + usyms->udev_device_unref(pUdevDevice); } } } @@ -370,10 +377,14 @@ HIDAPI_ShutdownDiscovery() #if defined(SDL_USE_LIBUDEV) if (SDL_HIDAPI_discovery.m_pUdevMonitor) { - udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor); + usyms->udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor); } if (SDL_HIDAPI_discovery.m_pUdev) { - udev_unref(SDL_HIDAPI_discovery.m_pUdev); + usyms->udev_unref(SDL_HIDAPI_discovery.m_pUdev); + } + if (usyms) { + SDL_UDEV_ReleaseUdevSyms(); + usyms = NULL; } #endif } From ef34704875475eb39e31131449169af33e7a77e9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 16:41:55 -0700 Subject: [PATCH 025/151] Fixed bug 4264 - SDL_CreateTextureFromSurface generates error message but returns ok Anthony @ POW Games SDL_CreateTextureFromSurface makes an internal call to SDL_GetColorKey which can return an error and spams the error log with "Surface doesn't have a colorkey" even though the original function didn't return an error. --- include/SDL_surface.h | 7 +++++++ src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + src/render/SDL_render.c | 2 +- src/video/SDL_surface.c | 14 ++++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/SDL_surface.h b/include/SDL_surface.h index 45e5366fe5139..730d49fc805ec 100644 --- a/include/SDL_surface.h +++ b/include/SDL_surface.h @@ -248,6 +248,13 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface, extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key); +/** + * \brief Returns whether the surface has a color key + * + * \return SDL_TRUE if the surface has a color key, or SDL_FALSE if the surface is NULL or has no color key + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface); + /** * \brief Gets the color key (transparent pixel) in a blittable surface. * diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index b1f029f37098a..9ef18c5a60df4 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -696,3 +696,4 @@ #define SDL_SensorUpdate SDL_SensorUpdate_REAL #define SDL_IsTablet SDL_IsTablet_REAL #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL +#define SDL_HasColorKey SDL_HasColorKey_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 6619f882a8674..02f6170bd9327 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -738,3 +738,4 @@ SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),) SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),) SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return) SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_HasColorKey,(SDL_Surface *a),(a),return) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index b1bcc46c1b9c3..f8b29d95c88af 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -649,7 +649,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) /* See what the best texture format is */ fmt = surface->format; - if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) { + if (fmt->Amask || (SDL_HasColorKey(surface) && SDL_GetColorKey(surface, NULL) == 0)) { needAlpha = SDL_TRUE; } else { needAlpha = SDL_FALSE; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 719f831e82658..c6fd3b5fb92f5 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -292,6 +292,20 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) return 0; } +SDL_bool +SDL_HasColorKey(SDL_Surface * surface) +{ + if (!surface) { + return SDL_FALSE; + } + + if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) { + return SDL_FALSE; + } + + return SDL_TRUE; +} + int SDL_GetColorKey(SDL_Surface * surface, Uint32 * key) { From da89b81c3c8328c9545189e4496e8053e49bb2da Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Sep 2018 20:31:24 -0700 Subject: [PATCH 026/151] Fixed rare null pointer dereference --- .../main/java/org/libsdl/app/SDLActivity.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index a624fb547feba..0ece200d100f8 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -583,7 +583,7 @@ public void handleMessage(Message msg) { View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE; + View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE; window.getDecorView().setSystemUiVisibility(flags); window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); @@ -1512,6 +1512,10 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.v("SDL", "surfaceChanged()"); + if (SDLActivity.mSingleton == null) { + return; + } + int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default switch (format) { case PixelFormat.A_8: @@ -1559,24 +1563,23 @@ public void surfaceChanged(SurfaceHolder holder, mWidth = width; mHeight = height; - int nDeviceWidth = width; - int nDeviceHeight = height; - try - { - if ( android.os.Build.VERSION.SDK_INT >= 17 ) - { - android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics(); - mDisplay.getRealMetrics( realMetrics ); - nDeviceWidth = realMetrics.widthPixels; - nDeviceHeight = realMetrics.heightPixels; - } - } - catch ( java.lang.Throwable throwable ) {} - - Log.v("SDL", "Window size: " + width + "x" + height); - Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); - SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate()); + int nDeviceWidth = width; + int nDeviceHeight = height; + try + { + if ( android.os.Build.VERSION.SDK_INT >= 17 ) + { + android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics(); + mDisplay.getRealMetrics( realMetrics ); + nDeviceWidth = realMetrics.widthPixels; + nDeviceHeight = realMetrics.heightPixels; + } + } + catch ( java.lang.Throwable throwable ) {} + Log.v("SDL", "Window size: " + width + "x" + height); + Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); + SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate()); boolean skip = false; int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); From 870c44bfed01542b36aaa205d34f19245bb7ad88 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 25 Sep 2018 09:20:56 +0300 Subject: [PATCH 027/151] safer this way, just in case.. --- src/joystick/hidapi/SDL_hidapijoystick.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index d238fc2981337..d37a7ca889f57 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -376,13 +376,13 @@ HIDAPI_ShutdownDiscovery() #endif #if defined(SDL_USE_LIBUDEV) - if (SDL_HIDAPI_discovery.m_pUdevMonitor) { - usyms->udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor); - } - if (SDL_HIDAPI_discovery.m_pUdev) { - usyms->udev_unref(SDL_HIDAPI_discovery.m_pUdev); - } if (usyms) { + if (SDL_HIDAPI_discovery.m_pUdevMonitor) { + usyms->udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor); + } + if (SDL_HIDAPI_discovery.m_pUdev) { + usyms->udev_unref(SDL_HIDAPI_discovery.m_pUdev); + } SDL_UDEV_ReleaseUdevSyms(); usyms = NULL; } From fb0e68ae0f01fa951a8481d4a1f893d4cec1a6a3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Sep 2018 08:23:57 -0700 Subject: [PATCH 028/151] Fixed building with newer Android NDK --- src/hidapi/android/hid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index a8c6b1fdd3ccb..fbe1832b0dbd0 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -9,9 +9,9 @@ #include #include #include -#include #include // For ETIMEDOUT and ECONNRESET #include // For malloc() and free() +#include // For memcpy() #define TAG "hidapi" #ifdef DEBUG From aa9683bb6fe21f1ae328b2016b604d02d445871e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Sep 2018 19:41:33 -0700 Subject: [PATCH 029/151] Added 8bitdo SF 30 PRO controller support for Linux / DInput mode (thanks Frank Hartung) --- src/joystick/SDL_gamecontrollerdb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h index d1eb17d152ab7..9d95c90788861 100644 --- a/src/joystick/SDL_gamecontrollerdb.h +++ b/src/joystick/SDL_gamecontrollerdb.h @@ -362,6 +362,7 @@ static const char *s_ControllerMappings [] = "03000000022000000090000011010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,", "05000000203800000900000000010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,", "05000000c82d00002038000000010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,", + "05000000c82d00000061000000010000,8Bitdo SF30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,", "05000000102800000900000000010000,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,", "05000000c82d00003028000000010000,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,", "05000000a00500003232000001000000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b3,y:b4,", From 7f9854b9b2177dea32eb5d2f4434609ea5dd58d5 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 25 Sep 2018 01:45:12 -0400 Subject: [PATCH 030/151] WinRT: Wait until audio device activation is complete and PrepDevice during OpenAudio --- src/audio/wasapi/SDL_wasapi.c | 6 +++ src/audio/wasapi/SDL_wasapi_win32.c | 6 --- src/audio/wasapi/SDL_wasapi_winrt.cpp | 63 +++++++++++++++------------ 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c index b7c8dda5d1a44..f517539657262 100644 --- a/src/audio/wasapi/SDL_wasapi.c +++ b/src/audio/wasapi/SDL_wasapi.c @@ -725,6 +725,12 @@ WASAPI_ThreadDeinit(_THIS) WASAPI_PlatformThreadDeinit(this); } +void +WASAPI_BeginLoopIteration(_THIS) +{ + /* no-op. */ +} + static void WASAPI_Deinitialize(void) { diff --git a/src/audio/wasapi/SDL_wasapi_win32.c b/src/audio/wasapi/SDL_wasapi_win32.c index 8b55582c30c3d..731dcffb7fa9e 100644 --- a/src/audio/wasapi/SDL_wasapi_win32.c +++ b/src/audio/wasapi/SDL_wasapi_win32.c @@ -405,12 +405,6 @@ WASAPI_PlatformDeleteActivationHandler(void *handler) SDL_assert(!"This function should have only been called on WinRT."); } -void -WASAPI_BeginLoopIteration(_THIS) -{ - /* no-op. */ -} - #endif /* SDL_AUDIO_DRIVER_WASAPI && !defined(__WINRT__) */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp index 309ec6a78886e..2ca09de863f4a 100644 --- a/src/audio/wasapi/SDL_wasapi_winrt.cpp +++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp @@ -185,20 +185,9 @@ struct SDL_WasapiActivationHandler : public RuntimeClass< RuntimeClassFlags< Cla HRESULT SDL_WasapiActivationHandler::ActivateCompleted(IActivateAudioInterfaceAsyncOperation *async) { - HRESULT result = S_OK; - IUnknown *iunknown = nullptr; - const HRESULT ret = async->GetActivateResult(&result, &iunknown); - - if (SUCCEEDED(ret) && SUCCEEDED(result)) { - iunknown->QueryInterface(IID_PPV_ARGS(&device->hidden->client)); - if (device->hidden->client) { - // Just set a flag, since we're probably in a different thread. We'll pick it up and init everything on our own thread to prevent races. - SDL_AtomicSet(&device->hidden->just_activated, 1); - } - } - + // Just set a flag, since we're probably in a different thread. We'll pick it up and init everything on our own thread to prevent races. + SDL_AtomicSet(&device->hidden->just_activated, 1); WASAPI_UnrefDevice(device); - return S_OK; } @@ -236,27 +225,47 @@ WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery) IActivateAudioInterfaceAsyncOperation *async = nullptr; const HRESULT ret = ActivateAudioInterfaceAsync(devid, __uuidof(IAudioClient), nullptr, handler.Get(), &async); - if (async != nullptr) { - async->Release(); - } - - if (FAILED(ret)) { + if (FAILED(ret) || async == nullptr) { + if (async != nullptr) { + async->Release(); + } handler.Get()->Release(); WASAPI_UnrefDevice(_this); return WIN_SetErrorFromHRESULT("WASAPI can't activate requested audio endpoint", ret); } - return 0; -} + /* Spin until the async operation is complete. + * If we don't PrepDevice before leaving this function, the bug list gets LONG: + * - device.spec is not filled with the correct information + * - The 'obtained' spec will be wrong for ALLOW_CHANGE properties + * - SDL_AudioStreams will/will not be allocated at the right time + * - SDL_assert(device->callbackspec.size == device->spec.size) will fail + * - When the assert is ignored, skipping or a buffer overflow will occur + */ + while (!SDL_AtomicCAS(&_this->hidden->just_activated, 1, 0)) { + SDL_Delay(1); + } -void -WASAPI_BeginLoopIteration(_THIS) -{ - if (SDL_AtomicCAS(&_this->hidden->just_activated, 1, 0)) { - if (WASAPI_PrepDevice(_this, SDL_TRUE) == -1) { - SDL_OpenedAudioDeviceDisconnected(_this); - } + HRESULT activateRes = S_OK; + IUnknown *iunknown = nullptr; + const HRESULT getActivateRes = async->GetActivateResult(&activateRes, &iunknown); + async->Release(); + if (FAILED(getActivateRes)) { + return WIN_SetErrorFromHRESULT("Failed to get WASAPI activate result", getActivateRes); + } else if (FAILED(activateRes)) { + return WIN_SetErrorFromHRESULT("Failed to activate WASAPI device", activateRes); + } + + iunknown->QueryInterface(IID_PPV_ARGS(&_this->hidden->client)); + if (!_this->hidden->client) { + return SDL_SetError("Failed to query WASAPI client interface"); + } + + if (WASAPI_PrepDevice(_this, isrecovery) == -1) { + return -1; } + + return 0; } void From 60afec79bf7828d451d7d73a221b42bb835a21a3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Sep 2018 19:53:16 -0700 Subject: [PATCH 031/151] Removed redundant SDL_GetColorKey() call. (thanks Sylvain!) --- src/render/SDL_render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index f8b29d95c88af..07ced0dff03cc 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -649,7 +649,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) /* See what the best texture format is */ fmt = surface->format; - if (fmt->Amask || (SDL_HasColorKey(surface) && SDL_GetColorKey(surface, NULL) == 0)) { + if (fmt->Amask || SDL_HasColorKey(surface)) { needAlpha = SDL_TRUE; } else { needAlpha = SDL_FALSE; @@ -708,7 +708,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) SDL_GetSurfaceAlphaMod(surface, &a); SDL_SetTextureAlphaMod(texture, a); - if (SDL_GetColorKey(surface, NULL) == 0) { + if (SDL_HasColorKey(surface)) { /* We converted to a texture with alpha format */ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); } else { From e236e8435a85862265c039cdc06f701520497ff9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Sep 2018 20:08:51 -0700 Subject: [PATCH 032/151] Fixed bug 4268 - Android_JNI_OpenAudioDevice function has error alittle where iscapture == 1 1.param set error (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) param:audioBuffer16Bit need change to captureBuffer16Bit 2.logic error if (is16Bit) { // ALITTLE Modify the source code if (iscapture) { audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)captureBuffer); } else { audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy); audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer); } // if (!iscapture) { // audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy); // } // audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer); } else { // ALITTLE Modify the source code if (iscapture) { audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer); } else { audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy); audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer); } // if (!iscapture) { // audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy); // } // audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer); } --- src/core/android/SDL_android.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 15a1a74f2aa7b..7f0c1262433f0 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -1046,8 +1046,8 @@ static jobject captureBuffer = NULL; int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames) { - jboolean audioBufferStereo; - int audioBufferFrames; + jboolean isStereo; + int numBufferFrames; jobject jbufobj = NULL; jboolean isCopy; @@ -1058,12 +1058,12 @@ int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int } Android_JNI_SetupThread(); - audioBufferStereo = channelCount > 1; + isStereo = channelCount > 1; if (iscapture) { __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for capture"); captureBuffer16Bit = is16Bit; - if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) { + if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) { /* Error during audio initialization */ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioRecord initialization!"); return 0; @@ -1071,7 +1071,7 @@ int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int } else { __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output"); audioBuffer16Bit = is16Bit; - if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) { + if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) { /* Error during audio initialization */ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioTrack initialization!"); return 0; @@ -1082,14 +1082,14 @@ int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */ if (is16Bit) { - jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1)); + jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (isStereo ? 2 : 1)); if (audioBufferLocal) { jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); (*env)->DeleteLocalRef(env, audioBufferLocal); } } else { - jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1)); + jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (isStereo ? 2 : 1)); if (audioBufferLocal) { jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); (*env)->DeleteLocalRef(env, audioBufferLocal); @@ -1110,22 +1110,26 @@ int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int isCopy = JNI_FALSE; if (is16Bit) { - if (!iscapture) { + if (iscapture) { + numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)captureBuffer); + } else { audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy); + numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer); } - audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer); } else { - if (!iscapture) { + if (iscapture) { + numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer); + } else { audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy); + numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer); } - audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer); } - if (audioBufferStereo) { - audioBufferFrames /= 2; + if (isStereo) { + numBufferFrames /= 2; } - return audioBufferFrames; + return numBufferFrames; } int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi) From d40657bfc99f461557116c98b4fe7c40cbe60de3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Sep 2018 20:11:52 -0700 Subject: [PATCH 033/151] Fixed bug 4270 - Android HIDDeviceManager function needs to be public Sylvain Can't run an android app without declaring the JNI interface function as public. --- .../src/main/java/org/libsdl/app/HIDDeviceManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 0759efff6e20b..8d29cf3645564 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -504,7 +504,7 @@ private HIDDevice getDevice(int id) { ////////// JNI interface functions ////////////////////////////////////////////////////////////////////////////////////////////////////// - boolean openDevice(int deviceID) { + public boolean openDevice(int deviceID) { // Look to see if this is a USB device and we have permission to access it for (HIDDeviceUSB device : mUSBDevices.values()) { if (deviceID == device.getId()) { @@ -539,7 +539,7 @@ boolean openDevice(int deviceID) { return false; } - int sendOutputReport(int deviceID, byte[] report) { + public int sendOutputReport(int deviceID, byte[] report) { try { Log.v(TAG, "sendOutputReport deviceID=" + deviceID + " length=" + report.length); HIDDevice device; @@ -556,7 +556,7 @@ int sendOutputReport(int deviceID, byte[] report) { return -1; } - int sendFeatureReport(int deviceID, byte[] report) { + public int sendFeatureReport(int deviceID, byte[] report) { try { Log.v(TAG, "sendFeatureReport deviceID=" + deviceID + " length=" + report.length); HIDDevice device; @@ -573,7 +573,7 @@ int sendFeatureReport(int deviceID, byte[] report) { return -1; } - boolean getFeatureReport(int deviceID, byte[] report) { + public boolean getFeatureReport(int deviceID, byte[] report) { try { Log.v(TAG, "getFeatureReport deviceID=" + deviceID); HIDDevice device; @@ -590,7 +590,7 @@ boolean getFeatureReport(int deviceID, byte[] report) { return false; } - void closeDevice(int deviceID) { + public void closeDevice(int deviceID) { try { Log.v(TAG, "closeDevice deviceID=" + deviceID); HIDDevice device; From d0e9a364608a9ff12d16fcaf8fb7119bc775715f Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 26 Sep 2018 10:38:40 +0300 Subject: [PATCH 034/151] SDL_vsnprintf: %.* and %* now parse precision and width. (bug #4263.) --- src/stdlib/SDL_string.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 22aceedb18106..db91a0431078c 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1593,11 +1593,18 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, if (*fmt >= '0' && *fmt <= '9') { info.width = SDL_strtol(fmt, (char **)&fmt, 0); } + else if (*fmt == '*') { + ++fmt; + info.width = va_arg(ap, int); + } if (*fmt == '.') { ++fmt; if (*fmt >= '0' && *fmt <= '9') { info.precision = SDL_strtol(fmt, (char **)&fmt, 0); + } else if (*fmt == '*') { + ++fmt; + info.precision = va_arg(ap, int); } else { info.precision = 0; } From 69ab8541a912fcd3bcec9b084dda3b611ab8b9d1 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 26 Sep 2018 10:40:02 +0300 Subject: [PATCH 035/151] SDL_vsnprintf: string printer now honors the precision. (bug #4263.) --- src/stdlib/SDL_string.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index db91a0431078c..0ba6be74dfb43 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1374,15 +1374,18 @@ static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string) { size_t length = 0; - size_t slen; + size_t slen, sz; if (string == NULL) { string = "(null)"; } - if (info && info->width && (size_t)info->width > SDL_strlen(string)) { + sz = SDL_strlen(string); + if (info && info->width > 0 && (size_t)info->width > sz) { char fill = info->pad_zeroes ? '0' : ' '; - size_t width = info->width - SDL_strlen(string); + size_t width = info->width - sz; + if (info->precision >= 0 && (size_t)info->precision < sz) + width += sz - (size_t)info->precision; while (width-- > 0 && maxlen > 0) { *text++ = fill; ++length; @@ -1394,6 +1397,13 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str length += SDL_min(slen, maxlen); if (info) { + if (info->precision >= 0 && info->precision < sz) { + slen = info->precision; + if (slen < maxlen) { + text[slen] = 0; + length -= (sz - slen); + } + } if (info->force_case == SDL_CASE_LOWER) { SDL_strlwr(text); } else if (info->force_case == SDL_CASE_UPPER) { From 8743e9759e82bc07f19ee64fbb610d76da02f6d9 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 26 Sep 2018 17:11:40 +0300 Subject: [PATCH 036/151] SDL_vsnprintf: when '.' is specified, take precision as 0 if it is < 0. --- src/stdlib/SDL_string.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 0ba6be74dfb43..047b320390da7 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1618,6 +1618,9 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, } else { info.precision = 0; } + if (info.precision < 0) { + info.precision = 0; + } } while (!done) { From bc6c1997904f1e5cf69113d35b05da1e9de66c9e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Sep 2018 10:08:14 -0700 Subject: [PATCH 037/151] Updated version to 2.0.9 --- CMakeLists.txt | 4 ++-- Xcode/SDL/Info-Framework.plist | 4 ++-- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 4 ++-- build-scripts/winrtbuild.ps1 | 2 +- configure | 4 ++-- configure.in | 4 ++-- debian/changelog | 6 ++++++ include/SDL_version.h | 2 +- src/main/windows/version.rc | 8 ++++---- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 659a61b7d8048..376f27f7163ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,9 @@ include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake) # set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0. set(SDL_MAJOR_VERSION 2) set(SDL_MINOR_VERSION 0) -set(SDL_MICRO_VERSION 8) +set(SDL_MICRO_VERSION 9) set(SDL_INTERFACE_AGE 0) -set(SDL_BINARY_AGE 8) +set(SDL_BINARY_AGE 9) set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}") # Set defaults preventing destination file conflicts diff --git a/Xcode/SDL/Info-Framework.plist b/Xcode/SDL/Info-Framework.plist index ff3c220f5cff7..0b89cc42beb75 100644 --- a/Xcode/SDL/Info-Framework.plist +++ b/Xcode/SDL/Info-Framework.plist @@ -19,10 +19,10 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.8 + 2.0.9 CFBundleSignature SDLX CFBundleVersion - 2.0.8 + 2.0.9 diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 67ac2b0181893..0fd37778a6705 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -3157,7 +3157,7 @@ CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; - DYLIB_CURRENT_VERSION = 9.0.0; + DYLIB_CURRENT_VERSION = 10.0.0; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", @@ -3251,7 +3251,7 @@ CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; - DYLIB_CURRENT_VERSION = 9.0.0; + DYLIB_CURRENT_VERSION = 10.0.0; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", diff --git a/build-scripts/winrtbuild.ps1 b/build-scripts/winrtbuild.ps1 index 49e6e5a908583..0d7a24e7bbd6b 100644 --- a/build-scripts/winrtbuild.ps1 +++ b/build-scripts/winrtbuild.ps1 @@ -39,7 +39,7 @@ # # Base version of SDL, used for packaging purposes -$SDLVersion = "2.0.7" +$SDLVersion = "2.0.9" # Gets the .bat file that sets up an MSBuild environment, given one of # Visual Studio's, "PlatformToolset"s. diff --git a/configure b/configure index 40ac14d21738a..841fa59898bb8 100755 --- a/configure +++ b/configure @@ -2719,9 +2719,9 @@ orig_CFLAGS="$CFLAGS" # SDL_MAJOR_VERSION=2 SDL_MINOR_VERSION=0 -SDL_MICRO_VERSION=8 +SDL_MICRO_VERSION=9 SDL_INTERFACE_AGE=0 -SDL_BINARY_AGE=8 +SDL_BINARY_AGE=9 SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION diff --git a/configure.in b/configure.in index ce1d57ea1fefb..3adebaba080ec 100644 --- a/configure.in +++ b/configure.in @@ -20,9 +20,9 @@ dnl Set various version strings - taken gratefully from the GTk sources # SDL_MAJOR_VERSION=2 SDL_MINOR_VERSION=0 -SDL_MICRO_VERSION=8 +SDL_MICRO_VERSION=9 SDL_INTERFACE_AGE=0 -SDL_BINARY_AGE=8 +SDL_BINARY_AGE=9 SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION AC_SUBST(SDL_MAJOR_VERSION) diff --git a/debian/changelog b/debian/changelog index 54f43972d6dca..ba4cf4a3eb390 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libsdl2 (2.0.9) UNRELEASED; urgency=low + + * Updated SDL to version 2.0.9 + + -- Sam Lantinga Wed, 26 Sep 2018 10:02:21 -0800 + libsdl2 (2.0.8) UNRELEASED; urgency=low * Updated SDL to version 2.0.8 diff --git a/include/SDL_version.h b/include/SDL_version.h index 584b48c7a288c..31443e149adc0 100644 --- a/include/SDL_version.h +++ b/include/SDL_version.h @@ -59,7 +59,7 @@ typedef struct SDL_version */ #define SDL_MAJOR_VERSION 2 #define SDL_MINOR_VERSION 0 -#define SDL_PATCHLEVEL 8 +#define SDL_PATCHLEVEL 9 /** * \brief Macro to determine SDL version program was compiled against. diff --git a/src/main/windows/version.rc b/src/main/windows/version.rc index 6f4f1b753dc4d..808d11139db10 100644 --- a/src/main/windows/version.rc +++ b/src/main/windows/version.rc @@ -9,8 +9,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,0,8,0 - PRODUCTVERSION 2,0,8,0 + FILEVERSION 2,0,9,0 + PRODUCTVERSION 2,0,9,0 FILEFLAGSMASK 0x3fL FILEFLAGS 0x0L FILEOS 0x40004L @@ -23,12 +23,12 @@ BEGIN BEGIN VALUE "CompanyName", "\0" VALUE "FileDescription", "SDL\0" - VALUE "FileVersion", "2, 0, 8, 0\0" + VALUE "FileVersion", "2, 0, 9, 0\0" VALUE "InternalName", "SDL\0" VALUE "LegalCopyright", "Copyright © 2018 Sam Lantinga\0" VALUE "OriginalFilename", "SDL2.dll\0" VALUE "ProductName", "Simple DirectMedia Layer\0" - VALUE "ProductVersion", "2, 0, 8, 0\0" + VALUE "ProductVersion", "2, 0, 9, 0\0" END END BLOCK "VarFileInfo" From ffc19ee25551f6ec807831805ee22d7b038a08fa Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 26 Sep 2018 20:47:34 +0300 Subject: [PATCH 038/151] SDL_string.c: added comments to three SDL_FormatInfo members. --- src/stdlib/SDL_string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 047b320390da7..1f55b51bfe1a2 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1360,9 +1360,9 @@ typedef enum typedef struct { - SDL_bool left_justify; - SDL_bool force_sign; - SDL_bool force_type; + SDL_bool left_justify; /* for now: ignored. */ + SDL_bool force_sign; /* for now: used only by float printer, ignored otherwise. */ + SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */ SDL_bool pad_zeroes; SDL_letter_case force_case; int width; From 55b24b93b406d8213e7eaa7c0b319f138225c9c9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Sep 2018 11:17:43 -0700 Subject: [PATCH 039/151] Fixed bug 4265 - SDL window falls to the bottom of the screen when dragged down and stuck there Alexei On WM_WINDOWPOSCHANGED event, WIN_UpdateClipCursor() is called. SDL_WINDOW_INPUT_FOCUS is set even when the mouse pointer is not inside the SDL window and therefore ClipCursor(&rect) is called. When dragging the window and rect.bottom=800 (i.e. the bottom edge of the screen) the SDL window is clipped to the bottom of the screen and it is not possible to move it back to the center of the screen. --- src/video/windows/SDL_windowsevents.c | 7 +++++++ src/video/windows/SDL_windowswindow.c | 6 +++++- src/video/windows/SDL_windowswindow.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5773f39953f7f..e961cf568e710 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -414,6 +414,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; + case WM_NCACTIVATE: + { + /* Don't immediately clip the cursor in case we're clicking minimize/maximize buttons */ + data->skip_update_clipcursor = SDL_TRUE; + } + break; + case WM_ACTIVATE: { POINT cursorPos; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index ba5ef0583905e..45463c4c7f1d1 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -904,7 +904,11 @@ WIN_UpdateClipCursor(SDL_Window *window) SDL_Mouse *mouse = SDL_GetMouse(); RECT rect; - if (data->focus_click_pending) { + if (data->in_title_click || data->focus_click_pending) { + return; + } + if (data->skip_update_clipcursor) { + data->skip_update_clipcursor = SDL_FALSE; return; } diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index 0dacff6a5cb5d..b738c3494961b 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -44,6 +44,7 @@ typedef struct SDL_bool in_border_change; SDL_bool in_title_click; Uint8 focus_click_pending; + SDL_bool skip_update_clipcursor; SDL_bool windowed_mode_was_maximized; SDL_bool in_window_deactivation; RECT cursor_clipped_rect; From d2131ac16554582a4952e8064a2f0feda3ad2404 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 27 Sep 2018 00:32:15 +0300 Subject: [PATCH 040/151] SDL_vsnprintf: implement precision for the integral value printers. --- src/stdlib/SDL_string.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 1f55b51bfe1a2..5ca6526ff084e 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1413,12 +1413,36 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str return length; } +static void +SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) +{/* left-pad num with zeroes, if needed. */ + size_t sz, pad, i; + + if (!info || info->precision < 0) + return; + + if (*num == '-') + ++num; + sz = SDL_strlen(num); + if (sz < (size_t)info->precision) { + pad = (size_t)info->precision - sz; + if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */ + SDL_memmove(num + pad, num, sz + 1); + for(i = 0; i < pad; ++i) { + num[i] = '0'; + } + } + } + info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */ +} + static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value) { char num[130]; SDL_ltoa(value, num, info ? info->radix : 10); + SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } @@ -1428,6 +1452,7 @@ SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned char num[130]; SDL_ultoa(value, num, info ? info->radix : 10); + SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } @@ -1437,6 +1462,7 @@ SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value) char num[130]; SDL_lltoa(value, num, info ? info->radix : 10); + SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } @@ -1446,6 +1472,7 @@ SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint6 char num[130]; SDL_ulltoa(value, num, info ? info->radix : 10); + SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } From 5342ae2bba2957793db2eea716746f9df4681d8e Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 27 Sep 2018 01:00:50 +0300 Subject: [PATCH 041/151] SDL_string.c (SDL_IntPrecisionAdjust): avoid MSVC generating a memset() --- src/stdlib/SDL_string.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 5ca6526ff084e..4ef742d9dec9e 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1416,7 +1416,7 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) {/* left-pad num with zeroes, if needed. */ - size_t sz, pad, i; + size_t sz, pad; if (!info || info->precision < 0) return; @@ -1428,9 +1428,7 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) pad = (size_t)info->precision - sz; if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */ SDL_memmove(num + pad, num, sz + 1); - for(i = 0; i < pad; ++i) { - num[i] = '0'; - } + SDL_memset(num, '0', pad); } } info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */ From 6eeb8593ba8eb46fe37d1345587e3563e4c54f57 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 27 Sep 2018 01:10:50 +0300 Subject: [PATCH 042/151] SDL_string.c (SDL_PrintString): avoid MSVC signed/unsigned mismatch warning --- src/stdlib/SDL_string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 4ef742d9dec9e..b65af54971fa0 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1397,8 +1397,8 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str length += SDL_min(slen, maxlen); if (info) { - if (info->precision >= 0 && info->precision < sz) { - slen = info->precision; + if (info->precision >= 0 && (size_t)info->precision < sz) { + slen = (size_t)info->precision; if (slen < maxlen) { text[slen] = 0; length -= (sz - slen); From 7689162ca0a35f8bf60cad46d7dc4bef49548b6c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 26 Sep 2018 20:10:32 -0400 Subject: [PATCH 043/151] cocoa: Force an OpenGL context update when the window becomes key. Fixes missing rendering on macOS 10.14 ("Mojave"). Fixes Bugzilla #4272. --- src/video/cocoa/SDL_cocoawindow.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 71ff8db1ba0a6..2294e777d480d 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -632,6 +632,8 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock; _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags; SDL_ToggleModState(KMOD_CAPS, newflags != 0); + + ScheduleContextUpdates(_data); } - (void)windowDidResignKey:(NSNotification *)aNotification From bb5516ac8edcd52edb41e216ebb496983fd4ff8e Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 27 Sep 2018 09:37:36 +0300 Subject: [PATCH 044/151] SDL_vsnprintf() updates for zero-padding: - remove force-enabling of pad_zeroes for %u for compatibility (was added in https://hg.libsdl.org/SDL/rev/701f4a25df89) - ignore pad_zeroes for %s and %S - ignore pad_zeroes for %d, %i and %u if a precision is given --- src/stdlib/SDL_string.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index b65af54971fa0..a41dc253432d6 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1415,7 +1415,7 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) -{/* left-pad num with zeroes, if needed. */ +{/* left-pad num with zeroes. */ size_t sz, pad; if (!info || info->precision < 0) @@ -1681,6 +1681,9 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, break; case 'i': case 'd': + if (info.precision >= 0) { + info.pad_zeroes = SDL_FALSE; + } switch (inttype) { case DO_INT: len = SDL_PrintLong(text, left, &info, @@ -1718,7 +1721,9 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, } /* Fall through to unsigned handling */ case 'u': - info.pad_zeroes = SDL_TRUE; + if (info.precision >= 0) { + info.pad_zeroes = SDL_FALSE; + } switch (inttype) { case DO_INT: len = SDL_PrintUnsignedLong(text, left, &info, @@ -1745,12 +1750,14 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, /* In practice this is used on Windows for WCHAR strings */ wchar_t *wide_arg = va_arg(ap, wchar_t *); char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg)); + info.pad_zeroes = SDL_FALSE; len = SDL_PrintString(text, left, &info, arg); SDL_free(arg); done = SDL_TRUE; } break; case 's': + info.pad_zeroes = SDL_FALSE; len = SDL_PrintString(text, left, &info, va_arg(ap, char *)); done = SDL_TRUE; break; From d9fb77a3c196e4091e9150df3c4cfca4d7e8a372 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 27 Sep 2018 11:55:02 +0300 Subject: [PATCH 045/151] SDL_atomic.c, SDL_spinlock.c: use lock prefix with xchg in Watcom asm. --- src/atomic/SDL_atomic.c | 3 ++- src/atomic/SDL_spinlock.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index df4920139c8cb..d0022cdc17746 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -53,10 +53,11 @@ #endif #if defined(__WATCOMC__) && defined(__386__) +SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int)); #define HAVE_WATCOM_ATOMICS extern _inline int _SDL_xchg_watcom(volatile int *a, int v); #pragma aux _SDL_xchg_watcom = \ - "xchg [ecx], eax" \ + "lock xchg [ecx], eax" \ parm [ecx] [eax] \ value [eax] \ modify exact [eax]; diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index cbc1056c985ff..6a7b14a981b8d 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -40,7 +40,7 @@ SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock)); extern _inline int _SDL_xchg_watcom(volatile int *a, int v); #pragma aux _SDL_xchg_watcom = \ - "xchg [ecx], eax" \ + "lock xchg [ecx], eax" \ parm [ecx] [eax] \ value [eax] \ modify exact [eax]; From 7df0f4fdacea9ba2d7184738522f6e31c4260d60 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Sep 2018 14:56:29 -0700 Subject: [PATCH 046/151] Fixed bug 4277 - warnings patch Sylvain Patch a few warnings when using: -Wmissing-prototypes -Wdocumentation -Wdocumentation-unknown-command They are automatically enabled with -Wall --- include/SDL_sensor.h | 2 +- include/SDL_vulkan.h | 4 +-- src/core/android/SDL_android.c | 5 ++++ src/core/android/SDL_android.h | 11 ++++++-- src/cpuinfo/SDL_cpuinfo.c | 1 + src/hidapi/android/hid.cpp | 28 ++++++++++++++++++- src/hidapi/hidapi/hidapi.h | 2 +- src/render/SDL_render.c | 3 +- src/sensor/SDL_sensor.c | 6 ++-- src/video/SDL_blit_N.c | 51 ++++++++++++++++++++++++++++++++++ src/video/SDL_surface.c | 2 +- src/video/SDL_yuv.c | 1 + 12 files changed, 104 insertions(+), 12 deletions(-) diff --git a/include/SDL_sensor.h b/include/SDL_sensor.h index fa19c41ff6772..ac163a8cd1be7 100644 --- a/include/SDL_sensor.h +++ b/include/SDL_sensor.h @@ -41,7 +41,7 @@ extern "C" { #endif /** - * \file SDL_sensor.h + * \brief SDL_sensor.h * * In order to use these functions, SDL_Init() must have been called * with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system diff --git a/include/SDL_vulkan.h b/include/SDL_vulkan.h index 51373b18c0812..972cca4d7c265 100644 --- a/include/SDL_vulkan.h +++ b/include/SDL_vulkan.h @@ -137,9 +137,9 @@ extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void); * * \param [in] \c NULL or window Window for which the required Vulkan instance * extensions should be retrieved - * \param [in,out] count pointer to an \c unsigned related to the number of + * \param [in,out] pCount pointer to an \c unsigned related to the number of * required Vulkan instance extensions - * \param [out] names \c NULL or a pointer to an array to be filled with the + * \param [out] pNames \c NULL or a pointer to an array to be filled with the * required Vulkan instance extensions * * \return \c SDL_TRUE on success, \c SDL_FALSE on error. diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 7f0c1262433f0..6a03bdc5e2ad7 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -144,6 +144,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)( JNIEnv* env, jclass cls, jstring text, jint newCursorPosition); +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar)( + JNIEnv* env, jclass cls, + jchar chUnicode); + JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)( JNIEnv* env, jclass cls, jstring text, jint newCursorPosition); @@ -195,6 +199,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( /* #define DEBUG_JNI */ static void Android_JNI_ThreadDestroyed(void*); +static void checkJNIReady(void); /******************************************************************************* This file links the Java side of Android with libsdl diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index a3a7b192cfd0a..0f7561b412de4 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -85,8 +85,9 @@ void Android_JNI_HapticStop(int device_id); void Android_JNI_SuspendScreenSaver(SDL_bool suspend); /* Touch support */ -int Android_JNI_GetTouchDeviceIds(int **ids); +int Android_JNI_InitTouch(void); void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value); +int Android_JNI_GetTouchDeviceIds(int **ids); /* Threads */ #include @@ -109,9 +110,15 @@ SDL_bool Android_JNI_SetCustomCursor(int cursorID); SDL_bool Android_JNI_SetSystemCursor(int cursorID); /* Relative mouse support */ -SDL_bool Android_JNI_SupportsRelativeMouse(); +SDL_bool Android_JNI_SupportsRelativeMouse(void); SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled); + +SDL_bool SDL_IsAndroidTablet(void); +SDL_bool SDL_IsAndroidTV(void); +SDL_bool SDL_IsChromebook(void); +SDL_bool SDL_IsDeXMode(void); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus /* *INDENT-OFF* */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 1decb2dc0b781..441035883e243 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -22,6 +22,7 @@ #include "SDL_config.h" #else #include "../SDL_internal.h" +#include "SDL_simd.h" #endif #if defined(__WIN32__) diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index fbe1832b0dbd0..b9d95e9de078f 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -336,7 +336,7 @@ static jmethodID g_midHIDDeviceManagerSendFeatureReport; static jmethodID g_midHIDDeviceManagerGetFeatureReport; static jmethodID g_midHIDDeviceManagerClose; -uint64_t get_timespec_ms( const struct timespec &ts ) +static uint64_t get_timespec_ms( const struct timespec &ts ) { return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000; } @@ -694,6 +694,32 @@ static void ThreadDestroyed(void* value) } } + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface ); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenPending)(JNIEnv *env, jobject thiz, int nDeviceID); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenResult)(JNIEnv *env, jobject thiz, int nDeviceID, bool bOpened); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceDisconnected)(JNIEnv *env, jobject thiz, int nDeviceID); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceInputReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value); + +extern "C" +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value); + + extern "C" JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler) { diff --git a/src/hidapi/hidapi/hidapi.h b/src/hidapi/hidapi/hidapi.h index e9a74d559539b..15d632365998d 100644 --- a/src/hidapi/hidapi/hidapi.h +++ b/src/hidapi/hidapi/hidapi.h @@ -225,7 +225,7 @@ namespace NAMESPACE { -1 on error. If no packet was available to be read within the timeout period, this function returns 0. */ - int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds); + int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds); /** @brief Read an Input report from a HID device. diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 07ced0dff03cc..4985b16ba2570 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -521,7 +521,8 @@ GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format) return renderer->info.texture_formats[0]; } -SDL_ScaleMode SDL_GetScaleMode(void) + +static SDL_ScaleMode SDL_GetScaleMode(void) { const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 46f94a496606e..5c7a990193462 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -48,7 +48,7 @@ static SDL_bool SDL_updating_sensor = SDL_FALSE; static SDL_mutex *SDL_sensor_lock = NULL; /* This needs to support recursive locks */ static SDL_atomic_t SDL_next_sensor_instance_id; -void +static void SDL_LockSensors(void) { if (SDL_sensor_lock) { @@ -56,7 +56,7 @@ SDL_LockSensors(void) } } -void +static void SDL_UnlockSensors(void) { if (SDL_sensor_lock) { @@ -118,7 +118,7 @@ SDL_SensorID SDL_GetNextSensorInstanceID() * Get the driver and device index for an API device index * This should be called while the sensor lock is held, to prevent another thread from updating the list */ -SDL_bool +static SDL_bool SDL_GetDriverAndSensorIndex(int device_index, SDL_SensorDriver **driver, int *driver_index) { int i, num_sensors, total_sensors = 0; diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 441cd9a21987d..5a7ba9d496a9c 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -2333,6 +2333,30 @@ BlitNtoNKey(SDL_BlitInfo * info) /* Set up some basic variables */ ckey &= rgbmask; + /* Fastpath: same source/destination format, no Amask, bpp 32, loop is vectorized. ~10x faster */ + if (srcfmt->format == dstfmt->format && + (srcfmt->format == SDL_PIXELFORMAT_RGB888 || srcfmt->format == SDL_PIXELFORMAT_BGR888)) { + Uint32 *src32 = (Uint32*)src; + Uint32 *dst32 = (Uint32*)dst; + srcskip /= sizeof(Uint32); + dstskip /= sizeof(Uint32); + while (height--) { + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + Uint32 Pixel = (*src32 == ckey) ? *dst32 : *src32; + *dst32 = Pixel; + ++src32; + ++dst32; + }, + width); + /* *INDENT-ON* */ + src32 += srcskip; + dst32 += dstskip; + } + return; + } + while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( @@ -2380,6 +2404,33 @@ BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) dstbpp = dstfmt->BytesPerPixel; ckey &= rgbmask; + /* Fastpath: same source/destination format, with Amask, bpp 32, loop is vectorized. ~10x faster */ + if (srcfmt->format == dstfmt->format && + (srcfmt->format == SDL_PIXELFORMAT_ARGB8888 || + srcfmt->format == SDL_PIXELFORMAT_ABGR8888 || + srcfmt->format == SDL_PIXELFORMAT_BGRA8888 || + srcfmt->format == SDL_PIXELFORMAT_RGBA8888)) { + Uint32 *src32 = (Uint32*)src; + Uint32 *dst32 = (Uint32*)dst; + srcskip /= sizeof(Uint32); + dstskip /= sizeof(Uint32); + while (height--) { + /* *INDENT-OFF* */ + DUFFS_LOOP( + { + Uint32 Pixel = ((*src32 & rgbmask) == ckey) ? *dst32 : *src32; + *dst32 = Pixel; + ++src32; + ++dst32; + }, + width); + /* *INDENT-ON* */ + src32 += srcskip; + dst32 += dstskip; + } + return; + } + while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index c6fd3b5fb92f5..1b2ee6cea6beb 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -37,7 +37,7 @@ SDL_COMPILE_TIME_ASSERT(surface_size_assumptions, /* * Calculate the pad-aligned scanline width of a surface */ -int +static int SDL_CalculatePitch(Uint32 format, int width) { int pitch; diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 7c1e6b4673d2c..03b04dc8a1e69 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -23,6 +23,7 @@ #include "SDL_endian.h" #include "SDL_video.h" #include "SDL_pixels_c.h" +#include "SDL_yuv_c.h" #include "yuv2rgb/yuv_rgb.h" From 88f9f0307dfae9523f00c15f57c1d57f01f259be Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Sep 2018 23:54:40 -0700 Subject: [PATCH 047/151] Added patch notes for SDL 2.0.9 --- WhatsNew.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/WhatsNew.txt b/WhatsNew.txt index 0cd283e535115..771262381f3db 100644 --- a/WhatsNew.txt +++ b/WhatsNew.txt @@ -6,7 +6,39 @@ This is a list of major changes in SDL's version history. --------------------------------------------------------------------------- General: +* Added a new sensor API, initialized by passing SDL_INIT_SENSOR to SDL_Init(), and defined in SDL_sensor.h +* Added an event SDL_SENSORUPDATE which is sent when a sensor is updated +* Added SDL_GetDisplayOrientation() to return the current display orientation +* Added an event SDL_DISPLAYEVENT which is sent when the display orientation changes +* Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms. (Thanks to Valve for contributing the PS4 and Nintendo Switch Pro controller support) +* Added support for many other popular game controllers +* Added SDL_GameControllerRumble() and SDL_JoystickRumble() which allow simple rumble without using the haptics API * Added SDL_GameControllerMappingForDeviceIndex() to get the mapping for a controller before it's opened +* Added the hint SDL_HINT_MOUSE_DOUBLE_CLICK_TIME to control the mouse double-click time +* Added the hint SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to control the mouse double-click radius, in pixels +* Added SDL_HasColorKey() to return whether a surface has a colorkey active +* Added SDL_HasAVX512F() to return whether the CPU has AVX-512F features +* Added SDL_IsTablet() to return whether the application is running on a tablet +* Added SDL_THREAD_PRIORITY_TIME_CRITICAL for threads that must run at the highest priority + +Mac OS X: +* Fixed black screen at start on Mac OS X Mojave + +Linux: +* Added SDL_LinuxSetThreadPriority() to allow adjusting the thread priority of native threads using RealtimeKit if available. + +iOS: +* Fixed Asian IME input + +Android: +* Updated required Android SDK to API 26, to match Google's new App Store requirements +* Added support for wired USB Xbox, PS4, and Nintendo Switch Pro controllers +* Added support for relative mouse mode on Android 7.0 and newer (except where it's broken, on Chromebooks and when in DeX mode with Samsung Experience 9.0) +* Added support for custom mouse cursors on Android 7.0 and newer +* Added the hint SDL_HINT_ANDROID_TRAP_BACK_BUTTON to control whether the back button will back out of the app (the default) or be passed to the application as SDL_SCANCODE_AC_BACK +* Added SDL_AndroidBackButton() to trigger the Android system back button behavior when handling the back button in the application +* Added SDL_IsChromebook() to return whether the app is running in the Chromebook Android runtime +* Added SDL_IsDeXMode() to return whether the app is running while docked in the Samsung DeX --------------------------------------------------------------------------- From 20dfda44894cb8871fd13c7e2d70b8ef1eb947ca Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 00:40:35 -0700 Subject: [PATCH 048/151] Fixed mingw-w64 build --- configure | 7 +++++++ configure.in | 5 +++++ src/render/direct3d11/SDL_render_d3d11.c | 4 ---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 841fa59898bb8..523c1c6c9b425 100755 --- a/configure +++ b/configure @@ -24299,6 +24299,13 @@ $as_echo "#define SDL_JOYSTICK_WINMM 1" >>confdefs.h SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" have_joystick=yes fi + if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then + +$as_echo "#define SDL_JOYSTICK_HIDAPI 1" >>confdefs.h + + EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c" + fi if test x$enable_haptic = xyes; then if test x$have_dinput = xyes -o x$have_xinput = xyes; then if test x$have_xinput = xyes; then diff --git a/configure.in b/configure.in index 3adebaba080ec..03e23c81c8ffc 100644 --- a/configure.in +++ b/configure.in @@ -3631,6 +3631,11 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" have_joystick=yes fi + if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then + AC_DEFINE(SDL_JOYSTICK_HIDAPI, 1, [ ]) + EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c" + fi if test x$enable_haptic = xyes; then if test x$have_dinput = xyes -o x$have_xinput = xyes; then if test x$have_xinput = xyes; then diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 153cee743cbb3..7a370392fa90f 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -2223,8 +2223,6 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; float minu, maxu, minv, maxv; Float4 color; VertexPositionColor vertices[4]; @@ -2296,8 +2294,6 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect, const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) { - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; float minu, maxu, minv, maxv; Float4 color; Float4X4 modelMatrix; From f964ce03b4d77a0b74cb50d8c5b409c9c9395d98 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 01:00:47 -0700 Subject: [PATCH 049/151] Fixed mingw-w64 build --- configure | 11 +++++------ configure.in | 11 +++++------ src/hidapi/windows/hid.c | 1 + src/joystick/hidapi/SDL_hidapi_ps4.c | 10 +++++----- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/configure b/configure index 523c1c6c9b425..c5d3e85fade82 100755 --- a/configure +++ b/configure @@ -24296,15 +24296,14 @@ $as_echo "#define SDL_JOYSTICK_DINPUT 1" >>confdefs.h $as_echo "#define SDL_JOYSTICK_WINMM 1" >>confdefs.h fi - SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" - have_joystick=yes - fi - if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then $as_echo "#define SDL_JOYSTICK_HIDAPI 1" >>confdefs.h - EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c" + SOURCES="$SOURCES $srcdir/src/hidapi/windows/hid.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + have_joystick=yes fi if test x$enable_haptic = xyes; then if test x$have_dinput = xyes -o x$have_xinput = xyes; then @@ -24367,7 +24366,7 @@ $as_echo "#define SDL_LOADSO_WINDOWS 1" >>confdefs.h else LIBUUID=-luuid fi - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion $LIBUUID -static-libgcc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion $LIBUUID -static-libgcc" # The Windows platform requires special setup VERSION_SOURCES="$srcdir/src/main/windows/*.rc" SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c" diff --git a/configure.in b/configure.in index 03e23c81c8ffc..66a00c4654b2d 100644 --- a/configure.in +++ b/configure.in @@ -3628,13 +3628,12 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau else AC_DEFINE(SDL_JOYSTICK_WINMM, 1, [ ]) fi - SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" - have_joystick=yes - fi - if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then AC_DEFINE(SDL_JOYSTICK_HIDAPI, 1, [ ]) - EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + SOURCES="$SOURCES $srcdir/src/joystick/windows/*.c" SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c" + SOURCES="$SOURCES $srcdir/src/hidapi/windows/hid.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -I$srcdir/src/hidapi/hidapi" + have_joystick=yes fi if test x$enable_haptic = xyes; then if test x$have_dinput = xyes -o x$have_xinput = xyes; then @@ -3683,7 +3682,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau else LIBUUID=-luuid fi - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion $LIBUUID -static-libgcc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion $LIBUUID -static-libgcc" # The Windows platform requires special setup VERSION_SOURCES="$srcdir/src/main/windows/*.rc" SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c" diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 11a2555b22ea8..86b297ca09782 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -37,6 +37,7 @@ typedef LONG NTSTATUS; #endif /* SDL C runtime functions */ +#include "../../SDL_internal.h" #include "SDL_stdinc.h" #define calloc SDL_calloc diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index 3484ddb9757a8..f33b660ea1b7c 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -162,9 +162,9 @@ static Uint32 crc32(Uint32 crc, const void *data, int count) #undef DEFINE_GUID #define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} -DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E); -DEFINE_GUID(IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6); -DEFINE_GUID(IID_IAudioEndpointVolume, 0x5CDF2C82, 0x841E, 0x4546, 0x97, 0x22, 0x0C, 0xF7, 0x40, 0x78, 0x22, 0x9A); +DEFINE_GUID(SDL_CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E); +DEFINE_GUID(SDL_IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6); +DEFINE_GUID(SDL_IID_IAudioEndpointVolume, 0x5CDF2C82, 0x841E, 0x4546, 0x97, 0x22, 0x0C, 0xF7, 0x40, 0x78, 0x22, 0x9A); #endif @@ -179,7 +179,7 @@ static float GetSystemVolume(void) IMMDeviceEnumerator *pEnumerator; /* This should gracefully fail on XP and succeed on everything Vista and above */ - hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (LPVOID*)&pEnumerator); + hr = CoCreateInstance(&SDL_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &SDL_IID_IMMDeviceEnumerator, (LPVOID*)&pEnumerator); if (SUCCEEDED(hr)) { IMMDevice *pDevice; @@ -187,7 +187,7 @@ static float GetSystemVolume(void) if (SUCCEEDED(hr)) { IAudioEndpointVolume *pEndpointVolume; - hr = IMMDevice_Activate(pDevice, &IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (LPVOID*)&pEndpointVolume); + hr = IMMDevice_Activate(pDevice, &SDL_IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (LPVOID*)&pEndpointVolume); if (SUCCEEDED(hr)) { IAudioEndpointVolume_GetMasterVolumeLevelScalar(pEndpointVolume, &volume); IUnknown_Release(pEndpointVolume); From 283680f2c1ecaff1779e6e60c1fdec4764e1ac61 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 11:04:55 +0300 Subject: [PATCH 050/151] hidapi/windows/hid.c: fix misplaced #if 0 VendorID && ProductID are only used by the test main(), otherwise they are unwanted globals. --- src/hidapi/windows/hid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 86b297ca09782..69b53231c2885 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -913,6 +913,8 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) } +#if 0 + /*#define PICPGM*/ /*#define S11*/ #define P32 @@ -932,8 +934,6 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) unsigned short ProductID = 0x0033; #endif - -#if 0 int __cdecl main(int argc, char* argv[]) { int res; From 9aa8a75d26547bb789f46a12ad1b67dabd60f5d3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 01:18:54 -0700 Subject: [PATCH 051/151] Fixed building with Xcode 10.0 --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 8 +++++--- src/joystick/hidapi/SDL_hidapi_xbox360.c | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 0fd37778a6705..6884684faf018 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -2614,7 +2614,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; }; buildConfigurationList = 0073178E0858DB0500B2BC32 /* Build configuration list for PBXProject "SDL" */; compatibilityVersion = "Xcode 3.2"; @@ -3112,11 +3112,13 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; @@ -3153,7 +3155,6 @@ 00CFA622106A567900758660 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; @@ -3206,11 +3207,13 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; @@ -3247,7 +3250,6 @@ 00CFA628106A568900758660 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index d8c5edb9ab788..84c63c667a34d 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -752,7 +752,9 @@ HIDAPI_DriverXbox360_Update(SDL_Joystick *joystick, hid_device *dev, void *conte static void HIDAPI_DriverXbox360_Quit(SDL_Joystick *joystick, hid_device *dev, void *context) { +#if defined(SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT) || defined(SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT) SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context; +#endif #ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT if (ctx->xinput_enabled) { From cf7460e477dffa3c4addd8e9513b9b84b9cfe000 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 11:30:50 +0300 Subject: [PATCH 052/151] configury, cmake: make wasapi option independent of directx. --- CMakeLists.txt | 8 +++++--- configure | 44 ++++++++++++++++++++++---------------------- configure.in | 12 ++++++------ 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 376f27f7163ac..886e1a58604c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,7 +334,7 @@ foreach(_SUB ${SDL_X11_OPTIONS}) endforeach() set_option(VIDEO_COCOA "Use Cocoa video driver" ${APPLE}) set_option(DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS}) -dep_option(WASAPI "Use the Windows WASAPI audio driver" ON "DIRECTX" OFF) +set_option(WASAPI "Use the Windows WASAPI audio driver" ${WINDOWS}) set_option(RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS}) set_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS}) dep_option(VIDEO_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF) @@ -1200,8 +1200,6 @@ elseif(WINDOWS) check_include_file(ddraw.h HAVE_DDRAW_H) check_include_file(dsound.h HAVE_DSOUND_H) check_include_file(dinput.h HAVE_DINPUT_H) - check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H) - check_include_file(audioclient.h HAVE_AUDIOCLIENT_H) check_include_file(dxgi.h HAVE_DXGI_H) if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H) set(HAVE_DIRECTX TRUE) @@ -1226,6 +1224,10 @@ elseif(WINDOWS) set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES}) endif() + # headers needed for WASAPI support: + check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H) + check_include_file(audioclient.h HAVE_AUDIOCLIENT_H) + if(WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H) set(SDL_AUDIO_DRIVER_WASAPI 1) file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c) diff --git a/configure b/configure index c5d3e85fade82..1d7ec144c8fb9 100755 --- a/configure +++ b/configure @@ -23165,20 +23165,6 @@ if test "x$ac_cv_header_xinput_h" = xyes; then : fi - ac_fn_c_check_header_mongrel "$LINENO" "mmdeviceapi.h" "ac_cv_header_mmdeviceapi_h" "$ac_includes_default" -if test "x$ac_cv_header_mmdeviceapi_h" = xyes; then : - have_wasapi=yes -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "audioclient.h" "ac_cv_header_audioclient_h" "$ac_includes_default" -if test "x$ac_cv_header_audioclient_h" = xyes; then : - -else - have_wasapi=no -fi - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -23257,14 +23243,6 @@ $as_echo "#define HAVE_XINPUT_STATE_EX 1" >>confdefs.h SUMMARY_video="${SUMMARY_video} directx" SUMMARY_audio="${SUMMARY_audio} directx" - # Check whether --enable-wasapi was given. -if test "${enable_wasapi+set}" = set; then : - enableval=$enable_wasapi; -else - enable_wasapi=yes -fi - - # FIXME: latest Cygwin finds dinput headers, but we die on other win32 headers. # FIXME: ...so force it off for now. case "$host" in @@ -23273,6 +23251,28 @@ fi ;; esac fi + + ac_fn_c_check_header_mongrel "$LINENO" "mmdeviceapi.h" "ac_cv_header_mmdeviceapi_h" "$ac_includes_default" +if test "x$ac_cv_header_mmdeviceapi_h" = xyes; then : + have_wasapi=yes +fi + + + ac_fn_c_check_header_mongrel "$LINENO" "audioclient.h" "ac_cv_header_audioclient_h" "$ac_includes_default" +if test "x$ac_cv_header_audioclient_h" = xyes; then : + +else + have_wasapi=no +fi + + + # Check whether --enable-wasapi was given. +if test "${enable_wasapi+set}" = set; then : + enableval=$enable_wasapi; +else + enable_wasapi=yes +fi + } CheckDLOPEN() diff --git a/configure.in b/configure.in index 66a00c4654b2d..177a7bdc02f26 100644 --- a/configure.in +++ b/configure.in @@ -3052,8 +3052,6 @@ AC_HELP_STRING([--enable-directx], [use DirectX for Windows audio/video [[defaul AC_CHECK_HEADER(dinput.h, have_dinput=yes) AC_CHECK_HEADER(dxgi.h, have_dxgi=yes) AC_CHECK_HEADER(xinput.h, have_xinput=yes) - AC_CHECK_HEADER(mmdeviceapi.h, have_wasapi=yes) - AC_CHECK_HEADER(audioclient.h,,have_wasapi=no) AC_TRY_COMPILE([ #include #include @@ -3090,10 +3088,6 @@ XINPUT_STATE_EX s1; SUMMARY_video="${SUMMARY_video} directx" SUMMARY_audio="${SUMMARY_audio} directx" - AC_ARG_ENABLE(wasapi, -AC_HELP_STRING([--enable-wasapi], [use the Windows WASAPI audio driver [[default=yes]]]), - , enable_wasapi=yes) - # FIXME: latest Cygwin finds dinput headers, but we die on other win32 headers. # FIXME: ...so force it off for now. case "$host" in @@ -3102,6 +3096,12 @@ AC_HELP_STRING([--enable-wasapi], [use the Windows WASAPI audio driver [[default ;; esac fi + + AC_CHECK_HEADER(mmdeviceapi.h, have_wasapi=yes) + AC_CHECK_HEADER(audioclient.h,,have_wasapi=no) + AC_ARG_ENABLE(wasapi, +AC_HELP_STRING([--enable-wasapi], [use the Windows WASAPI audio driver [[default=yes]]]), + , enable_wasapi=yes) } dnl Check for the dlfcn.h interface for dynamically loading objects From b11c75e9f47823b41b356ac4ccd9d1afdddecbd1 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 13:41:04 +0300 Subject: [PATCH 053/151] configury, cmake: add check for endpointvolume.h : add HAVE_ENDPOINTVOLUME_H, HAVE_MMDEVICEAPI_H and HAVE_AUDIOCLIENT_H in SDL_config.h.in, SDL_config.h.cmake, SDL_config_windows.h, and in SDL_config_winrt.h. --- CMakeLists.txt | 9 +++++---- configure | 17 +++++++++++++++++ configure.in | 9 +++++++++ include/SDL_config.h.cmake | 5 +++++ include/SDL_config.h.in | 3 +++ include/SDL_config_windows.h | 3 +++ include/SDL_config_winrt.h | 5 +++++ 7 files changed, 47 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 886e1a58604c9..0840f71e95179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1212,6 +1212,11 @@ elseif(WINDOWS) set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) endif() + # headers needed elsewhere ... + check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H) + check_include_file(audioclient.h HAVE_AUDIOCLIENT_H) + check_include_file(endpointvolume.h HAVE_ENDPOINTVOLUME_H) + if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_WINMM 1) file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c) @@ -1224,10 +1229,6 @@ elseif(WINDOWS) set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES}) endif() - # headers needed for WASAPI support: - check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H) - check_include_file(audioclient.h HAVE_AUDIOCLIENT_H) - if(WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H) set(SDL_AUDIO_DRIVER_WASAPI 1) file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c) diff --git a/configure b/configure index 1d7ec144c8fb9..e5ecea0a2ea79 100755 --- a/configure +++ b/configure @@ -23258,6 +23258,10 @@ if test "x$ac_cv_header_mmdeviceapi_h" = xyes; then : fi + if test x$have_wasapi = xyes; then + $as_echo "#define HAVE_MMDEVICEAPI_H 1" >>confdefs.h + + fi ac_fn_c_check_header_mongrel "$LINENO" "audioclient.h" "ac_cv_header_audioclient_h" "$ac_includes_default" if test "x$ac_cv_header_audioclient_h" = xyes; then : @@ -23266,6 +23270,19 @@ else fi + if test x$have_wasapi = xyes; then + $as_echo "#define HAVE_AUDIOCLIENT_H 1" >>confdefs.h + + fi + + ac_fn_c_check_header_mongrel "$LINENO" "endpointvolume.h" "ac_cv_header_endpointvolume_h" "$ac_includes_default" +if test "x$ac_cv_header_endpointvolume_h" = xyes; then : + $as_echo "#define HAVE_ENDPOINTVOLUME_H 1" >>confdefs.h + +fi + + + # Check whether --enable-wasapi was given. if test "${enable_wasapi+set}" = set; then : enableval=$enable_wasapi; diff --git a/configure.in b/configure.in index 177a7bdc02f26..8711587019a84 100644 --- a/configure.in +++ b/configure.in @@ -3098,7 +3098,16 @@ XINPUT_STATE_EX s1; fi AC_CHECK_HEADER(mmdeviceapi.h, have_wasapi=yes) + if test x$have_wasapi = xyes; then + AC_DEFINE(HAVE_MMDEVICEAPI_H,1,[]) + fi AC_CHECK_HEADER(audioclient.h,,have_wasapi=no) + if test x$have_wasapi = xyes; then + AC_DEFINE(HAVE_AUDIOCLIENT_H,1,[]) + fi + + AC_CHECK_HEADER(endpointvolume.h,AC_DEFINE(HAVE_ENDPOINTVOLUME_H,1,[])) + AC_ARG_ENABLE(wasapi, AC_HELP_STRING([--enable-wasapi], [use the Windows WASAPI audio driver [[default=yes]]]), , enable_wasapi=yes) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index f46984bad0fbb..48dd2d41b7851 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -209,6 +209,11 @@ #cmakedefine HAVE_DINPUT_H @HAVE_DINPUT_H@ #cmakedefine HAVE_XINPUT_H @HAVE_XINPUT_H@ #cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@ + +#cmakedefine HAVE_ENDPOINTVOLUME_H @HAVE_ENDPOINTVOLUME_H@ +#cmakedefine HAVE_MMDEVICEAPI_H @HAVE_MMDEVICEAPI_H@ +#cmakedefine HAVE_AUDIOCLIENT_H @HAVE_AUDIOCLIENT_H@ + #cmakedefine HAVE_XINPUT_GAMEPAD_EX @HAVE_XINPUT_GAMEPAD_EX@ #cmakedefine HAVE_XINPUT_STATE_EX @HAVE_XINPUT_STATE_EX@ diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 45a80aec95740..883b6f427e31b 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -209,6 +209,9 @@ #undef HAVE_DSOUND_H #undef HAVE_DXGI_H #undef HAVE_XINPUT_H +#undef HAVE_ENDPOINTVOLUME_H +#undef HAVE_MMDEVICEAPI_H +#undef HAVE_AUDIOCLIENT_H #undef HAVE_XINPUT_GAMEPAD_EX #undef HAVE_XINPUT_STATE_EX diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index 4aa06f7247419..c58be8e72ee0d 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -82,6 +82,9 @@ typedef unsigned int uintptr_t; #define HAVE_DSOUND_H 1 #define HAVE_DXGI_H 1 #define HAVE_XINPUT_H 1 +#define HAVE_MMDEVICEAPI_H 1 +#define HAVE_AUDIOCLIENT_H 1 +#define HAVE_ENDPOINTVOLUME_H 1 /* This is disabled by default to avoid C runtime dependencies and manifest requirements */ #ifdef HAVE_LIBC diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index 568b4211f605b..e3fe55b0738e2 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -97,6 +97,11 @@ typedef unsigned int uintptr_t; #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP #define HAVE_XINPUT_H 1 #endif + +#define HAVE_MMDEVICEAPI_H 1 +#define HAVE_AUDIOCLIENT_H 1 +#define HAVE_ENDPOINTVOLUME_H 1 + #define HAVE_LIBC 1 #define STDC_HEADERS 1 #define HAVE_CTYPE_H 1 From cf7d64f2662cee538f0b5dce9fea926a45127e23 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 13:44:10 +0300 Subject: [PATCH 054/151] hidapi/windows/hid.c: comment out ntdef.h include after windows.h. not necessary and can cause redefinition errors in some toolchains. --- src/hidapi/windows/hid.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 69b53231c2885..1d3803c407276 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -22,10 +22,7 @@ #include -#ifndef _NTDEF_ -typedef LONG NTSTATUS; -#endif - +#if 0 /* can cause redefinition errors on some toolchains */ #ifdef __MINGW32__ #include #include @@ -35,6 +32,11 @@ typedef LONG NTSTATUS; #include #define _wcsdup wcsdup #endif +#endif /* */ + +#ifndef _NTDEF_ +typedef LONG NTSTATUS; +#endif /* SDL C runtime functions */ #include "../../SDL_internal.h" @@ -906,7 +908,6 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string(hid_device *dev, int return 0; } - HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) { return (wchar_t*)dev->last_error_str; @@ -918,7 +919,7 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) /*#define PICPGM*/ /*#define S11*/ #define P32 -#ifdef S11 +#ifdef S11 unsigned short VendorID = 0xa0a0; unsigned short ProductID = 0x0001; #endif @@ -928,7 +929,6 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) unsigned short ProductID = 0x3f; #endif - #ifdef PICPGM unsigned short VendorID = 0x04d8; unsigned short ProductID = 0x0033; From fde82e5972fdb072f4c31f068a075451d98af872 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 14:01:40 +0300 Subject: [PATCH 055/151] SDL_hidapi_ps4.c: add HAVE_ENDPOINTVOLUME_H check to win32 volume code. this makes it build with my old toolchain with mingw-w64 1.0.10 headers --- src/joystick/hidapi/SDL_hidapi_ps4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index f33b660ea1b7c..cdd478a07397f 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -140,7 +140,7 @@ static Uint32 crc32(Uint32 crc, const void *data, int count) return crc; } -#ifdef __WIN32__ +#if defined(__WIN32__) && defined(HAVE_ENDPOINTVOLUME_H) #include "../../core/windows/SDL_windows.h" #ifndef NTDDI_VISTA @@ -173,7 +173,7 @@ static float GetSystemVolume(void) { float volume = -1.0f; /* Return this if we can't get system volume */ -#ifdef __WIN32__ +#if defined(__WIN32__) && defined(HAVE_ENDPOINTVOLUME_H) HRESULT hr = WIN_CoInitialize(); if (SUCCEEDED(hr)) { IMMDeviceEnumerator *pEnumerator; From 5454765a2293863f0a3925ab7d2c710fbe481afd Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 28 Sep 2018 17:01:24 +0300 Subject: [PATCH 056/151] replace bool stuff in controller_type.h with SDL_bool. remove bool<->SDL_bool dance in SDL_joystick.c:SDL_IsJoystickSteamController() after the controller_type.h change. --- src/joystick/SDL_joystick.c | 2 +- src/joystick/controller_type.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 5dece76fcc863..f7d862b3cc763 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1135,7 +1135,7 @@ SDL_IsJoystickNintendoSwitchPro(Uint16 vendor, Uint16 product) SDL_bool SDL_IsJoystickSteamController(Uint16 vendor, Uint16 product) { - return BIsSteamController(GuessControllerType(vendor, product)) ? SDL_TRUE : SDL_FALSE; + return BIsSteamController(GuessControllerType(vendor, product)); } SDL_bool diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h index 26054edfa0b1f..51ac20b4e1eb5 100644 --- a/src/joystick/controller_type.h +++ b/src/joystick/controller_type.h @@ -25,7 +25,6 @@ #endif #ifndef __cplusplus -typedef enum { false, true } bool; #define inline SDL_INLINE #endif @@ -65,7 +64,7 @@ typedef enum k_eControllertype_GenericMouse = 800, } EControllerType; -static inline bool BIsSteamController( EControllerType eType ) +static inline SDL_bool BIsSteamController( EControllerType eType ) { return ( eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2 ); } From 49803c8660d54ee795d5c4cfbd2a38f405f9bd71 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 29 Sep 2018 00:51:24 +0300 Subject: [PATCH 057/151] SDL_vsnprintf: fix numerics if both zero-padding and a field are given. it used to place zeroes between the sign and the number. (space-padding from within SDL_PrintString() seems OK: spaces are added before sign.) also fixed the maxlen handling if the number has a sign. --- src/stdlib/SDL_string.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index a41dc253432d6..94e461bbf4c2a 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1416,15 +1416,19 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) {/* left-pad num with zeroes. */ - size_t sz, pad; + size_t sz, pad, have_sign; - if (!info || info->precision < 0) + if (!info) return; - if (*num == '-') + have_sign = 0; + if (*num == '-' || *num == '+') { + have_sign = 1; ++num; + --maxlen; + } sz = SDL_strlen(num); - if (sz < (size_t)info->precision) { + if (info->precision > 0 && sz < (size_t)info->precision) { pad = (size_t)info->precision - sz; if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */ SDL_memmove(num + pad, num, sz + 1); @@ -1432,6 +1436,18 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) } } info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */ + + if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) { + /* handle here: spaces are added before the sign + but zeroes must be placed _after_ the sign. */ + /* sz hasn't changed: we ignore pad_zeroes if a precision is given. */ + pad = (size_t)info->width - sz - have_sign; + if (pad + sz + 1 <= maxlen) { + SDL_memmove(num + pad, num, sz + 1); + SDL_memset(num, '0', pad); + } + info->width = 0; /* so that SDL_PrintString() doesn't make a mess. */ + } } static size_t From 31596f23cec7f20e83e91f8cc8393c512a1d8a77 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 29 Sep 2018 01:24:10 +0300 Subject: [PATCH 058/151] SDL_vsnprintf: implemented '+' flag for signed integers printing. it is, of course, ignored for %u, %x, %o and %p. --- src/stdlib/SDL_string.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 94e461bbf4c2a..0fedcf4355e10 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1361,7 +1361,7 @@ typedef enum typedef struct { SDL_bool left_justify; /* for now: ignored. */ - SDL_bool force_sign; /* for now: used only by float printer, ignored otherwise. */ + SDL_bool force_sign; SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */ SDL_bool pad_zeroes; SDL_letter_case force_case; @@ -1453,9 +1453,13 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value) { - char num[130]; + char num[130], *p = num; + + if (info->force_sign && value >= 0L) { + *p++ = '+'; + } - SDL_ltoa(value, num, info ? info->radix : 10); + SDL_ltoa(value, p, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } @@ -1473,9 +1477,13 @@ SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned static size_t SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value) { - char num[130]; + char num[130], *p = num; + + if (info->force_sign && value >= (Sint64)0) { + *p++ = '+'; + } - SDL_lltoa(value, num, info ? info->radix : 10); + SDL_lltoa(value, p, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } @@ -1737,6 +1745,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, } /* Fall through to unsigned handling */ case 'u': + info.force_sign = SDL_FALSE; if (info.precision >= 0) { info.pad_zeroes = SDL_FALSE; } From 74638ea3c5b3f8c0fa3b2514b1b6b61483ceb216 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 20:39:57 -0700 Subject: [PATCH 059/151] Ensure we wait on the surface resize before returning from setting fullscreen mode. --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 .../main/java/org/libsdl/app/SDLActivity.java | 21 ++++++++++++++++++- src/core/android/SDL_android.h | 5 +++++ src/video/android/SDL_androidwindow.c | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) mode change 100644 => 100755 Xcode/SDL/SDL.xcodeproj/project.pbxproj diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 0ece200d100f8..071b343b41095 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -643,7 +643,22 @@ boolean sendCommand(int command, Object data) { Message msg = commandHandler.obtainMessage(); msg.arg1 = command; msg.obj = data; - return commandHandler.sendMessage(msg); + boolean result = commandHandler.sendMessage(msg); + + // Ensure we don't return until the resize has actually happened, + // or 250ms have passed. + if (command == COMMAND_CHANGE_WINDOW_STYLE) { + synchronized(SDLActivity.getContext()) { + try { + SDLActivity.getContext().wait(250); + } + catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + } + + return result; } // C functions we call @@ -1577,6 +1592,10 @@ public void surfaceChanged(SurfaceHolder holder, } catch ( java.lang.Throwable throwable ) {} + synchronized(SDLActivity.getContext()) { + SDLActivity.getContext().notifyAll(); + } + Log.v("SDL", "Window size: " + width + "x" + height); Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate()); diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index 0f7561b412de4..bac4fd33ef123 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -19,6 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" +#include "SDL_system.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -53,6 +54,10 @@ extern int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen); extern void Android_JNI_FlushCapturedAudio(void); extern void Android_JNI_CloseAudioDevice(const int iscapture); +/* Detecting device type */ +extern SDL_bool Android_IsDeXMode(); +extern SDL_bool Android_IsChromebook(); + #include "SDL_rwops.h" int Android_JNI_FileOpen(SDL_RWops* ctx, const char* fileName, const char* mode); diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 93d60d35090b6..037b49079fdbc 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -27,6 +27,7 @@ #include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_mouse_c.h" #include "../../events/SDL_windowevents_c.h" +#include "../../core/android/SDL_android.h" #include "SDL_androidvideo.h" #include "SDL_androidwindow.h" @@ -109,6 +110,10 @@ Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * displ // Samsung DeX or Chromebooks or other windowed Android environemtns, our window may // still not be the full display size. // + if (!SDL_IsDeXMode() && !SDL_IsChromebook()) { + return; + } + SDL_WindowData * data = (SDL_WindowData *)window->driverdata; if (!data || !data->native_window) { From 9e8e0fb7b14034a19365f0d4c3b8c250cd441163 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 20:48:18 -0700 Subject: [PATCH 060/151] Fixed bug 4283 - SDL's version of memset is different from libc's janisozaur memset's documentation reads: * The memset() function shall copy c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html) * Sets the first count characters of dest to the character c. (https://msdn.microsoft.com/en-us/library/1fdeehz6.aspx) * write a byte to a byte string (https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/memset.3.html) The highlight here is they all mean a single _byte_, even though memset receives a parameter of type int, which can hold more data than a single byte. SDL's implementation of memset, however, does not clear any of the higher bits, causing an erroneous behaviour when passed an argument bigger than 0xff. --- src/stdlib/SDL_string.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 0fedcf4355e10..a563adfcc233a 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -271,12 +271,16 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len) size_t left; Uint32 *dstp4; Uint8 *dstp1 = (Uint8 *) dst; - Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24)); - Uint8 value1 = (Uint8) c; + Uint8 value1; + Uint32 value4; + + /* The value used in memset() is a byte, passed as an int */ + c &= 0xff; /* The destination pointer needs to be aligned on a 4-byte boundary to * execute a 32-bit set. Set first bytes manually if needed until it is * aligned. */ + value1 = (Uint8)c; while ((intptr_t)dstp1 & 0x3) { if (len--) { *dstp1++ = value1; @@ -285,6 +289,7 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len) } } + value4 = (c | (c << 8) | (c << 16) | (c << 24)); dstp4 = (Uint32 *) dstp1; left = (len % 4); len /= 4; From 14d2ec80e741ab6092f183f2707e10b2de920470 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 21:03:39 -0700 Subject: [PATCH 061/151] commit 8f4dedc039190f5e734c47dcc4fc021b5793b659 Author: Micha? Janiszewski Date: Fri Sep 28 20:38:04 2018 +0200 CMake: fix building tests on Linux In case where libunwind.h has been found, it will be used by compiler, but linker wasn't updated to reflect use of this new library. --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0840f71e95179..c213bc455e37a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1059,6 +1059,12 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID) include_directories(${IBUS_INCLUDE_DIRS}) list(APPEND EXTRA_LIBS ${IBUS_LIBRARIES}) endif() + if(HAVE_LIBUNWIND_H) + # We've already found the header, so REQUIRE the lib to be present + pkg_search_module(UNWIND REQUIRED libunwind) + pkg_search_module(UNWIND_GENERIC REQUIRED libunwind-generic) + list(APPEND EXTRA_LIBS ${UNWIND_LIBRARIES} ${UNWIND_GENERIC_LIBRARIES}) + endif() endif() check_include_file("fcitx/frontend.h" HAVE_FCITX_FRONTEND_H) From c17d62996fbbaf1fd041c60c27471c387f63b0cf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 28 Sep 2018 21:19:27 -0700 Subject: [PATCH 062/151] Mark a subsystem as dummy, not disabled, if it was intended to be compiled in. From Tom Black: I'm having problems initializing the sensor module. I'm compiling with a standard ./configure && make && sudo make install, and the module says it's enabled, but SDL_Init(SDL_INIT_EVERYTHING) is failing with SDL_GetError() returning "SDL not built with sensor support". --- CMakeLists.txt | 14 +++++++------- configure | 6 +++--- configure.in | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c213bc455e37a..302ba2c9e38e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1565,7 +1565,7 @@ endif() # This leads to missing internal references on building, since the # src/X/*.c does not get included. if(NOT HAVE_SDL_JOYSTICK) - set(SDL_JOYSTICK_DISABLED 1) + set(SDL_JOYSTICK_DUMMY 1) if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c) @@ -1573,10 +1573,15 @@ if(NOT HAVE_SDL_JOYSTICK) endif() endif() if(NOT HAVE_SDL_HAPTIC) - set(SDL_HAPTIC_DISABLED 1) + set(SDL_HAPTIC_DUMMY 1) file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c) set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES}) endif() +if(NOT HAVE_SDL_SENSORS) + set(SDL_SENSOR_DUMMY 1) + file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${SENSORS_SOURCES}) +endif() if(NOT HAVE_SDL_LOADSO) set(SDL_LOADSO_DISABLED 1) file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c) @@ -1587,11 +1592,6 @@ if(NOT HAVE_SDL_FILESYSTEM) file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c) set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES}) endif() -if(NOT HAVE_SDL_SENSORS) - set(SDL_SENSOR_DISABLED 1) - file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c) - set(SOURCE_FILES ${SOURCE_FILES} ${SENSORS_SOURCES}) -endif() # We always need to have threads and timers around if(NOT HAVE_SDL_THREADS) diff --git a/configure b/configure index e5ecea0a2ea79..aee0cb6ecdde1 100755 --- a/configure +++ b/configure @@ -24819,7 +24819,7 @@ esac if test x$have_joystick != xyes; then if test x$enable_joystick = xyes; then -$as_echo "#define SDL_JOYSTICK_DISABLED 1" >>confdefs.h +$as_echo "#define SDL_JOYSTICK_DUMMY 1" >>confdefs.h fi SOURCES="$SOURCES $srcdir/src/joystick/dummy/*.c" @@ -24827,7 +24827,7 @@ fi if test x$have_haptic != xyes; then if test x$enable_haptic = xyes; then -$as_echo "#define SDL_HAPTIC_DISABLED 1" >>confdefs.h +$as_echo "#define SDL_HAPTIC_DUMMY 1" >>confdefs.h fi SOURCES="$SOURCES $srcdir/src/haptic/dummy/*.c" @@ -24835,7 +24835,7 @@ fi if test x$have_sensor != xyes; then if test x$enable_sensor = xyes; then -$as_echo "#define SDL_SENSOR_DISABLED 1" >>confdefs.h +$as_echo "#define SDL_SENSOR_DUMMY 1" >>confdefs.h fi SOURCES="$SOURCES $srcdir/src/sensor/dummy/*.c" diff --git a/configure.in b/configure.in index 8711587019a84..ae866ff0c55cc 100644 --- a/configure.in +++ b/configure.in @@ -4012,19 +4012,19 @@ esac if test x$have_joystick != xyes; then if test x$enable_joystick = xyes; then - AC_DEFINE(SDL_JOYSTICK_DISABLED, 1, [ ]) + AC_DEFINE(SDL_JOYSTICK_DUMMY, 1, [ ]) fi SOURCES="$SOURCES $srcdir/src/joystick/dummy/*.c" fi if test x$have_haptic != xyes; then if test x$enable_haptic = xyes; then - AC_DEFINE(SDL_HAPTIC_DISABLED, 1, [ ]) + AC_DEFINE(SDL_HAPTIC_DUMMY, 1, [ ]) fi SOURCES="$SOURCES $srcdir/src/haptic/dummy/*.c" fi if test x$have_sensor != xyes; then if test x$enable_sensor = xyes; then - AC_DEFINE(SDL_SENSOR_DISABLED, 1, [ ]) + AC_DEFINE(SDL_SENSOR_DUMMY, 1, [ ]) fi SOURCES="$SOURCES $srcdir/src/sensor/dummy/*.c" fi From 35422bd893f17019cb9003b46cf44e92c15d82d6 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 29 Sep 2018 09:20:50 +0300 Subject: [PATCH 063/151] fix permissions --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Xcode/SDL/SDL.xcodeproj/project.pbxproj diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100755 new mode 100644 From e77ec8896974a37c172f765fffeef1ecdb85c2b0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 29 Sep 2018 02:14:46 -0700 Subject: [PATCH 064/151] Fixed tablet detection on Android --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 071b343b41095..360176253e28d 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -843,16 +843,16 @@ public static boolean isAndroidTV() { */ public static boolean isTablet() { DisplayMetrics metrics = new DisplayMetrics(); - Activity sdlActivity = (Activity)getContext(); - sdlActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + Activity activity = (Activity)getContext(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - double dWidthInches = metrics.widthPixels / (double)metrics.densityDpi; - double dHeightInches = metrics.heightPixels / (double)metrics.densityDpi; + double dWidthInches = metrics.widthPixels / (double)metrics.xdpi; + double dHeightInches = metrics.heightPixels / (double)metrics.ydpi; double dDiagonal = Math.sqrt((dWidthInches * dWidthInches) + (dHeightInches * dHeightInches)); // If our diagonal size is seven inches or greater, we consider ourselves a tablet. - return (dDiagonal > 7.0); + return (dDiagonal >= 7.0); } /** From 56ec349d2aff14972f15e83a5e30de8c660386f7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 29 Sep 2018 16:48:15 -0400 Subject: [PATCH 065/151] audio: disable NEON converters for now. To be revisited after 2.0.9 ships! (doesn't fix Bugzilla #4186, but stops the regression for the time being.) --- src/audio/SDL_audiotypecvt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/audio/SDL_audiotypecvt.c b/src/audio/SDL_audiotypecvt.c index e76ecdb80492f..5f8cc22dae7cf 100644 --- a/src/audio/SDL_audiotypecvt.c +++ b/src/audio/SDL_audiotypecvt.c @@ -25,7 +25,8 @@ #include "SDL_cpuinfo.h" #include "SDL_assert.h" -#ifdef __ARM_NEON__ +/* !!! FIXME: disabled until we fix https://bugzilla.libsdl.org/show_bug.cgi?id=4186 */ +#if 0 /*def __ARM_NEON__*/ #define HAVE_NEON_INTRINSICS 1 #endif From fb485986eb64e01e6d60398ee1024d118bd3a698 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 30 Sep 2018 11:26:41 -0300 Subject: [PATCH 066/151] macOS: Fix a crash when the video subsystem quits, if SDL_MAC_NO_SANDBOX was defined when SDL was compiled. --- src/video/cocoa/SDL_cocoamousetap.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/video/cocoa/SDL_cocoamousetap.m b/src/video/cocoa/SDL_cocoamousetap.m index 05a7d77d8afbf..aa4f152e6acab 100644 --- a/src/video/cocoa/SDL_cocoamousetap.m +++ b/src/video/cocoa/SDL_cocoamousetap.m @@ -237,6 +237,13 @@ SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata; int status; + if (tapdata == NULL) { + /* event tap was already cleaned up (possibly due to CGEventTapCreate + * returning null.) + */ + return; + } + /* Ensure that the runloop has been started first. * TODO: Move this to InitMouseEventTap, check for error conditions that can * happen in Cocoa_MouseTapThread, and fall back to the non-EventTap way of From f8b4cd410bf616083757d1221207434194e11dc8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 30 Sep 2018 19:53:26 -0700 Subject: [PATCH 067/151] Re-enable drag-and-drop events by default --- src/events/SDL_events.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index da6d73b52aa87..25e8ac49c0a5e 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -417,8 +417,10 @@ SDL_StartEventLoop(void) SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); +#if 0 /* Leave these events enabled so apps can respond to items being dragged onto them at startup */ SDL_EventState(SDL_DROPFILE, SDL_DISABLE); SDL_EventState(SDL_DROPTEXT, SDL_DISABLE); +#endif SDL_AtomicSet(&SDL_EventQ.active, 1); From 48f7e7f34de4db74678b5717d4161b4b9a351d11 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 30 Sep 2018 22:43:12 -0700 Subject: [PATCH 068/151] Corrected PS4 controller entry --- src/joystick/controller_type.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h index 51ac20b4e1eb5..c419cb22a205b 100644 --- a/src/joystick/controller_type.h +++ b/src/joystick/controller_type.h @@ -118,7 +118,6 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x11ff, 0x3331 ), k_eControllerType_PS3Controller }, // SRXJ-PH2400 { MAKE_CONTROLLER_ID( 0x20bc, 0x5500 ), k_eControllerType_PS3Controller }, // ShanWan PS3 { MAKE_CONTROLLER_ID( 0x05b8, 0x1004 ), k_eControllerType_PS3Controller }, // From SDL - { MAKE_CONTROLLER_ID( 0x146b, 0x0603 ), k_eControllerType_PS3Controller }, // From SDL { MAKE_CONTROLLER_ID( 0x044f, 0xb315 ), k_eControllerType_PS3Controller }, // Firestorm Dual Analog 3 { MAKE_CONTROLLER_ID( 0x0925, 0x8888 ), k_eControllerType_PS3Controller }, // Actually ps2 -maybe break out later Lakeview Research WiseGroup Ltd, MP-8866 Dual Joypad { MAKE_CONTROLLER_ID( 0x0f0d, 0x004d ), k_eControllerType_PS3Controller }, // Horipad 3 @@ -179,7 +178,7 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x7545, 0x0104 ), k_eControllerType_PS4Controller }, // Armor 3 or Level Up Cobra - At least one variant has gyro { MAKE_CONTROLLER_ID( 0x0c12, 0x0e15 ), k_eControllerType_PS4Controller }, // Game:Pad 4 { MAKE_CONTROLLER_ID( 0x11c0, 0x4001 ), k_eControllerType_PS4Controller }, // "PS4 Fun Controller" added from user log - + { MAKE_CONTROLLER_ID( 0x146b, 0x0603 ), k_eControllerType_PS4Controller }, // NcaconCompact PS4 controller { MAKE_CONTROLLER_ID( 0x1532, 0x1007 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition USB- untested and added for razer { MAKE_CONTROLLER_ID( 0x1532, 0x100A ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition BT - untested and added for razer { MAKE_CONTROLLER_ID( 0x1532, 0x1004 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Ultimate USB - untested and added for razer From 95579f5f19e524ea313b780a97bb28318d7c4f62 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 09:40:58 -0700 Subject: [PATCH 069/151] Fixed bug 4220 - SDL_GL_CONTEXT_DEBUG_FLAG can fail silently on some Android devices --- src/video/SDL_egl.c | 21 +++++++++++++++++++++ src/video/SDL_egl_c.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index c3b43760800f0..78abc030efe33 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -406,6 +406,9 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa } } + _this->egl_data->egl_version_major = egl_version_major; + _this->egl_data->egl_version_minor = egl_version_minor; + if (egl_version_major == 1 && egl_version_minor == 5) { LOAD_FUNC(eglGetPlatformDisplay); } @@ -658,6 +661,24 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) share_context = (EGLContext)SDL_GL_GetCurrentContext(); } +#if SDL_VIDEO_DRIVER_ANDROID + if ((_this->gl_config.flags & SDL_GL_CONTEXT_DEBUG_FLAG) != 0) { + /* If SDL_GL_CONTEXT_DEBUG_FLAG is set but EGL_KHR_debug unsupported, unset. + * This is required because some Android devices like to complain about it + * by "silently" failing, logging a hint which could be easily overlooked: + * E/libEGL (26984): validate_display:255 error 3008 (EGL_BAD_DISPLAY) + * The following explicitly checks for EGL_KHR_debug before EGL 1.5 + */ + int egl_version_major = _this->egl_data->egl_version_major; + int egl_version_minor = _this->egl_data->egl_version_minor; + if (((egl_version_major < 1) || (egl_version_major == 1 && egl_version_minor < 5)) && + !SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_debug")) { + /* SDL profile bits match EGL profile bits. */ + _this->gl_config.flags &= ~SDL_GL_CONTEXT_DEBUG_FLAG; + } + } +#endif + /* Set the context version and other attributes. */ if ((major_version < 3 || (minor_version == 0 && profile_es)) && _this->gl_config.flags == 0 && diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h index 80b13192e2858..d1c41297c3ff4 100644 --- a/src/video/SDL_egl_c.h +++ b/src/video/SDL_egl_c.h @@ -36,6 +36,7 @@ typedef struct SDL_EGL_VideoData EGLConfig egl_config; int egl_swapinterval; int egl_surfacetype; + int egl_version_major, egl_version_minor; EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display); EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplay) (EGLenum platform, From de9f5415b368f03d2ce375a61fd41b3cb19dd5a6 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Mon, 13 Aug 2018 12:52:52 -0400 Subject: [PATCH 070/151] Filter both SIZE_CHANGED and RESIZED on any SIZE_CHANGED --- src/events/SDL_windowevents.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index a62a2ce61be48..1670841092d1d 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -28,26 +28,13 @@ static int SDLCALL -RemovePendingResizedEvents(void * userdata, SDL_Event *event) +RemovePendingSizeChangedAndResizedEvents(void * userdata, SDL_Event *event) { SDL_Event *new_event = (SDL_Event *)userdata; if (event->type == SDL_WINDOWEVENT && - event->window.event == SDL_WINDOWEVENT_RESIZED && - event->window.windowID == new_event->window.windowID) { - /* We're about to post a new size event, drop the old one */ - return 0; - } - return 1; -} - -static int SDLCALL -RemovePendingSizeChangedEvents(void * userdata, SDL_Event *event) -{ - SDL_Event *new_event = (SDL_Event *)userdata; - - if (event->type == SDL_WINDOWEVENT && - event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED && + (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED || + event->window.event == SDL_WINDOWEVENT_RESIZED) && event->window.windowID == new_event->window.windowID) { /* We're about to post a new size event, drop the old one */ return 0; @@ -199,11 +186,8 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, event.window.windowID = window->id; /* Fixes queue overflow with resize events that aren't processed */ - if (windowevent == SDL_WINDOWEVENT_RESIZED) { - SDL_FilterEvents(RemovePendingResizedEvents, &event); - } if (windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) { - SDL_FilterEvents(RemovePendingSizeChangedEvents, &event); + SDL_FilterEvents(RemovePendingSizeChangedAndResizedEvents, &event); } if (windowevent == SDL_WINDOWEVENT_MOVED) { SDL_FilterEvents(RemovePendingMoveEvents, &event); From 0a7faa4ae54c0d4f355e3ee0f86fdcd4852f796a Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 4 May 2018 21:58:39 -0400 Subject: [PATCH 071/151] Fix Linux haptic scaling, add 2.1 FIXME --- include/SDL_haptic.h | 11 +++++++++++ src/haptic/linux/SDL_syshaptic.c | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index cfb91c53139e1..2ea1bfc1602ee 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -117,6 +117,17 @@ extern "C" { #endif /* __cplusplus */ +/* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF). + * + * At the moment the magnitude variables are mixed between signed/unsigned, and + * it is also not made clear that ALL of those variables expect a max of 0x7FFF. + * + * Some platforms may have higher precision than that (Linux FF, Windows XInput) + * so we should fix the inconsistency in favor of higher possible precision, + * adjusting for platforms that use different scales. + * -flibit + */ + /** * \typedef SDL_Haptic * diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 2f6bd4059df05..4e4f8a5f2f5d0 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -801,7 +801,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) dest->u.periodic.waveform = FF_SAW_DOWN; dest->u.periodic.period = CLAMP(periodic->period); - dest->u.periodic.magnitude = periodic->magnitude; + /* Linux expects 0-65535, so multiply by 2 */ + dest->u.periodic.magnitude = CLAMP(periodic->magnitude) * 2; dest->u.periodic.offset = periodic->offset; /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */ dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000; @@ -908,9 +909,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) dest->trigger.button = 0; dest->trigger.interval = 0; - /* Rumble */ - dest->u.rumble.strong_magnitude = leftright->large_magnitude; - dest->u.rumble.weak_magnitude = leftright->small_magnitude; + /* Rumble (Linux expects 0-65535, so multiply by 2) */ + dest->u.rumble.strong_magnitude = CLAMP(leftright->large_magnitude) * 2; + dest->u.rumble.weak_magnitude = CLAMP(leftright->small_magnitude) * 2; break; From b251876126e07891122abde462114d867d957204 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 09:47:10 -0700 Subject: [PATCH 072/151] commit c6b28f46b8116552ec2b38d1d3c8535df28ba7a1 Author: Anthony Pesch Date: Fri May 4 20:21:21 2018 -0400 Added SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag enabling users of SDL_OpenAudioDevice to get the sample size of the actual hardware buffer vs having a stream created to handle the delta --- include/SDL_audio.h | 3 ++- src/audio/SDL_audio.c | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/SDL_audio.h b/include/SDL_audio.h index d6ea689543c05..d3e1bface4d40 100644 --- a/include/SDL_audio.h +++ b/include/SDL_audio.h @@ -140,7 +140,8 @@ typedef Uint16 SDL_AudioFormat; #define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001 #define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002 #define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004 -#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE) +#define SDL_AUDIO_ALLOW_SAMPLES_CHANGE 0x00000008 +#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE) /* @} */ /* @} *//* Audio flags */ diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 23daf002a0790..2f0854dde94ae 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1324,15 +1324,12 @@ open_audio_device(const char *devname, int iscapture, build_stream = SDL_TRUE; } } - - /* !!! FIXME in 2.1: add SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag? - As of 2.0.6, we will build a stream to buffer the difference between - what the app wants to feed and the device wants to eat, so everyone - gets their way. In prior releases, SDL would force the callback to - feed at the rate the device requested, adjusted for resampling. - */ if (device->spec.samples != obtained->samples) { - build_stream = SDL_TRUE; + if (allowed_changes & SDL_AUDIO_ALLOW_SAMPLES_CHANGE) { + obtained->samples = device->spec.samples; + } else { + build_stream = SDL_TRUE; + } } SDL_CalculateAudioSpec(obtained); /* recalc after possible changes. */ From 922623e1b6fe201516f69d20d04ec993d94020c9 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 1 Oct 2018 21:29:11 +0300 Subject: [PATCH 073/151] SDL_blit_N.c (BlitNtoNKeyCopyAlpha): fix -Wshadow warnings by adding _ suffix to the temp Pixel local in the DUFFS_LOOP. SDL_blit.h (ASSEMBLE_RGB): add _ prefix to temp Pixel locals to avoid any possible shadowings. The warnings were like the following: In file included from src/video/SDL_blit_N.c:26:0: src/video/SDL_blit_N.c: In function 'BlitNtoNKeyCopyAlpha': src/video/SDL_blit_N.c:2421:24: warning: declaration of 'Pixel' shadows a previous local [-Wshadow] Uint32 Pixel = ((*src32 & rgbmask) == ckey) ? *dst32 : *src32; ^ src/video/SDL_blit.h:475:21: note: in definition of macro 'DUFFS_LOOP8' case 0: do { pixel_copy_increment; /* fallthrough */ \ ^ src/video/SDL_blit_N.c:2419:13: note: in expansion of macro 'DUFFS_LOOP' DUFFS_LOOP( ^ src/video/SDL_blit_N.c:2399:12: warning: shadowed declaration is here [-Wshadow] Uint32 Pixel; ^ --- src/video/SDL_blit.h | 20 ++++++++++---------- src/video/SDL_blit_N.c | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index ca10534453f6f..6c95aafd050f4 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -126,7 +126,7 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface); b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \ } #define RGB_FROM_RGB565(Pixel, r, g, b) \ - { \ +{ \ r = SDL_expand_byte[3][((Pixel&0xF800)>>11)]; \ g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; \ b = SDL_expand_byte[3][(Pixel&0x001F)]; \ @@ -262,18 +262,18 @@ do { \ { \ switch (bpp) { \ case 1: { \ - Uint8 Pixel; \ + Uint8 _Pixel; \ \ - PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \ - *((Uint8 *)(buf)) = Pixel; \ + PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ + *((Uint8 *)(buf)) = _Pixel; \ } \ break; \ \ case 2: { \ - Uint16 Pixel; \ + Uint16 _Pixel; \ \ - PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \ - *((Uint16 *)(buf)) = Pixel; \ + PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ + *((Uint16 *)(buf)) = _Pixel; \ } \ break; \ \ @@ -291,10 +291,10 @@ do { \ break; \ \ case 4: { \ - Uint32 Pixel; \ + Uint32 _Pixel; \ \ - PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \ - *((Uint32 *)(buf)) = Pixel; \ + PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ + *((Uint32 *)(buf)) = _Pixel; \ } \ break; \ } \ diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 5a7ba9d496a9c..de495163a8db5 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -2418,8 +2418,8 @@ BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) /* *INDENT-OFF* */ DUFFS_LOOP( { - Uint32 Pixel = ((*src32 & rgbmask) == ckey) ? *dst32 : *src32; - *dst32 = Pixel; + Uint32 Pixel_ = ((*src32 & rgbmask) == ckey) ? *dst32 : *src32; + *dst32 = Pixel_; ++src32; ++dst32; }, From 6e35e4214559c8db22e3f45734daa3dada42da1a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 14:43:03 -0700 Subject: [PATCH 074/151] Working on bug 3921 - Add some Fastpath to BlitNtoNKey and BlitNtoNKeyCopyAlpha Sylvain I did various benches. with clang 6.0.0 on linux, and ndk-r16b on android (NDK_TOOLCHAIN_VERSION=clang). - still see a x10 speed factor. - with duff_loops, it does not use vectorisation (but doesn't seem to be a problem). on linux my patch is already at full speed on -O2, whereas the duff_loops need -O3 (200 ms at -03, and 300ms at -02). I realized that on Android, I had a slight variation which fits best. both on linux with -O2 and -O3, and on android with 02/03 and armeabi-v7a/arm64. Here's the patch. --- src/video/SDL_blit_N.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index de495163a8db5..d6ec417fe20df 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -2344,8 +2344,9 @@ BlitNtoNKey(SDL_BlitInfo * info) /* *INDENT-OFF* */ DUFFS_LOOP( { - Uint32 Pixel = (*src32 == ckey) ? *dst32 : *src32; - *dst32 = Pixel; + if (*src32 != ckey) { + *dst32 = *src32; + } ++src32; ++dst32; }, @@ -2418,8 +2419,9 @@ BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) /* *INDENT-OFF* */ DUFFS_LOOP( { - Uint32 Pixel_ = ((*src32 & rgbmask) == ckey) ? *dst32 : *src32; - *dst32 = Pixel_; + if ((*src32 & rgbmask) != ckey) { + *dst32 = *src32; + } ++src32; ++dst32; }, From 679d3553170318ef690a920c7157e029206fcf05 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 14:52:28 -0700 Subject: [PATCH 075/151] Fixed UnsatisfiedLinkError when initializing the HIDDeviceManager in some cases --- .../main/java/org/libsdl/app/HIDDeviceManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 8d29cf3645564..33ddb712059a0 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -80,6 +80,14 @@ public void onReceive(Context context, Intent intent) { public HIDDeviceManager(Context context) { mContext = context; + // Make sure we have the HIDAPI library loaded with the native functions + try { + System.loadLibrary("hidapi"); + } catch (Exception e) { + Log.w(TAG, "Couldn't load hidapi: " + e.toString()); + return; + } + HIDDeviceRegisterCallback(this); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); @@ -180,7 +188,11 @@ UsbManager getUSBManager() { } protected void shutdownUSB() { - mContext.unregisterReceiver(mUsbBroadcast); + try { + mContext.unregisterReceiver(mUsbBroadcast); + } catch (Exception e) { + // We may not have registered, that's okay + } } protected boolean isHIDDeviceUSB(UsbDevice usbDevice) { From ae5317e84452e69ed03750a77a83caca5b3ac3b1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 2 Oct 2018 13:17:31 -0700 Subject: [PATCH 076/151] The Amlogic X96 is a set-top box --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 360176253e28d..c53970f64e43c 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -835,6 +835,9 @@ public static boolean isAndroidTV() { if (Build.MANUFACTURER.equals("MINIX") && Build.MODEL.equals("NEO-U1")) { return true; } + if (Build.MANUFACTURER.equals("Amlogic") && Build.MODEL.equals("X96-W")) { + return true; + } return false; } From 19445561716eb96f7bae6ae7f1c25adc2c8d7794 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 2 Oct 2018 20:51:33 -0700 Subject: [PATCH 077/151] Make sure we don't read and write to HIDAPI at the same time, it's not thread-safe on Windows --- src/joystick/hidapi/SDL_hidapijoystick.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index d37a7ca889f57..13fcec9fc40fd 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -25,6 +25,7 @@ #include "SDL_endian.h" #include "SDL_hints.h" #include "SDL_log.h" +#include "SDL_mutex.h" #include "SDL_thread.h" #include "SDL_timer.h" #include "SDL_joystick.h" @@ -54,6 +55,7 @@ struct joystick_hwdata SDL_HIDAPI_DeviceDriver *driver; void *context; + SDL_mutex *mutex; hid_device *dev; }; @@ -959,6 +961,7 @@ HIDAPI_JoystickOpen(SDL_Joystick * joystick, int device_index) SDL_free(hwdata); return SDL_SetError("Couldn't open HID device %s", device->path); } + hwdata->mutex = SDL_CreateMutex(); if (!device->driver->Init(joystick, hwdata->dev, device->vendor_id, device->product_id, &hwdata->context)) { hid_close(hwdata->dev); @@ -975,7 +978,12 @@ HIDAPI_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint { struct joystick_hwdata *hwdata = joystick->hwdata; SDL_HIDAPI_DeviceDriver *driver = hwdata->driver; - return driver->Rumble(joystick, hwdata->dev, hwdata->context, low_frequency_rumble, high_frequency_rumble, duration_ms); + int result; + + SDL_LockMutex(hwdata->mutex); + result = driver->Rumble(joystick, hwdata->dev, hwdata->context, low_frequency_rumble, high_frequency_rumble, duration_ms); + SDL_UnlockMutex(hwdata->mutex); + return result; } static void @@ -983,7 +991,13 @@ HIDAPI_JoystickUpdate(SDL_Joystick * joystick) { struct joystick_hwdata *hwdata = joystick->hwdata; SDL_HIDAPI_DeviceDriver *driver = hwdata->driver; - if (!driver->Update(joystick, hwdata->dev, hwdata->context)) { + SDL_bool succeeded; + + SDL_LockMutex(hwdata->mutex); + succeeded = driver->Update(joystick, hwdata->dev, hwdata->context); + SDL_UnlockMutex(hwdata->mutex); + + if (!succeeded) { SDL_HIDAPI_Device *device; for (device = SDL_HIDAPI_devices; device; device = device->next) { if (device->instance_id == joystick->instance_id) { @@ -1002,6 +1016,7 @@ HIDAPI_JoystickClose(SDL_Joystick * joystick) driver->Quit(joystick, hwdata->dev, hwdata->context); hid_close(hwdata->dev); + SDL_DestroyMutex(hwdata->mutex); SDL_free(hwdata); joystick->hwdata = NULL; } From 93fb710a46dc7144d003f9a8e01e6c81b93c0c4b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 3 Oct 2018 16:54:24 -0400 Subject: [PATCH 078/151] evdev: Don't initialize struct sigaction with "{ 0 }". It causes warnings on some platforms, depending on the actual definition of sigaction, and since this is static data, it'll be zero'd out anyhow. --- src/core/linux/SDL_evdev_kbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index 4359136d98bcc..00a3a54d619bc 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -198,7 +198,7 @@ static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL; static int kbd_cleanup_sigactions_installed = 0; static int kbd_cleanup_atexit_installed = 0; -static struct sigaction old_sigaction[NSIG] = { 0 }; +static struct sigaction old_sigaction[NSIG]; static int fatal_signals[] = { From b60e5b82fb484a0a985b0762ee50bd35c38aa9d5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 3 Oct 2018 15:48:26 -0700 Subject: [PATCH 079/151] Update documentation to note that this hint works on Android too (thanks Trent!) --- include/SDL_hints.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 3f6653bb98eea..3ee40c41ae28d 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -339,7 +339,7 @@ extern "C" { #define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED" /** - * \brief A variable controlling which orientations are allowed on iOS. + * \brief A variable controlling which orientations are allowed on iOS/Android. * * In some circumstances it is necessary to be able to explicitly control * which UI orientations are allowed. From 41ee51b9a8436908ea485c4d5293c949102fc7c0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 4 Oct 2018 15:23:42 -0700 Subject: [PATCH 080/151] Fixed updating bindings for controllers using the wildcard mappings --- src/joystick/SDL_gamecontroller.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 15a44a84347e1..b2a17acd1054a 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -111,7 +111,6 @@ struct _SDL_GameController SDL_Joystick *joystick; /* underlying joystick device */ int ref_count; - SDL_JoystickGUID guid; const char *name; int num_bindings; SDL_ExtendedGameControllerBind *bindings; @@ -683,11 +682,10 @@ SDL_PrivateGameControllerParseControllerConfigString(SDL_GameController *gamecon /* * Make a new button mapping struct */ -static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping) +static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, const char *pchName, const char *pchMapping) { int i; - gamecontroller->guid = guid; gamecontroller->name = pchName; gamecontroller->num_bindings = 0; SDL_memset(gamecontroller->last_match_axis, 0, gamecontroller->joystick->naxes * sizeof(*gamecontroller->last_match_axis)); @@ -801,14 +799,16 @@ static void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pContro { SDL_GameController *gamecontrollerlist = SDL_gamecontrollers; while (gamecontrollerlist) { - if (!SDL_memcmp(&gamecontrollerlist->guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) { - SDL_Event event; - event.type = SDL_CONTROLLERDEVICEREMAPPED; - event.cdevice.which = gamecontrollerlist->joystick->instance_id; - SDL_PushEvent(&event); - + if (!SDL_memcmp(&gamecontrollerlist->joystick->guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) { /* Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? */ - SDL_PrivateLoadButtonMapping(gamecontrollerlist, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping); + SDL_PrivateLoadButtonMapping(gamecontrollerlist, pControllerMapping->name, pControllerMapping->mapping); + + { + SDL_Event event; + event.type = SDL_CONTROLLERDEVICEREMAPPED; + event.cdevice.which = gamecontrollerlist->joystick->instance_id; + SDL_PushEvent(&event); + } } gamecontrollerlist = gamecontrollerlist->next; @@ -1273,7 +1273,7 @@ SDL_GameControllerMapping(SDL_GameController * gamecontroller) return NULL; } - return SDL_GameControllerMappingForGUID(gamecontroller->guid); + return SDL_GameControllerMappingForGUID(gamecontroller->joystick->guid); } static void @@ -1582,7 +1582,7 @@ SDL_GameControllerOpen(int device_index) } } - SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping); + SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->name, pSupportedController->mapping); /* Add the controller to list */ ++gamecontroller->ref_count; From a0c53668e6a85e59c4a80a3b4e8c95e78cd6e2e5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 4 Oct 2018 16:29:17 -0700 Subject: [PATCH 081/151] Allow SDL to use ReLinker if present. This fixes issues for applications that have a large number of shared libraries For more information, see https://github.com/KeepSafe/ReLinker for ReLinker's repository. --- .../app/HIDDeviceBLESteamController.java | 2 +- .../java/org/libsdl/app/HIDDeviceManager.java | 6 +-- .../app/src/main/java/org/libsdl/app/SDL.java | 47 +++++++++++++++++++ .../main/java/org/libsdl/app/SDLActivity.java | 2 +- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java index bd9de19541991..0ab226957ed63 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java @@ -577,7 +577,7 @@ public int sendFeatureReport(byte[] report) { } // We need to skip the first byte, as that doesn't go over the air - byte[] actual_report = Arrays.copyOfRange(report, 1, report.length - 1); + byte[] actual_report = Arrays.copyOfRange(report, 1, report.length - 1); //Log.v(TAG, "sendFeatureReport " + HexDump.dumpHexString(actual_report)); writeCharacteristic(reportCharacteristic, actual_report); return report.length; diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 33ddb712059a0..ba30d0a01121f 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -80,14 +80,14 @@ public void onReceive(Context context, Intent intent) { public HIDDeviceManager(Context context) { mContext = context; - // Make sure we have the HIDAPI library loaded with the native functions + // Make sure we have the HIDAPI library loaded with the native functions try { - System.loadLibrary("hidapi"); + SDL.loadLibrary("hidapi"); } catch (Exception e) { Log.w(TAG, "Couldn't load hidapi: " + e.toString()); return; } - + HIDDeviceRegisterCallback(this); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); diff --git a/android-project/app/src/main/java/org/libsdl/app/SDL.java b/android-project/app/src/main/java/org/libsdl/app/SDL.java index cfe483094534e..58597c6555f51 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDL.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDL.java @@ -2,6 +2,8 @@ import android.content.Context; +import java.lang.reflect.*; + /** SDL library initialization */ @@ -33,5 +35,50 @@ public static Context getContext() { return mContext; } + public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException { + + if (libraryName == null) { + throw new NullPointerException("No library name provided."); + } + + try { + // Let's see if we have ReLinker available in the project. This is necessary for + // some projects that have huge numbers of local libraries bundled, and thus may + // trip a bug in Android's native library loader which ReLinker works around. (If + // loadLibrary works properly, ReLinker will simply use the normal Android method + // internally.) + // + // To use ReLinker, just add it as a dependency. For more information, see + // https://github.com/KeepSafe/ReLinker for ReLinker's repository. + // + Class relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker"); + Class relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener"); + Class contextClass = mContext.getClassLoader().loadClass("android.content.Context"); + Class stringClass = mContext.getClassLoader().loadClass("java.lang.String"); + + // Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if + // they've changed during updates. + Method forceMethod = relinkClass.getDeclaredMethod("force"); + Object relinkInstance = forceMethod.invoke(null); + Class relinkInstanceClass = relinkInstance.getClass(); + + // Actually load the library! + Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass); + loadMethod.invoke(relinkInstance, mContext, libraryName, null, null); + } + catch (final Exception e) { + // Fall back + try { + System.loadLibrary(libraryName); + } + catch (final UnsatisfiedLinkError ule) { + throw ule; + } + catch (final SecurityException se) { + throw se; + } + } + } + protected static Context mContext; } diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index c53970f64e43c..67cb3a3871682 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -154,7 +154,7 @@ protected String[] getLibraries() { // Load the .so public void loadLibraries() { for (String lib : getLibraries()) { - System.loadLibrary(lib); + SDL.loadLibrary(lib); } } From f01cdcedbcd2eb82af3a2aa4ad989f889657b11a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 5 Oct 2018 01:41:59 -0700 Subject: [PATCH 082/151] It turns out HIDAPI for Xbox controllers doesn't allow background input, so we won't enable it by default on Windows. --- src/joystick/hidapi/SDL_hidapijoystick_c.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h index 34582ea6b07fd..18a448339e280 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h @@ -34,6 +34,8 @@ #ifdef __WINDOWS__ /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */ #undef SDL_JOYSTICK_HIDAPI_XBOXONE +/* It turns out HIDAPI for Xbox controllers doesn't allow background input */ +#undef SDL_JOYSTICK_HIDAPI_XBOX360 #endif #ifdef __MACOSX__ From 367f9b915c7c0a4cae8f1d27f2337430d31e67ab Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 5 Oct 2018 17:24:03 -0400 Subject: [PATCH 083/151] wayland: Fixed missing window sizing events. Fixes Bugzilla #4242. --- src/video/wayland/SDL_waylandwindow.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index aaebea9acb075..aa7299181df77 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -79,19 +79,15 @@ handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_sur } } - if (width == window->w && height == window->h) { - return; - } - - window->w = width; - window->h = height; - WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); - + WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0); region = wl_compositor_create_region(wind->waylandData->compositor); - wl_region_add(region, 0, 0, window->w, window->h); + wl_region_add(region, 0, 0, width, height); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h); + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; } static void @@ -123,7 +119,6 @@ handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, ui wl_region_add(region, 0, 0, window->w, window->h); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h); zxdg_surface_v6_ack_configure(zxdg, serial); } @@ -165,10 +160,7 @@ handle_configure_zxdg_toplevel(void *data, } } - if (width == window->w && height == window->h) { - return; - } - + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); window->w = width; window->h = height; } @@ -202,7 +194,6 @@ handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t wl_region_add(region, 0, 0, window->w, window->h); wl_surface_set_opaque_region(wind->surface, region); wl_region_destroy(region); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h); xdg_surface_ack_configure(xdg, serial); } @@ -248,6 +239,7 @@ handle_configure_xdg_toplevel(void *data, return; } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); window->w = width; window->h = height; } From 3ac9e2aa4e8352ca410f07b18d80a23686cfbaf6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 5 Oct 2018 17:06:05 -0700 Subject: [PATCH 084/151] Fixed bug 4296 - kmsdrm video driver leaks 1 bo in KMSDRM_GLES_SetupCrtc() Icenowy Zheng One front buffer is locked in GLES_SetupCrtc() and overrides the next_bo just locked in KMSDRM_GLES_SwapWindow, then the next_bo gets lost and is not released even when quitting the video. It may leads to problems with GLES drivers that doesn't clean up GBM correctly if there's any bo left (e.g. the Mali Utgard r6p2 blob). In the case of Mali Utgard r6p2 blob, the DRM device file is still hold by the blob, and if you try to SDL_Quit to let another program to run (this is done by EmulationStation), the new program will fail to open DRM device. --- src/video/kmsdrm/SDL_kmsdrmopengles.c | 6 +++--- src/video/kmsdrm/SDL_kmsdrmvideo.c | 4 ++++ src/video/kmsdrm/SDL_kmsdrmvideo.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index 7e8fae725d2b2..fc6304d5f434f 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -54,13 +54,13 @@ KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) { return SDL_FALSE; } - wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs); - if (wdata->next_bo == NULL) { + wdata->crtc_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs); + if (wdata->crtc_bo == NULL) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup"); return SDL_FALSE; } - fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo); + fb_info = KMSDRM_FBFromBO(_this, wdata->crtc_bo); if (fb_info == NULL) { return SDL_FALSE; } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 7855eeddb3d83..973a726027ecc 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -566,6 +566,10 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window * window) if(data) { /* Wait for any pending page flips and unlock buffer */ KMSDRM_WaitPageFlip(_this, data, -1); + if (data->crtc_bo != NULL) { + KMSDRM_gbm_surface_release_buffer(data->gs, data->crtc_bo); + data->crtc_bo = NULL; + } if (data->next_bo != NULL) { KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo); data->next_bo = NULL; diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index 5f00f0ebc1bba..34f0b105a9037 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -62,6 +62,7 @@ typedef struct SDL_WindowData struct gbm_surface *gs; struct gbm_bo *current_bo; struct gbm_bo *next_bo; + struct gbm_bo *crtc_bo; SDL_bool waiting_for_flip; SDL_bool crtc_ready; SDL_bool double_buffer; From 53260b31b529e51d2b9f5a2b4146d9b15b1449dd Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 12:49:23 -0700 Subject: [PATCH 085/151] There are legitimate reasons to skip full cleanup at shutdown, don't assert in that case. --- src/haptic/SDL_haptic.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 48bb818d663d6..f23ba18df2aa8 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -389,9 +389,11 @@ SDL_HapticClose(SDL_Haptic * haptic) void SDL_HapticQuit(void) { + while (SDL_haptics) { + SDL_HapticClose(SDL_haptics); + } + SDL_SYS_HapticQuit(); - SDL_assert(SDL_haptics == NULL); - SDL_haptics = NULL; } /* From 4d771c598a9eaf14ab8fd666ec0030ae092629cf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 12:49:25 -0700 Subject: [PATCH 086/151] Don't flash the navigation bar when destroying a fullscreen SDL window --- src/video/android/SDL_androidwindow.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 037b49079fdbc..cf18e67b43619 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -102,14 +102,17 @@ Android_SetWindowTitle(_THIS, SDL_Window * window) void Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen) { - Android_JNI_SetWindowStyle(fullscreen); - - // Ensure our size matches reality after we've executed the window style change. - // - // It is possible that we've set width and height to the full-size display, but on - // Samsung DeX or Chromebooks or other windowed Android environemtns, our window may - // still not be the full display size. - // + /* If the window is being destroyed don't change visible state */ + if (!window->is_destroying) { + Android_JNI_SetWindowStyle(fullscreen); + } + + /* Ensure our size matches reality after we've executed the window style change. + * + * It is possible that we've set width and height to the full-size display, but on + * Samsung DeX or Chromebooks or other windowed Android environemtns, our window may + * still not be the full display size. + */ if (!SDL_IsDeXMode() && !SDL_IsChromebook()) { return; } From e4c9806f4f40dcfdcc370ee8d4968b551f5898ec Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 12:49:26 -0700 Subject: [PATCH 087/151] Trying to track down NullPointerException in USB input thread --- .../src/main/java/org/libsdl/app/HIDDeviceUSB.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java index 48a87e24d71a3..c9fc58ece2167 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java @@ -276,7 +276,16 @@ public void run() { int packetSize = mInputEndpoint.getMaxPacketSize(); byte[] packet = new byte[packetSize]; while (mRunning) { - int r = mConnection.bulkTransfer(mInputEndpoint, packet, packetSize, 1000); + int r; + try + { + r = mConnection.bulkTransfer(mInputEndpoint, packet, packetSize, 1000); + } + catch (Exception e) + { + Log.v(TAG, "Exception in UsbDeviceConnection bulktransfer: " + e); + break; + } if (r < 0) { // Could be a timeout or an I/O error } From 1e728f5075a2449678de210e527133037c96035f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 12:49:28 -0700 Subject: [PATCH 088/151] Close on shutdown, for consistency --- .../main/java/org/libsdl/app/HIDDeviceBLESteamController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java index 0ab226957ed63..4cf114a299a85 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java @@ -624,6 +624,8 @@ public void setFrozen(boolean frozen) { @Override public void shutdown() { + close(); + BluetoothGatt g = mGatt; if (g != null) { g.disconnect(); From 337cea44110d1223b12a7509613f03caa56d3045 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 12:49:30 -0700 Subject: [PATCH 089/151] Fixed life-cycle issues with two activities sharing HIDDeviceManager --- .../java/org/libsdl/app/HIDDeviceManager.java | 55 +++++++++++++------ .../main/java/org/libsdl/app/SDLActivity.java | 4 +- src/hidapi/android/hid.cpp | 27 ++++++--- 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index ba30d0a01121f..761ecca0d39b9 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -24,7 +24,28 @@ public class HIDDeviceManager { private static final String TAG = "hidapi"; private static final String ACTION_USB_PERMISSION = "org.libsdl.app.USB_PERMISSION"; - protected Context mContext; + private static HIDDeviceManager sManager; + private static int sManagerRefCount = 0; + + public static HIDDeviceManager acquire(Context context) { + if (sManagerRefCount == 0) { + sManager = new HIDDeviceManager(context); + } + ++sManagerRefCount; + return sManager; + } + + public static void release(HIDDeviceManager manager) { + if (manager == sManager) { + --sManagerRefCount; + if (sManagerRefCount == 0) { + sManager.close(); + sManager = null; + } + } + } + + private Context mContext; private HashMap mDevicesById = new HashMap(); private HashMap mUSBDevices = new HashMap(); private HashMap mBluetoothDevices = new HashMap(); @@ -77,7 +98,7 @@ public void onReceive(Context context, Intent intent) { } }; - public HIDDeviceManager(Context context) { + private HIDDeviceManager(Context context) { mContext = context; // Make sure we have the HIDAPI library loaded with the native functions @@ -88,7 +109,7 @@ public HIDDeviceManager(Context context) { return; } - HIDDeviceRegisterCallback(this); + HIDDeviceRegisterCallback(); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); mIsChromebook = mContext.getPackageManager().hasSystemFeature("org.chromium.arc.device_management"); @@ -125,7 +146,7 @@ public int getDeviceIDForIdentifier(String identifier) { return result; } - protected void initializeUSB() { + private void initializeUSB() { mUsbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE); /* @@ -187,7 +208,7 @@ UsbManager getUSBManager() { return mUsbManager; } - protected void shutdownUSB() { + private void shutdownUSB() { try { mContext.unregisterReceiver(mUsbBroadcast); } catch (Exception e) { @@ -195,7 +216,7 @@ protected void shutdownUSB() { } } - protected boolean isHIDDeviceUSB(UsbDevice usbDevice) { + private boolean isHIDDeviceUSB(UsbDevice usbDevice) { for (int interface_number = 0; interface_number < usbDevice.getInterfaceCount(); ++interface_number) { if (isHIDDeviceInterface(usbDevice, interface_number)) { return true; @@ -204,7 +225,7 @@ protected boolean isHIDDeviceUSB(UsbDevice usbDevice) { return false; } - protected boolean isHIDDeviceInterface(UsbDevice usbDevice, int interface_number) { + private boolean isHIDDeviceInterface(UsbDevice usbDevice, int interface_number) { UsbInterface usbInterface = usbDevice.getInterface(interface_number); if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_HID) { return true; @@ -217,7 +238,7 @@ protected boolean isHIDDeviceInterface(UsbDevice usbDevice, int interface_number return false; } - protected boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInterface) { + private boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInterface) { final int XB360_IFACE_SUBCLASS = 93; final int XB360_IFACE_PROTOCOL = 1; // Wired only final int[] SUPPORTED_VENDORS = { @@ -256,7 +277,7 @@ protected boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInter return false; } - protected boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterface) { + private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterface) { final int XB1_IFACE_SUBCLASS = 71; final int XB1_IFACE_PROTOCOL = 208; final int[] SUPPORTED_VENDORS = { @@ -281,13 +302,13 @@ protected boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInter return false; } - protected void handleUsbDeviceAttached(UsbDevice usbDevice) { + private void handleUsbDeviceAttached(UsbDevice usbDevice) { if (isHIDDeviceUSB(usbDevice)) { connectHIDDeviceUSB(usbDevice); } } - protected void handleUsbDeviceDetached(UsbDevice usbDevice) { + private void handleUsbDeviceDetached(UsbDevice usbDevice) { HIDDeviceUSB device = mUSBDevices.get(usbDevice); if (device == null) return; @@ -299,7 +320,7 @@ protected void handleUsbDeviceDetached(UsbDevice usbDevice) { HIDDeviceDisconnected(id); } - protected void handleUsbDevicePermission(UsbDevice usbDevice, boolean permission_granted) { + private void handleUsbDevicePermission(UsbDevice usbDevice, boolean permission_granted) { HIDDeviceUSB device = mUSBDevices.get(usbDevice); if (device == null) return; @@ -311,7 +332,7 @@ protected void handleUsbDevicePermission(UsbDevice usbDevice, boolean permission HIDDeviceOpenResult(device.getId(), opened); } - protected void connectHIDDeviceUSB(UsbDevice usbDevice) { + private void connectHIDDeviceUSB(UsbDevice usbDevice) { synchronized (this) { for (int interface_number = 0; interface_number < usbDevice.getInterfaceCount(); interface_number++) { if (isHIDDeviceInterface(usbDevice, interface_number)) { @@ -326,7 +347,7 @@ protected void connectHIDDeviceUSB(UsbDevice usbDevice) { } } - protected void initializeBluetooth() { + private void initializeBluetooth() { Log.d(TAG, "Initializing Bluetooth"); if (mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) { @@ -377,7 +398,7 @@ protected void initializeBluetooth() { } } - protected void shutdownBluetooth() { + private void shutdownBluetooth() { try { mContext.unregisterReceiver(mBluetoothBroadcast); } catch (Exception e) { @@ -476,7 +497,7 @@ public boolean isSteamController(BluetoothDevice bluetoothDevice) { return bluetoothDevice.getName().equals("SteamController") && ((bluetoothDevice.getType() & BluetoothDevice.DEVICE_TYPE_LE) != 0); } - public void close() { + private void close() { shutdownUSB(); shutdownBluetooth(); synchronized (this) { @@ -623,7 +644,7 @@ public void closeDevice(int deviceID) { /////////////// Native methods ////////////////////////////////////////////////////////////////////////////////////////////////////// - private native void HIDDeviceRegisterCallback(Object callbackHandler); + private native void HIDDeviceRegisterCallback(); private native void HIDDeviceReleaseCallback(); native void HIDDeviceConnected(int deviceID, String identifier, int vendorId, int productId, String serial_number, int release_number, String manufacturer_string, String product_string, int interface_number); diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 67cb3a3871682..c5901abea2ba1 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -250,7 +250,7 @@ public void onClick(DialogInterface dialog,int id) { mClipboardHandler = new SDLClipboardHandler_Old(); } - mHIDDeviceManager = new HIDDeviceManager(this); + mHIDDeviceManager = HIDDeviceManager.acquire(this); // Set up the surface mSurface = new SDLSurface(getApplication()); @@ -380,7 +380,7 @@ protected void onDestroy() { Log.v(TAG, "onDestroy()"); if (mHIDDeviceManager != null) { - mHIDDeviceManager.close(); + HIDDeviceManager.release(mHIDDeviceManager); mHIDDeviceManager = null; } diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index b9d95e9de078f..403a77d7281e3 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -696,7 +696,7 @@ static void ThreadDestroyed(void* value) extern "C" -JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler); +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz); extern "C" JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz); @@ -721,7 +721,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport) extern "C" -JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz, jobject callbackHandler) +JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz ) { LOGV( "HIDDeviceRegisterCallback()"); @@ -735,11 +735,19 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallba __android_log_print(ANDROID_LOG_ERROR, TAG, "Error initializing pthread key"); } - g_HIDDeviceManagerCallbackHandler = env->NewGlobalRef( callbackHandler ); - jclass objClass = env->GetObjectClass( callbackHandler ); + if ( g_HIDDeviceManagerCallbackHandler != NULL ) + { + env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass ); + g_HIDDeviceManagerCallbackClass = NULL; + env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler ); + g_HIDDeviceManagerCallbackHandler = NULL; + } + + g_HIDDeviceManagerCallbackHandler = env->NewGlobalRef( thiz ); + jclass objClass = env->GetObjectClass( thiz ); if ( objClass ) { - g_HIDDeviceManagerCallbackClass = reinterpret_cast< jclass >( env->NewGlobalRef(objClass) ); + g_HIDDeviceManagerCallbackClass = reinterpret_cast< jclass >( env->NewGlobalRef( objClass ) ); g_midHIDDeviceManagerOpen = env->GetMethodID( g_HIDDeviceManagerCallbackClass, "openDevice", "(I)Z" ); if ( !g_midHIDDeviceManagerOpen ) { @@ -773,8 +781,13 @@ extern "C" JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz) { LOGV("HIDDeviceReleaseCallback"); - env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass ); - env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler ); + if ( env->IsSameObject( thiz, g_HIDDeviceManagerCallbackHandler ) ) + { + env->DeleteGlobalRef( g_HIDDeviceManagerCallbackClass ); + g_HIDDeviceManagerCallbackClass = NULL; + env->DeleteGlobalRef( g_HIDDeviceManagerCallbackHandler ); + g_HIDDeviceManagerCallbackHandler = NULL; + } } extern "C" From 62f806ed6c6c4cbe7133ecb1c6efbf206c31cf01 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 8 Oct 2018 19:46:01 -0700 Subject: [PATCH 090/151] This device gets Xinput driver loaded on windows. --- src/joystick/controller_type.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h index c419cb22a205b..51ac20b4e1eb5 100644 --- a/src/joystick/controller_type.h +++ b/src/joystick/controller_type.h @@ -118,6 +118,7 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x11ff, 0x3331 ), k_eControllerType_PS3Controller }, // SRXJ-PH2400 { MAKE_CONTROLLER_ID( 0x20bc, 0x5500 ), k_eControllerType_PS3Controller }, // ShanWan PS3 { MAKE_CONTROLLER_ID( 0x05b8, 0x1004 ), k_eControllerType_PS3Controller }, // From SDL + { MAKE_CONTROLLER_ID( 0x146b, 0x0603 ), k_eControllerType_PS3Controller }, // From SDL { MAKE_CONTROLLER_ID( 0x044f, 0xb315 ), k_eControllerType_PS3Controller }, // Firestorm Dual Analog 3 { MAKE_CONTROLLER_ID( 0x0925, 0x8888 ), k_eControllerType_PS3Controller }, // Actually ps2 -maybe break out later Lakeview Research WiseGroup Ltd, MP-8866 Dual Joypad { MAKE_CONTROLLER_ID( 0x0f0d, 0x004d ), k_eControllerType_PS3Controller }, // Horipad 3 @@ -178,7 +179,7 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x7545, 0x0104 ), k_eControllerType_PS4Controller }, // Armor 3 or Level Up Cobra - At least one variant has gyro { MAKE_CONTROLLER_ID( 0x0c12, 0x0e15 ), k_eControllerType_PS4Controller }, // Game:Pad 4 { MAKE_CONTROLLER_ID( 0x11c0, 0x4001 ), k_eControllerType_PS4Controller }, // "PS4 Fun Controller" added from user log - { MAKE_CONTROLLER_ID( 0x146b, 0x0603 ), k_eControllerType_PS4Controller }, // NcaconCompact PS4 controller + { MAKE_CONTROLLER_ID( 0x1532, 0x1007 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition USB- untested and added for razer { MAKE_CONTROLLER_ID( 0x1532, 0x100A ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Tournament edition BT - untested and added for razer { MAKE_CONTROLLER_ID( 0x1532, 0x1004 ), k_eControllerType_PS4Controller }, // Razer Raiju 2 Ultimate USB - untested and added for razer From 88b3252555f8984adf5a3c9c6b346eaa97966031 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 9 Oct 2018 00:27:55 -0400 Subject: [PATCH 091/151] kmsdrm: find available card if called without index. This work was done by Michael Grzeschik, I just cleaned up the patch a little. Fixes Bugzilla #4241. --- src/video/kmsdrm/SDL_kmsdrmvideo.c | 83 +++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 973a726027ecc..bacbe0c1e04d0 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -41,20 +41,27 @@ #include "SDL_kmsdrmopengles.h" #include "SDL_kmsdrmmouse.h" #include "SDL_kmsdrmdyn.h" +#include +#include +#include -#define KMSDRM_DRI_CARD_0 "/dev/dri/card0" +#define KMSDRM_DRI_PATH "/dev/dri/" static int -KMSDRM_Available(void) +check_modestting(int devindex) { - int available = 0; + SDL_bool available = SDL_FALSE; + char device[512]; + int drm_fd; + + SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_DRI_PATH, devindex); - int drm_fd = open(KMSDRM_DRI_CARD_0, O_RDWR | O_CLOEXEC); + drm_fd = open(device, O_RDWR | O_CLOEXEC); if (drm_fd >= 0) { if (SDL_KMSDRM_LoadSymbols()) { drmModeRes *resources = KMSDRM_drmModeGetResources(drm_fd); if (resources != NULL) { - available = 1; + available = SDL_TRUE; KMSDRM_drmModeFreeResources(resources); } SDL_KMSDRM_UnloadSymbols(); @@ -65,6 +72,66 @@ KMSDRM_Available(void) return available; } +static int get_dricount(void) +{ + int devcount = 0; + struct dirent *res; + struct stat sb; + DIR *folder; + + if (!(stat(KMSDRM_DRI_PATH, &sb) == 0 + && S_ISDIR(sb.st_mode))) { + printf("The path %s cannot be opened or is not available\n", + KMSDRM_DRI_PATH); + return 0; + } + + if (access(KMSDRM_DRI_PATH, F_OK) == -1) { + printf("The path %s cannot be opened\n", + KMSDRM_DRI_PATH); + return 0; + } + + folder = opendir(KMSDRM_DRI_PATH); + if (folder) { + while ((res = readdir(folder))) { + if (res->d_type == DT_CHR) { + devcount++; + } + } + closedir(folder); + } + + return devcount; +} + +static int +get_driindex(void) +{ + const int devcount = get_dricount(); + int i; + + for (i = 0; i < devcount; i++) { + if (check_modestting(i)) { + return i; + } + } + + return -ENOENT; +} + +static int +KMSDRM_Available(void) +{ + int ret = -ENOENT; + + ret = get_driindex(); + if (ret >= 0) + return 1; + + return ret; +} + static void KMSDRM_Destroy(SDL_VideoDevice * device) { @@ -83,7 +150,11 @@ KMSDRM_Create(int devindex) SDL_VideoDevice *device; SDL_VideoData *vdata; - if (devindex < 0 || devindex > 99) { + if (!devindex || (devindex > 99)) { + devindex = get_driindex(); + } + + if (devindex < 0) { SDL_SetError("devindex (%d) must be between 0 and 99.\n", devindex); return NULL; } From 82c2f04e611e33bb886a3ca32d3673fd665091e2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 9 Oct 2018 17:41:40 -0700 Subject: [PATCH 092/151] Fixed bug 4188 - Software renderer SDL_RenderCopyEx blits corrupt image under certain cases duckgrease SDL_RenderCopyEx blits wrong image (in some cases it's bunch of alternating horizontal lines, some cases it's image from the wrong coordinate, and in some cases it's just a bunch of garbled pixels), when the following conditions are met: - Use software renderer. - Enable either horizontal or vertical flip. - source and destination rectangles must have same width and height, and must be smaller than the size of the texture. - source rectangle's X and Y coordinates must be 0. --- src/render/software/SDL_rotate.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index 44762048fa9fe..43811ef908555 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -150,17 +150,17 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */ static void computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy, - int *sincx, int *sincy, int *signx, int *signy) + int *sincx, int *sincy, int *signx, int *signy, SDL_Surface *dst) { int pitch = flipy ? -src->pitch : src->pitch; if (flipx) { bpp = -bpp; } switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break; - case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break; - case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break; - case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break; + case 0: *sincx = bpp; *sincy = pitch - dst->w * *sincx; *signx = *signy = 1; break; + case 1: *sincx = -pitch; *sincy = bpp - *sincx * dst->h; *signx = 1; *signy = -1; break; + case 2: *sincx = -bpp; *sincy = -dst->w * *sincx - pitch; *signx = *signy = -1; break; + case 3: default: *sincx = pitch; *sincy = -*sincx * dst->h - bpp; *signx = -1; *signy = 1; break; } if (flipx) { *signx = -*signx; @@ -175,10 +175,9 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \ Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \ \ - computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \ - if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \ - if (signy < 0) sp += (src->h-1)*src->pitch; \ - \ + computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy, dst); \ + if (signx < 0) sp += (dst->w-1)*sizeof(pixelType); \ + if (signy < 0) sp += (dst->h-1)*src->pitch; \ for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \ if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \ SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \ From 4679f6826d15fa8baf102306fa289b0fceb61334 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 9 Oct 2018 20:12:40 -0700 Subject: [PATCH 093/151] Removed unneeded variable qualifiers --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index c5901abea2ba1..df35787c89a13 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -191,8 +191,8 @@ public static void initialize() { // Setup @Override protected void onCreate(Bundle savedInstanceState) { - Log.v(TAG, "Device: " + android.os.Build.DEVICE); - Log.v(TAG, "Model: " + android.os.Build.MODEL); + Log.v(TAG, "Device: " + Build.DEVICE); + Log.v(TAG, "Model: " + Build.MODEL); Log.v(TAG, "onCreate()"); super.onCreate(savedInstanceState); @@ -1585,8 +1585,7 @@ public void surfaceChanged(SurfaceHolder holder, int nDeviceHeight = height; try { - if ( android.os.Build.VERSION.SDK_INT >= 17 ) - { + if (Build.VERSION.SDK_INT >= 17) { android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics(); mDisplay.getRealMetrics( realMetrics ); nDeviceWidth = realMetrics.widthPixels; From f5a21ebf0c450e57d1f9924188030d4fea5566c4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 9 Oct 2018 20:12:43 -0700 Subject: [PATCH 094/151] Added support for surround sound and float audio on Android --- .../java/org/libsdl/app/SDLAudioManager.java | 308 ++++++++++++++---- src/audio/SDL_audio.c | 5 +- src/audio/android/SDL_androidaudio.c | 25 +- src/core/android/SDL_android.c | 273 +++++++++++----- src/core/android/SDL_android.h | 3 +- 5 files changed, 449 insertions(+), 165 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java index 26baf8220a9bc..bed0eb5c3c77c 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java @@ -1,6 +1,7 @@ package org.libsdl.app; import android.media.*; +import android.os.Build; import android.util.Log; public class SDLAudioManager @@ -17,41 +18,250 @@ public static void initialize() { // Audio - /** - * This method is called by SDL using JNI. - */ - public static int audioOpen(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { - int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; - int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; - int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); + protected static String getAudioFormatString(int audioFormat) { + switch (audioFormat) { + case AudioFormat.ENCODING_PCM_8BIT: + return "8-bit"; + case AudioFormat.ENCODING_PCM_16BIT: + return "16-bit"; + case AudioFormat.ENCODING_PCM_FLOAT: + return "float"; + default: + return Integer.toString(audioFormat); + } + } + + protected static int[] open(boolean isCapture, int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { + int channelConfig; + int sampleSize; + int frameSize; + + Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", requested " + desiredFrames + " frames of " + desiredChannels + " channel " + getAudioFormatString(audioFormat) + " audio at " + sampleRate + " Hz"); + + /* On older devices let's use known good settings */ + if (Build.VERSION.SDK_INT < 21) { + if (desiredChannels > 2) { + desiredChannels = 2; + } + if (sampleRate < 8000) { + sampleRate = 8000; + } else if (sampleRate > 48000) { + sampleRate = 48000; + } + } - Log.v(TAG, "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + (sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); + if (audioFormat == AudioFormat.ENCODING_PCM_FLOAT) { + int minSDKVersion = (isCapture ? 23 : 21); + if (Build.VERSION.SDK_INT < minSDKVersion) { + audioFormat = AudioFormat.ENCODING_PCM_16BIT; + } + } + switch (audioFormat) + { + case AudioFormat.ENCODING_PCM_8BIT: + sampleSize = 1; + break; + case AudioFormat.ENCODING_PCM_16BIT: + sampleSize = 2; + break; + case AudioFormat.ENCODING_PCM_FLOAT: + sampleSize = 4; + break; + default: + Log.v(TAG, "Requested format " + audioFormat + ", getting ENCODING_PCM_16BIT"); + audioFormat = AudioFormat.ENCODING_PCM_16BIT; + sampleSize = 2; + break; + } + + if (isCapture) { + switch (desiredChannels) { + case 1: + channelConfig = AudioFormat.CHANNEL_IN_MONO; + break; + case 2: + channelConfig = AudioFormat.CHANNEL_IN_STEREO; + break; + default: + Log.v(TAG, "Requested " + desiredChannels + " channels, getting stereo"); + desiredChannels = 2; + channelConfig = AudioFormat.CHANNEL_IN_STEREO; + break; + } + } else { + switch (desiredChannels) { + case 1: + channelConfig = AudioFormat.CHANNEL_OUT_MONO; + break; + case 2: + channelConfig = AudioFormat.CHANNEL_OUT_STEREO; + break; + case 3: + channelConfig = AudioFormat.CHANNEL_OUT_STEREO | AudioFormat.CHANNEL_OUT_FRONT_CENTER; + break; + case 4: + channelConfig = AudioFormat.CHANNEL_OUT_QUAD; + break; + case 5: + channelConfig = AudioFormat.CHANNEL_OUT_QUAD | AudioFormat.CHANNEL_OUT_FRONT_CENTER; + break; + case 6: + channelConfig = AudioFormat.CHANNEL_OUT_5POINT1; + break; + case 7: + channelConfig = AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; + break; + case 8: + if (Build.VERSION.SDK_INT >= 23) { + channelConfig = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; + } else { + Log.v(TAG, "Requested " + desiredChannels + " channels, getting 5.1 surround"); + desiredChannels = 6; + channelConfig = AudioFormat.CHANNEL_OUT_5POINT1; + } + break; + default: + Log.v(TAG, "Requested " + desiredChannels + " channels, getting stereo"); + desiredChannels = 2; + channelConfig = AudioFormat.CHANNEL_OUT_STEREO; + break; + } + +/* + Log.v(TAG, "Speaker configuration (and order of channels):"); + + if ((channelConfig & 0x00000004) != 0) { + Log.v(TAG, " CHANNEL_OUT_FRONT_LEFT"); + } + if ((channelConfig & 0x00000008) != 0) { + Log.v(TAG, " CHANNEL_OUT_FRONT_RIGHT"); + } + if ((channelConfig & 0x00000010) != 0) { + Log.v(TAG, " CHANNEL_OUT_FRONT_CENTER"); + } + if ((channelConfig & 0x00000020) != 0) { + Log.v(TAG, " CHANNEL_OUT_LOW_FREQUENCY"); + } + if ((channelConfig & 0x00000040) != 0) { + Log.v(TAG, " CHANNEL_OUT_BACK_LEFT"); + } + if ((channelConfig & 0x00000080) != 0) { + Log.v(TAG, " CHANNEL_OUT_BACK_RIGHT"); + } + if ((channelConfig & 0x00000100) != 0) { + Log.v(TAG, " CHANNEL_OUT_FRONT_LEFT_OF_CENTER"); + } + if ((channelConfig & 0x00000200) != 0) { + Log.v(TAG, " CHANNEL_OUT_FRONT_RIGHT_OF_CENTER"); + } + if ((channelConfig & 0x00000400) != 0) { + Log.v(TAG, " CHANNEL_OUT_BACK_CENTER"); + } + if ((channelConfig & 0x00000800) != 0) { + Log.v(TAG, " CHANNEL_OUT_SIDE_LEFT"); + } + if ((channelConfig & 0x00001000) != 0) { + Log.v(TAG, " CHANNEL_OUT_SIDE_RIGHT"); + } +*/ + } + frameSize = (sampleSize * desiredChannels); // Let the user pick a larger buffer if they really want -- but ye // gods they probably shouldn't, the minimums are horrifyingly high // latency already - desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); + int minBufferSize; + if (isCapture) { + minBufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat); + } else { + minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat); + } + desiredFrames = Math.max(desiredFrames, (minBufferSize + frameSize - 1) / frameSize); - if (mAudioTrack == null) { - mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, - channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); + int[] results = new int[4]; - // Instantiating AudioTrack can "succeed" without an exception and the track may still be invalid - // Ref: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/media/java/android/media/AudioTrack.java - // Ref: http://developer.android.com/reference/android/media/AudioTrack.html#getState() + if (isCapture) { + if (mAudioRecord == null) { + mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, sampleRate, + channelConfig, audioFormat, desiredFrames * frameSize); - if (mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) { - Log.e(TAG, "Failed during initialization of Audio Track"); - mAudioTrack = null; - return -1; + // see notes about AudioTrack state in audioOpen(), above. Probably also applies here. + if (mAudioRecord.getState() != AudioRecord.STATE_INITIALIZED) { + Log.e(TAG, "Failed during initialization of AudioRecord"); + mAudioRecord.release(); + mAudioRecord = null; + return null; + } + + mAudioRecord.startRecording(); + } + + results[0] = mAudioRecord.getSampleRate(); + results[1] = mAudioRecord.getAudioFormat(); + results[2] = mAudioRecord.getChannelCount(); + results[3] = desiredFrames; + + } else { + if (mAudioTrack == null) { + mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); + + // Instantiating AudioTrack can "succeed" without an exception and the track may still be invalid + // Ref: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/media/java/android/media/AudioTrack.java + // Ref: http://developer.android.com/reference/android/media/AudioTrack.html#getState() + if (mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) { + /* Try again, with safer values */ + + Log.e(TAG, "Failed during initialization of Audio Track"); + mAudioTrack.release(); + mAudioTrack = null; + return null; + } + + mAudioTrack.play(); } - mAudioTrack.play(); + results[0] = mAudioTrack.getSampleRate(); + results[1] = mAudioTrack.getAudioFormat(); + results[2] = mAudioTrack.getChannelCount(); + results[3] = desiredFrames; } - Log.v(TAG, "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + (mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer"); + Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", got " + results[3] + " frames of " + results[2] + " channel " + getAudioFormatString(results[1]) + " audio at " + results[0] + " Hz"); + + return results; + } - return 0; + /** + * This method is called by SDL using JNI. + */ + public static int[] audioOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { + return open(false, sampleRate, audioFormat, desiredChannels, desiredFrames); + } + + /** + * This method is called by SDL using JNI. + */ + public static void audioWriteFloatBuffer(float[] buffer) { + if (mAudioTrack == null) { + Log.e(TAG, "Attempted to make audio call with uninitialized audio!"); + return; + } + + for (int i = 0; i < buffer.length;) { + int result = mAudioTrack.write(buffer, i, buffer.length - i, AudioTrack.WRITE_BLOCKING); + if (result > 0) { + i += result; + } else if (result == 0) { + try { + Thread.sleep(1); + } catch(InterruptedException e) { + // Nom nom + } + } else { + Log.w(TAG, "SDL audio: error return from write(float)"); + return; + } + } } /** @@ -63,7 +273,7 @@ public static void audioWriteShortBuffer(short[] buffer) { return; } - for (int i = 0; i < buffer.length; ) { + for (int i = 0; i < buffer.length;) { int result = mAudioTrack.write(buffer, i, buffer.length - i); if (result > 0) { i += result; @@ -109,53 +319,33 @@ public static void audioWriteByteBuffer(byte[] buffer) { /** * This method is called by SDL using JNI. */ - public static int captureOpen(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { - int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; - int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; - int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); - - Log.v(TAG, "SDL capture: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + (sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); - - // Let the user pick a larger buffer if they really want -- but ye - // gods they probably shouldn't, the minimums are horrifyingly high - // latency already - desiredFrames = Math.max(desiredFrames, (AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); - - if (mAudioRecord == null) { - mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, sampleRate, - channelConfig, audioFormat, desiredFrames * frameSize); - - // see notes about AudioTrack state in audioOpen(), above. Probably also applies here. - if (mAudioRecord.getState() != AudioRecord.STATE_INITIALIZED) { - Log.e(TAG, "Failed during initialization of AudioRecord"); - mAudioRecord.release(); - mAudioRecord = null; - return -1; - } - - mAudioRecord.startRecording(); - } - - Log.v(TAG, "SDL capture: got " + ((mAudioRecord.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioRecord.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + (mAudioRecord.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer"); + public static int[] captureOpen(int sampleRate, int audioFormat, int desiredChannels, int desiredFrames) { + return open(true, sampleRate, audioFormat, desiredChannels, desiredFrames); + } - return 0; + /** This method is called by SDL using JNI. */ + public static int captureReadFloatBuffer(float[] buffer, boolean blocking) { + return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); } /** This method is called by SDL using JNI. */ public static int captureReadShortBuffer(short[] buffer, boolean blocking) { - // !!! FIXME: this is available in API Level 23. Until then, we always block. :( - //return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); - return mAudioRecord.read(buffer, 0, buffer.length); + if (Build.VERSION.SDK_INT < 23) { + return mAudioRecord.read(buffer, 0, buffer.length); + } else { + return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); + } } /** This method is called by SDL using JNI. */ public static int captureReadByteBuffer(byte[] buffer, boolean blocking) { - // !!! FIXME: this is available in API Level 23. Until then, we always block. :( - //return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); - return mAudioRecord.read(buffer, 0, buffer.length); + if (Build.VERSION.SDK_INT < 23) { + return mAudioRecord.read(buffer, 0, buffer.length); + } else { + return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); + } } - /** This method is called by SDL using JNI. */ public static void audioClose() { if (mAudioTrack != null) { diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 2f0854dde94ae..aed347b6a4f78 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1130,8 +1130,9 @@ prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared) } case 1: /* Mono */ case 2: /* Stereo */ - case 4: /* surround */ - case 6: /* surround with center and lfe */ + case 4: /* Quadrophonic */ + case 6: /* 5.1 surround */ + case 8: /* 7.1 surround */ break; default: SDL_SetError("Unsupported number of audio channels."); diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 7a2542461d5fb..77a5f0da81b02 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -57,7 +57,9 @@ ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) test_format = SDL_FirstAudioFormat(this->spec.format); while (test_format != 0) { /* no "UNKNOWN" constant */ - if ((test_format == AUDIO_U8) || (test_format == AUDIO_S16LSB)) { + if ((test_format == AUDIO_U8) || + (test_format == AUDIO_S16) || + (test_format == AUDIO_F32)) { this->spec.format = test_format; break; } @@ -69,25 +71,8 @@ ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) return SDL_SetError("No compatible audio format!"); } - if (this->spec.channels > 1) { - this->spec.channels = 2; - } else { - this->spec.channels = 1; - } - - if (this->spec.freq < 8000) { - this->spec.freq = 8000; - } - if (this->spec.freq > 48000) { - this->spec.freq = 48000; - } - - /* TODO: pass in/return a (Java) device ID */ - this->spec.samples = Android_JNI_OpenAudioDevice(iscapture, this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples); - - if (this->spec.samples == 0) { - /* Init failed? */ - return SDL_SetError("Java-side initialization failed!"); + if (Android_JNI_OpenAudioDevice(iscapture, &this->spec) < 0) { + return -1; } SDL_CalculateAudioSpec(&this->spec); diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 6a03bdc5e2ad7..37f328baeacf8 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -61,6 +61,10 @@ #define SDL_JAVA_CONTROLLER_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLControllerManager, function) #define SDL_JAVA_INTERFACE_INPUT_CONNECTION(function) CONCAT1(SDL_JAVA_PREFIX, SDLInputConnection, function) +/* Audio encoding definitions */ +#define ENCODING_PCM_8BIT 3 +#define ENCODING_PCM_16BIT 2 +#define ENCODING_PCM_FLOAT 4 /* Java class SDLActivity */ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)( @@ -248,12 +252,14 @@ static jclass mAudioManagerClass; /* method signatures */ static jmethodID midAudioOpen; -static jmethodID midAudioWriteShortBuffer; static jmethodID midAudioWriteByteBuffer; +static jmethodID midAudioWriteShortBuffer; +static jmethodID midAudioWriteFloatBuffer; static jmethodID midAudioClose; static jmethodID midCaptureOpen; -static jmethodID midCaptureReadShortBuffer; static jmethodID midCaptureReadByteBuffer; +static jmethodID midCaptureReadShortBuffer; +static jmethodID midCaptureReadFloatBuffer; static jmethodID midCaptureClose; /* controller manager */ @@ -397,24 +403,28 @@ JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jc mAudioManagerClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls)); midAudioOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, - "audioOpen", "(IZZI)I"); - midAudioWriteShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, - "audioWriteShortBuffer", "([S)V"); + "audioOpen", "(IIII)[I"); midAudioWriteByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, "audioWriteByteBuffer", "([B)V"); + midAudioWriteShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, + "audioWriteShortBuffer", "([S)V"); + midAudioWriteFloatBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, + "audioWriteFloatBuffer", "([F)V"); midAudioClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, "audioClose", "()V"); midCaptureOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, - "captureOpen", "(IZZI)I"); - midCaptureReadShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, - "captureReadShortBuffer", "([SZ)I"); + "captureOpen", "(IIII)[I"); midCaptureReadByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, "captureReadByteBuffer", "([BZ)I"); + midCaptureReadShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, + "captureReadShortBuffer", "([SZ)I"); + midCaptureReadFloatBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, + "captureReadFloatBuffer", "([FZ)I"); midCaptureClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, "captureClose", "()V"); - if (!midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose || - !midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose) { + if (!midAudioOpen || !midAudioWriteByteBuffer || !midAudioWriteShortBuffer || !midAudioWriteFloatBuffer || !midAudioClose || + !midCaptureOpen || !midCaptureReadByteBuffer || !midCaptureReadShortBuffer || !midCaptureReadFloatBuffer || !midCaptureClose) { __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLAudioManager.java?"); } @@ -1043,17 +1053,19 @@ int Android_JNI_SetupThread(void) /* * Audio support */ -static jboolean audioBuffer16Bit = JNI_FALSE; +static int audioBufferFormat = 0; static jobject audioBuffer = NULL; static void* audioBufferPinned = NULL; -static jboolean captureBuffer16Bit = JNI_FALSE; +static int captureBufferFormat = 0; static jobject captureBuffer = NULL; -int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames) +int Android_JNI_OpenAudioDevice(int iscapture, SDL_AudioSpec *spec) { - jboolean isStereo; + int audioformat; int numBufferFrames; jobject jbufobj = NULL; + jobject result; + int *resultElements; jboolean isCopy; JNIEnv *env = Android_JNI_GetEnv(); @@ -1063,78 +1075,123 @@ int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int } Android_JNI_SetupThread(); - isStereo = channelCount > 1; + switch (spec->format) { + case AUDIO_U8: + audioformat = ENCODING_PCM_8BIT; + break; + case AUDIO_S16: + audioformat = ENCODING_PCM_16BIT; + break; + case AUDIO_F32: + audioformat = ENCODING_PCM_FLOAT; + break; + default: + return SDL_SetError("Unsupported audio format: 0x%x", spec->format); + } if (iscapture) { __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for capture"); - captureBuffer16Bit = is16Bit; - if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) { - /* Error during audio initialization */ - __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioRecord initialization!"); - return 0; - } + result = (*env)->CallStaticObjectMethod(env, mAudioManagerClass, midCaptureOpen, spec->freq, audioformat, spec->channels, spec->samples); } else { __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output"); - audioBuffer16Bit = is16Bit; - if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) { - /* Error during audio initialization */ - __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioTrack initialization!"); - return 0; - } + result = (*env)->CallStaticObjectMethod(env, mAudioManagerClass, midAudioOpen, spec->freq, audioformat, spec->channels, spec->samples); + } + if (result == NULL) { + /* Error during audio initialization, error printed from Java */ + return SDL_SetError("Java-side initialization failed"); } + if ((*env)->GetArrayLength(env, (jintArray)result) != 4) { + return SDL_SetError("Unexpected results from Java, expected 4, got %d", (*env)->GetArrayLength(env, (jintArray)result)); + } + isCopy = JNI_FALSE; + resultElements = (*env)->GetIntArrayElements(env, (jintArray)result, &isCopy); + spec->freq = resultElements[0]; + audioformat = resultElements[1]; + switch (audioformat) { + case ENCODING_PCM_8BIT: + spec->format = AUDIO_U8; + break; + case ENCODING_PCM_16BIT: + spec->format = AUDIO_S16; + break; + case ENCODING_PCM_FLOAT: + spec->format = AUDIO_F32; + break; + default: + return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat); + } + spec->channels = resultElements[2]; + spec->samples = resultElements[3]; + (*env)->ReleaseIntArrayElements(env, (jintArray)result, resultElements, JNI_ABORT); + (*env)->DeleteLocalRef(env, result); + /* Allocating the audio buffer from the Java side and passing it as the return value for audioInit no longer works on * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */ - - if (is16Bit) { - jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (isStereo ? 2 : 1)); - if (audioBufferLocal) { - jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); - (*env)->DeleteLocalRef(env, audioBufferLocal); + switch (audioformat) { + case ENCODING_PCM_8BIT: + { + jbyteArray audioBufferLocal = (*env)->NewByteArray(env, spec->samples * spec->channels); + if (audioBufferLocal) { + jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); + (*env)->DeleteLocalRef(env, audioBufferLocal); + } } - } - else { - jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (isStereo ? 2 : 1)); - if (audioBufferLocal) { - jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); - (*env)->DeleteLocalRef(env, audioBufferLocal); + break; + case ENCODING_PCM_16BIT: + { + jshortArray audioBufferLocal = (*env)->NewShortArray(env, spec->samples * spec->channels); + if (audioBufferLocal) { + jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); + (*env)->DeleteLocalRef(env, audioBufferLocal); + } } + break; + case ENCODING_PCM_FLOAT: + { + jfloatArray audioBufferLocal = (*env)->NewFloatArray(env, spec->samples * spec->channels); + if (audioBufferLocal) { + jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal); + (*env)->DeleteLocalRef(env, audioBufferLocal); + } + } + break; + default: + return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat); } if (jbufobj == NULL) { - __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer!"); - return 0; + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer"); + return SDL_OutOfMemory(); } if (iscapture) { + captureBufferFormat = audioformat; captureBuffer = jbufobj; } else { + audioBufferFormat = audioformat; audioBuffer = jbufobj; } + numBufferFrames = (*env)->GetArrayLength(env, (jarray)jbufobj); - isCopy = JNI_FALSE; + if (!iscapture) { + isCopy = JNI_FALSE; - if (is16Bit) { - if (iscapture) { - numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)captureBuffer); - } else { - audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy); - numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer); - } - } else { - if (iscapture) { - numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer); - } else { + switch (audioformat) { + case ENCODING_PCM_8BIT: audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy); - numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer); + break; + case ENCODING_PCM_16BIT: + audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy); + break; + case ENCODING_PCM_FLOAT: + audioBufferPinned = (*env)->GetFloatArrayElements(env, (jfloatArray)audioBuffer, &isCopy); + break; + default: + return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat); } } - - if (isStereo) { - numBufferFrames /= 2; - } - - return numBufferFrames; + return 0; } int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi) @@ -1178,12 +1235,22 @@ void Android_JNI_WriteAudioBuffer(void) { JNIEnv *mAudioEnv = Android_JNI_GetEnv(); - if (audioBuffer16Bit) { - (*mAudioEnv)->ReleaseShortArrayElements(mAudioEnv, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT); - (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer); - } else { + switch (audioBufferFormat) { + case ENCODING_PCM_8BIT: (*mAudioEnv)->ReleaseByteArrayElements(mAudioEnv, (jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT); (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer); + break; + case ENCODING_PCM_16BIT: + (*mAudioEnv)->ReleaseShortArrayElements(mAudioEnv, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT); + (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer); + break; + case ENCODING_PCM_FLOAT: + (*mAudioEnv)->ReleaseFloatArrayElements(mAudioEnv, (jfloatArray)audioBuffer, (jfloat *)audioBufferPinned, JNI_COMMIT); + (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteFloatBuffer, (jfloatArray)audioBuffer); + break; + default: + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: unhandled audio buffer format"); + break; } /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */ @@ -1195,44 +1262,84 @@ int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen) jboolean isCopy = JNI_FALSE; jint br; - if (captureBuffer16Bit) { - SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == (buflen / 2)); + switch (captureBufferFormat) { + case ENCODING_PCM_8BIT: + SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == buflen); + br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_TRUE); + if (br > 0) { + jbyte *ptr = (*env)->GetByteArrayElements(env, (jbyteArray)captureBuffer, &isCopy); + SDL_memcpy(buffer, ptr, br); + (*env)->ReleaseByteArrayElements(env, (jbyteArray)captureBuffer, (jbyte *)ptr, JNI_ABORT); + } + break; + case ENCODING_PCM_16BIT: + SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == (buflen / sizeof(Sint16))); br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_TRUE); if (br > 0) { jshort *ptr = (*env)->GetShortArrayElements(env, (jshortArray)captureBuffer, &isCopy); - br *= 2; + br *= sizeof(Sint16); SDL_memcpy(buffer, ptr, br); (*env)->ReleaseShortArrayElements(env, (jshortArray)captureBuffer, (jshort *)ptr, JNI_ABORT); } - } else { - SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == buflen); - br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_TRUE); + break; + case ENCODING_PCM_FLOAT: + SDL_assert((*env)->GetArrayLength(env, (jfloatArray)captureBuffer) == (buflen / sizeof(float))); + br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadFloatBuffer, (jfloatArray)captureBuffer, JNI_TRUE); if (br > 0) { - jbyte *ptr = (*env)->GetByteArrayElements(env, (jbyteArray)captureBuffer, &isCopy); + jfloat *ptr = (*env)->GetFloatArrayElements(env, (jfloatArray)captureBuffer, &isCopy); + br *= sizeof(float); SDL_memcpy(buffer, ptr, br); - (*env)->ReleaseByteArrayElements(env, (jbyteArray)captureBuffer, (jbyte *)ptr, JNI_ABORT); + (*env)->ReleaseFloatArrayElements(env, (jfloatArray)captureBuffer, (jfloat *)ptr, JNI_ABORT); } + break; + default: + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: unhandled capture buffer format"); + break; } - - return (int) br; + return br; } void Android_JNI_FlushCapturedAudio(void) { JNIEnv *env = Android_JNI_GetEnv(); #if 0 /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */ - if (captureBuffer16Bit) { - const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer); - while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ } - } else { - const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer); - while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ } + switch (captureBufferFormat) { + case ENCODING_PCM_8BIT: + { + const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer); + while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ } + } + break; + case ENCODING_PCM_16BIT: + { + const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer); + while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ } + } + break; + case ENCODING_PCM_FLOAT: + { + const jint len = (*env)->GetArrayLength(env, (jfloatArray)captureBuffer); + while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadFloatBuffer, (jfloatArray)captureBuffer, JNI_FALSE) == len) { /* spin */ } + } + break; + default: + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: flushing unhandled capture buffer format"); + break; } #else - if (captureBuffer16Bit) { - (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE); - } else { + switch (captureBufferFormat) { + case ENCODING_PCM_8BIT: (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE); + break; + case ENCODING_PCM_16BIT: + (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE); + break; + case ENCODING_PCM_FLOAT: + (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadFloatBuffer, (jfloatArray)captureBuffer, JNI_FALSE); + break; + default: + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: flushing unhandled capture buffer format"); + break; } #endif } diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index bac4fd33ef123..006f5fdb083a6 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -31,6 +31,7 @@ extern "C" { #include #include +#include "SDL_audio.h" #include "SDL_rect.h" /* Interface from the SDL library into the Android Java activity */ @@ -47,7 +48,7 @@ extern ANativeWindow* Android_JNI_GetNativeWindow(void); extern int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi); /* Audio support */ -extern int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames); +extern int Android_JNI_OpenAudioDevice(int iscapture, SDL_AudioSpec *spec); extern void* Android_JNI_GetAudioBuffer(void); extern void Android_JNI_WriteAudioBuffer(void); extern int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen); From 0378529e1e2dda29d6b584e220a85b7439a711fd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 10 Oct 2018 14:55:24 -0400 Subject: [PATCH 095/151] audio: clean_out_device_list() already sets this flag to false for us. --- src/audio/SDL_audio.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index aed347b6a4f78..69781eeaa6fe3 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1003,7 +1003,6 @@ SDL_GetNumAudioDevices(int iscapture) if (!iscapture && current_audio.outputDevicesRemoved) { clean_out_device_list(¤t_audio.outputDevices, ¤t_audio.outputDeviceCount, ¤t_audio.outputDevicesRemoved); - current_audio.outputDevicesRemoved = SDL_FALSE; } retval = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount; From 04cbf132613dbf425f328131150a9492f8efb2fb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 10 Oct 2018 15:20:56 -0400 Subject: [PATCH 096/151] audio: All device names reported by SDL must be unique. This means that if you have two devices named "Soundblaster Pro" in your machine, one will be reported as "Soundblaster Pro" and the other as "Soundblaster Pro (2)". This makes it so you can't into a position where one of your devices can't be opened because another is sitting on the same name. --- src/audio/SDL_audio.c | 60 +++++++++++++++++++++++++++++++++++----- src/audio/SDL_sysaudio.h | 4 ++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 69781eeaa6fe3..f4999f1363b52 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -378,21 +378,57 @@ static int add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount) { int retval = -1; - const size_t size = sizeof (SDL_AudioDeviceItem) + SDL_strlen(name) + 1; - SDL_AudioDeviceItem *item = (SDL_AudioDeviceItem *) SDL_malloc(size); - if (item == NULL) { - return -1; - } + SDL_AudioDeviceItem *item; + const SDL_AudioDeviceItem *i; + int dupenum = 0; SDL_assert(handle != NULL); /* we reserve NULL, audio backends can't use it. */ + SDL_assert(name != NULL); + item = (SDL_AudioDeviceItem *) SDL_malloc(sizeof (SDL_AudioDeviceItem)); + if (!item) { + return SDL_OutOfMemory(); + } + + item->original_name = SDL_strdup(name); + if (!item->original_name) { + SDL_free(item); + return SDL_OutOfMemory(); + } + + item->dupenum = 0; + item->name = item->original_name; item->handle = handle; - SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem)); SDL_LockMutex(current_audio.detectionLock); + + for (i = *devices; i != NULL; i = i->next) { + if (SDL_strcmp(name, i->original_name) == 0) { + dupenum = i->dupenum + 1; + break; /* stop at the highest-numbered dupe. */ + } + } + + if (dupenum) { + const size_t len = SDL_strlen(name) + 16; + char *replacement = (char *) SDL_malloc(len); + if (!replacement) { + SDL_UnlockMutex(current_audio.detectionLock); + SDL_free(item->original_name); + SDL_free(item); + SDL_OutOfMemory(); + return -1; + } + + SDL_snprintf(replacement, len, "%s (%d)", name, dupenum + 1); + item->dupenum = dupenum; + item->name = replacement; + } + item->next = *devices; *devices = item; - retval = (*devCount)++; + retval = (*devCount)++; /* !!! FIXME: this should be an atomic increment */ + SDL_UnlockMutex(current_audio.detectionLock); return retval; @@ -420,6 +456,11 @@ free_device_list(SDL_AudioDeviceItem **devices, int *devCount) if (item->handle != NULL) { current_audio.impl.FreeDeviceHandle(item->handle); } + /* these two pointers are the same if not a duplicate devname */ + if (item->name != item->original_name) { + SDL_free(item->name); + } + SDL_free(item->original_name); SDL_free(item); } *devices = NULL; @@ -977,6 +1018,11 @@ clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *re } else { *devices = next; } + /* these two pointers are the same if not a duplicate devname */ + if (item->name != item->original_name) { + SDL_free(item->name); + } + SDL_free(item->original_name); SDL_free(item); } item = next; diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index f0e1f3dad7bf9..579dea5b40784 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -98,8 +98,10 @@ typedef struct SDL_AudioDriverImpl typedef struct SDL_AudioDeviceItem { void *handle; + char *name; + char *original_name; + int dupenum; struct SDL_AudioDeviceItem *next; - char name[SDL_VARIABLE_LENGTH_ARRAY]; } SDL_AudioDeviceItem; From eff5f65096d406191ba87102b0909aac9fc2a98b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 9 Oct 2018 23:01:43 -0700 Subject: [PATCH 097/151] Implement SuspendScreenSaver for Win32 Creating a full-screen SDL renderer on Windows will keep the screensaver suspended by DirectX, as is default for full-screen DX applications. However, for applications that render in windowed-mode, the screensaver will still kick in, even if SDL_DisableScreenSaver() is called or SDL_HINT_VIDEO_ALLOW_SCREENSAVER is set to 0 (default). Implementing a SuspendScreenSaver() function for Win32 fixes this behavior. --- src/video/windows/SDL_windowsvideo.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 300bd2f36bff1..358ab2356c89e 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -63,6 +63,15 @@ UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const } } +static void WIN_SuspendScreenSaver(_THIS) +{ + if (_this->suspend_screensaver) { + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + } else { + SetThreadExecutionState(ES_CONTINUOUS); + } +} + /* Windows driver bootstrap functions */ @@ -136,6 +145,7 @@ WIN_CreateDevice(int devindex) device->GetDisplayModes = WIN_GetDisplayModes; device->SetDisplayMode = WIN_SetDisplayMode; device->PumpEvents = WIN_PumpEvents; + device->SuspendScreenSaver = WIN_SuspendScreenSaver; device->CreateSDLWindow = WIN_CreateWindow; device->CreateSDLWindowFrom = WIN_CreateWindowFrom; From acb05f50d810cd805c03b867bd8057f56cfcd187 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 11 Oct 2018 16:40:01 -0400 Subject: [PATCH 098/151] thread: make SDL_CreateThreadWithStackSize() a public API. --- include/SDL_hints.h | 4 ++++ include/SDL_thread.h | 34 ++++++++++++++++++++++++++++++- src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 13 ++++++++++++ src/thread/SDL_thread.c | 6 ++++-- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 3ee40c41ae28d..4ee72e97d66db 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -619,6 +619,10 @@ extern "C" { * This is specially useful if you build SDL against a non glibc libc library (such as musl) which * provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses). * Support for this hint is currently available only in the pthread, Windows, and PSP backend. +* +* Instead of this hint, in 2.0.9 and later, you can use +* SDL_CreateThreadWithStackSize(). This hint only works with the classic +* SDL_CreateThread(). */ #define SDL_HINT_THREAD_STACK_SIZE "SDL_THREAD_STACK_SIZE" diff --git a/include/SDL_thread.h b/include/SDL_thread.h index 5d01d5a52c86f..8ccd613c52904 100644 --- a/include/SDL_thread.h +++ b/include/SDL_thread.h @@ -106,14 +106,23 @@ SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); +extern DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), + const char *name, const size_t stacksize, void *data, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread); + + /** * Create a thread. */ #if defined(SDL_CreateThread) && SDL_DYNAMIC_API #undef SDL_CreateThread #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) #else #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) #endif #elif defined(__OS2__) @@ -133,15 +142,30 @@ extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); +extern DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread); #if defined(SDL_CreateThread) && SDL_DYNAMIC_API #undef SDL_CreateThread #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) #else #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) #endif #else +/** + * Create a thread with a default stack size. + * + * This is equivalent to calling: + * SDL_CreateThreadWithStackSize(fn, name, 0, data); + */ +extern DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data); + /** * Create a thread. * @@ -159,9 +183,17 @@ SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, * If a system imposes requirements, SDL will try to munge the string for * it (truncate, etc), but the original string contents will be available * from SDL_GetThreadName(). + * + * The size (in bytes) of the new stack can be specified. Zero means "use + * the system default" which might be wildly different between platforms + * (x86 Linux generally defaults to eight megabytes, an embedded device + * might be a few kilobytes instead). + * + * In SDL 2.1, stacksize will be folded into the original SDL_CreateThread + * function. */ extern DECLSPEC SDL_Thread *SDLCALL -SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data); +SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data); #endif diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 9ef18c5a60df4..22e4d63d99a60 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -697,3 +697,4 @@ #define SDL_IsTablet SDL_IsTablet_REAL #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL #define SDL_HasColorKey SDL_HasColorKey_REAL +#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 02f6170bd9327..cd50c02e995b1 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -739,3 +739,16 @@ SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),) SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return) SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasColorKey,(SDL_Surface *a),(a),return) + +#ifdef SDL_CreateThreadWithStackSize +#undef SDL_CreateThreadWithStackSize +#endif + +#if defined(__WIN32__) && !defined(HAVE_LIBC) +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, pfnSDL_CurrentBeginThread e, pfnSDL_CurrentEndThread f),(a,b,c,d,e,f),return) +#elif defined(__OS2__) +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, pfnSDL_CurrentBeginThread e, pfnSDL_CurrentEndThread f),(a,b,c,d,e,f),return) +#else +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return) +#endif + diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 84b72d5771085..5570adbffad96 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -299,19 +299,21 @@ SDL_RunThread(void *data) #ifdef SDL_CreateThread #undef SDL_CreateThread +#undef SDL_CreateThreadWithStackSize #endif #if SDL_DYNAMIC_API #define SDL_CreateThread SDL_CreateThread_REAL +#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL #endif #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD -static SDL_Thread * +SDL_Thread * SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) #else -static SDL_Thread * +SDL_Thread * SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data) #endif From 0e5a3f6ecfd0581a5febea5fd621254a925fccec Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Fri, 12 Oct 2018 01:03:40 +0300 Subject: [PATCH 099/151] SDL_thread.h: undefine SDL_CreateThreadWithStackSize before redefining. --- include/SDL_thread.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/SDL_thread.h b/include/SDL_thread.h index 8ccd613c52904..554dd0b61d024 100644 --- a/include/SDL_thread.h +++ b/include/SDL_thread.h @@ -119,6 +119,7 @@ SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), #if defined(SDL_CreateThread) && SDL_DYNAMIC_API #undef SDL_CreateThread #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) +#undef SDL_CreateThreadWithStackSize #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) #else #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex) @@ -149,6 +150,7 @@ SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const siz #if defined(SDL_CreateThread) && SDL_DYNAMIC_API #undef SDL_CreateThread #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) +#undef SDL_CreateThreadWithStackSize #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) #else #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread) From 9a98e4b6472aed466ef76a53f1698d2818d0a1ef Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 11 Oct 2018 15:14:48 -0700 Subject: [PATCH 100/151] Allow Android haptics to work when SDL is reinitialized (thanks Rachel!) --- src/haptic/android/SDL_syshaptic.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/haptic/android/SDL_syshaptic.c b/src/haptic/android/SDL_syshaptic.c index 5dd15526b12e6..391b7b5d5bab7 100644 --- a/src/haptic/android/SDL_syshaptic.c +++ b/src/haptic/android/SDL_syshaptic.c @@ -195,6 +195,10 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic) void SDL_SYS_HapticQuit(void) { +/* We don't have any way to scan for joysticks (and their vibrators) at init, so don't wipe the list + * of joysticks here in case this is a reinit. + */ +#if 0 SDL_hapticlist_item *item = NULL; SDL_hapticlist_item *next = NULL; @@ -206,6 +210,7 @@ SDL_SYS_HapticQuit(void) SDL_hapticlist = SDL_hapticlist_tail = NULL; numhaptics = 0; return; +#endif } From d9094421e16594438f248ac73491b7a75224ad77 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 12 Oct 2018 17:55:42 -0300 Subject: [PATCH 101/151] metal: Fix high dpi and resizing on macOS, and clean up iOS code. Fixes bug #4250. --- src/render/metal/SDL_render_metal.m | 15 +++++--- src/video/cocoa/SDL_cocoametalview.h | 8 ++-- src/video/cocoa/SDL_cocoametalview.m | 56 +++++++++++++++------------- src/video/uikit/SDL_uikitmetalview.m | 17 +++++---- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 10c585b206876..1fc0a4f29157e 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -752,11 +752,6 @@ - (void)dealloc static void METAL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) { - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { - METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; - data.mtllayer.drawableSize = CGSizeMake(event->data1, event->data2); - } - if (event->event == SDL_WINDOWEVENT_SHOWN || event->event == SDL_WINDOWEVENT_HIDDEN) { // !!! FIXME: write me @@ -848,12 +843,20 @@ - (void)dealloc mtltexdesc.height = (texture->h + 1) / 2; mtltexdesc.textureType = MTLTextureType2DArray; mtltexdesc.arrayLength = 2; - mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; } else if (nv12) { mtltexdesc.pixelFormat = MTLPixelFormatRG8Unorm; mtltexdesc.width = (texture->w + 1) / 2; mtltexdesc.height = (texture->h + 1) / 2; + } + + if (yuv || nv12) { mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; + if (mtltexture_uv == nil) { +#if !__has_feature(objc_arc) + [mtltexture release]; +#endif + return SDL_SetError("Texture allocation failed"); + } } METAL_TextureData *texturedata = [[METAL_TextureData alloc] init]; diff --git a/src/video/cocoa/SDL_cocoametalview.h b/src/video/cocoa/SDL_cocoametalview.h index c0a582ff4f42b..185d45deb6005 100644 --- a/src/video/cocoa/SDL_cocoametalview.h +++ b/src/video/cocoa/SDL_cocoametalview.h @@ -39,16 +39,16 @@ #define METALVIEW_TAG 255 -@interface SDL_cocoametalview : NSView { - NSInteger _tag; -} +@interface SDL_cocoametalview : NSView - (instancetype)initWithFrame:(NSRect)frame - scale:(CGFloat)scale; + highDPI:(BOOL)highDPI; /* Override superclass tag so this class can set it. */ @property (assign, readonly) NSInteger tag; +@property (nonatomic) BOOL highDPI; + @end SDL_cocoametalview* Cocoa_Mtl_AddMetalView(SDL_Window* window); diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index 8b7a697a4a131..9447fb8c6f56b 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -33,9 +33,6 @@ @implementation SDL_cocoametalview -/* The synthesized getter should be called by super's viewWithTag. */ -@synthesize tag = _tag; - /* Return a Metal-compatible layer. */ + (Class)layerClass { @@ -57,27 +54,48 @@ - (CALayer*)makeBackingLayer } - (instancetype)initWithFrame:(NSRect)frame - scale:(CGFloat)scale + highDPI:(BOOL)highDPI { if ((self = [super initWithFrame:frame])) { - _tag = METALVIEW_TAG; + self.highDPI = highDPI; self.wantsLayer = YES; /* Allow resize. */ self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; - /* Set the desired scale. */ - ((CAMetalLayer *) self.layer).drawableSize = NSSizeToCGSize([self bounds].size); - self.layer.contentsScale = scale; + [self updateDrawableSize]; } return self; } +- (NSInteger)tag +{ + return METALVIEW_TAG; +} + +- (void)updateDrawableSize +{ + CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer; + CGSize size = self.bounds.size; + CGSize backingSize = size; + + if (self.highDPI) { + /* Note: NSHighResolutionCapable must be set to true in the app's + * Info.plist in order for the backing size to be high res. + */ + backingSize = [self convertSizeToBacking:size]; + } + + metalLayer.contentsScale = backingSize.height / size.height; + metalLayer.drawableSize = backingSize; +} + /* Set the size of the metal drawables when the view is resized. */ - (void)resizeWithOldSuperviewSize:(NSSize)oldSize { [super resizeWithOldSuperviewSize:oldSize]; + [self updateDrawableSize]; } @end @@ -87,24 +105,10 @@ - (void)resizeWithOldSuperviewSize:(NSSize)oldSize { SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata; NSView *view = data->nswindow.contentView; - CGFloat scale = 1.0; - - if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { - /* Set the scale to the natural scale factor of the screen - then - * the backing dimensions of the Metal view will match the pixel - * dimensions of the screen rather than the dimensions in points - * yielding high resolution on retine displays. - * - * N.B. In order for backingScaleFactor to be > 1, - * NSHighResolutionCapable must be set to true in the app's Info.plist. - */ - NSWindow* nswindow = data->nswindow; - if ([nswindow.screen respondsToSelector:@selector(backingScaleFactor)]) - scale = data->nswindow.screen.backingScaleFactor; - } - - SDL_cocoametalview *metalview - = [[SDL_cocoametalview alloc] initWithFrame:view.frame scale:scale]; + BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; + SDL_cocoametalview *metalview; + + metalview = [[SDL_cocoametalview alloc] initWithFrame:view.frame highDPI:highDPI]; [view addSubview:metalview]; return metalview; } diff --git a/src/video/uikit/SDL_uikitmetalview.m b/src/video/uikit/SDL_uikitmetalview.m index fd94300d07b9c..436e7425a398e 100644 --- a/src/video/uikit/SDL_uikitmetalview.m +++ b/src/video/uikit/SDL_uikitmetalview.m @@ -49,9 +49,8 @@ - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.tag = METALVIEW_TAG; - /* Set the desired scale. */ - ((CAMetalLayer *) self.layer).drawableSize = self.bounds.size; self.layer.contentsScale = scale; + [self updateDrawableSize]; } return self; @@ -60,14 +59,16 @@ - (instancetype)initWithFrame:(CGRect)frame /* Set the size of the metal drawables when the view is resized. */ - (void)layoutSubviews { - CGSize bounds; - [super layoutSubviews]; + [self updateDrawableSize]; +} - bounds = [self bounds].size; - bounds.width *= self.layer.contentsScale; - bounds.height *= self.layer.contentsScale; - ((CAMetalLayer *) self.layer).drawableSize = bounds; +- (void)updateDrawableSize +{ + CGSize size = self.bounds.size; + size.width *= self.layer.contentsScale; + size.height *= self.layer.contentsScale; + ((CAMetalLayer *)self.layer).drawableSize = size; } @end From d8022d19b4bf1a73b3d17737f68fdd154dbd43c8 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 12 Oct 2018 23:23:52 -0300 Subject: [PATCH 102/151] macOS: Fixed MoltenVK dynamic library loading code. --- src/video/cocoa/SDL_cocoavulkan.m | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m index 2cf55bb5ad692..0e53d219ddd15 100644 --- a/src/video/cocoa/SDL_cocoavulkan.m +++ b/src/video/cocoa/SDL_cocoavulkan.m @@ -58,8 +58,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path) PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; if (_this->vulkan_config.loader_handle) { - SDL_SetError("Vulkan/MoltenVK already loaded"); - return -1; + return SDL_SetError("Vulkan/MoltenVK already loaded"); } /* Load the Vulkan loader library */ @@ -80,6 +79,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path) _this->vulkan_config.loader_handle = DEFAULT_HANDLE; } else { const char** paths; + const char *foundPath = NULL; int numPaths; int i; @@ -92,18 +92,17 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path) paths = defaultPaths; numPaths = SDL_arraysize(defaultPaths); } - - for (i=0; i < numPaths; i++) { - _this->vulkan_config.loader_handle = SDL_LoadObject(paths[i]); - if (_this->vulkan_config.loader_handle) - break; - else - continue; + + for (i = 0; i < numPaths && _this->vulkan_config.loader_handle == NULL; i++) { + foundPath = paths[i]; + _this->vulkan_config.loader_handle = SDL_LoadObject(foundPath); + } + + if (_this->vulkan_config.loader_handle == NULL) { + return SDL_SetError("Failed to load Vulkan/MoltenVK library"); } - if (i == numPaths) - return -1; - SDL_strlcpy(_this->vulkan_config.loader_path, paths[i], + SDL_strlcpy(_this->vulkan_config.loader_path, foundPath, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); From 8c41e2624e49b994dcd1b1fe39be077c4d0bab5b Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 13 Oct 2018 03:36:42 -0300 Subject: [PATCH 103/151] metal: Fix SDL_RenderReadPixels to wait for the GPU to finish rendering to the active texture before reading its pixels. --- src/render/metal/SDL_render_metal.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 1fc0a4f29157e..5b4d8ea27cfb3 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -1351,10 +1351,23 @@ - (void)dealloc METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { @autoreleasepool { + METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; + + /* Make sure we have a valid MTLTexture to read from, and an active command + * buffer we can wait for. */ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad); - // !!! FIXME: this probably needs to commit the current command buffer, and probably waitUntilCompleted - METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; + /* Wait for the current command buffer to finish, so we don't read from the + * texture before the GPU finishes rendering to it. */ + if (data.mtlcmdencoder) { + [data.mtlcmdencoder endEncoding]; + [data.mtlcmdbuffer commit]; + [data.mtlcmdbuffer waitUntilCompleted]; + + data.mtlcmdencoder = nil; + data.mtlcmdbuffer = nil; + } + id mtltexture = data.mtlpassdesc.colorAttachments[0].texture; MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h); @@ -1370,6 +1383,13 @@ - (void)dealloc const Uint32 temp_format = (mtltexture.pixelFormat == MTLPixelFormatBGRA8Unorm) ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_ABGR8888; const int status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch); SDL_free(temp_pixels); + + /* Set up an active command buffer and encoder once we're done. It will use + * the same texture that was active before (even if it's part of the swap + * chain), since we didn't clear that when waiting for the command buffer to + * complete. */ + METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad); + return status; }} From cd63709ed817c4c363a9d6480e7a959bba2fde80 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Sat, 13 Oct 2018 17:18:59 +0100 Subject: [PATCH 104/151] Emscripten: Load eglQueryString and eglGetError This prevents an assertion on context creation failure (calling a null function pointer). --- src/video/emscripten/SDL_emscriptenopengles.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/video/emscripten/SDL_emscriptenopengles.c b/src/video/emscripten/SDL_emscriptenopengles.c index a6609edc0817e..7d8c0057535c5 100644 --- a/src/video/emscripten/SDL_emscriptenopengles.c +++ b/src/video/emscripten/SDL_emscriptenopengles.c @@ -60,7 +60,9 @@ Emscripten_GLES_LoadLibrary(_THIS, const char *path) { LOAD_FUNC(eglWaitNative); LOAD_FUNC(eglWaitGL); LOAD_FUNC(eglBindAPI); - + LOAD_FUNC(eglQueryString); + LOAD_FUNC(eglGetError); + _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!_this->egl_data->egl_display) { return SDL_SetError("Could not get EGL display"); From e2ad654f2e29d4bccc9a4852f40f78997f99f575 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 14 Oct 2018 17:26:10 -0300 Subject: [PATCH 105/151] iOS: Don't ignore the requested alpha bit size when determining whether to use an RGBA8 backbuffer. --- src/video/uikit/SDL_uikitopenglview.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/uikit/SDL_uikitopenglview.m b/src/video/uikit/SDL_uikitopenglview.m index b0628bfdb1824..9024376320c86 100644 --- a/src/video/uikit/SDL_uikitopenglview.m +++ b/src/video/uikit/SDL_uikitopenglview.m @@ -101,7 +101,7 @@ - (instancetype)initWithFrame:(CGRect)frame SDL_SetError("sRGB drawables are not supported."); return nil; } - } else if (rBits >= 8 || gBits >= 8 || bBits >= 8) { + } else if (rBits >= 8 || gBits >= 8 || bBits >= 8 || aBits > 0) { /* if user specifically requests rbg888 or some color format higher than 16bpp */ colorFormat = kEAGLColorFormatRGBA8; colorBufferFormat = GL_RGBA8; From cbacb0f1ea05de098642a56914a982aa0acfffab Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 14 Oct 2018 23:50:50 +0300 Subject: [PATCH 106/151] add missing include. --- src/dynapi/SDL_dynapi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c index 7574cf5f49be5..97bc218462ecc 100644 --- a/src/dynapi/SDL_dynapi.c +++ b/src/dynapi/SDL_dynapi.c @@ -27,6 +27,7 @@ #if defined(__OS2__) #define INCL_DOS #define INCL_DOSERRORS +#include #include #endif From 703361e47dca8b1800b777c3877b1b7785e8cd29 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 14 Oct 2018 23:55:02 +0300 Subject: [PATCH 107/151] SDL_GetPowerInfo_Hardwired is static in SDL_power.c .. therefore, comment out its extern declaration in SDL_syspower.h. --- src/power/SDL_syspower.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/power/SDL_syspower.h b/src/power/SDL_syspower.h index a9bf70cfc6002..afd6268fb1231 100644 --- a/src/power/SDL_syspower.h +++ b/src/power/SDL_syspower.h @@ -40,7 +40,9 @@ SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *); -SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *); + +/* this one is static in SDL_power.c */ +/* SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *);*/ #endif /* SDL_syspower_h_ */ From ee97d4f4c11940a5dd0acb01a7545e10997df17e Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 14 Oct 2018 23:56:56 +0300 Subject: [PATCH 108/151] add a minimal config and makefile to test watcom/os2 builds. --- OWMakefile.os2 | 114 ++++++++++++++++++++++++++ include/SDL_config.h | 4 +- include/SDL_config_os2.h | 169 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 OWMakefile.os2 create mode 100644 include/SDL_config_os2.h diff --git a/OWMakefile.os2 b/OWMakefile.os2 new file mode 100644 index 0000000000000..1bba8c30b6f09 --- /dev/null +++ b/OWMakefile.os2 @@ -0,0 +1,114 @@ +# Open Watcom Makefile to build a minimal OS/2 SDL2.dll + +DLLFILE = SDL2.dll +IMPLIB = SDL2.lib +MAPFILE = SDL2.map +EXPFILE = SDL2.exp +LNKFILE = SDL2.lnk + +INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" +INCPATH+= -Iinclude + +CFLAGS = -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei +# max warnings: +CFLAGS+= -wx +# building dll: +CFLAGS+= -bd +# the include paths : +CFLAGS+= $(INCPATH) +# building SDL itself: +CFLAGS+= -DBUILD_SDL + +# this is so that build doesn't fail with E1112: +#CFLAGS+= -DSDL_POWER_DISABLED +CFLAGS+= -DSDL_POWER_HARDWIRED + +.extensions: +.extensions: .lib .dll .obj .c .asm + +.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; + +SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c +SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c +SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c +SRCS+= SDL_rwops.c SDL_power.c +SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SDL_wave.c +SRCS+= SDL_events.c SDL_quit.c SDL_keyboard.c SDL_mouse.c SDL_windowevents.c & + SDL_clipboardevents.c SDL_dropevents.c SDL_displayevents.c SDL_gesture.c & + SDL_sensor.c SDL_touch.c +SRCS+= SDL_haptic.c SDL_gamecontroller.c SDL_joystick.c +SRCS+= SDL_render.c yuv_rgb.c SDL_yuv.c SDL_yuv_sw.c SDL_blendfillrect.c & + SDL_blendline.c SDL_blendpoint.c SDL_drawline.c SDL_drawpoint.c & + SDL_render_sw.c SDL_rotate.c +SRCS+= SDL_blit.c SDL_blit_0.c SDL_blit_1.c SDL_blit_A.c SDL_blit_auto.c & + SDL_blit_copy.c SDL_blit_N.c SDL_blit_slow.c SDL_fillrect.c SDL_bmp.c & + SDL_pixels.c SDL_rect.c SDL_RLEaccel.c SDL_shape.c SDL_stretch.c & + SDL_surface.c SDL_video.c SDL_clipboard.c SDL_vulkan_utils.c SDL_egl.c + +SRCS+= SDL_syscond.c SDL_sysmutex.c SDL_syssem.c SDL_systhread.c SDL_systls.c +SRCS+= SDL_systimer.c +SRCS+= SDL_sysloadso.c +SRCS+= SDL_sysfilesystem.c +SRCS+= SDL_syshaptic.c SDL_sysjoystick.c +SRCS+= SDL_dummyaudio.c SDL_diskaudio.c +SRCS+= SDL_nullvideo.c SDL_nullframebuffer.c SDL_nullevents.c +SRCS+= SDL_dummysensor.c + +SRCS+= SDL_dynapi.c + +OBJS = $(SRCS:.c=.obj) + +all: $(DLLFILE) $(LIBFILE) .symbolic + +$(DLLFILE): $(OBJS) $(LNKFILE) + wlink @$(LNKFILE) + +$(IMPLIB): $(DLLFILE) + wlib -q -b -n -c -pa -s -t -zld -ii -io $* $(DLLFILE) + +.c.obj: + wcc386 $(CFLAGS) -fo=$^@ $< + +SDL_cpuinfo.obj: SDL_cpuinfo.c + wcc386 $(CFLAGS) -wcd=200 -fo=$^@ $< + +SDL_rwops.obj: SDL_rwops.c + wcc386 $(CFLAGS) -wcd=136 -fo=$^@ $< + +SDL_blendfillrect.obj: SDL_blendfillrect.c + wcc386 $(CFLAGS) -wcd=200 -fo=$^@ $< + +SDL_blendline.obj: SDL_blendline.c + wcc386 $(CFLAGS) -wcd=200 -fo=$^@ $< + +SDL_blendpoint.obj: SDL_blendpoint.c + wcc386 $(CFLAGS) -wcd=200 -fo=$^@ $< + +SDL_RLEaccel.obj: SDL_RLEaccel.c + wcc386 $(CFLAGS) -wcd=201 -fo=$^@ $< + +$(LNKFILE): + @%create $@ + @%append $@ SYSTEM os2v2_dll INITINSTANCE TERMINSTANCE + @%append $@ NAME $(DLLFILE) + @for %i in ($(OBJS)) do @%append $@ FILE %i + @%append $@ OPTION QUIET + @%append $@ OPTION IMPF=$(EXPFILE) + @%append $@ OPTION MAP=$(MAPFILE) + @%append $@ OPTION QUIET + @%append $@ OPTION ELIMINATE + @%append $@ OPTION MANYAUTODATA + @%append $@ OPTION OSNAME='OS/2 and eComStation' + @%append $@ OPTION SHOWDEAD + +clean: .SYMBOLIC + @ echo * Clean: $(LIBNAME) + @if exist *.obj rm *.obj + @if exist *.err rm *.err + @if exist $(LNKFILE) rm $(LNKFILE) + +distclean: .SYMBOLIC clean + @if exist $(MAPFILE) rm $(MAPFILE) + @if exist $(EXPFILE) rm $(EXPFILE) + @if exist $(IMPLIB) rm $(IMPLIB) + @if exist $(DLLFILE) rm $(DLLFILE) diff --git a/include/SDL_config.h b/include/SDL_config.h index 7e0340cdffb52..32f4113ffa09c 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -41,8 +41,10 @@ #include "SDL_config_android.h" #elif defined(__PSP__) #include "SDL_config_psp.h" +#elif defined(__OS2__) +#include "SDL_config_os2.h" #else -/* This is a minimal configuration just to get SDL running on new platforms */ +/* This is a minimal configuration just to get SDL running on new platforms. */ #include "SDL_config_minimal.h" #endif /* platform config */ diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h new file mode 100644 index 0000000000000..eb1d7d44dbcd1 --- /dev/null +++ b/include/SDL_config_os2.h @@ -0,0 +1,169 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_config_os2_h_ +#define SDL_config_os2_h_ +#define SDL_config_h_ + +#include "SDL_platform.h" + +#define SDL_AUDIO_DRIVER_DUMMY 1 +#define SDL_AUDIO_DRIVER_DISK 1 + +#define SDL_JOYSTICK_DISABLED 1 +#define SDL_HAPTIC_DISABLED 1 +/*#undef SDL_JOYSTICK_HIDAPI */ + +#define SDL_SENSOR_DUMMY 1 +#define SDL_VIDEO_DRIVER_DUMMY 1 + +/* Enable OpenGL support */ +/* #undef SDL_VIDEO_OPENGL */ + +/* Enable Vulkan support */ +/* #undef SDL_VIDEO_VULKAN */ + +#define SDL_LOADSO_DISABLED 1 +#define SDL_THREADS_DISABLED 1 +#define SDL_TIMERS_DISABLED 1 +#define SDL_FILESYSTEM_DUMMY 1 + +/* Enable assembly routines */ +#define SDL_ASSEMBLY_ROUTINES 1 + +/* #undef HAVE_LIBSAMPLERATE_H */ + +/* Enable dynamic libsamplerate support */ +/* #undef SDL_LIBSAMPLERATE_DYNAMIC */ + +#define HAVE_LIBC 1 + +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDDEF_H 1 +#define HAVE_MALLOC_H 1 +#define HAVE_MEMORY_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRINGS_H 1 +#define HAVE_WCHAR_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_LIMITS_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_FLOAT_H 1 +#define HAVE_SIGNAL_H 1 + +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#if defined(__WATCOMC__) +#define HAVE__FSEEKI64 1 +#define HAVE__FTELLI64 1 +#endif +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_SETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_WCSLEN 1 +#define HAVE_WCSLCPY 1 +#define HAVE_WCSLCAT 1 +#define HAVE_WCSCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE__STRREV 1 +#define HAVE__STRUPR 1 +#define HAVE__STRLWR 1 +#define HAVE_INDEX 1 +#define HAVE_RINDEX 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_ITOA 1 +#define HAVE__LTOA 1 +#define HAVE__ULTOA 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE__I64TOA 1 +#define HAVE__UI64TOA 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRICMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_SETJMP 1 +#define HAVE_ACOS 1 +/* #undef HAVE_ACOSF */ +#define HAVE_ASIN 1 +/* #undef HAVE_ASINF */ +#define HAVE_ATAN 1 +#define HAVE_ATAN2 1 +/* #undef HAVE_ATAN2F */ +#define HAVE_CEIL 1 +/* #undef HAVE_CEILF */ +/* #undef HAVE_COPYSIGN */ +/* #undef HAVE_COPYSIGNF */ +#define HAVE_COS 1 +/* #undef HAVE_COSF */ +#define HAVE_EXP 1 +/* #undef HAVE_EXPF */ +#define HAVE_FABS 1 +/* #undef HAVE_FABSF */ +#define HAVE_FLOOR 1 +/* #undef HAVE_FLOORF */ +#define HAVE_FMOD 1 +/* #undef HAVE_FMODF */ +#define HAVE_LOG 1 +/* #undef HAVE_LOGF */ +#define HAVE_LOG10 1 +/* #undef HAVE_LOG10F */ +#define HAVE_POW 1 +/* #undef HAVE_POWF */ +#define HAVE_SIN 1 +/* #undef HAVE_SINF */ +/* #undef HAVE_SCALBN */ +/* #undef HAVE_SCALBNF */ +#define HAVE_SQRT 1 +/* #undef HAVE_SQRTF */ +#define HAVE_TAN 1 +/* #undef HAVE_TANF */ + +#endif /* SDL_config_os2_h_ */ From dae4a01361a83ef5f4bf3a83a8ac0229fb6b1336 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 15 Oct 2018 00:46:43 -0400 Subject: [PATCH 109/151] x11: Don't hardcode limit on lines of text in message boxes. Plus other text parsing fixes. Fixes Bugzilla #4306. --- src/video/x11/SDL_x11messagebox.c | 41 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index fe6ab199e0c98..70a472ab4a513 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -44,7 +44,6 @@ #endif #define MAX_BUTTONS 8 /* Maximum number of buttons supported */ -#define MAX_TEXT_LINES 32 /* Maximum number of text lines supported */ #define MIN_BUTTON_WIDTH 64 /* Minimum button width */ #define MIN_DIALOG_WIDTH 200 /* Minimum dialog width */ #define MIN_DIALOG_HEIGHT 100 /* Minimum dialog height */ @@ -101,7 +100,7 @@ typedef struct SDL_MessageBoxDataX11 int xtext, ytext; /* Text position to start drawing at. */ int numlines; /* Count of Text lines. */ int text_height; /* Height for text lines. */ - TextLineData linedata[ MAX_TEXT_LINES ]; + TextLineData *linedata; int *pbuttonid; /* Pointer to user return buttonid value. */ @@ -223,6 +222,18 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess return 0; } +static int +CountLinesOfText(const char *text) +{ + int retval = 0; + while (text && *text) { + const char *lf = SDL_strchr(text, '\n'); + retval++; /* even without an endline, this counts as a line. */ + text = lf ? lf + 1 : NULL; + } + return retval; +} + /* Calculate and initialize text and button locations. */ static int X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data ) @@ -237,29 +248,35 @@ X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data ) /* Go over text and break linefeeds into separate lines. */ if ( messageboxdata->message && messageboxdata->message[ 0 ] ) { const char *text = messageboxdata->message; - TextLineData *plinedata = data->linedata; + const int linecount = CountLinesOfText(text); + TextLineData *plinedata = (TextLineData *) SDL_malloc(sizeof (TextLineData) * linecount); - for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ ) { - int height; - char *lf = SDL_strchr( ( char * )text, '\n' ); + if (!plinedata) { + return SDL_OutOfMemory(); + } - data->numlines++; + data->linedata = plinedata; + data->numlines = linecount; + + for ( i = 0; i < linecount; i++, plinedata++ ) { + const char *lf = SDL_strchr( text, '\n' ); + const int length = lf ? ( lf - text ) : SDL_strlen( text ); + int height; - /* Only grab length up to lf if it exists and isn't the last line. */ - plinedata->length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen( text ); plinedata->text = text; - GetTextWidthHeight( data, text, plinedata->length, &plinedata->width, &height ); + GetTextWidthHeight( data, text, length, &plinedata->width, &height ); /* Text and widths are the largest we've ever seen. */ data->text_height = IntMax( data->text_height, height ); text_width_max = IntMax( text_width_max, plinedata->width ); + plinedata->length = length; if (lf && (lf > text) && (lf[-1] == '\r')) { plinedata->length--; } - text += plinedata->length + 1; + text += length + 1; /* Break if there are no more linefeeds. */ if ( !lf ) @@ -369,6 +386,8 @@ X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data ) X11_XCloseDisplay( data->display ); data->display = NULL; } + + SDL_free(data->linedata); } /* Create and set up our X11 dialog box indow. */ From 7be4fca62cd0e1f7a9ba820afd016f054922d447 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 15 Oct 2018 11:01:00 +0300 Subject: [PATCH 110/151] SDL_power.c: Adjust SDL_POWER_DISABLED ifdefs to avoid zero-size array Otherwise if SDL_POWER_DISABLED is disabled (eg with --disable-power): ... with clang -pedantic: src/power/SDL_power.c:48:50: warning: use of GNU empty initializer extension [-Wgnu-empty-initializer] static SDL_GetPowerInfo_Impl implementations[] = { ^ src/power/SDL_power.c:48:50: warning: zero size arrays are an extension [-Wzero-length-array] 2 warnings generated. ... with gcc -pedantic: src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic] src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic] static SDL_GetPowerInfo_Impl implementations[] = { ^ src/power/SDL_power.c:48:30: error: zero or negative size array ?implementations? static SDL_GetPowerInfo_Impl implementations[] = { ^~~~~~~~~~~~~~~ ... with Watcom: ./src/power/SDL_power.c(85): Error! E1112: Initializer list cannot be empty --- OWMakefile.os2 | 14 +++++--------- include/SDL_config_os2.h | 1 + src/power/SDL_power.c | 12 ++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/OWMakefile.os2 b/OWMakefile.os2 index 1bba8c30b6f09..e709835eb03b7 100644 --- a/OWMakefile.os2 +++ b/OWMakefile.os2 @@ -19,15 +19,6 @@ CFLAGS+= $(INCPATH) # building SDL itself: CFLAGS+= -DBUILD_SDL -# this is so that build doesn't fail with E1112: -#CFLAGS+= -DSDL_POWER_DISABLED -CFLAGS+= -DSDL_POWER_HARDWIRED - -.extensions: -.extensions: .lib .dll .obj .c .asm - -.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; - SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c @@ -58,6 +49,11 @@ SRCS+= SDL_dynapi.c OBJS = $(SRCS:.c=.obj) +.extensions: +.extensions: .lib .dll .obj .c .asm + +.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; + all: $(DLLFILE) $(LIBFILE) .symbolic $(DLLFILE): $(OBJS) $(LNKFILE) diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index eb1d7d44dbcd1..d1e4bb24d60bd 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -28,6 +28,7 @@ #define SDL_AUDIO_DRIVER_DUMMY 1 #define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_POWER_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1 #define SDL_HAPTIC_DISABLED 1 /*#undef SDL_JOYSTICK_HIDAPI */ diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index e09e27ba23844..de77c0951ae9a 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -42,11 +42,8 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent) return SDL_TRUE; } #endif -#endif - static SDL_GetPowerInfo_Impl implementations[] = { -#ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */ SDL_GetPowerInfo_Linux_org_freedesktop_upower, SDL_GetPowerInfo_Linux_sys_class_power_supply, @@ -81,31 +78,34 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_HARDWIRED SDL_GetPowerInfo_Hardwired, #endif -#endif }; +#endif SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent) { +#ifndef SDL_POWER_DISABLED const int total = sizeof(implementations) / sizeof(implementations[0]); - int _seconds, _percent; SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN; int i; +#endif + int _seconds, _percent; /* Make these never NULL for platform-specific implementations. */ if (seconds == NULL) { seconds = &_seconds; } - if (percent == NULL) { percent = &_percent; } +#ifndef SDL_POWER_DISABLED for (i = 0; i < total; i++) { if (implementations[i](&retval, seconds, percent)) { return retval; } } +#endif /* nothing was definitive. */ *seconds = -1; From b0c48dd9dd55b460ab1f6f69604f182f6a7b33e4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Oct 2018 08:29:27 -0700 Subject: [PATCH 111/151] Support vibration magnitude on Android 8.0 (thanks Rachel!) --- .../org/libsdl/app/SDLControllerManager.java | 49 +++++++++++++++++-- src/core/android/SDL_android.c | 6 +-- src/core/android/SDL_android.h | 2 +- src/haptic/android/SDL_syshaptic.c | 7 ++- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index a631c3ed0a6a0..c6a33e8073146 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -1,5 +1,6 @@ package org.libsdl.app; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -77,8 +78,8 @@ public static void pollHapticDevices() { /** * This method is called by SDL using JNI. */ - public static void hapticRun(int device_id, int length) { - mHapticHandler.run(device_id, length); + public static void hapticRun(int device_id, float intensity, int length) { + mHapticHandler.run(device_id, intensity, length); } /** @@ -423,10 +424,50 @@ public SDLHapticHandler() { mHaptics = new ArrayList(); } - public void run(int device_id, int length) { + public void run(int device_id, float intensity, int length) { SDLHaptic haptic = getHaptic(device_id); if (haptic != null) { - haptic.vib.vibrate (length); + + Log.d("SDL", "Rtest: Vibe with intensity " + intensity + " for " + length); + if (intensity == 0.0f) { + stop(device_id); + return; + } + + if (Build.VERSION.SDK_INT >= 26) { + // We have to do this dynamically to avoid issues on earlier SDKs. + // But we want to use the VibrationEffect so we can set amplitude. + + try { + int vibeValue = Math.round(intensity * 255); + + if (vibeValue > 255) { + vibeValue = 255; + } + if (vibeValue < 1) { + stop(device_id); + return; + } + + long longLength = length; + Class vibrationEffectClass = Class.forName("android.os.VibrationEffect"); + Method oneShotMethod = vibrationEffectClass.getMethod("createOneShot", long.class, int.class); + Object effect = oneShotMethod.invoke(null, longLength, vibeValue); + Method vibeEffect = android.os.Vibrator.class.getMethod("vibrate", vibrationEffectClass); + vibeEffect.invoke(haptic.vib, vibrationEffectClass.cast(effect)); + } + catch (Exception e) { + // Fall back to the generic method, which uses DEFAULT_AMPLITUDE, but works even if + // something went horribly wrong with the Android 8.0 APIs. + haptic.vib.vibrate(length); + } + } + else { + // Fall back to the generic method, which uses DEFAULT_AMPLITUDE, but exists + // on earlier SDKs. + + haptic.vib.vibrate (length); + } } } diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 37f328baeacf8..a56575e09deb7 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -445,7 +445,7 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv* mEn midPollHapticDevices = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, "pollHapticDevices", "()V"); midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, - "hapticRun", "(II)V"); + "hapticRun", "(IFI)V"); midHapticStop = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, "hapticStop", "(I)V"); @@ -2005,10 +2005,10 @@ void Android_JNI_PollHapticDevices(void) (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midPollHapticDevices); } -void Android_JNI_HapticRun(int device_id, int length) +void Android_JNI_HapticRun(int device_id, float intensity, int length) { JNIEnv *env = Android_JNI_GetEnv(); - (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticRun, device_id, length); + (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticRun, device_id, intensity, length); } void Android_JNI_HapticStop(int device_id) diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index 006f5fdb083a6..b2ff32ea659dd 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -84,7 +84,7 @@ void Android_JNI_PollInputDevices(void); /* Haptic support */ void Android_JNI_PollHapticDevices(void); -void Android_JNI_HapticRun(int device_id, int length); +void Android_JNI_HapticRun(int device_id, float intensity, int length); void Android_JNI_HapticStop(int device_id); /* Video */ diff --git a/src/haptic/android/SDL_syshaptic.c b/src/haptic/android/SDL_syshaptic.c index 391b7b5d5bab7..7cb289ba581df 100644 --- a/src/haptic/android/SDL_syshaptic.c +++ b/src/haptic/android/SDL_syshaptic.c @@ -235,7 +235,12 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations) { - Android_JNI_HapticRun (((SDL_hapticlist_item *)haptic->hwdata)->device_id, effect->effect.leftright.length); + float large = effect->effect.leftright.large_magnitude / 32767.0f; + float small = effect->effect.leftright.small_magnitude / 32767.0f; + + float total = (large * 0.6f) + (small * 0.4f); + + Android_JNI_HapticRun (((SDL_hapticlist_item *)haptic->hwdata)->device_id, total, effect->effect.leftright.length); return 0; } From 708ad1fd8ddf597868c0313bef8e7114a540ec0b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Oct 2018 14:58:07 -0700 Subject: [PATCH 112/151] Fixed updating the rumble parameters on Linux --- src/joystick/linux/SDL_sysjoystick.c | 38 +++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 795f92b35eb74..d70ee02ea2cad 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -814,26 +814,24 @@ LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint1 { struct input_event event; - if (joystick->hwdata->effect.id < 0) { - if (joystick->hwdata->ff_rumble) { - struct ff_effect *effect = &joystick->hwdata->effect; - - effect->type = FF_RUMBLE; - effect->replay.length = SDL_min(duration_ms, 32767); - effect->u.rumble.strong_magnitude = low_frequency_rumble; - effect->u.rumble.weak_magnitude = high_frequency_rumble; - } else if (joystick->hwdata->ff_sine) { - /* Scale and average the two rumble strengths */ - Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2); - struct ff_effect *effect = &joystick->hwdata->effect; - - effect->type = FF_PERIODIC; - effect->replay.length = SDL_min(duration_ms, 32767); - effect->u.periodic.waveform = FF_SINE; - effect->u.periodic.magnitude = magnitude; - } else { - return SDL_Unsupported(); - } + if (joystick->hwdata->ff_rumble) { + struct ff_effect *effect = &joystick->hwdata->effect; + + effect->type = FF_RUMBLE; + effect->replay.length = SDL_min(duration_ms, 32767); + effect->u.rumble.strong_magnitude = low_frequency_rumble; + effect->u.rumble.weak_magnitude = high_frequency_rumble; + } else if (joystick->hwdata->ff_sine) { + /* Scale and average the two rumble strengths */ + Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2); + struct ff_effect *effect = &joystick->hwdata->effect; + + effect->type = FF_PERIODIC; + effect->replay.length = SDL_min(duration_ms, 32767); + effect->u.periodic.waveform = FF_SINE; + effect->u.periodic.magnitude = magnitude; + } else { + return SDL_Unsupported(); } if (ioctl(joystick->hwdata->fd, EVIOCSFF, &joystick->hwdata->effect) < 0) { From 3e3ce6e95cfbebeae030f99e1e570dfca0c31b68 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Oct 2018 15:00:43 -0700 Subject: [PATCH 113/151] Fixed bug 4318 - Android move Haptic code to API26 class Sylvain - Create SDLHapticHandler_API26 - No need of reflection since SDL2 compile with Android 26 as a min requirement. - remove spaces --- .../org/libsdl/app/SDLControllerManager.java | 102 +++++++++--------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index c6a33e8073146..782a92edef4b3 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -1,6 +1,5 @@ package org.libsdl.app; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -12,7 +11,7 @@ import android.util.Log; -public class SDLControllerManager +public class SDLControllerManager { public static native int nativeSetupJNI(); @@ -53,7 +52,12 @@ public static void setup() { } else { mJoystickHandler = new SDLJoystickHandler(); } - mHapticHandler = new SDLHapticHandler(); + + if (Build.VERSION.SDK_INT >= 26) { + mHapticHandler = new SDLHapticHandler_API26(); + } else { + mHapticHandler = new SDLHapticHandler(); + } } // Joystick glue code, just a series of stubs that redirect to the SDLJoystickHandler instance @@ -410,6 +414,38 @@ public int getButtonMask(InputDevice joystickDevice) { } } +class SDLHapticHandler_API26 extends SDLHapticHandler { + @Override + public void run(int device_id, float intensity, int length) { + SDLHaptic haptic = getHaptic(device_id); + if (haptic != null) { + Log.d("SDL", "Rtest: Vibe with intensity " + intensity + " for " + length); + if (intensity == 0.0f) { + stop(device_id); + return; + } + + int vibeValue = Math.round(intensity * 255); + + if (vibeValue > 255) { + vibeValue = 255; + } + if (vibeValue < 1) { + stop(device_id); + return; + } + try { + haptic.vib.vibrate(VibrationEffect.createOneShot(length, vibeValue)); + } + catch (Exception e) { + // Fall back to the generic method, which uses DEFAULT_AMPLITUDE, but works even if + // something went horribly wrong with the Android 8.0 APIs. + haptic.vib.vibrate(length); + } + } + } +} + class SDLHapticHandler { class SDLHaptic { @@ -419,7 +455,7 @@ class SDLHaptic { } private ArrayList mHaptics; - + public SDLHapticHandler() { mHaptics = new ArrayList(); } @@ -427,47 +463,7 @@ public SDLHapticHandler() { public void run(int device_id, float intensity, int length) { SDLHaptic haptic = getHaptic(device_id); if (haptic != null) { - - Log.d("SDL", "Rtest: Vibe with intensity " + intensity + " for " + length); - if (intensity == 0.0f) { - stop(device_id); - return; - } - - if (Build.VERSION.SDK_INT >= 26) { - // We have to do this dynamically to avoid issues on earlier SDKs. - // But we want to use the VibrationEffect so we can set amplitude. - - try { - int vibeValue = Math.round(intensity * 255); - - if (vibeValue > 255) { - vibeValue = 255; - } - if (vibeValue < 1) { - stop(device_id); - return; - } - - long longLength = length; - Class vibrationEffectClass = Class.forName("android.os.VibrationEffect"); - Method oneShotMethod = vibrationEffectClass.getMethod("createOneShot", long.class, int.class); - Object effect = oneShotMethod.invoke(null, longLength, vibeValue); - Method vibeEffect = android.os.Vibrator.class.getMethod("vibrate", vibrationEffectClass); - vibeEffect.invoke(haptic.vib, vibrationEffectClass.cast(effect)); - } - catch (Exception e) { - // Fall back to the generic method, which uses DEFAULT_AMPLITUDE, but works even if - // something went horribly wrong with the Android 8.0 APIs. - haptic.vib.vibrate(length); - } - } - else { - // Fall back to the generic method, which uses DEFAULT_AMPLITUDE, but exists - // on earlier SDKs. - - haptic.vib.vibrate (length); - } + haptic.vib.vibrate(length); } } @@ -479,7 +475,7 @@ public void stop(int device_id) { } public void pollHapticDevices() { - + final int deviceId_VIBRATOR_SERVICE = 999999; boolean hasVibratorService = false; @@ -523,7 +519,7 @@ public void pollHapticDevices() { haptic = new SDLHaptic(); haptic.device_id = deviceId_VIBRATOR_SERVICE; haptic.name = "VIBRATOR_SERVICE"; - haptic.vib = vib; + haptic.vib = vib; mHaptics.add(haptic); SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name); } @@ -565,7 +561,7 @@ protected SDLHaptic getHaptic(int device_id) { } } return null; - } + } } class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener { @@ -655,7 +651,7 @@ public boolean onGenericMotion(View v, MotionEvent event) { case InputDevice.SOURCE_GAMEPAD: case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); - + case InputDevice.SOURCE_MOUSE: if (!SDLActivity.mSeparateMouseAndTouch) { break; @@ -746,7 +742,7 @@ public boolean onGenericMotion(View v, MotionEvent event) { case InputDevice.SOURCE_GAMEPAD: case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); - + case InputDevice.SOURCE_MOUSE: case 12290: // DeX desktop mouse cursor is a separate non-standard input type. if (!SDLActivity.mSeparateMouseAndTouch) { @@ -820,12 +816,12 @@ public boolean setRelativeMouseEnabled(boolean enabled) { SDLActivity.getContentView().requestPointerCapture(); } else { - SDLActivity.getContentView().releasePointerCapture(); + SDLActivity.getContentView().releasePointerCapture(); } mRelativeModeEnabled = enabled; return true; } - else + else { return false; } @@ -850,4 +846,4 @@ public float getEventY(MotionEvent event) { // Relative mouse in capture mode will only have relative for X/Y return event.getY(0); } -} \ No newline at end of file +} From 4db5e872aab0c8338c29b2fb8d3d0e8941983769 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 18 Oct 2018 11:58:00 +0300 Subject: [PATCH 114/151] use less ancient versions of autofoo scripts --- build-scripts/install-sh | 538 +++++++++++++++++++++++++----------- build-scripts/mkinstalldirs | 185 +++++++++---- 2 files changed, 495 insertions(+), 228 deletions(-) diff --git a/build-scripts/install-sh b/build-scripts/install-sh index 1a8353401c422..377bb8687ffe1 100755 --- a/build-scripts/install-sh +++ b/build-scripts/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2005-02-02.21 +scriptversion=2011-11-20.07; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -35,42 +35,72 @@ scriptversion=2005-02-02.21 # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it +# 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. +# from scratch. + +nl=' +' +IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" +doit=${DOITPROG-} +if test -z "$doit"; then + doit_exec=exec +else + doit_exec=$doit +fi -# put in absolute paths if you don't have them in your path; or use env. vars. +# Put in absolute file names if you don't have them in your path; +# or use environment vars. + +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} + +posix_glob='?' +initialize_posix_glob=' + test "$posix_glob" != "?" || { + if (set -f) 2>/dev/null; then + posix_glob= + else + posix_glob=: + fi + } +' -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" +posix_mkdir= + +# Desired mode of installed file. +mode=0755 -chmodcmd="$chmodprog 0755" -chowncmd= chgrpcmd= -stripcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog rmcmd="$rmprog -f" -mvcmd="$mvprog" +stripcmd= + src= dst= dir_arg= -dstarg= +dst_arg= + +copy_on_change=false no_target_directory= -usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... @@ -80,108 +110,148 @@ In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --c (ignored) --d create directories instead of installing files. --g GROUP $chgrpprog installed files to GROUP. --m MODE $chmodprog installed files to MODE. --o USER $chownprog installed files to USER. --s $stripprog installed files. --t DIRECTORY install into DIRECTORY. --T report an error if DSTFILE is a directory. ---help display this help and exit. ---version display version info and exit. + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve the last data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -s $stripprog installed files. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. Environment variables override the default commands: - CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG " -while test -n "$1"; do +while test $# -ne 0; do case $1 in - -c) shift - continue;; + -c) ;; + + -C) copy_on_change=true;; - -d) dir_arg=true - shift - continue;; + -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; + shift;; --help) echo "$usage"; exit $?;; - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; + -m) mode=$2 + case $mode in + *' '* | *' '* | *' +'* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; -o) chowncmd="$chownprog $2" - shift - shift - continue;; + shift;; - -s) stripcmd=$stripprog - shift - continue;; + -s) stripcmd=$stripprog;; - -t) dstarg=$2 - shift - shift - continue;; + -t) dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; - -T) no_target_directory=true - shift - continue;; + -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; - *) # When -d is used, all remaining arguments are directories to create. - # When -t is used, the destination is already specified. - test -n "$dir_arg$dstarg" && break - # Otherwise, the last argument is the destination. Remove it from $@. - for arg - do - if test -n "$dstarg"; then - # $@ is not empty: it contains at least $arg. - set fnord "$@" "$dstarg" - shift # fnord - fi - shift # arg - dstarg=$arg - done + --) shift break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; esac + shift done -if test -z "$1"; then +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + done +fi + +if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi - # It's OK to call `install-sh -d' without argument. + # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 + + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; + + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac +fi + for src do - # Protect names starting with `-'. + # Protect names problematic for 'test' and other utilities. case $src in - -*) src=./$src ;; + -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src - src= - - if test -d "$dst"; then - mkdircmd=: - chmodcmd= - else - mkdircmd=$mkdirprog - fi + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? else + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. @@ -190,71 +260,194 @@ do exit 1 fi - if test -z "$dstarg"; then + if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi - - dst=$dstarg - # Protect names starting with `-'. - case $dst in - -*) dst=./$dst ;; - esac + dst=$dst_arg # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then - echo "$0: $dstarg: Is a directory" >&2 + echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi - dst=$dst/`basename "$src"` + dstdir=$dst + dst=$dstdir/`basename "$src"` + dstdir_status=0 + else + # Prefer dirname, but fall back on a substitute if dirname fails. + dstdir=` + (dirname "$dst") 2>/dev/null || + expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$dst" : 'X\(//\)[^/]' \| \ + X"$dst" : 'X\(//\)$' \| \ + X"$dst" : 'X\(/\)' \| . 2>/dev/null || + echo X"$dst" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q' + ` + + test -d "$dstdir" + dstdir_status=$? fi fi - # This sed command emulates the dirname command. - dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'` + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; + esac - # Make sure that the destination directory exists. + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else - # Skip lots of stat calls in the usual case. - if test ! -d "$dstdir"; then - defaultIFS=' - ' - IFS="${IFS-$defaultIFS}" + # The umask is ridiculous, or mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. - oIFS=$IFS - # Some sh's can't handle IFS=/ for some reason. - IFS='%' - set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` - shift - IFS=$oIFS + case $dstdir in + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; + esac - pathcomp= + eval "$initialize_posix_glob" - while test $# -ne 0 ; do - pathcomp=$pathcomp$1 + oIFS=$IFS + IFS=/ + $posix_glob set -f + set fnord $dstdir shift - if test ! -d "$pathcomp"; then - $mkdirprog "$pathcomp" - # mkdir can fail with a `File exist' error in case several - # install-sh are creating the directory concurrently. This - # is OK. - test -d "$pathcomp" || exit + $posix_glob set +f + IFS=$oIFS + + prefixes= + + for d + do + test X"$d" = X && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done + + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true fi - pathcomp=$pathcomp/ - done + fi fi if test -n "$dir_arg"; then - $doit $mkdircmd "$dst" \ - && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } - + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else - dstfile=`basename "$dst"` # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ @@ -262,10 +455,9 @@ do # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 - trap '(exit $?); exit' 1 2 13 15 # Copy the file name to the temp name. - $doit $cpprog "$src" "$dsttmp" && + (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # @@ -273,51 +465,63 @@ do # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # - { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && - - # Now rename the file to the real destination. - { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ - || { - # The rename failed, perhaps because mv can't rename something else - # to itself, or perhaps because mv is so ancient that it does not - # support -f. - - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - if test -f "$dstdir/$dstfile"; then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ - || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ - || { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit 1 - } - else - : - fi - } && - - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - } - } - fi || { (exit 1); exit 1; } + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + + eval "$initialize_posix_glob" && + $posix_glob set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + $posix_glob set +f && + + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi done -# The final little trick to "correctly" pass the exit status to the exit trap. -{ - (exit 0); exit 0 -} - # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" # End: diff --git a/build-scripts/mkinstalldirs b/build-scripts/mkinstalldirs index 8ab885ec92d9e..55d537f872ccd 100755 --- a/build-scripts/mkinstalldirs +++ b/build-scripts/mkinstalldirs @@ -1,29 +1,59 @@ #! /bin/sh # mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain +scriptversion=2009-04-28.21; # UTC + +# Original author: Noah Friedman +# Created: 1993-05-16 +# Public domain. +# +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +nl=' +' +IFS=" "" $nl" errstatus=0 -dirmode="" +dirmode= usage="\ -Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." +Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... + +Create each directory DIR (with mode MODE, if specified), including all +leading file name components. + +Report bugs to ." # process command line arguments while test $# -gt 0 ; do - case "${1}" in - -h | --help | --h* ) # -h for help - echo "${usage}" 1>&2; exit 0 ;; - -m ) # -m PERM arg - shift - test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } - dirmode="${1}" - shift ;; - -- ) shift; break ;; # stop option processing - -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option - * ) break ;; # first non-opt arg - esac + case $1 in + -h | --help | --h*) # -h for help + echo "$usage" + exit $? + ;; + -m) # -m PERM arg + shift + test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } + dirmode=$1 + shift + ;; + --version) + echo "$0 $scriptversion" + exit $? + ;; + --) # stop option processing + shift + break + ;; + -*) # unknown option + echo "$usage" 1>&2 + exit 1 + ;; + *) # first non-opt arg + break + ;; + esac done for file @@ -36,64 +66,97 @@ do done case $# in -0) exit 0 ;; + 0) exit 0 ;; esac +# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and +# mkdir -p a/c at the same time, both will detect that a is missing, +# one will create a, then the other will try to create a and die with +# a "File exists" error. This is a problem when calling mkinstalldirs +# from a parallel make. We use --version in the probe to restrict +# ourselves to GNU mkdir, which is thread-safe. case $dirmode in -'') - if mkdir -p -- . 2>/dev/null; then - echo "mkdir -p -- $*" - exec mkdir -p -- "$@" - fi ;; -*) - if mkdir -m "$dirmode" -p -- . 2>/dev/null; then - echo "mkdir -m $dirmode -p -- $*" - exec mkdir -m "$dirmode" -p -- "$@" - fi ;; + '') + if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + else + # On NextStep and OpenStep, the 'mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because '.' already + # exists. + test -d ./-p && rmdir ./-p + test -d ./--version && rmdir ./--version + fi + ;; + *) + if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && + test ! -d ./--version; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + else + # Clean up after NextStep and OpenStep mkdir. + for d in ./-m ./-p ./--version "./$dirmode"; + do + test -d $d && rmdir $d + done + fi + ;; esac for file do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - else - if test ! -z "$dirmode"; then - echo "chmod $dirmode $pathcomp" - - lasterr="" - chmod "$dirmode" "$pathcomp" || lasterr=$? - - if test ! -z "$lasterr"; then - errstatus=$lasterr - fi + case $file in + /*) pathcomp=/ ;; + *) pathcomp= ;; + esac + oIFS=$IFS + IFS=/ + set fnord $file + shift + IFS=$oIFS + + for d + do + test "x$d" = x && continue + + pathcomp=$pathcomp$d + case $pathcomp in + -*) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + lasterr= + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr fi fi - fi + fi + fi - pathcomp="$pathcomp/" - done + pathcomp=$pathcomp/ + done done exit $errstatus # Local Variables: # mode: shell-script -# sh-indentation: 3 +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" # End: -# mkinstalldirs ends here From eac3fd28d84b5c8ff6e44de35e33fc53ad231601 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 18 Oct 2018 11:59:48 -0400 Subject: [PATCH 115/151] cocoa: GL_GetDrawableSize only uses -[NSView convertRectToBacking] for highDPI. On Mojave, this will report large numbers for retina displays in fullscreen mode, which isn't how it works on previous versions. --- src/video/cocoa/SDL_cocoaopengl.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 5f18a2ee89813..c7d0c60e52c12 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -347,10 +347,12 @@ - (void)setWindow:(SDL_Window *)newWindow NSView *contentView = [windata->nswindow contentView]; NSRect viewport = [contentView bounds]; - /* This gives us the correct viewport for a Retina-enabled view, only - * supported on 10.7+. */ - if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) { - viewport = [contentView convertRectToBacking:viewport]; + if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { + /* This gives us the correct viewport for a Retina-enabled view, only + * supported on 10.7+. */ + if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) { + viewport = [contentView convertRectToBacking:viewport]; + } } if (w) { From f677377339919eea90339c0385ef15dc84285093 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 18 Oct 2018 12:05:05 -0400 Subject: [PATCH 116/151] cocoa: Fix OpenGL rendering on macOS 10.14 ("Mojave"). Fixes Bugzilla #4272. --- src/video/cocoa/SDL_cocoawindow.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 2294e777d480d..a8e95ccd98f1a 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -632,8 +632,6 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock; _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags; SDL_ToggleModState(KMOD_CAPS, newflags != 0); - - ScheduleContextUpdates(_data); } - (void)windowDidResignKey:(NSNotification *)aNotification @@ -1145,14 +1143,18 @@ - (void)rightMouseDown:(NSEvent *)theEvent; - (BOOL)mouseDownCanMoveWindow; - (void)drawRect:(NSRect)dirtyRect; - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent; +- (BOOL)wantsUpdateLayer; +- (void)updateLayer; @end @implementation SDLView + - (void)setSDLWindow:(SDL_Window*)window { _sdlWindow = window; } +/* this is used on older macOS revisions. 10.8 and later use updateLayer. */ - (void)drawRect:(NSRect)dirtyRect { /* Force the graphics context to clear to black so we don't get a flash of @@ -1163,6 +1165,21 @@ - (void)drawRect:(NSRect)dirtyRect SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0); } +-(BOOL) wantsUpdateLayer +{ + return YES; +} + +-(void) updateLayer +{ + /* Force the graphics context to clear to black so we don't get a flash of + white until the app is ready to draw. In practice on modern macOS, this + only gets called for window creation and other extraordinary events. */ + self.layer.backgroundColor = NSColor.blackColor.CGColor; + ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata); + SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0); +} + - (void)rightMouseDown:(NSEvent *)theEvent { [[self nextResponder] rightMouseDown:theEvent]; @@ -1345,6 +1362,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent [contentView setWantsBestResolutionOpenGLSurface:YES]; } } + #if SDL_VIDEO_OPENGL_ES2 #if SDL_VIDEO_OPENGL_EGL if ((window->flags & SDL_WINDOW_OPENGL) && From 30def8e26b83d244a62cf01fe52d6f71daff950b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 18 Oct 2018 15:40:39 -0700 Subject: [PATCH 117/151] Fixed bug 4324 - Xcode 10 - more cleanup for macOS and iOS projects Dominik Reichardt Similar to bug/patch #4228, the iOS Demo Xcode project needs to add the CoreBluetooth framework. --- Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj index d4ace900b68a1..3715cfa63b012 100644 --- a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj @@ -10,6 +10,13 @@ 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; + 8A476D2B217923FE00FAEF79 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A680883217924680074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A680886217924B60074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A680887217924D70074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A680888217924F00074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A6808892179250B0074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; + 8A68088A217925270074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; FA30DEB01BBF5A8F009C397F /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FD77A0060E26BC0500F39101 /* common.c */; }; FA30DEB11BBF5A93009C397F /* happy.c in Sources */ = {isa = PBXBuildFile; fileRef = FD77A0080E26BC0500F39101 /* happy.c */; }; FA30DEB31BBF5AD7009C397F /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDB651CC0E43D19800F688B5 /* icon.bmp */; }; @@ -225,6 +232,7 @@ 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 1D6058910D05DD3D006BFB54 /* Rectangles.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Rectangles.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = System/Library/Frameworks/CoreBluetooth.framework; sourceTree = SDKROOT; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; FA30DE961BBF59D9009C397F /* Happy-TV.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Happy-TV.app"; sourceTree = BUILT_PRODUCTS_DIR; }; FA86C0361D9765BA009CB637 /* iOS Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "iOS Launch Screen.storyboard"; sourceTree = ""; }; @@ -271,6 +279,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A476D2B217923FE00FAEF79 /* CoreBluetooth.framework in Frameworks */, FABA34D41D8B5E5600915323 /* AVFoundation.framework in Frameworks */, FD1B48DD0E313255007AB34E /* libSDL2.a in Frameworks */, FAE0E96A1BAF96A00098DFA4 /* GameController.framework in Frameworks */, @@ -306,6 +315,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A680883217924680074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34D61D8B5E5A00915323 /* AVFoundation.framework in Frameworks */, FD1B49980E313261007AB34E /* libSDL2.a in Frameworks */, FAE0E96C1BAF96A90098DFA4 /* GameController.framework in Frameworks */, @@ -324,6 +334,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A680886217924B60074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34D91D8B5E7B00915323 /* AVFoundation.framework in Frameworks */, FD1B499C0E313269007AB34E /* libSDL2.a in Frameworks */, FAE0E96D1BAF96AF0098DFA4 /* GameController.framework in Frameworks */, @@ -342,6 +353,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A68088A217925270074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DD1D8B5E8D00915323 /* AVFoundation.framework in Frameworks */, FDB652000E43D1F300F688B5 /* libSDL2.a in Frameworks */, FAE0E9711BAF96BB0098DFA4 /* GameController.framework in Frameworks */, @@ -360,6 +372,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A680887217924D70074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DA1D8B5E7F00915323 /* AVFoundation.framework in Frameworks */, FD1B499E0E31326C007AB34E /* libSDL2.a in Frameworks */, FAE0E96E1BAF96B10098DFA4 /* GameController.framework in Frameworks */, @@ -378,6 +391,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A6808892179250B0074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DC1D8B5E8900915323 /* AVFoundation.framework in Frameworks */, FD1B49A20E313273007AB34E /* libSDL2.a in Frameworks */, FAE0E9701BAF96B80098DFA4 /* GameController.framework in Frameworks */, @@ -396,6 +410,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8A680888217924F00074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DB1D8B5E8500915323 /* AVFoundation.framework in Frameworks */, FD1B49A00E313270007AB34E /* libSDL2.a in Frameworks */, FAE0E96F1BAF96B50098DFA4 /* GameController.framework in Frameworks */, @@ -455,6 +470,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */, FABA34D71D8B5E7700915323 /* AVFoundation.framework */, FABA34D31D8B5E5600915323 /* AVFoundation.framework */, FAE0E9691BAF96A00098DFA4 /* GameController.framework */, From 568068048fa3a808fcd5e83902e7a007b6d77da4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 18 Oct 2018 15:41:50 -0700 Subject: [PATCH 118/151] Fixed bug 4324 - Xcode 10 - more cleanup for macOS and iOS projects Dominik Reichardt Xcode warns about "Traditional headermap style is no longer supported; please migrate to using separate headermaps and set 'ALWAYS_SEARCH_USER_PATHS' to NO." Just doing the latter is enough to silence the warning without ill effects on compiling. This affects the macOS Xcode projects as well as the iOS projects. Definitely not a bug but an annoying warning that could go away. --- Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj | 2 ++ Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 2 ++ Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj | 2 ++ Xcode/SDL/SDL.xcodeproj/project.pbxproj | 10 ++++++++++ Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj | 2 ++ 5 files changed, 18 insertions(+) diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj index 3715cfa63b012..1d52b6b4296a4 100644 --- a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj @@ -991,6 +991,7 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_OPTIMIZATION_LEVEL = 0; HEADER_SEARCH_PATHS = ../../include; @@ -1004,6 +1005,7 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; HEADER_SEARCH_PATHS = ../../include; PRELINK_LIBS = ""; diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj index f319c3b8c00d7..aace16b77be0f 100644 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj @@ -1973,6 +1973,7 @@ FD6526640DE8FCCB002AD96B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; @@ -1989,6 +1990,7 @@ FD6526650DE8FCCB002AD96B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; diff --git a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj index 12e8c9903acbd..b8b90c510de37 100644 --- a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj @@ -2384,6 +2384,7 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -2400,6 +2401,7 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ../../include; diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 6884684faf018..d6041be582c7e 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -3107,6 +3107,7 @@ 00CFA621106A567900758660 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; @@ -3155,6 +3156,7 @@ 00CFA622106A567900758660 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; @@ -3177,6 +3179,7 @@ 00CFA623106A567900758660 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; COMBINE_HIDPI_IMAGES = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "$(GCC_PREPROCESSOR_DEFINITIONS)", @@ -3194,6 +3197,7 @@ 00CFA625106A567900758660 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; PRODUCT_NAME = "Standard DMG"; PROVISIONING_PROFILE = ""; }; @@ -3202,6 +3206,7 @@ 00CFA627106A568900758660 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; @@ -3250,6 +3255,7 @@ 00CFA628106A568900758660 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; CLANG_LINK_OBJC_RUNTIME = NO; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1.0.0; @@ -3272,6 +3278,7 @@ 00CFA629106A568900758660 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; COMBINE_HIDPI_IMAGES = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "$(GCC_PREPROCESSOR_DEFINITIONS)", @@ -3289,6 +3296,7 @@ 00CFA62B106A568900758660 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; PRODUCT_NAME = "Standard DMG"; PROVISIONING_PROFILE = ""; }; @@ -3297,6 +3305,7 @@ DB31407517554B71006C0E22 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; COMBINE_HIDPI_IMAGES = YES; EXECUTABLE_PREFIX = lib; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -3316,6 +3325,7 @@ DB31407617554B71006C0E22 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; COMBINE_HIDPI_IMAGES = YES; EXECUTABLE_PREFIX = lib; GCC_PREPROCESSOR_DEFINITIONS = ( diff --git a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj index 8e6e142e50a9a..8c524cc54e71a 100644 --- a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj +++ b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj @@ -4040,6 +4040,7 @@ 002A85B21073008E007319AE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; FRAMEWORK_SEARCH_PATHS = ( "$(SRCROOT)/../SDL/build/$(CONFIGURATION)", "$(HOME)/Library/Frameworks", @@ -4166,6 +4167,7 @@ 002A85D41073009D007319AE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; FRAMEWORK_SEARCH_PATHS = ( "$(SRCROOT)/../SDL/build/$(CONFIGURATION)", "$(HOME)/Library/Frameworks", From 84e78320180d2ffe1cd013e91b3d649b4abfb560 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Thu, 23 Aug 2018 14:47:38 +0200 Subject: [PATCH 119/151] Fix "unresponsible application" issues in Wayland Polling without wl_display_flush() never responds to ping requests. In that case ping-pong works only on other events, such as user input or on frame swapped. From https://git.merproject.org/mer-core/libsdl/merge_requests/3 Original author: Alexander Akulich --- src/video/wayland/SDL_waylandevents.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 5ee76afea5582..0c953a54c203f 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -178,6 +178,8 @@ Wayland_PumpEvents(_THIS) { SDL_VideoData *d = _this->driverdata; + WAYLAND_wl_display_flush(d->display); + if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0)) { WAYLAND_wl_display_dispatch(d->display); } From 1fb20f0ab9f1b1ad51a79dbf59c50db5cc91d6f9 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 18 Oct 2018 23:38:27 -0400 Subject: [PATCH 120/151] cocoa: Put a mutex around GL_SwapBuffers. Prevents deadlock when swapping two different GL contexts on two different threads at the same time on macOS 10.14 ("Mojave"). Fixes Bugzilla #4278. --- src/video/cocoa/SDL_cocoaopengl.m | 6 ++++++ src/video/cocoa/SDL_cocoavideo.h | 2 +- src/video/cocoa/SDL_cocoavideo.m | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index c7d0c60e52c12..9539c17799e68 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -410,8 +410,14 @@ - (void)setWindow:(SDL_Window *)newWindow { @autoreleasepool { SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext(); + SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; + + /* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two + threads try to swap at the same time, so put a mutex around it. */ + SDL_LockMutex(videodata->swaplock); [nscontext flushBuffer]; [nscontext updateIfNeeded]; + SDL_UnlockMutex(videodata->swaplock); return 0; }} diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h index 05bbd34838185..b1c26fa7e8c6e 100644 --- a/src/video/cocoa/SDL_cocoavideo.h +++ b/src/video/cocoa/SDL_cocoavideo.h @@ -107,7 +107,7 @@ typedef struct SDL_VideoData Uint32 screensaver_activity; BOOL screensaver_use_iopm; IOPMAssertionID screensaver_assertion; - + SDL_mutex *swaplock; } SDL_VideoData; /* Utility functions */ diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 977022494a0ff..20bdfa79165cb 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -175,15 +175,23 @@ /* The IOPM assertion API can disable the screensaver as of 10.7. */ data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; + data->swaplock = SDL_CreateMutex(); + if (!data->swaplock) { + return -1; + } + return 0; } void Cocoa_VideoQuit(_THIS) { + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; Cocoa_QuitModes(_this); Cocoa_QuitKeyboard(_this); Cocoa_QuitMouse(_this); + SDL_DestroyMutex(data->swaplock); + data->swaplock = NULL; } /* This function assumes that it's called from within an autorelease pool */ From 1ec56f730231b1bc62b5ab5d253efa2a1f1c2929 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 20 Oct 2018 21:35:48 -0400 Subject: [PATCH 121/151] x11: Fixed incorrect function signature for XkbSetDetectableAutoRepeat. It needs to use Bool (which is an int) and not BOOL (which is CARD8), which causes problems on platforms with different byte order and alignment, etc. Fixes Bugzilla #4326. --- src/video/x11/SDL_x11keyboard.c | 2 +- src/video/x11/SDL_x11sym.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index 4e87b4c22c6b9..a57adf9bbf33b 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -266,7 +266,7 @@ X11_InitKeyboard(_THIS) int best_distance; int best_index; int distance; - BOOL xkb_repeat = 0; + Bool xkb_repeat = 0; X11_XAutoRepeatOn(data->display); diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h index a4c6d1db0f390..6709992155223 100644 --- a/src/video/x11/SDL_x11sym.h +++ b/src/video/x11/SDL_x11sym.h @@ -180,7 +180,7 @@ SDL_X11_SYM(Status,XkbGetUpdatedMap,(Display* a,unsigned int b,XkbDescPtr c),(a, SDL_X11_SYM(XkbDescPtr,XkbGetMap,(Display* a,unsigned int b,unsigned int c),(a,b,c),return) SDL_X11_SYM(void,XkbFreeClientMap,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),) SDL_X11_SYM(void,XkbFreeKeyboard,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),) -SDL_X11_SYM(BOOL,XkbSetDetectableAutoRepeat,(Display* a, BOOL b, BOOL* c),(a,b,c),return) +SDL_X11_SYM(Bool,XkbSetDetectableAutoRepeat,(Display* a, Bool b, Bool* c),(a,b,c),return) #endif #if NeedWidePrototypes From 4a50a04213b9f2c214702a77af3254f08f550c1b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 21 Oct 2018 22:40:17 -0400 Subject: [PATCH 122/151] wasapi/win32: Sort initial device lists by device GUID. This makes an unchanged set of hardware always report devices in the same order on each run. --- src/audio/wasapi/SDL_wasapi_win32.c | 62 +++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/audio/wasapi/SDL_wasapi_win32.c b/src/audio/wasapi/SDL_wasapi_win32.c index 731dcffb7fa9e..9d7c1591b38bd 100644 --- a/src/audio/wasapi/SDL_wasapi_win32.c +++ b/src/audio/wasapi/SDL_wasapi_win32.c @@ -351,10 +351,42 @@ WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery) } +typedef struct +{ + LPWSTR devid; + char *devname; +} EndpointItem; + +static int sort_endpoints(const void *_a, const void *_b) +{ + LPWSTR a = ((const EndpointItem *) _a)->devid; + LPWSTR b = ((const EndpointItem *) _b)->devid; + if (!a && b) { + return -1; + } else if (a && !b) { + return 1; + } + + while (SDL_TRUE) { + if (*a < *b) { + return -1; + } else if (*a > *b) { + return 1; + } else if (*a == 0) { + break; + } + a++; + b++; + } + + return 0; +} + static void WASAPI_EnumerateEndpointsForFlow(const SDL_bool iscapture) { IMMDeviceCollection *collection = NULL; + EndpointItem *items; UINT i, total; /* Note that WASAPI separates "adapter devices" from "audio endpoint devices" @@ -369,22 +401,36 @@ WASAPI_EnumerateEndpointsForFlow(const SDL_bool iscapture) return; } + items = (EndpointItem *) SDL_calloc(total, sizeof (EndpointItem)); + if (!items) { + return; /* oh well. */ + } + for (i = 0; i < total; i++) { + EndpointItem *item = items + i; IMMDevice *device = NULL; if (SUCCEEDED(IMMDeviceCollection_Item(collection, i, &device))) { - LPWSTR devid = NULL; - if (SUCCEEDED(IMMDevice_GetId(device, &devid))) { - char *devname = GetWasapiDeviceName(device); - if (devname) { - WASAPI_AddDevice(iscapture, devname, devid); - SDL_free(devname); - } - CoTaskMemFree(devid); + if (SUCCEEDED(IMMDevice_GetId(device, &item->devid))) { + item->devname = GetWasapiDeviceName(device); } IMMDevice_Release(device); } } + /* sort the list of devices by their guid so list is consistent between runs */ + SDL_qsort(items, total, sizeof (*items), sort_endpoints); + + /* Send the sorted list on to the SDL's higher level. */ + for (i = 0; i < total; i++) { + EndpointItem *item = items + i; + if ((item->devid) && (item->devname)) { + WASAPI_AddDevice(iscapture, item->devname, item->devid); + } + SDL_free(item->devname); + CoTaskMemFree(item->devid); + } + + SDL_free(items); IMMDeviceCollection_Release(collection); } From c4918db58094ec85f672bf2c22358b846598bcb7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 22 Oct 2018 14:55:42 -0700 Subject: [PATCH 123/151] Add exception handling to Android hidapi. --- .../Demos/Demos.xcodeproj/project.pbxproj | 0 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 0 .../TestiPhoneOS.xcodeproj/project.pbxproj | 0 Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 .../SDLTest/SDLTest.xcodeproj/project.pbxproj | 0 src/hidapi/android/hid.cpp | 39 ++++++++++++++++++- 6 files changed, 38 insertions(+), 1 deletion(-) mode change 100644 => 100755 Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj mode change 100644 => 100755 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj mode change 100644 => 100755 Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj mode change 100644 => 100755 Xcode/SDL/SDL.xcodeproj/project.pbxproj mode change 100644 => 100755 Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index 403a77d7281e3..7b8d41c71aec7 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -14,6 +14,10 @@ #include // For memcpy() #define TAG "hidapi" + +// Have error log always available +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) + #ifdef DEBUG #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) @@ -398,6 +402,33 @@ class CHIDDevice return m_pDevice; } + void ExceptionCheck( JNIEnv *env, const char *pszMethodName ) + { + if ( env->ExceptionCheck() ) + { + // Get our exception + jthrowable jExcept = env->ExceptionOccurred(); + + // Clear the exception so we can call JNI again + env->ExceptionClear(); + + // Get our exception message + jclass jExceptClass = env->GetObjectClass( jExcept ); + jmethodID jMessageMethod = env->GetMethodID( jExceptClass, "getMessage", "()Ljava/lang/String;" ); + jstring jMessage = (jstring)( env->CallObjectMethod( jExcept, jMessageMethod ) ); + const char *pszMessage = env->GetStringUTFChars( jMessage, NULL ); + + // ...and log it. + LOGE( "CHIDDevice::%s threw an exception: %s", pszMethodName, pszMessage ); + + // Cleanup + env->ReleaseStringUTFChars( jMessage, pszMessage ); + env->DeleteLocalRef( jMessage ); + env->DeleteLocalRef( jExceptClass ); + env->DeleteLocalRef( jExcept ); + } + } + bool BOpen() { // Make sure thread is attached to JVM/env @@ -407,6 +438,7 @@ class CHIDDevice m_bIsWaitingForOpen = false; m_bOpenResult = env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerOpen, m_nId ); + ExceptionCheck( env, "BOpen" ); if ( m_bIsWaitingForOpen ) { @@ -515,6 +547,8 @@ class CHIDDevice jbyteArray pBuf = NewByteArray( env, pData, nDataLen ); int nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendOutputReport, m_nId, pBuf ); + ExceptionCheck( env, "SendOutputReport" ); + env->DeleteLocalRef( pBuf ); return nRet; } @@ -528,6 +562,7 @@ class CHIDDevice jbyteArray pBuf = NewByteArray( env, pData, nDataLen ); int nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendFeatureReport, m_nId, pBuf ); + ExceptionCheck( env, "SendFeatureReport" ); env->DeleteLocalRef( pBuf ); return nRet; } @@ -564,6 +599,7 @@ class CHIDDevice jbyteArray pBuf = NewByteArray( env, pData, nDataLen ); int nRet = env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerGetFeatureReport, m_nId, pBuf ) ? 0 : -1; + ExceptionCheck( env, "GetFeatureReport" ); env->DeleteLocalRef( pBuf ); if ( nRet < 0 ) { @@ -622,7 +658,8 @@ class CHIDDevice pthread_setspecific( g_ThreadKey, (void*)env ); env->CallVoidMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerClose, m_nId ); - + ExceptionCheck( env, "Close" ); + hid_mutex_guard dataLock( &m_dataLock ); m_vecData.clear(); From e6068b5b15a2b014b60e70470fe7bdbebc5ba2d4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 22 Oct 2018 14:55:45 -0700 Subject: [PATCH 124/151] Handle failure to load hidapi gracefully --- .../java/org/libsdl/app/HIDDeviceManager.java | 31 +++++++++++++++++-- .../app/src/main/java/org/libsdl/app/SDL.java | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 761ecca0d39b9..db9400f6d6574 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -1,5 +1,7 @@ package org.libsdl.app; +import android.app.Activity; +import android.app.AlertDialog; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -8,6 +10,7 @@ import android.util.Log; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -98,17 +101,39 @@ public void onReceive(Context context, Intent intent) { } }; - private HIDDeviceManager(Context context) { + private HIDDeviceManager(final Context context) { mContext = context; // Make sure we have the HIDAPI library loaded with the native functions try { SDL.loadLibrary("hidapi"); - } catch (Exception e) { + } catch (Throwable e) { Log.w(TAG, "Couldn't load hidapi: " + e.toString()); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setCancelable(false); + builder.setTitle("SDL HIDAPI Error"); + builder.setMessage("Please report the following error to the SDL maintainers: " + e.getMessage()); + builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + try { + // If our context is an activity, exit rather than crashing when we can't + // call our native functions. + Activity activity = (Activity)context; + + activity.finish(); + } + catch (ClassCastException cce) { + // Context wasn't an activity, there's nothing we can do. Give up and return. + } + } + }); + builder.show(); + return; } - + HIDDeviceRegisterCallback(); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); diff --git a/android-project/app/src/main/java/org/libsdl/app/SDL.java b/android-project/app/src/main/java/org/libsdl/app/SDL.java index 58597c6555f51..fb7f7319a8979 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDL.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDL.java @@ -66,7 +66,7 @@ public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass); loadMethod.invoke(relinkInstance, mContext, libraryName, null, null); } - catch (final Exception e) { + catch (final Throwable e) { // Fall back try { System.loadLibrary(libraryName); From d7fa11204f409c414160ebdf8e872dc093611555 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 22 Oct 2018 14:55:47 -0700 Subject: [PATCH 125/151] Change our fullscreen wait logic to only wait if we need to. (thanks Rachel!) --- .../main/java/org/libsdl/app/SDLActivity.java | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index df35787c89a13..311b2f1df4f7d 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -645,15 +645,54 @@ boolean sendCommand(int command, Object data) { msg.obj = data; boolean result = commandHandler.sendMessage(msg); - // Ensure we don't return until the resize has actually happened, - // or 250ms have passed. - if (command == COMMAND_CHANGE_WINDOW_STYLE) { - synchronized(SDLActivity.getContext()) { - try { - SDLActivity.getContext().wait(250); + if ((Build.VERSION.SDK_INT >= 19) && (command == COMMAND_CHANGE_WINDOW_STYLE)) { + // Ensure we don't return until the resize has actually happened, + // or 500ms have passed. + + boolean bShouldWait = false; + + if (data instanceof Integer) { + // Let's figure out if we're already laid out fullscreen or not. + Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics(); + display.getRealMetrics( realMetrics ); + + boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) && + (realMetrics.heightPixels == mSurface.getHeight())); + + if (((Integer)data).intValue() == 1) { + // If we aren't laid out fullscreen or actively in fullscreen mode already, we're going + // to change size and should wait for surfaceChanged() before we return, so the size + // is right back in native code. If we're already laid out fullscreen, though, we're + // not going to change size even if we change decor modes, so we shouldn't wait for + // surfaceChanged() -- which may not even happen -- and should return immediately. + bShouldWait = !bFullscreenLayout; + } + else { + // If we're laid out fullscreen (even if the status bar and nav bar are present), + // or are actively in fullscreen, we're going to change size and should wait for + // surfaceChanged before we return, so the size is right back in native code. + bShouldWait = bFullscreenLayout; } - catch (InterruptedException ie) { - ie.printStackTrace(); + } + + if (bShouldWait) { + // We'll wait for the surfaceChanged() method, which will notify us + // when called. That way, we know our current size is really the + // size we need, instead of grabbing a size that's still got + // the navigation and/or status bars before they're hidden. + // + // We'll wait for up to half a second, because some devices + // take a surprisingly long time for the surface resize, but + // then we'll just give up and return. + // + synchronized(SDLActivity.getContext()) { + try { + SDLActivity.getContext().wait(500); + } + catch (InterruptedException ie) { + ie.printStackTrace(); + } } } } @@ -1595,6 +1634,7 @@ public void surfaceChanged(SurfaceHolder holder, catch ( java.lang.Throwable throwable ) {} synchronized(SDLActivity.getContext()) { + // In case we're waiting on a size change after going fullscreen, send a notification. SDLActivity.getContext().notifyAll(); } From f0549cc9c98de855a4d5380881a13e1f2ea1b2db Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 23 Oct 2018 09:10:02 +0300 Subject: [PATCH 126/151] fix permissions --- Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj | 0 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 0 Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj | 0 Xcode/SDL/SDL.xcodeproj/project.pbxproj | 0 Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj | 0 5 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj mode change 100755 => 100644 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj mode change 100755 => 100644 Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj mode change 100755 => 100644 Xcode/SDL/SDL.xcodeproj/project.pbxproj mode change 100755 => 100644 Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj old mode 100755 new mode 100644 diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj old mode 100755 new mode 100644 diff --git a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj old mode 100755 new mode 100644 diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj old mode 100755 new mode 100644 diff --git a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj old mode 100755 new mode 100644 From b699ddc0a91fea4f3be79e29587a6cf548386dc2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 23 Oct 2018 12:40:25 -0700 Subject: [PATCH 127/151] Fixed reinitializing the SDL joystick subsystem on Android --- .../org/libsdl/app/SDLControllerManager.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 782a92edef4b3..6c5623d27d87b 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -36,27 +36,24 @@ public static native void onNativeHat(int device_id, int hat_id, private static final String TAG = "SDLControllerManager"; public static void initialize() { - mJoystickHandler = null; - mHapticHandler = null; - - SDLControllerManager.setup(); - } - - public static void setup() { - if (Build.VERSION.SDK_INT >= 19) { - mJoystickHandler = new SDLJoystickHandler_API19(); - } else if (Build.VERSION.SDK_INT >= 16) { - mJoystickHandler = new SDLJoystickHandler_API16(); - } else if (Build.VERSION.SDK_INT >= 12) { - mJoystickHandler = new SDLJoystickHandler_API12(); - } else { - mJoystickHandler = new SDLJoystickHandler(); + if (mJoystickHandler == null) { + if (Build.VERSION.SDK_INT >= 19) { + mJoystickHandler = new SDLJoystickHandler_API19(); + } else if (Build.VERSION.SDK_INT >= 16) { + mJoystickHandler = new SDLJoystickHandler_API16(); + } else if (Build.VERSION.SDK_INT >= 12) { + mJoystickHandler = new SDLJoystickHandler_API12(); + } else { + mJoystickHandler = new SDLJoystickHandler(); + } } - if (Build.VERSION.SDK_INT >= 26) { - mHapticHandler = new SDLHapticHandler_API26(); - } else { - mHapticHandler = new SDLHapticHandler(); + if (mHapticHandler == null) { + if (Build.VERSION.SDK_INT >= 26) { + mHapticHandler = new SDLHapticHandler_API26(); + } else { + mHapticHandler = new SDLHapticHandler(); + } } } @@ -846,4 +843,4 @@ public float getEventY(MotionEvent event) { // Relative mouse in capture mode will only have relative for X/Y return event.getY(0); } -} +} \ No newline at end of file From 04761d7d6be7750c862731a1f4f189f75ba67e91 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 25 Oct 2018 11:11:02 +0300 Subject: [PATCH 128/151] CMakeLists.txt: set dylib version numbers properly. (bug #2915.) --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 302ba2c9e38e4..0128c7ac7d3e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,9 @@ set(SDL_MICRO_VERSION 9) set(SDL_INTERFACE_AGE 0) set(SDL_BINARY_AGE 9) set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}") +# the following should match the versions in Xcode project file: +set(DYLIB_CURRENT_VERSION 10.0.0) +set(DYLIB_COMPATIBILITY_VERSION 1.0.0) # Set defaults preventing destination file conflicts set(SDL_CMAKE_DEBUG_POSTFIX "d" @@ -451,6 +454,8 @@ if(USE_GCC OR USE_CLANG) if(APPLE) list(APPEND EXTRA_LDFLAGS "-Wl,-undefined,error") + list(APPEND EXTRA_LDFLAGS "-Wl,-compatibility_version,${DYLIB_COMPATIBILITY_VERSION}") + list(APPEND EXTRA_LDFLAGS "-Wl,-current_version,${DYLIB_CURRENT_VERSION}") else() set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined") check_c_compiler_flag("" HAVE_NO_UNDEFINED) From 4d4e18c4bbdb4e797d10c2d3308f971639af1bb5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Oct 2018 12:54:39 -0700 Subject: [PATCH 129/151] Added vi style for the Emscripten joystick code --- src/joystick/emscripten/SDL_sysjoystick.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index 847db7a921202..2e42bd03d42e3 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -404,3 +404,5 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = }; #endif /* SDL_JOYSTICK_EMSCRIPTEN */ + +/* vi: set ts=4 sw=4 expandtab: */ From 9987ca69f3da9e958a622c8c2ef35e4e3871d96b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Oct 2018 12:54:42 -0700 Subject: [PATCH 130/151] Added SDL_JoystickGetXInputUserIndex() --- include/SDL_joystick.h | 5 +++++ src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + src/joystick/SDL_joystick.c | 9 +++++++++ src/joystick/SDL_sysjoystick.h | 1 + src/joystick/windows/SDL_xinputjoystick.c | 1 + 6 files changed, 18 insertions(+) diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 8303c5e8620bf..20c314ac83b92 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -384,6 +384,11 @@ extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick); */ extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick); +/** + * Return the XInput user index for this joystick, or -1 if it's not available + */ +extern DECLSPEC int SDLCALL SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus } diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 22e4d63d99a60..e2a627d518650 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -698,3 +698,4 @@ #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL #define SDL_HasColorKey SDL_HasColorKey_REAL #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL +#define SDL_JoystickGetXInputUserIndex SDL_JoystickGetXInputUserIndex_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index cd50c02e995b1..7c228beaee6ec 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -752,3 +752,4 @@ SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return) #endif +SDL_DYNAPI_PROC(int,SDL_JoystickGetXInputUserIndex,(SDL_Joystick *a),(a),return) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index f7d862b3cc763..c68dbfd6d1171 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -322,6 +322,7 @@ SDL_JoystickOpen(int device_index) } joystick->guid = driver->GetDeviceGUID(device_index); + joystick->userid = -1; if (joystick->naxes > 0) { joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo)); @@ -1556,4 +1557,12 @@ SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick) return joystick->epowerlevel; } +int SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick) +{ + if (!SDL_PrivateJoystickValid(joystick)) { + return -1; + } + return joystick->userid; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index 2b609dbc7136e..6fb0fecb0d85f 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -43,6 +43,7 @@ struct _SDL_Joystick SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */ char *name; /* Joystick name - system dependent */ SDL_JoystickGUID guid; /* Joystick guid */ + int userid; /* XInput user index, if any */ int naxes; /* Number of axis controls on the joystick */ SDL_JoystickAxisInfo *axes; diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c index d81436febd9eb..a13ca9f0f84ae 100644 --- a/src/joystick/windows/SDL_xinputjoystick.c +++ b/src/joystick/windows/SDL_xinputjoystick.c @@ -322,6 +322,7 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde SDL_zero(state); joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS); joystick->hwdata->userid = userId; + joystick->userid = userId; /* The XInput API has a hard coded button/axis mapping, so we just match it */ if (SDL_XInputUseOldJoystickMapping()) { From 545febcf21023c87276d105a8567ca2c962f0684 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Oct 2018 13:22:34 -0700 Subject: [PATCH 131/151] Fixed initializing XInput user index --- src/joystick/SDL_joystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index c68dbfd6d1171..8fa46744c9b08 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -307,6 +307,7 @@ SDL_JoystickOpen(int device_index) joystick->driver = driver; joystick->instance_id = instance_id; joystick->attached = SDL_TRUE; + joystick->userid = -1; if (driver->Open(joystick, device_index) < 0) { SDL_free(joystick); @@ -322,7 +323,6 @@ SDL_JoystickOpen(int device_index) } joystick->guid = driver->GetDeviceGUID(device_index); - joystick->userid = -1; if (joystick->naxes > 0) { joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo)); From 14329256cb240dde7bf8da110b96892787a6dc0e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Oct 2018 16:53:14 -0700 Subject: [PATCH 132/151] Generalized the XInput user index into a player index --- include/SDL_gamecontroller.h | 7 +++++ include/SDL_joystick.h | 18 ++++++++---- src/dynapi/SDL_dynapi_overrides.h | 4 ++- src/dynapi/SDL_dynapi_procs.h | 4 ++- src/joystick/SDL_gamecontroller.c | 6 ++++ src/joystick/SDL_joystick.c | 34 ++++++++++++++++------ src/joystick/SDL_sysjoystick.h | 5 +++- src/joystick/android/SDL_sysjoystick.c | 7 +++++ src/joystick/bsd/SDL_sysjoystick.c | 7 +++++ src/joystick/darwin/SDL_sysjoystick.c | 7 +++++ src/joystick/dummy/SDL_sysjoystick.c | 7 +++++ src/joystick/emscripten/SDL_sysjoystick.c | 7 +++++ src/joystick/haiku/SDL_haikujoystick.cc | 6 ++++ src/joystick/hidapi/SDL_hidapijoystick.c | 7 +++++ src/joystick/iphoneos/SDL_sysjoystick.m | 7 +++++ src/joystick/linux/SDL_sysjoystick.c | 7 +++++ src/joystick/windows/SDL_windowsjoystick.c | 13 +++++++++ src/joystick/windows/SDL_xinputjoystick.c | 3 +- 18 files changed, 138 insertions(+), 18 deletions(-) diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index fb8a7a52540c3..6ae9c95428907 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -204,6 +204,13 @@ extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL */ extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller); +/** + * Get the player index of an opened game controller, or -1 if it's not available + * + * For XInput controllers this returns the XInput user index. + */ +extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller); + /** * Get the USB vendor ID of an opened controller, if available. * If the vendor ID isn't available this function returns 0. diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 20c314ac83b92..6e05a9c2056cf 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -132,6 +132,12 @@ extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); */ extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index); +/** + * Get the player index of a joystick, or -1 if it's not available + * This can be called before any joysticks are opened. + */ +extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index); + /** * Return the GUID for the joystick at this index * This can be called before any joysticks are opened. @@ -194,6 +200,13 @@ extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID */ extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick); +/** + * Get the player index of an opened joystick, or -1 if it's not available + * + * For XInput controllers this returns the XInput user index. + */ +extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick); + /** * Return the GUID for this opened joystick */ @@ -384,11 +397,6 @@ extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick); */ extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick); -/** - * Return the XInput user index for this joystick, or -1 if it's not available - */ -extern DECLSPEC int SDLCALL SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick); - /* Ends C function definitions when using C++ */ #ifdef __cplusplus } diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index e2a627d518650..745421382cdef 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -698,4 +698,6 @@ #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL #define SDL_HasColorKey SDL_HasColorKey_REAL #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL -#define SDL_JoystickGetXInputUserIndex SDL_JoystickGetXInputUserIndex_REAL +#define SDL_JoystickGetDevicePlayerIndex SDL_JoystickGetDevicePlayerIndex_REAL +#define SDL_JoystickGetPlayerIndex SDL_JoystickGetPlayerIndex_REAL +#define SDL_GameControllerGetPlayerIndex SDL_GameControllerGetPlayerIndex_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 7c228beaee6ec..0a1f3aefa5203 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -752,4 +752,6 @@ SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return) #endif -SDL_DYNAPI_PROC(int,SDL_JoystickGetXInputUserIndex,(SDL_Joystick *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_JoystickGetDevicePlayerIndex,(int a),(a),return) +SDL_DYNAPI_PROC(int,SDL_JoystickGetPlayerIndex,(SDL_Joystick *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_GameControllerGetPlayerIndex,(SDL_GameController *a),(a),return) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index b2a17acd1054a..eb1ef065468a6 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -1716,6 +1716,12 @@ SDL_GameControllerName(SDL_GameController * gamecontroller) } } +int +SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller) +{ + return SDL_JoystickGetPlayerIndex(SDL_GameControllerGetJoystick(gamecontroller)); +} + Uint16 SDL_GameControllerGetVendor(SDL_GameController * gamecontroller) { diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 8fa46744c9b08..02903f5f96970 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -227,6 +227,21 @@ SDL_JoystickNameForIndex(int device_index) return name; } +int +SDL_JoystickGetDevicePlayerIndex(int device_index) +{ + SDL_JoystickDriver *driver; + int player_index = -1; + + SDL_LockJoysticks(); + if (SDL_GetDriverAndJoystickIndex(device_index, &driver, &device_index)) { + player_index = driver->GetDevicePlayerIndex(device_index); + } + SDL_UnlockJoysticks(); + + return player_index; +} + /* * Return true if this joystick is known to have all axes centered at zero * This isn't generally needed unless the joystick never generates an initial axis value near zero, @@ -307,7 +322,7 @@ SDL_JoystickOpen(int device_index) joystick->driver = driver; joystick->instance_id = instance_id; joystick->attached = SDL_TRUE; - joystick->userid = -1; + joystick->player_index = -1; if (driver->Open(joystick, device_index) < 0) { SDL_free(joystick); @@ -603,6 +618,15 @@ SDL_JoystickName(SDL_Joystick * joystick) return SDL_FixupJoystickName(joystick->name); } +int +SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick) +{ + if (!SDL_PrivateJoystickValid(joystick)) { + return -1; + } + return joystick->player_index; +} + int SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) { @@ -1557,12 +1581,4 @@ SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick) return joystick->epowerlevel; } -int SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick) -{ - if (!SDL_PrivateJoystickValid(joystick)) { - return -1; - } - return joystick->userid; -} - /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index 6fb0fecb0d85f..3416693610e67 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -42,8 +42,8 @@ struct _SDL_Joystick { SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */ char *name; /* Joystick name - system dependent */ + int player_index; /* Joystick player index, or -1 if unavailable */ SDL_JoystickGUID guid; /* Joystick guid */ - int userid; /* XInput user index, if any */ int naxes; /* Number of axis controls on the joystick */ SDL_JoystickAxisInfo *axes; @@ -106,6 +106,9 @@ typedef struct _SDL_JoystickDriver /* Function to get the device-dependent name of a joystick */ const char *(*GetDeviceName)(int device_index); + /* Function to get the player index of a joystick */ + int (*GetDevicePlayerIndex)(int device_index); + /* Function to return the stable GUID for a plugged in device */ SDL_JoystickGUID (*GetDeviceGUID)(int device_index); diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index c60555166fc02..69b657fc9f1ab 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -581,6 +581,12 @@ ANDROID_JoystickGetDeviceName(int device_index) return JoystickByDevIndex(device_index)->name; } +static int +ANDROID_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID ANDROID_JoystickGetDeviceGUID(int device_index) { @@ -689,6 +695,7 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver = ANDROID_JoystickGetCount, ANDROID_JoystickDetect, ANDROID_JoystickGetDeviceName, + ANDROID_JoystickGetDevicePlayerIndex, ANDROID_JoystickGetDeviceGUID, ANDROID_JoystickGetDeviceInstanceID, ANDROID_JoystickOpen, diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index a282155c8450f..679b80c109ac9 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -227,6 +227,12 @@ BSD_JoystickGetDeviceName(int device_index) return (joynames[device_index]); } +static int +BSD_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + /* Function to perform the mapping from device index to the instance id for this index */ static SDL_JoystickID BSD_JoystickGetDeviceInstanceID(int device_index) @@ -687,6 +693,7 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver = BSD_JoystickGetCount, BSD_JoystickDetect, BSD_JoystickGetDeviceName, + BSD_JoystickGetDevicePlayerIndex, BSD_JoystickGetDeviceGUID, BSD_JoystickGetDeviceInstanceID, BSD_JoystickOpen, diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 3d0de56e43cec..8af3b9610989e 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -700,6 +700,12 @@ DARWIN_JoystickGetDeviceName(int device_index) return device ? device->product : "UNKNOWN"; } +static int +DARWIN_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID DARWIN_JoystickGetDeviceGUID( int device_index ) { @@ -998,6 +1004,7 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver = DARWIN_JoystickGetCount, DARWIN_JoystickDetect, DARWIN_JoystickGetDeviceName, + DARWIN_JoystickGetDevicePlayerIndex, DARWIN_JoystickGetDeviceGUID, DARWIN_JoystickGetDeviceInstanceID, DARWIN_JoystickOpen, diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c index f03ee3c20c627..ce0965daf0c47 100644 --- a/src/joystick/dummy/SDL_sysjoystick.c +++ b/src/joystick/dummy/SDL_sysjoystick.c @@ -52,6 +52,12 @@ DUMMY_JoystickGetDeviceName(int device_index) return NULL; } +static int +DUMMY_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID DUMMY_JoystickGetDeviceGUID(int device_index) { @@ -99,6 +105,7 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver = DUMMY_JoystickGetCount, DUMMY_JoystickDetect, DUMMY_JoystickGetDeviceName, + DUMMY_JoystickGetDevicePlayerIndex, DUMMY_JoystickGetDeviceGUID, DUMMY_JoystickGetDeviceInstanceID, DUMMY_JoystickOpen, diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index 2e42bd03d42e3..d551c8aa1357e 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -279,6 +279,12 @@ EMSCRIPTEN_JoystickGetDeviceName(int device_index) return JoystickByDeviceIndex(device_index)->name; } +static int +EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickID EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index) { @@ -394,6 +400,7 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = EMSCRIPTEN_JoystickGetCount, EMSCRIPTEN_JoystickDetect, EMSCRIPTEN_JoystickGetDeviceName, + EMSCRIPTEN_JoystickGetDevicePlayerIndex, EMSCRIPTEN_JoystickGetDeviceGUID, EMSCRIPTEN_JoystickGetDeviceInstanceID, EMSCRIPTEN_JoystickOpen, diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc index b3b0467f153b3..9fa8ca9924702 100644 --- a/src/joystick/haiku/SDL_haikujoystick.cc +++ b/src/joystick/haiku/SDL_haikujoystick.cc @@ -99,6 +99,11 @@ extern "C" return SDL_joyname[device_index]; } + static int HAIKU_JoystickGetDevicePlayerIndex(int device_index) + { + return -1; + } + /* Function to perform the mapping from device index to the instance id for this index */ static SDL_JoystickID HAIKU_JoystickGetDeviceInstanceID(int device_index) { @@ -256,6 +261,7 @@ extern "C" HAIKU_JoystickGetCount, HAIKU_JoystickDetect, HAIKU_JoystickGetDeviceName, + HAIKU_JoystickGetDevicePlayerIndex, HAIKU_JoystickGetDeviceGUID, HAIKU_JoystickGetDeviceInstanceID, HAIKU_JoystickOpen, diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 13fcec9fc40fd..2b33cd762b990 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -932,6 +932,12 @@ HIDAPI_JoystickGetDeviceName(int device_index) return HIDAPI_GetJoystickByIndex(device_index)->name; } +static int +HIDAPI_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID HIDAPI_JoystickGetDeviceGUID(int device_index) { @@ -1048,6 +1054,7 @@ SDL_JoystickDriver SDL_HIDAPI_JoystickDriver = HIDAPI_JoystickGetCount, HIDAPI_JoystickDetect, HIDAPI_JoystickGetDeviceName, + HIDAPI_JoystickGetDevicePlayerIndex, HIDAPI_JoystickGetDeviceGUID, HIDAPI_JoystickGetDeviceInstanceID, HIDAPI_JoystickOpen, diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index ed7ddf1da03cb..d85efad33e8ca 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -358,6 +358,12 @@ return device ? device->name : "Unknown"; } +static int +IOS_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID IOS_JoystickGetDeviceGUID( int device_index ) { @@ -715,6 +721,7 @@ IOS_JoystickGetCount, IOS_JoystickDetect, IOS_JoystickGetDeviceName, + IOS_JoystickGetDevicePlayerIndex, IOS_JoystickGetDeviceGUID, IOS_JoystickGetDeviceInstanceID, IOS_JoystickOpen, diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index d70ee02ea2cad..06a2d9a215f9e 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -582,6 +582,12 @@ LINUX_JoystickGetDeviceName(int device_index) return JoystickByDevIndex(device_index)->name; } +static int +LINUX_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + static SDL_JoystickGUID LINUX_JoystickGetDeviceGUID( int device_index ) { @@ -1100,6 +1106,7 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver = LINUX_JoystickGetCount, LINUX_JoystickDetect, LINUX_JoystickGetDeviceName, + LINUX_JoystickGetDevicePlayerIndex, LINUX_JoystickGetDeviceGUID, LINUX_JoystickGetDeviceInstanceID, LINUX_JoystickOpen, diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index ebd15a81046d3..71b72e6103730 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -407,6 +407,18 @@ WINDOWS_JoystickGetDeviceName(int device_index) return device->joystickname; } +static int +WINDOWS_JoystickGetDevicePlayerIndex(int device_index) +{ + JoyStick_DeviceData *device = SYS_Joystick; + int index; + + for (index = device_index; index > 0; index--) + device = device->pNext; + + return device->bXInputDevice ? (int)device->XInputUserId : -1; +} + /* return the stable device guid for this device index */ static SDL_JoystickGUID WINDOWS_JoystickGetDeviceGUID(int device_index) @@ -544,6 +556,7 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver = WINDOWS_JoystickGetCount, WINDOWS_JoystickDetect, WINDOWS_JoystickGetDeviceName, + WINDOWS_JoystickGetDevicePlayerIndex, WINDOWS_JoystickGetDeviceGUID, WINDOWS_JoystickGetDeviceInstanceID, WINDOWS_JoystickOpen, diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c index a13ca9f0f84ae..6bbe475750be5 100644 --- a/src/joystick/windows/SDL_xinputjoystick.c +++ b/src/joystick/windows/SDL_xinputjoystick.c @@ -312,6 +312,8 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde SDL_assert(XINPUTSETSTATE); SDL_assert(userId < XUSER_MAX_COUNT); + joystick->player_index = userId; + joystick->hwdata->bXInputDevice = SDL_TRUE; if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) { @@ -322,7 +324,6 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde SDL_zero(state); joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS); joystick->hwdata->userid = userId; - joystick->userid = userId; /* The XInput API has a hard coded button/axis mapping, so we just match it */ if (SDL_XInputUseOldJoystickMapping()) { From b08bdc440139ce92b7da22374883219b35f9514c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 26 Oct 2018 09:27:31 -0700 Subject: [PATCH 133/151] Don't build SDL_JOYSTICK_HIDAPI by default on iOS If you enable this, you'll need to link with CoreBluetooth.framework and add something like this to your Info.plist: NSBluetoothPeripheralUsageDescription MyApp would like to remain connected to nearby bluetooth Game Controllers and Game Pads even when you're not using the app. --- .../Demos/Demos.xcodeproj/project.pbxproj | 16 ----- .../TestiPhoneOS.xcodeproj/project.pbxproj | 58 ------------------- include/SDL_config_iphoneos.h | 2 +- src/hidapi/ios/hid.m | 5 ++ src/hidapi/libusb/hid.c | 5 ++ src/hidapi/linux/hid.c | 5 ++ src/hidapi/mac/hid.c | 5 ++ src/hidapi/windows/hid.c | 6 +- 8 files changed, 26 insertions(+), 76 deletions(-) diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj index 1d52b6b4296a4..29390844b19c3 100644 --- a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj @@ -10,13 +10,6 @@ 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; - 8A476D2B217923FE00FAEF79 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A680883217924680074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A680886217924B60074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A680887217924D70074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A680888217924F00074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A6808892179250B0074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; - 8A68088A217925270074BD9A /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */; }; FA30DEB01BBF5A8F009C397F /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FD77A0060E26BC0500F39101 /* common.c */; }; FA30DEB11BBF5A93009C397F /* happy.c in Sources */ = {isa = PBXBuildFile; fileRef = FD77A0080E26BC0500F39101 /* happy.c */; }; FA30DEB31BBF5AD7009C397F /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDB651CC0E43D19800F688B5 /* icon.bmp */; }; @@ -232,7 +225,6 @@ 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 1D6058910D05DD3D006BFB54 /* Rectangles.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Rectangles.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = System/Library/Frameworks/CoreBluetooth.framework; sourceTree = SDKROOT; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; FA30DE961BBF59D9009C397F /* Happy-TV.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Happy-TV.app"; sourceTree = BUILT_PRODUCTS_DIR; }; FA86C0361D9765BA009CB637 /* iOS Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "iOS Launch Screen.storyboard"; sourceTree = ""; }; @@ -279,7 +271,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A476D2B217923FE00FAEF79 /* CoreBluetooth.framework in Frameworks */, FABA34D41D8B5E5600915323 /* AVFoundation.framework in Frameworks */, FD1B48DD0E313255007AB34E /* libSDL2.a in Frameworks */, FAE0E96A1BAF96A00098DFA4 /* GameController.framework in Frameworks */, @@ -315,7 +306,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A680883217924680074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34D61D8B5E5A00915323 /* AVFoundation.framework in Frameworks */, FD1B49980E313261007AB34E /* libSDL2.a in Frameworks */, FAE0E96C1BAF96A90098DFA4 /* GameController.framework in Frameworks */, @@ -334,7 +324,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A680886217924B60074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34D91D8B5E7B00915323 /* AVFoundation.framework in Frameworks */, FD1B499C0E313269007AB34E /* libSDL2.a in Frameworks */, FAE0E96D1BAF96AF0098DFA4 /* GameController.framework in Frameworks */, @@ -353,7 +342,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A68088A217925270074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DD1D8B5E8D00915323 /* AVFoundation.framework in Frameworks */, FDB652000E43D1F300F688B5 /* libSDL2.a in Frameworks */, FAE0E9711BAF96BB0098DFA4 /* GameController.framework in Frameworks */, @@ -372,7 +360,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A680887217924D70074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DA1D8B5E7F00915323 /* AVFoundation.framework in Frameworks */, FD1B499E0E31326C007AB34E /* libSDL2.a in Frameworks */, FAE0E96E1BAF96B10098DFA4 /* GameController.framework in Frameworks */, @@ -391,7 +378,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A6808892179250B0074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DC1D8B5E8900915323 /* AVFoundation.framework in Frameworks */, FD1B49A20E313273007AB34E /* libSDL2.a in Frameworks */, FAE0E9701BAF96B80098DFA4 /* GameController.framework in Frameworks */, @@ -410,7 +396,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8A680888217924F00074BD9A /* CoreBluetooth.framework in Frameworks */, FABA34DB1D8B5E8500915323 /* AVFoundation.framework in Frameworks */, FD1B49A00E313270007AB34E /* libSDL2.a in Frameworks */, FAE0E96F1BAF96B50098DFA4 /* GameController.framework in Frameworks */, @@ -470,7 +455,6 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( - 8A476D27217923FE00FAEF79 /* CoreBluetooth.framework */, FABA34D71D8B5E7700915323 /* AVFoundation.framework */, FABA34D31D8B5E5600915323 /* AVFoundation.framework */, FAE0E9691BAF96A00098DFA4 /* GameController.framework */, diff --git a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj index b8b90c510de37..978833d0ea57c 100644 --- a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj @@ -26,34 +26,6 @@ 047A63E813285C3200CD7973 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; }; 047A63E913285C3200CD7973 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; }; 047A63F113285CD100CD7973 /* checkkeys.c in Sources */ = {isa = PBXBuildFile; fileRef = 047A63F013285CD100CD7973 /* checkkeys.c */; }; - 55FFA91C212232BA00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA91D212232BF00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA91E212232BF00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA91F212232C000D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA920212232C000D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA921212232C100D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA922212232C100D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA923212232C200D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA924212232C200D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA925212232C300D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA926212232C300D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA927212232C500D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA928212232C500D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA929212232C600D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92A212232C600D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92B212232C700D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92C212232C700D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92D212232C800D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92E212232CA00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA92F212232CA00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA930212232CB00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA931212232CB00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA932212232CC00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA933212232CC00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA934212232CD00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA935212232CE00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA936212232CE00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; - 55FFA937212232CF00D7CBED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */; }; 56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; 56ED0502118A8FE400A56AA6 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; 56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; @@ -451,7 +423,6 @@ 047A63ED13285C3200CD7973 /* checkkeys.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = checkkeys.app; sourceTree = BUILT_PRODUCTS_DIR; }; 047A63F013285CD100CD7973 /* checkkeys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = checkkeys.c; sourceTree = ""; }; 1D6058910D05DD3D006BFB54 /* testwm2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testwm2.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = System/Library/Frameworks/CoreBluetooth.framework; sourceTree = SDKROOT; }; 56ED050D118A8FE400A56AA6 /* testpower.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testpower.app; sourceTree = BUILT_PRODUCTS_DIR; }; 56ED0510118A904200A56AA6 /* testpower.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = testpower.c; sourceTree = ""; }; AA13B3261FB8AEBC00D9FEE6 /* testyuv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testyuv.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -543,7 +514,6 @@ 046CEF7F13254F23007AD51D /* CoreGraphics.framework in Frameworks */, 046CEF8013254F23007AD51D /* UIKit.framework in Frameworks */, 046CEF8113254F23007AD51D /* Foundation.framework in Frameworks */, - 55FFA926212232C300D7CBED /* CoreBluetooth.framework in Frameworks */, 046CEF8213254F23007AD51D /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -552,7 +522,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 55FFA91C212232BA00D7CBED /* CoreBluetooth.framework in Frameworks */, FABA34B01D8B5B6400915323 /* AVFoundation.framework in Frameworks */, AA1EE470176059D00029C7A5 /* libSDL2test.a in Frameworks */, 047A63E213285C3200CD7973 /* libSDL2.a in Frameworks */, @@ -575,7 +544,6 @@ FABA34C41D8B5BCB00915323 /* AVFoundation.framework in Frameworks */, AA1EE47817605BF60029C7A5 /* libSDL2test.a in Frameworks */, FDBDE5810E313465006BAC0B /* libSDL2.a in Frameworks */, - 55FFA935212232CE00D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F931BAF1A8A00DCFD1A /* GameController.framework in Frameworks */, FA8B4BE0196766F400F8EB7C /* CoreMotion.framework in Frameworks */, FDA8A89F0E2D111A00EA573E /* AudioToolbox.framework in Frameworks */, @@ -602,7 +570,6 @@ 56ED0506118A8FE400A56AA6 /* CoreGraphics.framework in Frameworks */, 56ED0507118A8FE400A56AA6 /* UIKit.framework in Frameworks */, 56ED0508118A8FE400A56AA6 /* Foundation.framework in Frameworks */, - 55FFA92D212232C800D7CBED /* CoreBluetooth.framework in Frameworks */, 56ED0509118A8FE400A56AA6 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -614,7 +581,6 @@ AA13B3171FB8AEBC00D9FEE6 /* AVFoundation.framework in Frameworks */, AA13B3181FB8AEBC00D9FEE6 /* libSDL2test.a in Frameworks */, AA13B3191FB8AEBC00D9FEE6 /* libSDL2.a in Frameworks */, - 55FFA936212232CE00D7CBED /* CoreBluetooth.framework in Frameworks */, AA13B31A1FB8AEBC00D9FEE6 /* GameController.framework in Frameworks */, AA13B31B1FB8AEBC00D9FEE6 /* CoreMotion.framework in Frameworks */, AA13B31C1FB8AEBC00D9FEE6 /* AudioToolbox.framework in Frameworks */, @@ -634,7 +600,6 @@ FABA34BE1D8B5BB000915323 /* AVFoundation.framework in Frameworks */, AA1EE47617605B9E0029C7A5 /* libSDL2test.a in Frameworks */, AAE7DEE114CBB1E100DF1A0E /* libSDL2.a in Frameworks */, - 55FFA92F212232CA00D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F8D1BAF1A7800DCFD1A /* GameController.framework in Frameworks */, FA8B4BDA196766E200F8EB7C /* CoreMotion.framework in Frameworks */, AAE7DEE214CBB1E100DF1A0E /* AudioToolbox.framework in Frameworks */, @@ -655,7 +620,6 @@ FABA34BD1D8B5BAB00915323 /* AVFoundation.framework in Frameworks */, AA1EE47517605B930029C7A5 /* libSDL2test.a in Frameworks */, AAE7DFA614CBB54E00DF1A0E /* libSDL2.a in Frameworks */, - 55FFA92E212232CA00D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F8C1BAF1A7400DCFD1A /* GameController.framework in Frameworks */, FA8B4BD9196766E000F8EB7C /* CoreMotion.framework in Frameworks */, AAE7DFA714CBB54E00DF1A0E /* AudioToolbox.framework in Frameworks */, @@ -680,7 +644,6 @@ FA3D994D1BC4E6AD002C96C8 /* CoreGraphics.framework in Frameworks */, FA3D994E1BC4E6AD002C96C8 /* UIKit.framework in Frameworks */, FA3D994F1BC4E6AD002C96C8 /* Foundation.framework in Frameworks */, - 55FFA925212232C300D7CBED /* CoreBluetooth.framework in Frameworks */, FA3D99501BC4E6AD002C96C8 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -699,7 +662,6 @@ FABA348A1D8B575200915323 /* CoreGraphics.framework in Frameworks */, FABA348B1D8B575200915323 /* UIKit.framework in Frameworks */, FABA348C1D8B575200915323 /* Foundation.framework in Frameworks */, - 55FFA91D212232BF00D7CBED /* CoreBluetooth.framework in Frameworks */, FABA348D1D8B575200915323 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -718,7 +680,6 @@ FABA34A31D8B582100915323 /* CoreGraphics.framework in Frameworks */, FABA34A41D8B582100915323 /* UIKit.framework in Frameworks */, FABA34A51D8B582100915323 /* Foundation.framework in Frameworks */, - 55FFA91F212232C000D7CBED /* CoreBluetooth.framework in Frameworks */, FABA34A61D8B582100915323 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -737,7 +698,6 @@ FAE0E98C1BAF9B230098DFA4 /* CoreGraphics.framework in Frameworks */, FAE0E98D1BAF9B230098DFA4 /* UIKit.framework in Frameworks */, FAE0E98E1BAF9B230098DFA4 /* Foundation.framework in Frameworks */, - 55FFA924212232C200D7CBED /* CoreBluetooth.framework in Frameworks */, FAE0E98F1BAF9B230098DFA4 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -756,7 +716,6 @@ FDA8AAB40E2D330F00EA573E /* CoreGraphics.framework in Frameworks */, FDA8AAB50E2D330F00EA573E /* UIKit.framework in Frameworks */, FDA8AAB60E2D330F00EA573E /* Foundation.framework in Frameworks */, - 55FFA91E212232BF00D7CBED /* CoreBluetooth.framework in Frameworks */, FDA8AAB70E2D330F00EA573E /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -775,7 +734,6 @@ FDAAC3C60E2D47E6001DB1D8 /* CoreGraphics.framework in Frameworks */, FDAAC3C70E2D47E6001DB1D8 /* UIKit.framework in Frameworks */, FDAAC3C80E2D47E6001DB1D8 /* Foundation.framework in Frameworks */, - 55FFA920212232C000D7CBED /* CoreBluetooth.framework in Frameworks */, FDAAC3C90E2D47E6001DB1D8 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -794,7 +752,6 @@ FDAAC5940E2D5429001DB1D8 /* CoreGraphics.framework in Frameworks */, FDAAC5950E2D5429001DB1D8 /* UIKit.framework in Frameworks */, FDAAC5960E2D5429001DB1D8 /* Foundation.framework in Frameworks */, - 55FFA923212232C200D7CBED /* CoreBluetooth.framework in Frameworks */, FDAAC5970E2D5429001DB1D8 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -813,7 +770,6 @@ FDAAC5C20E2D55B5001DB1D8 /* CoreGraphics.framework in Frameworks */, FDAAC5C30E2D55B5001DB1D8 /* UIKit.framework in Frameworks */, FDAAC5C40E2D55B5001DB1D8 /* Foundation.framework in Frameworks */, - 55FFA922212232C100D7CBED /* CoreBluetooth.framework in Frameworks */, FDAAC5C50E2D55B5001DB1D8 /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -825,7 +781,6 @@ FABA34B61D8B5B8900915323 /* AVFoundation.framework in Frameworks */, AA1EE47417605B5C0029C7A5 /* libSDL2test.a in Frameworks */, FDBDE57C0E313445006BAC0B /* libSDL2.a in Frameworks */, - 55FFA927212232C500D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F851BAF1A6000DCFD1A /* GameController.framework in Frameworks */, FA8B4BD2196766CB00F8EB7C /* CoreMotion.framework in Frameworks */, FDAAC61C0E2D5914001DB1D8 /* AudioToolbox.framework in Frameworks */, @@ -846,7 +801,6 @@ FABA34B21D8B5B7300915323 /* AVFoundation.framework in Frameworks */, AA1EE47117605A7F0029C7A5 /* libSDL2test.a in Frameworks */, FDC42FF40F0D866D009C87E1 /* libSDL2.a in Frameworks */, - 55FFA921212232C100D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F811BAF1A5300DCFD1A /* GameController.framework in Frameworks */, FA8B4BCE196766C100F8EB7C /* CoreMotion.framework in Frameworks */, FDC42FF60F0D866D009C87E1 /* AudioToolbox.framework in Frameworks */, @@ -873,7 +827,6 @@ FDD2C1030E2E4F4B00B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C1040E2E4F4B00B7A85F /* UIKit.framework in Frameworks */, FDD2C1050E2E4F4B00B7A85F /* Foundation.framework in Frameworks */, - 55FFA932212232CC00D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C1060E2E4F4B00B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -892,7 +845,6 @@ FDD2C17A0E2E52C000B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C17B0E2E52C000B7A85F /* UIKit.framework in Frameworks */, FDD2C17C0E2E52C000B7A85F /* Foundation.framework in Frameworks */, - 55FFA928212232C500D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C17D0E2E52C000B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -911,7 +863,6 @@ FDD2C19E0E2E534F00B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C19F0E2E534F00B7A85F /* UIKit.framework in Frameworks */, FDD2C1A00E2E534F00B7A85F /* Foundation.framework in Frameworks */, - 55FFA929212232C600D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C1A10E2E534F00B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -930,7 +881,6 @@ FDD2C4570E2E773800B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C4580E2E773800B7A85F /* UIKit.framework in Frameworks */, FDD2C4590E2E773800B7A85F /* Foundation.framework in Frameworks */, - 55FFA92A212232C600D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C45A0E2E773800B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -949,7 +899,6 @@ FDD2C4750E2E77D700B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C4760E2E77D700B7A85F /* UIKit.framework in Frameworks */, FDD2C4770E2E77D700B7A85F /* Foundation.framework in Frameworks */, - 55FFA92B212232C700D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C4780E2E77D700B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -968,7 +917,6 @@ FDD2C5040E2E7F4800B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C5050E2E7F4800B7A85F /* UIKit.framework in Frameworks */, FDD2C5060E2E7F4800B7A85F /* Foundation.framework in Frameworks */, - 55FFA92C212232C700D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C5070E2E7F4800B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -987,7 +935,6 @@ FDD2C5220E2E807600B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C5230E2E807600B7A85F /* UIKit.framework in Frameworks */, FDD2C5240E2E807600B7A85F /* Foundation.framework in Frameworks */, - 55FFA930212232CB00D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C5250E2E807600B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1000,7 +947,6 @@ FABA34C01D8B5BBA00915323 /* AVFoundation.framework in Frameworks */, AA1EE47717605BAB0029C7A5 /* libSDL2test.a in Frameworks */, FDBDE5CA0E313712006BAC0B /* libSDL2.a in Frameworks */, - 55FFA931212232CB00D7CBED /* CoreBluetooth.framework in Frameworks */, FA684F8F1BAF1A7E00DCFD1A /* GameController.framework in Frameworks */, FA8B4BDC196766E800F8EB7C /* CoreMotion.framework in Frameworks */, FDD2C5440E2E80E400B7A85F /* AudioToolbox.framework in Frameworks */, @@ -1027,7 +973,6 @@ FDD2C5800E2E8C7400B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C5810E2E8C7400B7A85F /* UIKit.framework in Frameworks */, FDD2C5820E2E8C7400B7A85F /* Foundation.framework in Frameworks */, - 55FFA934212232CD00D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C5830E2E8C7400B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1046,7 +991,6 @@ FDD2C5BE0E2E8CFC00B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C5BF0E2E8CFC00B7A85F /* UIKit.framework in Frameworks */, FDD2C5C00E2E8CFC00B7A85F /* Foundation.framework in Frameworks */, - 55FFA933212232CC00D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C5C10E2E8CFC00B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1065,7 +1009,6 @@ FDD2C6ED0E2E959E00B7A85F /* CoreGraphics.framework in Frameworks */, FDD2C6EE0E2E959E00B7A85F /* UIKit.framework in Frameworks */, FDD2C6EF0E2E959E00B7A85F /* Foundation.framework in Frameworks */, - 55FFA937212232CF00D7CBED /* CoreBluetooth.framework in Frameworks */, FDD2C6F00E2E959E00B7A85F /* CoreAudio.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1188,7 +1131,6 @@ FDA8A7C30E2D10FA00EA573E /* Frameworks */ = { isa = PBXGroup; children = ( - 55FFA91B212232BA00D7CBED /* CoreBluetooth.framework */, FA684F7A1BAF1A4400DCFD1A /* GameController.framework */, FA8B4BAC1967076F00F8EB7C /* CoreMotion.framework */, FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */, diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h index a0d4f52384d7e..56e2b4338e81c 100644 --- a/include/SDL_config_iphoneos.h +++ b/include/SDL_config_iphoneos.h @@ -137,7 +137,7 @@ /* Enable MFi joystick support */ #define SDL_JOYSTICK_MFI 1 -#define SDL_JOYSTICK_HIDAPI 1 +/*#define SDL_JOYSTICK_HIDAPI 1*/ #ifdef __TVOS__ #define SDL_SENSOR_DUMMY 1 diff --git a/src/hidapi/ios/hid.m b/src/hidapi/ios/hid.m index 1e206bfaeb5d1..a0ca7cd02227f 100644 --- a/src/hidapi/ios/hid.m +++ b/src/hidapi/ios/hid.m @@ -3,6 +3,9 @@ // Purpose: HID device abstraction temporary stub // //============================================================================= +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_HIDAPI #include #include @@ -907,3 +910,5 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t #endif return result; } + +#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c index cab58d1b9f886..17378fff4a949 100644 --- a/src/hidapi/libusb/hid.c +++ b/src/hidapi/libusb/hid.c @@ -22,6 +22,9 @@ code repository located at: http://github.com/signal11/hidapi . ********************************************************/ +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_HIDAPI #ifndef _GNU_SOURCE #define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */ @@ -1613,3 +1616,5 @@ uint16_t get_usb_code_for_current_locale(void) #ifdef NAMESPACE } #endif + +#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/linux/hid.c b/src/hidapi/linux/hid.c index 999a8a7552763..b78e009f0cff0 100644 --- a/src/hidapi/linux/hid.c +++ b/src/hidapi/linux/hid.c @@ -20,6 +20,9 @@ code repository located at: http://github.com/signal11/hidapi . ********************************************************/ +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_HIDAPI #ifndef _GNU_SOURCE #define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */ @@ -891,3 +894,5 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) #ifdef NAMESPACE } #endif + +#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c index 5e98e1ccaaeca..d462d26e38fff 100644 --- a/src/hidapi/mac/hid.c +++ b/src/hidapi/mac/hid.c @@ -19,6 +19,9 @@ code repository located at: http://github.com/signal11/hidapi . ********************************************************/ +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_HIDAPI /* See Apple Technical Note TN2187 for details on IOHidManager. */ @@ -1184,3 +1187,5 @@ int main(void) return 0; } #endif + +#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 1d3803c407276..3795e18adaea1 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -19,6 +19,9 @@ code repository located at: http://github.com/signal11/hidapi . ********************************************************/ +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_HIDAPI #include @@ -39,7 +42,6 @@ typedef LONG NTSTATUS; #endif /* SDL C runtime functions */ -#include "../../SDL_internal.h" #include "SDL_stdinc.h" #define calloc SDL_calloc @@ -982,3 +984,5 @@ int __cdecl main(int argc, char* argv[]) #ifdef __cplusplus } /* extern "C" */ #endif + +#endif /* SDL_JOYSTICK_HIDAPI */ From 91da4963d317e85f64a9af0d34048af63f77e2eb Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 26 Oct 2018 09:49:27 -0700 Subject: [PATCH 134/151] Added patch note for SDL_GameControllerGetPlayerIndex() and friends --- WhatsNew.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/WhatsNew.txt b/WhatsNew.txt index 771262381f3db..56de7b6781d81 100644 --- a/WhatsNew.txt +++ b/WhatsNew.txt @@ -12,6 +12,7 @@ General: * Added an event SDL_DISPLAYEVENT which is sent when the display orientation changes * Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms. (Thanks to Valve for contributing the PS4 and Nintendo Switch Pro controller support) * Added support for many other popular game controllers +* Added SDL_JoystickGetDevicePlayerIndex(), SDL_JoystickGetPlayerIndex(), and SDL_GameControllerGetPlayerIndex() to get the player index for a controller. For XInput controllers this returns the XInput index for the controller. * Added SDL_GameControllerRumble() and SDL_JoystickRumble() which allow simple rumble without using the haptics API * Added SDL_GameControllerMappingForDeviceIndex() to get the mapping for a controller before it's opened * Added the hint SDL_HINT_MOUSE_DOUBLE_CLICK_TIME to control the mouse double-click time From be8ef94f180c698fcb843fd50f431fe27a4de270 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 26 Oct 2018 14:43:39 -0400 Subject: [PATCH 135/151] hidapi: Don't run a separate event loop for device notifications. Fixes Bugzilla #4286. --- src/joystick/hidapi/SDL_hidapijoystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 2b33cd762b990..e89c4f6a9a85c 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -307,7 +307,7 @@ HIDAPI_UpdateDiscovery() return; } -#if defined(__WIN32__) +#if 0 /* just let the usual SDL_PumpEvents loop dispatch these. --ryan. defined(__WIN32__)*/ /* We'll only get messages on the same thread that created the window */ if (SDL_ThreadID() == SDL_HIDAPI_discovery.m_nThreadID) { MSG msg; From 14c55ac890d5ebddbeec50a7e16649da67130e69 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 26 Oct 2018 20:20:28 -0700 Subject: [PATCH 136/151] This change looks okay in the general case. If we run into problems where these events aren't dispatched (initialized on a different thread than the main thread?) we may need to create a separate thread to handle device notifications like we do with the windows joystick subsystem. --- src/joystick/hidapi/SDL_hidapijoystick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index e89c4f6a9a85c..064cb82040f3d 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -307,7 +307,8 @@ HIDAPI_UpdateDiscovery() return; } -#if 0 /* just let the usual SDL_PumpEvents loop dispatch these. --ryan. defined(__WIN32__)*/ +#if defined(__WIN32__) +#if 0 /* just let the usual SDL_PumpEvents loop dispatch these, fixing bug 4286. --ryan. */ /* We'll only get messages on the same thread that created the window */ if (SDL_ThreadID() == SDL_HIDAPI_discovery.m_nThreadID) { MSG msg; @@ -319,6 +320,7 @@ HIDAPI_UpdateDiscovery() } } #endif +#endif /* __WIN32__ */ #if defined(__MACOSX__) if (SDL_HIDAPI_discovery.m_notificationPort) { From e381a1599dabb0a33971c378969265ac5c17e4ef Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 28 Oct 2018 10:31:06 -0700 Subject: [PATCH 137/151] Updated Android project files and documentation --- android-project/app/build.gradle | 10 ++---- android-project/app/jni/Application.mk | 5 +-- .../app/src/main/AndroidManifest.xml | 3 -- android-project/build.gradle | 4 ++- .../gradle/wrapper/gradle-wrapper.properties | 2 +- docs/README-android.md | 35 ++++++------------- 6 files changed, 19 insertions(+), 40 deletions(-) diff --git a/android-project/app/build.gradle b/android-project/app/build.gradle index 0e361bc13884d..3900943557762 100644 --- a/android-project/app/build.gradle +++ b/android-project/app/build.gradle @@ -9,7 +9,6 @@ else { android { compileSdkVersion 26 - buildToolsVersion "26.0.1" defaultConfig { if (buildAsApplication) { applicationId "org.libsdl.app" @@ -21,10 +20,9 @@ android { externalNativeBuild { ndkBuild { arguments "APP_PLATFORM=android-14" - abiFilters 'armeabi-v7a', 'x86' + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -61,9 +59,5 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testCompile 'junit:junit:4.12' + implementation fileTree(include: ['*.jar'], dir: 'libs') } diff --git a/android-project/app/jni/Application.mk b/android-project/app/jni/Application.mk index 246136dc69502..15b2a73cabfa2 100644 --- a/android-project/app/jni/Application.mk +++ b/android-project/app/jni/Application.mk @@ -1,7 +1,8 @@ # Uncomment this if you're using STL in your project -# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information -# APP_STL := stlport_static +# You can find more information here: +# https://developer.android.com/ndk/guides/cpp-support +# APP_STL := c++_shared APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 diff --git a/android-project/app/src/main/AndroidManifest.xml b/android-project/app/src/main/AndroidManifest.xml index 0099eb5d7cc40..25730cf39a475 100644 --- a/android-project/app/src/main/AndroidManifest.xml +++ b/android-project/app/src/main/AndroidManifest.xml @@ -8,9 +8,6 @@ android:versionName="1.0" android:installLocation="auto"> - - - diff --git a/android-project/build.gradle b/android-project/build.gradle index c2eea8e27fd12..f6f90b25b17cc 100644 --- a/android-project/build.gradle +++ b/android-project/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +16,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/android-project/gradle/wrapper/gradle-wrapper.properties b/android-project/gradle/wrapper/gradle-wrapper.properties index 6035d0e12adca..f9b3be2f9fbfc 100644 --- a/android-project/gradle/wrapper/gradle-wrapper.properties +++ b/android-project/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/docs/README-android.md b/docs/README-android.md index 9af88be02395c..0aa90e70b624a 100644 --- a/docs/README-android.md +++ b/docs/README-android.md @@ -77,18 +77,16 @@ For more complex projects, follow these instructions: and rename it to the name of your project. 2. Move or symlink this SDL directory into the "/app/jni" directory 3. Edit "/app/jni/src/Android.mk" to include your source files -4. Run 'ndk-build' (a script provided by the NDK). This compiles the C source -If you want to use Android Studio (recommended), skip to the Android Studio section below. +4a. If you want to use Android Studio, simply open your directory and start building. -5. Run './gradlew installDebug' in the project directory. This compiles the .java, creates an .apk with the native code embedded, and installs it on any connected Android device +4b. If you want to build manually, run './gradlew installDebug' in the project directory. This compiles the .java, creates an .apk with the native code embedded, and installs it on any connected Android device Here's an explanation of the files in the Android project, so you can customize them: android-project/app build.gradle - build info including the application version and SDK - src/main/AndroidManifest.xml - package manifest. Among others, it contains the class name - of the main Activity and the package name of the application. + src/main/AndroidManifest.xml - package manifest. Among others, it contains the class name of the main Activity and the package name of the application. jni/ - directory holding native code jni/Application.mk - Application JNI settings, including target platform and STL library jni/Android.mk - Android makefile that can call recursively the Android.mk files in all subdirectories @@ -216,26 +214,10 @@ detach it. You can use STL in your project by creating an Application.mk file in the jni folder and adding the following line: - APP_STL := stlport_static + APP_STL := c++_shared -For more information check out CPLUSPLUS-SUPPORT.html in the NDK documentation. - - -================================================================================ - Additional documentation -================================================================================ - -The documentation in the NDK docs directory is very helpful in understanding the -build process and how to work with native code on the Android platform. - -The best place to start is with docs/OVERVIEW.TXT - - -================================================================================ - Using Android Studio -================================================================================ - -You can open your project directory with Android Studio and run it normally. +For more information go here: + https://developer.android.com/ndk/guides/cpp-support ================================================================================ @@ -291,7 +273,10 @@ You can see the complete command line that ndk-build is using by passing V=1 on ndk-build V=1 -If your application crashes in native code, you can use addr2line to convert the +If your application crashes in native code, you can use ndk-stack to get a symbolic stack trace: + https://developer.android.com/ndk/guides/ndk-stack + +If you want to go through the process manually, you can use addr2line to convert the addresses in the stack trace to lines in your code. For example, if your crash looks like this: From df89abb23ef27c1e10eb5311a47bf81a640139bb Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 28 Oct 2018 14:17:21 -0700 Subject: [PATCH 138/151] Fixed bug 4335 - Android NDK build error dmuratshin LOCAL_SRC_FILES shouldn't use $(LOCAL_PATH) --- Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android.mk b/Android.mk index 3e480fe1c0db4..9ce879a111267 100644 --- a/Android.mk +++ b/Android.mk @@ -102,7 +102,7 @@ include $(CLEAR_VARS) LOCAL_CPPFLAGS += -std=c++11 -LOCAL_SRC_FILES := $(LOCAL_PATH)/src/hidapi/android/hid.cpp +LOCAL_SRC_FILES := src/hidapi/android/hid.cpp LOCAL_MODULE := libhidapi LOCAL_LDLIBS := -llog From 91820998fc8561b69de0464c58b7f740a9a24728 Mon Sep 17 00:00:00 2001 From: Micha? Janiszewski Date: Sun, 28 Oct 2018 21:36:48 +0100 Subject: [PATCH 139/151] Add and update include guards Include guards in most changed files were missing, I added them keeping the same style as other SDL files. In some cases I moved the include guards around to be the first thing the header has to take advantage of any possible improvements compiler may have for inclusion guards. --- src/SDL_assert_c.h | 5 +++++ src/audio/SDL_audiodev_c.h | 6 ++++++ src/core/linux/SDL_evdev_kbd.h | 5 +++++ src/events/SDL_events_c.h | 6 ++++++ src/events/scancodes_xfree86.h | 6 ++++++ src/haptic/SDL_haptic_c.h | 5 +++++ src/joystick/SDL_joystick_c.h | 6 ++++++ src/joystick/linux/SDL_sysjoystick_c.h | 5 +++++ src/joystick/steam/SDL_steamcontroller.h | 6 ++++++ src/libm/math_libm.h | 6 ++++++ src/render/SDL_yuv_sw_c.h | 6 ++++++ src/render/opengl/SDL_shaders_gl.h | 6 ++++++ src/render/software/SDL_blendfillrect.h | 6 ++++++ src/render/software/SDL_blendline.h | 6 ++++++ src/render/software/SDL_blendpoint.h | 6 ++++++ src/render/software/SDL_drawline.h | 6 ++++++ src/render/software/SDL_drawpoint.h | 6 ++++++ src/render/software/SDL_render_sw_c.h | 5 +++++ src/render/software/SDL_rotate.h | 4 ++++ src/sensor/SDL_sensor_c.h | 6 ++++++ src/sensor/SDL_syssensor.h | 6 ++++++ src/timer/SDL_timer_c.h | 6 ++++++ src/video/SDL_RLEaccel_c.h | 7 +++++++ src/video/SDL_blit_copy.h | 5 +++++ src/video/SDL_blit_slow.h | 6 ++++++ src/video/SDL_pixels_c.h | 6 ++++++ src/video/SDL_rect_c.h | 6 ++++++ src/video/SDL_yuv_c.h | 6 ++++++ src/video/dummy/SDL_nullevents_c.h | 6 ++++++ src/video/dummy/SDL_nullframebuffer_c.h | 6 ++++++ src/video/wayland/SDL_waylandtouch.h | 10 +++++----- src/video/x11/SDL_x11framebuffer.h | 6 ++++++ src/video/x11/SDL_x11messagebox.h | 5 +++++ 33 files changed, 189 insertions(+), 5 deletions(-) diff --git a/src/SDL_assert_c.h b/src/SDL_assert_c.h index aa690a308e1a7..93263d6a15705 100644 --- a/src/SDL_assert_c.h +++ b/src/SDL_assert_c.h @@ -19,6 +19,11 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_assert_c_h_ +#define SDL_assert_c_h_ + extern void SDL_AssertionsQuit(void); +#endif /* SDL_assert_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audiodev_c.h b/src/audio/SDL_audiodev_c.h index 15928d10a4d81..2d3b0eac91ad6 100644 --- a/src/audio/SDL_audiodev_c.h +++ b/src/audio/SDL_audiodev_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_audiodev_c_h_ +#define SDL_audiodev_c_h_ + #include "SDL.h" #include "../SDL_internal.h" #include "SDL_sysaudio.h" @@ -35,4 +39,6 @@ extern void SDL_EnumUnixAudioDevices(const int classic, int (*test)(int)); +#endif /* SDL_audiodev_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/linux/SDL_evdev_kbd.h b/src/core/linux/SDL_evdev_kbd.h index 831ba3ade6f99..5e51cdd17739c 100644 --- a/src/core/linux/SDL_evdev_kbd.h +++ b/src/core/linux/SDL_evdev_kbd.h @@ -19,6 +19,9 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_evdev_kbd_h_ +#define SDL_evdev_kbd_h_ + struct SDL_EVDEV_keyboard_state; typedef struct SDL_EVDEV_keyboard_state SDL_EVDEV_keyboard_state; @@ -26,4 +29,6 @@ extern SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void); extern void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down); extern void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state); +#endif /* SDL_evdev_kbd_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index 7f3ac6a86ce10..d9684b5fa958e 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_events_c_h_ +#define SDL_events_c_h_ + #include "../SDL_internal.h" /* Useful functions and variables from SDL_events.c */ @@ -49,4 +53,6 @@ extern void SDL_QuitQuit(void); extern void SDL_SendPendingQuit(void); +#endif /* SDL_events_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/scancodes_xfree86.h b/src/events/scancodes_xfree86.h index 7d1f844b0b998..6e65507f61114 100644 --- a/src/events/scancodes_xfree86.h +++ b/src/events/scancodes_xfree86.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef scancodes_xfree86_h_ +#define scancodes_xfree86_h_ + #include "../../include/SDL_scancode.h" /* XFree86 key code to SDL scancode mapping table @@ -503,4 +507,6 @@ static const SDL_Scancode xvnc_scancode_table[] = { /* 80 */ SDL_SCANCODE_F12, }; +#endif /* scancodes_xfree86_h_ */ + /* *INDENT-ON* */ diff --git a/src/haptic/SDL_haptic_c.h b/src/haptic/SDL_haptic_c.h index 26d900d441fb4..390dc7854d4d3 100644 --- a/src/haptic/SDL_haptic_c.h +++ b/src/haptic/SDL_haptic_c.h @@ -19,7 +19,12 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_haptic_c_h_ +#define SDL_haptic_c_h_ + extern int SDL_HapticInit(void); extern void SDL_HapticQuit(void); +#endif /* SDL_haptic_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index 1ede4a15964f4..900d5904c9a01 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_joystick_c_h_ +#define SDL_joystick_c_h_ + #include "../SDL_internal.h" /* Useful functions and variables from SDL_joystick.c */ @@ -97,4 +101,6 @@ extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, /* Internal sanity checking functions */ extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick); +#endif /* SDL_joystick_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/linux/SDL_sysjoystick_c.h b/src/joystick/linux/SDL_sysjoystick_c.h index 617e3200dec40..83d593760ba9d 100644 --- a/src/joystick/linux/SDL_sysjoystick_c.h +++ b/src/joystick/linux/SDL_sysjoystick_c.h @@ -19,6 +19,9 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_sysjoystick_c_h_ +#define SDL_sysjoystick_c_h_ + #include struct SDL_joylist_item; @@ -61,4 +64,6 @@ struct joystick_hwdata SDL_bool m_bSteamController; }; +#endif /* SDL_sysjoystick_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/steam/SDL_steamcontroller.h b/src/joystick/steam/SDL_steamcontroller.h index ce37b4de5ce14..81b8879736dae 100644 --- a/src/joystick/steam/SDL_steamcontroller.h +++ b/src/joystick/steam/SDL_steamcontroller.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_steamcontroller_h_ +#define SDL_steamcontroller_h_ + #include "../../SDL_internal.h" typedef SDL_bool (*SteamControllerConnectedCallback_t)(const char *name, SDL_JoystickGUID guid, int *device_instance); @@ -30,4 +34,6 @@ void SDL_UpdateSteamControllers(void); void SDL_UpdateSteamController(SDL_Joystick *joystick); void SDL_QuitSteamControllers(void); +#endif /* SDL_steamcontroller_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/libm/math_libm.h b/src/libm/math_libm.h index 67f8c6a7918c3..3c751c5ed7532 100644 --- a/src/libm/math_libm.h +++ b/src/libm/math_libm.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef math_libm_h_ +#define math_libm_h_ + #include "../SDL_internal.h" /* Math routines from uClibc: http://www.uclibc.org */ @@ -38,4 +42,6 @@ double SDL_uclibc_sin(double x); double SDL_uclibc_sqrt(double x); double SDL_uclibc_tan(double x); +#endif /* math_libm_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_yuv_sw_c.h b/src/render/SDL_yuv_sw_c.h index 0dfb5db7f843a..34322f24c2959 100644 --- a/src/render/SDL_yuv_sw_c.h +++ b/src/render/SDL_yuv_sw_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_yuv_sw_c_h_ +#define SDL_yuv_sw_c_h_ + #include "../SDL_internal.h" #include "SDL_video.h" @@ -64,4 +68,6 @@ void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata); #define USE_MMX_ASSEMBLY 1 #endif +#endif /* SDL_yuv_sw_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/opengl/SDL_shaders_gl.h b/src/render/opengl/SDL_shaders_gl.h index 9805c599cc44c..36975214d91f4 100644 --- a/src/render/opengl/SDL_shaders_gl.h +++ b/src/render/opengl/SDL_shaders_gl.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_shaders_gl_h_ +#define SDL_shaders_gl_h_ + #include "../../SDL_internal.h" /* OpenGL shader implementation */ @@ -44,4 +48,6 @@ extern GL_ShaderContext * GL_CreateShaderContext(void); extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader); extern void GL_DestroyShaderContext(GL_ShaderContext *ctx); +#endif /* SDL_shaders_gl_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_blendfillrect.h b/src/render/software/SDL_blendfillrect.h index 262210f774e16..3cac834549a0e 100644 --- a/src/render/software/SDL_blendfillrect.h +++ b/src/render/software/SDL_blendfillrect.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendfillrect_h_ +#define SDL_blendfillrect_h_ + #include "../../SDL_internal.h" extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendfillrect_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_blendline.h b/src/render/software/SDL_blendline.h index 82072cb005274..a48a4984ea656 100644 --- a/src/render/software/SDL_blendline.h +++ b/src/render/software/SDL_blendline.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendline_h_ +#define SDL_blendline_h_ + #include "../../SDL_internal.h" extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendline_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_blendpoint.h b/src/render/software/SDL_blendpoint.h index dd9e49c1c772b..188557cea5c3c 100644 --- a/src/render/software/SDL_blendpoint.h +++ b/src/render/software/SDL_blendpoint.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendpoint_h_ +#define SDL_blendpoint_h_ + #include "../../SDL_internal.h" extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendpoint_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_drawline.h b/src/render/software/SDL_drawline.h index 9395d5050b869..4e8e2bd459218 100644 --- a/src/render/software/SDL_drawline.h +++ b/src/render/software/SDL_drawline.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_drawline_h_ +#define SDL_drawline_h_ + #include "../../SDL_internal.h" extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); +#endif /* SDL_drawline_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_drawpoint.h b/src/render/software/SDL_drawpoint.h index c36670007c21a..454774d068e64 100644 --- a/src/render/software/SDL_drawpoint.h +++ b/src/render/software/SDL_drawpoint.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_drawpoint_h_ +#define SDL_drawpoint_h_ + #include "../../SDL_internal.h" extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); +#endif /* SDL_drawpoint_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_render_sw_c.h b/src/render/software/SDL_render_sw_c.h index 8f065de7fd027..f228517c5b86f 100644 --- a/src/render/software/SDL_render_sw_c.h +++ b/src/render/software/SDL_render_sw_c.h @@ -19,6 +19,11 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_render_sw_c_h_ +#define SDL_render_sw_c_h_ + extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface); +#endif /* SDL_render_sw_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_rotate.h b/src/render/software/SDL_rotate.h index 2bf2ea82e349a..54c0927a1a645 100644 --- a/src/render/software/SDL_rotate.h +++ b/src/render/software/SDL_rotate.h @@ -19,6 +19,9 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_rotate_h_ +#define SDL_rotate_h_ + #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif @@ -26,3 +29,4 @@ extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle); extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle); +#endif /* SDL_rotate_h_ */ diff --git a/src/sensor/SDL_sensor_c.h b/src/sensor/SDL_sensor_c.h index eb2c99972671b..70974af5969f2 100644 --- a/src/sensor/SDL_sensor_c.h +++ b/src/sensor/SDL_sensor_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_sensor_c_h_ +#define SDL_sensor_c_h_ + #include "SDL_config.h" struct _SDL_SensorDriver; @@ -35,4 +39,6 @@ extern void SDL_SensorQuit(void); /* Internal event queueing functions */ extern int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values); +#endif /* SDL_sensor_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/sensor/SDL_syssensor.h b/src/sensor/SDL_syssensor.h index f10aee3ecdbad..210577a9d37ac 100644 --- a/src/sensor/SDL_syssensor.h +++ b/src/sensor/SDL_syssensor.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_syssensor_c_h_ +#define SDL_syssensor_c_h_ + #include "SDL_config.h" /* This is the system specific header for the SDL sensor API */ @@ -96,4 +100,6 @@ extern SDL_SensorDriver SDL_ANDROID_SensorDriver; extern SDL_SensorDriver SDL_COREMOTION_SensorDriver; extern SDL_SensorDriver SDL_DUMMY_SensorDriver; +#endif /* SDL_syssensor_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_timer_c.h b/src/timer/SDL_timer_c.h index f83bdded0d564..3ea350ffbd6cc 100644 --- a/src/timer/SDL_timer_c.h +++ b/src/timer/SDL_timer_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_timer_c_h_ +#define SDL_timer_c_h_ + #include "../SDL_internal.h" /* Useful functions and variables from SDL_timer.c */ @@ -31,4 +35,6 @@ extern void SDL_TicksQuit(void); extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); +#endif /* SDL_timer_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_RLEaccel_c.h b/src/video/SDL_RLEaccel_c.h index fe418358b4e00..b6fa6a11eb2db 100644 --- a/src/video/SDL_RLEaccel_c.h +++ b/src/video/SDL_RLEaccel_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_RLEaccel_c_h_ +#define SDL_RLEaccel_c_h_ + #include "../SDL_internal.h" /* Useful functions and variables from SDL_RLEaccel.c */ @@ -28,4 +32,7 @@ extern int SDLCALL SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect, extern int SDLCALL SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect); extern void SDL_UnRLESurface(SDL_Surface * surface, int recode); + +#endif /* SDL_RLEaccel_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_copy.h b/src/video/SDL_blit_copy.h index 46651791ee5d3..d569ae00ca49e 100644 --- a/src/video/SDL_blit_copy.h +++ b/src/video/SDL_blit_copy.h @@ -19,6 +19,11 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_blit_copy_h_ +#define SDL_blit_copy_h_ + void SDL_BlitCopy(SDL_BlitInfo * info); +#endif /* SDL_blit_copy_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_slow.h b/src/video/SDL_blit_slow.h index 02d360a6e96b6..d27fcd275f6b8 100644 --- a/src/video/SDL_blit_slow.h +++ b/src/video/SDL_blit_slow.h @@ -18,8 +18,14 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blit_slow_h_ +#define SDL_blit_slow_h_ + #include "../SDL_internal.h" extern void SDL_Blit_Slow(SDL_BlitInfo * info); +#endif /* SDL_blit_slow_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h index 900f0b080ce35..c84e155f1f51c 100644 --- a/src/video/SDL_pixels_c.h +++ b/src/video/SDL_pixels_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_pixels_c_h_ +#define SDL_pixels_c_h_ + #include "../SDL_internal.h" /* Useful functions and variables from SDL_pixel.c */ @@ -37,4 +41,6 @@ extern void SDL_FreeBlitMap(SDL_BlitMap * map); extern void SDL_DitherColors(SDL_Color * colors, int bpp); extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_pixels_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_rect_c.h b/src/video/SDL_rect_c.h index d67e49348029d..56d6f2e07a760 100644 --- a/src/video/SDL_rect_c.h +++ b/src/video/SDL_rect_c.h @@ -18,8 +18,14 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_rect_c_h_ +#define SDL_rect_c_h_ + #include "../SDL_internal.h" extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span); +#endif /* SDL_rect_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuv_c.h b/src/video/SDL_yuv_c.h index 6fe02b0fceb03..192bd2c571751 100644 --- a/src/video/SDL_yuv_c.h +++ b/src/video/SDL_yuv_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_yuv_c_h_ +#define SDL_yuv_c_h_ + #include "../SDL_internal.h" @@ -27,4 +31,6 @@ extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch); extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch); +#endif /* SDL_yuv_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/dummy/SDL_nullevents_c.h b/src/video/dummy/SDL_nullevents_c.h index a5636be5357c8..454d39401f37b 100644 --- a/src/video/dummy/SDL_nullevents_c.h +++ b/src/video/dummy/SDL_nullevents_c.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_nullevents_c_h_ +#define SDL_nullevents_c_h_ + #include "../../SDL_internal.h" #include "SDL_nullvideo.h" extern void DUMMY_PumpEvents(_THIS); +#endif /* SDL_nullevents_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/dummy/SDL_nullframebuffer_c.h b/src/video/dummy/SDL_nullframebuffer_c.h index 5d6b7aed50fe6..b7d0c633fc7fc 100644 --- a/src/video/dummy/SDL_nullframebuffer_c.h +++ b/src/video/dummy/SDL_nullframebuffer_c.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_nullframebuffer_c_h_ +#define SDL_nullframebuffer_c_h_ + #include "../../SDL_internal.h" extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window); +#endif /* SDL_nullframebuffer_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/wayland/SDL_waylandtouch.h b/src/video/wayland/SDL_waylandtouch.h index 9efc5a54a822f..eba0da80d6330 100644 --- a/src/video/wayland/SDL_waylandtouch.h +++ b/src/video/wayland/SDL_waylandtouch.h @@ -19,13 +19,13 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_waylandtouch_h_ +#define SDL_waylandtouch_h_ + #include "../../SDL_internal.h" #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH -#ifndef SDL_waylandtouch_h_ -#define SDL_waylandtouch_h_ - #include "SDL_waylandvideo.h" #include #include @@ -347,6 +347,6 @@ qt_windowmanager_open_url(struct qt_windowmanager *qt_windowmanager, uint32_t re QT_WINDOWMANAGER_OPEN_URL, remaining, url); } -#endif /* SDL_waylandtouch_h_ */ - #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +#endif /* SDL_waylandtouch_h_ */ diff --git a/src/video/x11/SDL_x11framebuffer.h b/src/video/x11/SDL_x11framebuffer.h index 61bb0c55cf2f8..6a3178869b38e 100644 --- a/src/video/x11/SDL_x11framebuffer.h +++ b/src/video/x11/SDL_x11framebuffer.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_x11framebuffer_h_ +#define SDL_x11framebuffer_h_ + #include "../../SDL_internal.h" @@ -28,4 +32,6 @@ extern int X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window); +#endif /* SDL_x11framebuffer_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/x11/SDL_x11messagebox.h b/src/video/x11/SDL_x11messagebox.h index cab407b2d1986..6515983fa56ef 100644 --- a/src/video/x11/SDL_x11messagebox.h +++ b/src/video/x11/SDL_x11messagebox.h @@ -19,10 +19,15 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_x11messagebox_h_ +#define SDL_x11messagebox_h_ + #if SDL_VIDEO_DRIVER_X11 extern int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid); #endif /* SDL_VIDEO_DRIVER_X11 */ +#endif /* SDL_x11messagebox_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ From b43f427fa660d4c1f7da57bad49cc85adc0854b0 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 29 Oct 2018 15:51:38 -0400 Subject: [PATCH 140/151] README-ios: added a note about enabling hidapi. --- docs/README-ios.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/README-ios.md b/docs/README-ios.md index bf34fe482f752..445524f5b81ee 100644 --- a/docs/README-ios.md +++ b/docs/README-ios.md @@ -228,6 +228,22 @@ Textures: Loading Shared Objects: This is disabled by default since it seems to break the terms of the iOS SDK agreement for iOS versions prior to iOS 8. It can be re-enabled in SDL_config_iphoneos.h. +============================================================================== +Notes -- CoreBluetooth.framework +============================================================================== + +SDL_JOYSTICK_HIDAPI is disabled by default. It can give you access to a lot +more game controller devices, but it requires permission from the user before +your app will be able to talk to the Bluetooth hardware. "Made For iOS" +branded controllers do not need this as we don't have to speak to them +directly with raw bluetooth, so many apps can live without this. + +You'll need to link with CoreBluetooth.framework and add something like this +to your Info.plist: + +NSBluetoothPeripheralUsageDescription +MyApp would like to remain connected to nearby bluetooth Game Controllers and Game Pads even when you're not using the app. + ============================================================================== Game Center ============================================================================== From f434a98c26b5cd2ad67a4f4ae67065cf4a6b8299 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 29 Oct 2018 20:00:03 -0400 Subject: [PATCH 141/151] winmain: Don't use SDL_malloc (or SDL_stack_alloc, which might be malloc). Otherwise, we are using the allocator before the app can set up its own hooks. Now we use VirtualAlloc, and WideCharToMultiByte (because SDL_iconv uses SDL_malloc, too!) to get ready to call into SDL_main. This also makes console_wmain() call into the same routines as everything else, so we don't have to deal with those allocations, too. Hopefully we end up with the same results from GetCommandLine() as we do in wargv. Fixes Bugzilla #4340. --- src/main/windows/SDL_windows_main.c | 81 +++++++++++++++-------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/main/windows/SDL_windows_main.c b/src/main/windows/SDL_windows_main.c index 5e643a44b5427..039503224b32b 100644 --- a/src/main/windows/SDL_windows_main.c +++ b/src/main/windows/SDL_windows_main.c @@ -116,50 +116,65 @@ OutOfMemory(void) # endif #endif -/* WinMain, main, and wmain eventually call into here. */ -static int -main_utf8(int argc, char *argv[]) -{ - SDL_SetMainReady(); - - /* Run the application main() code */ - return SDL_main(argc, argv); -} - /* Gets the arguments with GetCommandLine, converts them to argc and argv - and calls main_utf8 */ + and calls SDL_main */ static int main_getcmdline() { char **argv; int argc; - char *cmdline; + char *cmdline = NULL; int retval = 0; + int cmdalloc = 0; + const TCHAR *text = GetCommandLine(); + const TCHAR *ptr; + int argc_guess = 2; /* space for NULL and initial argument. */ + int rc; + + /* make a rough guess of command line arguments. Overestimates if there + are quoted things. */ + for (ptr = text; *ptr; ptr++) { + if ((*ptr == ' ') || (*ptr == '\t')) { + argc_guess++; + } + } - /* Grab the command line */ - TCHAR *text = GetCommandLine(); #if UNICODE - cmdline = WIN_StringToUTF8(text); + rc = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL); + if (rc > 0) { + cmdalloc = rc + (sizeof (char *) * argc_guess); + argv = (char **) VirtualAlloc(NULL, cmdalloc, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + if (argv) { + cmdline = (char *) (argv + argc_guess); + const int rc2 = WideCharToMultiByte(CP_UTF8, 0, text, -1, cmdline, rc, NULL, NULL); + SDL_assert(rc2 == rc); + } + } #else /* !!! FIXME: are these in the system codepage? We need to convert to UTF-8. */ - cmdline = SDL_strdup(text); + rc = ((int) SDL_strlen(text)) + 1; + cmdalloc = rc + (sizeof (char *) * argc_guess); + argv = (char **) VirtualAlloc(NULL, cmdalloc, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + if (argv) { + cmdline = (char *) (argv + argc_guess); + SDL_strcpy(cmdline, text); + } #endif if (cmdline == NULL) { return OutOfMemory(); } /* Parse it into argv and argc */ - argc = ParseCommandLine(cmdline, NULL); - argv = SDL_stack_alloc(char *, argc + 1); - if (argv == NULL) { - return OutOfMemory(); - } - ParseCommandLine(cmdline, argv); + SDL_assert(ParseCommandLine(cmdline, NULL) <= argc_guess); + argc = ParseCommandLine(cmdline, argv); - retval = main_utf8(argc, argv); + SDL_SetMainReady(); - SDL_stack_free(argv); - SDL_free(cmdline); + /* Run the application main() code */ + retval = SDL_main(argc, argv); + + VirtualFree(argv, cmdalloc, MEM_DECOMMIT); + VirtualFree(argv, 0, MEM_RELEASE); return retval; } @@ -177,21 +192,7 @@ console_ansi_main(int argc, char *argv[]) int console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp) { - int retval = 0; - char **argv = SDL_stack_alloc(char*, argc + 1); - int i; - - for (i = 0; i < argc; ++i) { - argv[i] = WIN_StringToUTF8(wargv[i]); - } - argv[argc] = NULL; - - retval = main_utf8(argc, argv); - - /* !!! FIXME: we are leaking all the elements of argv we allocated. */ - SDL_stack_free(argv); - - return retval; + return main_getcmdline(); } #endif From e542d1a36d6c5883ab0afbfc82f342588faf1615 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 29 Oct 2018 20:18:50 -0400 Subject: [PATCH 142/151] winmain: Patched to compile on C89 compilers. --- src/main/windows/SDL_windows_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/windows/SDL_windows_main.c b/src/main/windows/SDL_windows_main.c index 039503224b32b..32f672760e50c 100644 --- a/src/main/windows/SDL_windows_main.c +++ b/src/main/windows/SDL_windows_main.c @@ -145,8 +145,9 @@ main_getcmdline() cmdalloc = rc + (sizeof (char *) * argc_guess); argv = (char **) VirtualAlloc(NULL, cmdalloc, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); if (argv) { + int rc2; cmdline = (char *) (argv + argc_guess); - const int rc2 = WideCharToMultiByte(CP_UTF8, 0, text, -1, cmdline, rc, NULL, NULL); + rc2 = WideCharToMultiByte(CP_UTF8, 0, text, -1, cmdline, rc, NULL, NULL); SDL_assert(rc2 == rc); } } From 950f39e23b76cc54e33810aa20dcc35132ff9269 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 29 Oct 2018 19:58:59 -0700 Subject: [PATCH 143/151] Backed out changeset 2944045e695b, SDL_JOYSTICK_HIDAPI is only used on iOS for Steam Controller support, which is not publicly available. --- docs/README-ios.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/README-ios.md b/docs/README-ios.md index 445524f5b81ee..bf34fe482f752 100644 --- a/docs/README-ios.md +++ b/docs/README-ios.md @@ -228,22 +228,6 @@ Textures: Loading Shared Objects: This is disabled by default since it seems to break the terms of the iOS SDK agreement for iOS versions prior to iOS 8. It can be re-enabled in SDL_config_iphoneos.h. -============================================================================== -Notes -- CoreBluetooth.framework -============================================================================== - -SDL_JOYSTICK_HIDAPI is disabled by default. It can give you access to a lot -more game controller devices, but it requires permission from the user before -your app will be able to talk to the Bluetooth hardware. "Made For iOS" -branded controllers do not need this as we don't have to speak to them -directly with raw bluetooth, so many apps can live without this. - -You'll need to link with CoreBluetooth.framework and add something like this -to your Info.plist: - -NSBluetoothPeripheralUsageDescription -MyApp would like to remain connected to nearby bluetooth Game Controllers and Game Pads even when you're not using the app. - ============================================================================== Game Center ============================================================================== From da56cefa8bcaf4a33b33f4299921098278250867 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 30 Oct 2018 07:00:03 -0700 Subject: [PATCH 144/151] Fixed bug 4188 - Software renderer SDL_RenderCopyEx blits corrupt image under certain cases Sylvain Re-opening this issue. It fixes the test-case, but it introduces a regression with another bug (bug #4313). So here's a new patch that activate cropping of the source surface to solve the issue. It also reverts the wrong changeset. It prevents unneeded colorkey error message. --- src/render/software/SDL_render_sw.c | 5 +++++ src/render/software/SDL_rotate.c | 27 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 0c14cac5adcbb..709dfe8e48897 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -657,6 +657,11 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, blitRequired = SDL_TRUE; } + /* srcrect is not selecting the whole src surface, so cropping is needed */ + if (!(srcrect->w == src->w && srcrect->h == src->h && srcrect->x == 0 && srcrect->y == 0)) { + blitRequired = SDL_TRUE; + } + /* The color and alpha modulation has to be applied before the rotation when using the NONE and MOD blend modes. */ if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD) && (alphaMod & rMod & gMod & bMod) != 255) { applyModulation = SDL_TRUE; diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index 43811ef908555..09e099c391fee 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -83,7 +83,9 @@ static Uint32 _colorkey(SDL_Surface *src) { Uint32 key = 0; - SDL_GetColorKey(src, &key); + if (SDL_HasColorKey(src)) { + SDL_GetColorKey(src, &key); + } return key; } @@ -150,17 +152,17 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */ static void computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy, - int *sincx, int *sincy, int *signx, int *signy, SDL_Surface *dst) + int *sincx, int *sincy, int *signx, int *signy) { int pitch = flipy ? -src->pitch : src->pitch; if (flipx) { bpp = -bpp; } switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - case 0: *sincx = bpp; *sincy = pitch - dst->w * *sincx; *signx = *signy = 1; break; - case 1: *sincx = -pitch; *sincy = bpp - *sincx * dst->h; *signx = 1; *signy = -1; break; - case 2: *sincx = -bpp; *sincy = -dst->w * *sincx - pitch; *signx = *signy = -1; break; - case 3: default: *sincx = pitch; *sincy = -*sincx * dst->h - bpp; *signx = -1; *signy = 1; break; + case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break; + case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break; + case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break; + case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break; } if (flipx) { *signx = -*signx; @@ -175,9 +177,10 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \ Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \ \ - computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy, dst); \ - if (signx < 0) sp += (dst->w-1)*sizeof(pixelType); \ - if (signy < 0) sp += (dst->h-1)*src->pitch; \ + computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \ + if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \ + if (signy < 0) sp += (src->h-1)*src->pitch; \ + \ for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \ if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \ SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \ @@ -423,8 +426,10 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, if (src == NULL) return NULL; - if (SDL_GetColorKey(src, &colorkey) == 0) { - colorKeyAvailable = SDL_TRUE; + if (SDL_HasColorKey(src)) { + if (SDL_GetColorKey(src, &colorkey) == 0) { + colorKeyAvailable = SDL_TRUE; + } } /* This function requires a 32-bit surface or 8-bit surface with a colorkey */ From c49ecf6f7c10b668ebd87b89dfc3c7bfd215cb75 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 30 Oct 2018 20:11:02 +0300 Subject: [PATCH 145/151] rename os2 makefile so that 'make dist' catches it; update it a bit. --- OWMakefile.os2 => Makefile.os2 | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) rename OWMakefile.os2 => Makefile.os2 (74%) diff --git a/OWMakefile.os2 b/Makefile.os2 similarity index 74% rename from OWMakefile.os2 rename to Makefile.os2 index e709835eb03b7..95c5cef591c06 100644 --- a/OWMakefile.os2 +++ b/Makefile.os2 @@ -1,14 +1,22 @@ -# Open Watcom Makefile to build a minimal OS/2 SDL2.dll +# Open Watcom makefile to build SDL2.dll for OS/2: +# wmake -f Makefile.os2 -DLLFILE = SDL2.dll -IMPLIB = SDL2.lib -MAPFILE = SDL2.map -EXPFILE = SDL2.exp -LNKFILE = SDL2.lnk +LIBNAME = SDL2 +VERSION = 2.0.9 +DESCRIPTION = Simple DirectMedia Layer 2 + +LIBHOME = . +LIBPATH = $(LIBHOME)/lib +DLLFILE = $(LIBHOME)/$(LIBNAME).dll +LIBFILE = $(LIBHOME)/$(LIBNAME).lib +LNKFILE = $(LIBNAME).lnk INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" +INCPATH+= -I"$(LIBHOME)/h" INCPATH+= -Iinclude +LIBS = mmpm2.lib libuls.lib libconv.lib + CFLAGS = -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei # max warnings: CFLAGS+= -wx @@ -52,14 +60,18 @@ OBJS = $(SRCS:.c=.obj) .extensions: .extensions: .lib .dll .obj .c .asm -.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; +.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk; +.c: ./src/haptic/dummy;./src/joystick/dummy;./src/audio/dummy;./src/video/dummy;./src/sensor/dummy; +.c: ./src/loadso/dummy;./src/filesystem/dummy;./src/timer/dummy;./src/thread/generic; all: $(DLLFILE) $(LIBFILE) .symbolic $(DLLFILE): $(OBJS) $(LNKFILE) + @echo * Linking: $@ wlink @$(LNKFILE) -$(IMPLIB): $(DLLFILE) +$(LIBFILE): $(DLLFILE) + @echo * Creating LIB file: $@ wlib -q -b -n -c -pa -s -t -zld -ii -io $* $(DLLFILE) .c.obj: @@ -84,13 +96,17 @@ SDL_RLEaccel.obj: SDL_RLEaccel.c wcc386 $(CFLAGS) -wcd=201 -fo=$^@ $< $(LNKFILE): + @echo * Creating linker file: $@ @%create $@ @%append $@ SYSTEM os2v2_dll INITINSTANCE TERMINSTANCE @%append $@ NAME $(DLLFILE) @for %i in ($(OBJS)) do @%append $@ FILE %i + @%append $@ LIBPATH $(%LIB);$(LIBPATH) + @for %i in ($(LIBS)) do @%append $@ LIB %i @%append $@ OPTION QUIET - @%append $@ OPTION IMPF=$(EXPFILE) - @%append $@ OPTION MAP=$(MAPFILE) + @%append $@ OPTION IMPF=$(LIBHOME)/$^&.exp + @%append $@ OPTION MAP=$(LIBHOME)/$^&.map + @%append $@ OPTION DESCRIPTION '@$#libsdl org:$(VERSION)$#@$(DESCRIPTION)' @%append $@ OPTION QUIET @%append $@ OPTION ELIMINATE @%append $@ OPTION MANYAUTODATA @@ -104,7 +120,7 @@ clean: .SYMBOLIC @if exist $(LNKFILE) rm $(LNKFILE) distclean: .SYMBOLIC clean - @if exist $(MAPFILE) rm $(MAPFILE) - @if exist $(EXPFILE) rm $(EXPFILE) - @if exist $(IMPLIB) rm $(IMPLIB) + @if exist $(LIBHOME)/*.exp rm $(LIBHOME)/*.exp + @if exist $(LIBHOME)/*.map rm $(LIBHOME)/*.map + @if exist $(LIBFILE) rm $(LIBFILE) @if exist $(DLLFILE) rm $(DLLFILE) From 6c029f127d2238c01f800e59e22debc92396371f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 31 Oct 2018 10:18:05 -0700 Subject: [PATCH 146/151] Added tag release-2.0.9 for changeset c75013b56028 From 9af581bd75cae989dd300832feabc2396abc3e40 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 31 Oct 2018 15:01:20 -0700 Subject: [PATCH 147/151] Fixed bug 4347 - Keyboard LEDs don't work on linux console Rainer Sabelka When using SLD2 on a Linux console with the KMS/DRM video backend and Linux evdev keyboard support, the caps lock, scroll lock, and num lock leds do not work. The attached patch adds ioctls for setting the LED state in SDL_evdev_kbd.c --- src/core/linux/SDL_evdev_kbd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index 00a3a54d619bc..02cbc8dcc235d 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -510,17 +510,19 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - return ((kbd->ledflagstate >> flag) & 1); + return (kbd->ledflagstate & flag) != 0; } static void set_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate |= 1 << flag; + kbd->ledflagstate |= flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); } static void clr_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate &= ~(1 << flag); + kbd->ledflagstate &= ~flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); } static void chg_vc_kbd_lock(SDL_EVDEV_keyboard_state *kbd, int flag) @@ -535,7 +537,8 @@ static void chg_vc_kbd_slock(SDL_EVDEV_keyboard_state *kbd, int flag) static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { - kbd->ledflagstate ^= 1 << flag; + kbd->ledflagstate ^= flag; + ioctl(kbd->console_fd, KDSETLED, (unsigned long)(kbd->ledflagstate)); } /* From aeee424f656f164660f8f91d3b0af51d3d294b59 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 31 Oct 2018 15:16:51 -0700 Subject: [PATCH 148/151] Fixed bug 4349 - SDL_CreateWindow fails with KMS/DRM after upgrading Mesa to 18.2.3 Rainer Sabelka After I did an upgrade of my arch Linux installation (resulting in an update of Mesa to version 18.2.3), all my SDL2 applications which use the KMS/DRM driver stopped working. Reason: Creating a Window with SDL_CreateWindow failed because the call to EGL eglCreateWindowSurface() returns an error "EGL_BAD_MATCH". After investigating with the debugger I figured, that the configuration, which has been selected from the output of eglChooseConfig(), has an "EGL_NATIVE_VISUAL_ID" which does not match the "format" of the underlying gbm surface. The attached patch fixes the problem. It does so, by mimicking Weston's behavior. All configurations returned from eglChooseConfig() which have an visual_id different from the gbm format are discarded, and only from the remaining ones the "best" match is selected. --- src/video/SDL_egl.c | 22 ++++++++++++++++------ src/video/SDL_egl_c.h | 2 ++ src/video/kmsdrm/SDL_kmsdrmvideo.c | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 78abc030efe33..dfaf28eb9e9ea 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -449,6 +449,12 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa return 0; } +void +SDL_EGL_SetRequiredVisualId(_THIS, int visual_id) +{ + _this->egl_data->egl_required_visual_id=visual_id; +} + #ifdef DUMP_EGL_CONFIG #define ATTRIBUTE(_attr) { _attr, #_attr } @@ -513,14 +519,8 @@ SDL_EGL_ChooseConfig(_THIS) /* 64 seems nice. */ EGLint attribs[64]; EGLint found_configs = 0, value; -#ifdef SDL_VIDEO_DRIVER_KMSDRM - /* Intel EGL on KMS/DRM (al least) returns invalid configs that confuse the bitdiff search used */ - /* later in this function, so we simply use the first one when using the KMSDRM driver for now. */ - EGLConfig configs[1]; -#else /* 128 seems even nicer here */ EGLConfig configs[128]; -#endif int i, j, best_bitdiff = -1, bitdiff; if (!_this->egl_data) { @@ -603,6 +603,16 @@ SDL_EGL_ChooseConfig(_THIS) /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */ for (i = 0; i < found_configs; i++ ) { + if (_this->egl_data->egl_required_visual_id) + { + EGLint format; + _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, + configs[i], + EGL_NATIVE_VISUAL_ID, &format); + if (_this->egl_data->egl_required_visual_id != format) + continue; + } + bitdiff = 0; for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) { if (attribs[j] == EGL_NONE) { diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h index d1c41297c3ff4..9f7371f49b8c9 100644 --- a/src/video/SDL_egl_c.h +++ b/src/video/SDL_egl_c.h @@ -37,6 +37,7 @@ typedef struct SDL_EGL_VideoData int egl_swapinterval; int egl_surfacetype; int egl_version_major, egl_version_minor; + EGLint egl_required_visual_id; EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display); EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplay) (EGLenum platform, @@ -102,6 +103,7 @@ extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value); extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display, EGLenum platform); extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc); extern void SDL_EGL_UnloadLibrary(_THIS); +extern void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id); extern int SDL_EGL_ChooseConfig(_THIS); extern int SDL_EGL_SetSwapInterval(_THIS, int interval); extern int SDL_EGL_GetSwapInterval(_THIS); diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index bacbe0c1e04d0..1d53ee94a8b7e 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -587,6 +587,7 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) goto error; } } + SDL_EGL_SetRequiredVisualId(_this, surface_fmt); wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wdata->gs); if (wdata->egl_surface == EGL_NO_SURFACE) { From 329f2eb99edc16e85dd592d8278ed198916f0ffe Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 31 Oct 2018 20:17:53 -0700 Subject: [PATCH 149/151] Fix crash when GL_LoadFunctions()/GLES2_LoadFunctions() fails https://bugzilla.libsdl.org/show_bug.cgi?id=4350 We can't safely call GL_DestroyRenderer() until GL_LoadFunctions() succeeds because we will be missing functions that we try to use when activating the renderer for destruction if we have an GL context. --- src/render/opengl/SDL_render_gl.c | 13 +++++++++---- src/render/opengles2/SDL_render_gles2.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index f3e8326ac6b71..09db12de80f34 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -420,7 +420,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { - GL_DestroyRenderer(renderer); + SDL_free(renderer); SDL_OutOfMemory(); goto error; } @@ -455,16 +455,21 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) data->context = SDL_GL_CreateContext(window); if (!data->context) { - GL_DestroyRenderer(renderer); + SDL_free(renderer); + SDL_free(data); goto error; } if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GL_DestroyRenderer(renderer); + SDL_GL_DeleteContext(data->context); + SDL_free(renderer); + SDL_free(data); goto error; } if (GL_LoadFunctions(data) < 0) { - GL_DestroyRenderer(renderer); + SDL_GL_DeleteContext(data->context); + SDL_free(renderer); + SDL_free(data); goto error; } diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index fe51b9aaf6a16..f21a9576251f5 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -2122,7 +2122,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) data = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext)); if (!data) { - GLES2_DestroyRenderer(renderer); + SDL_free(renderer); SDL_OutOfMemory(); goto error; } @@ -2134,16 +2134,21 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) /* Create an OpenGL ES 2.0 context */ data->context = SDL_GL_CreateContext(window); if (!data->context) { - GLES2_DestroyRenderer(renderer); + SDL_free(renderer); + SDL_free(data); goto error; } if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GLES2_DestroyRenderer(renderer); + SDL_GL_DeleteContext(data->context); + SDL_free(renderer); + SDL_free(data); goto error; } if (GLES2_LoadFunctions(data) < 0) { - GLES2_DestroyRenderer(renderer); + SDL_GL_DeleteContext(data->context); + SDL_free(renderer); + SDL_free(data); goto error; } From d42728ec10c1082c368cb570cfc475b26c55134b Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 1 Nov 2018 12:35:00 +0300 Subject: [PATCH 150/151] fix NetBSD C90 build failure src/vendor/SDL2/src/joystick/bsd/SDL_sysjoystick.c:353:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement] reported by 'bch' at https://discourse.libsdl.org/t/25231 --- src/joystick/bsd/SDL_sysjoystick.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index 679b80c109ac9..316ebfbfc2407 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -299,6 +299,10 @@ BSD_JoystickOpen(SDL_Joystick * joy, int device_index) struct hid_item hitem; struct hid_data *hdata; struct report *rep = NULL; +#if defined(__NetBSD__) + usb_device_descriptor_t udd; + struct usb_string_desc usd; +#endif int fd; int i; @@ -350,8 +354,6 @@ BSD_JoystickOpen(SDL_Joystick * joy, int device_index) rep->rid = -1; /* XXX */ } #if defined(__NetBSD__) - usb_device_descriptor_t udd; - struct usb_string_desc usd; if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) == -1) goto desc_failed; From ff3bb857ff73647f129a9257694a43efb2edc30f Mon Sep 17 00:00:00 2001 From: "Steven M. Vascellaro" Date: Mon, 22 Oct 2018 10:55:18 -0400 Subject: [PATCH 151/151] joystick: Add Linux mappings for "Xbox One Wireless Controller (Model 1708)" Adds controller bindings to support the "Xbox One Wireless Controller (Model 1708)" on Linux. The Model 1708 was released in 2016 alongside the Xbox One S. It is the current model being sold by Microsoft as of writing. (October 22, 2018) --- src/joystick/SDL_gamecontrollerdb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h index 9d95c90788861..45c0dbc8dda50 100644 --- a/src/joystick/SDL_gamecontrollerdb.h +++ b/src/joystick/SDL_gamecontrollerdb.h @@ -549,6 +549,7 @@ static const char *s_ControllerMappings [] = "0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),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:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,", "050000005e040000e002000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,", "050000005e040000fd02000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b15,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b16,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,", + "030000005e040000ea02000001030000,Xbox One Wireless Controller (Model 1708),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,", "05000000172700004431000029010000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b20,leftshoulder:b6,leftstick:b13,lefttrigger:a7,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a6,rightx:a2,righty:a5,start:b11,x:b3,y:b4,", "03000000c0160000e105000001010000,Xin-Mo Xin-Mo Dual Arcade,a:b4,b:b3,back:b6,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b9,leftshoulder:b2,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b1,y:b0,", "03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",