Commit Graph

9302 Commits (db6b6bd75ef5fb1335d192cb4edc11719967f52e)

Author SHA1 Message Date
Sam Lantinga 05b57f6c2c Simplified SDL_SYS_RemovePath()
If we get ENOENT we call that success. If the parent directory doesn't exist, that's fine, other operations on it will fail if it matters to the application.
2024-03-21 21:16:14 -07:00
Anonymous Maarten 2521ba47fe jack: set error message when failing to open jack client 2024-03-22 01:22:39 +01:00
Mark Delk dd4636e3fd SDL_sysmutex.c: fix void return compile error 2024-03-21 13:25:01 -07:00
Sam Lantinga 70b0d33106 Poll for the initial controller state when using DirectInput
This fixes getting a deflected axis as the first buffered input reading on a generic USB controller (G-Shark GS-GP702)
2024-03-20 10:45:11 -07:00
Frank Praznik 4a7e3beeb9 filesystem: Use high-res file times on more platforms
Some POSIX platforms don't define macros to note the presence of the POSIX.1-2008 st_*tim timespec members of the stat struct, so check if this member exists during CMake configuration and conditionally enable it.

Apple platforms use st_*timespec naming, which is supported as of OSX 10.6. SDL3 requires 10.9+, so no fallback is needed.

Android only supports the POSIX.1-2008 semantics as of API version 26 or higher, so this has to be conditionally enabled in the makefile build via an API version definition check.

In other cases, file times fall back to the legacy path with second precision.
2024-03-20 11:39:42 -04:00
Sam Lantinga da027ec3ee Fixed signed/unsigned comparison warning 2024-03-19 17:00:46 -07:00
Pierre Wendling 390fff4ae0 N3DS: Fix locale name and early return.
- The name for simplified Chinese should be `zh_CN`.
- Ensure `cfguExit` is called even if `CFGU_GetSystemLanguage` failed.
2024-03-19 16:54:07 -07:00
Pierre Wendling 8f529d9d16 N3DS: Implement SDL_GetSystemTimeLocalePreferences
The formats are deduced based on the system's current language and region.
2024-03-19 16:52:56 -07:00
Sam Lantinga 478b965e6c Fixed warning C4702: unreachable code
Also switched SDL_IOFromFile() to use SDL_InvalidParamError()
2024-03-19 16:02:54 -07:00
Sam Lantinga b1215272ad Fixed warning C4244: '=': conversion from '__int64' to 'int', possible loss of data 2024-03-19 16:02:37 -07:00
Sam Lantinga c582a89f78 Fixed build warning 2024-03-19 14:53:49 -07:00
Ivan Epifanov 2e45568338 PSVita: fix SDL_GetSystemTimeLocalePreferences 2024-03-19 12:32:51 -07:00
Frank Praznik a6fbf0488c Add time and realtime clock functions
Adds functions to query the system's realtime clock, convert time intervals to/from a calendar date and time in either UTC or the local time, and perform time related calculations.

An SDL_Time type (a time interval represented in nanoseconds), and SDL_DateTime struct (broken down calendar date and time) were added to facilitate this functionality.

Querying the system time results in a value expressed in nanoseconds since the Unix epoch (Jan 1, 1970) in UTC +0000. Conversions to and from the various platform epochs and units are performed when required.

Any direct handling of timezones and DST were intentionally avoided. The offset from UTC is provided when converting from UTC to a local time by calculating the difference between the original UTC and the resulting local time, but no other timezone or DST information is used.

The preferred date formatting and 12/24 hour time for the system locale can be retrieved via global preferences.

Helper functions for obtaining the day of week or day or year for calendar date, and getting the number of days in a month in a given year are provided for convenience. These are simple, but useful for performing various time related calculations.

An automated test for time conversion is included, as is a simple standalone test to display the current system date and time onscreen along with a calendar, the rendering of which demonstrates the use of the utility functions (press up/down to increment or decrement the current month, and keys 1-5 to change the date and time formats).
2024-03-19 10:57:36 -07:00
Sam Lantinga 24ec1c09b9 Renamed SDL_PROP_IOSTREAM_STDIO_HANDLE_POINTER to SDL_PROP_IOSTREAM_STDIO_FILE_POINTER 2024-03-18 21:56:11 -07:00
Cameron Gutman d3a785e521 Improve event processing latency when gamepad/sensor is open
By using the SDL_WaitEventTimeout_Device() path even when polling is required,
we can still achieve sub-millisecond latency for non-gamepad/sensor events when
a gamepad or sensor is in use by the application.
2024-03-18 21:52:42 -07:00
Anonymous Maarten 009318c5a9 Fix warnings when building with -DSDL_LIBC=OFF on Linux 2024-03-18 21:29:08 +01:00
Anonymous Maarten f59dbf6a12 cmake: add -Wimplicit-fallthrough warning 2024-03-18 20:34:50 +01:00
Sam Lantinga 086a7a4687 Fixed signed/unsigned comparison warning 2024-03-18 09:48:45 -07:00
Sam Lantinga 491f18eea3 Fixed uninitialized signal_id
Also removed unnecessary SDL_OutOfMemory() calls

Fixes https://github.com/libsdl-org/SDL/issues/9300
2024-03-18 09:12:51 -07:00
Sam Lantinga 90e2551c4f Sort the SDL API symbols
API renames are almost complete, let's prepare for a preview release
2024-03-18 09:03:36 -07:00
Sam Lantinga 92d01ef12a You can pass NULL to SDL_GetPathInfo() and SDL_GetStoragePathInfo() to test for the existence of a file. 2024-03-18 08:56:24 -07:00
Frank Praznik ebb6582534 wayland: Handle the toplevel export property as a string
xdg-toplevel export handles are strings, so treat the property as one. Avoids the need to manually manage the string pointer.
2024-03-18 11:41:02 -04:00
Petar Popovic 9072b994f7 src/filesystem/unix/SDL_sysfilesystem.c add <stdio.h> inclusion
gets rid of some warnings
2024-03-18 15:55:40 +03:00
Mathieu Eyraud 6af979975f Add missing break 2024-03-18 15:55:14 +03:00
Sam Lantinga a1a0156756 Renamed SDL_SizeIO() SDL_GetIOSize() 2024-03-18 00:27:18 -04:00
Sam Lantinga df0f5deddf Added SDL_IOFromDynamicMem() 2024-03-18 00:27:18 -04:00
rofl0r 12245e4c75 PSP/Joystick: fix formatting
(cherry picked from commit c17d2246fb0ed2fa5b16acbf1f2b3aa7e5ddd3cf)
2024-03-17 13:23:51 -07:00
rofl0r 7169db1e62 PSP: don't block on joystick event query
using the blocking sceCtrlReadBufferPositive() effectively turns SDL_PollEvent() into WaitForVblank(), because the functions does exactly that if no input is buffered.
due to this, calling SDL_PollEvent() once per frame averaged in 7 ms delay out of the available 16ms budget to get a frame calculated and drawn to achieve 60 fps.

(cherry picked from commit 86f223d66426ad1a42db156d1f1d155ad987959b)
2024-03-17 13:23:51 -07:00
Sam Lantinga 747300b356 SDL file times are 64-bit integers representing nanoseconds since the Unix epoch 2024-03-17 13:21:04 -07:00
Sam Lantinga 9153287fa0 Added storage filesystem operations to the exported function list 2024-03-17 13:02:52 -07:00
Sam Lantinga d65ae710a1 Renamed SDL_LogGetOutputFunction() and SDL_LogSetOutputFunction() to match SDL 3.0 naming convention 2024-03-17 12:28:11 -07:00
Sam Lantinga d972244d3a Added a mapping for the Defender Joystick Cobra R4 (thanks @kotenok2000!) 2024-03-17 12:13:21 -07:00
Sam Lantinga 4697153d1e Use the CRC as part of the unique key for mappings 2024-03-17 12:13:21 -07:00
Ryan C. Gordon 9d83c0a65d filesystem: Rename some internal symbols to remove "FSops" terminology.
This removes the "FSops" naming scheme, which was meant to mirror the
"RWops" naming scheme, which was also recently removed from SDL3.

The build system defines (`SDL_FSOPS_POSIX`, etc) and the source code
filenames retain this, because there's already things using the word
"filesystem" that might overlap (for example, lots of things have a
unique "SDL_sysfilesystem.c", to query base dirs, etc, but almost
everything uses the POSIX "SDL_sysfsops.c" source code.

Fixes #9288.
2024-03-17 14:20:11 -04:00
Frank Praznik cb39740cfd wayland: Remove additional instance of setting the viewport source rect 2024-03-17 13:10:48 -04:00
Sam Lantinga 2f78e5f321 All storage interface functions are optional
If an application is creating custom storage, presumably they'll implement the functions they need.
2024-03-17 08:39:43 -07:00
Sam Lantinga f460f42e70 Added filesystem operations to SDL_Storage 2024-03-17 08:39:43 -07:00
Sam Lantinga 7a088527c1 Removed the reserved parameter from SDL_EnumerateDirectoryCallback
If someone needs to, say, include an SDL_Storage object, they can simply point userdata at a structure that includes the the storage and any other data needed in enumeration.
2024-03-17 08:39:43 -07:00
Sam Lantinga ec3ba387d1 Added SDL_OpenFileStorage() for local file storage 2024-03-17 08:39:43 -07:00
Sam Lantinga ee0a23c7ab The storage ready callback is optional 2024-03-17 08:39:43 -07:00
Sam Lantinga db0c1d7aeb Added portable file and directory operations (thanks @icculus!) 2024-03-17 08:39:43 -07:00
Sam Lantinga fe5c34d4bd Renamed storage functions to match SDL 3.0 naming convention 2024-03-17 08:39:43 -07:00
Frank Praznik 1bab87399f wayland: Always use the entire buffer for the viewport source
Not doing so can result in protocol errors if the viewport source region is updated and a buffer with the old, smaller dimensions is committed.
2024-03-17 10:44:10 -04:00
Ethan Lee 744227e6ab Add SDL_storage 2024-03-16 07:19:50 -07:00
Sam Lantinga 25c64a954d Removed UIKit_SetWindowMouseGrab(), mouse grab isn't supported on iOS 2024-03-15 16:26:40 -07:00
Sam Lantinga 41e187be4f Adjust Steam button names to match SDL 2024-03-15 16:05:19 -07:00
Anonymous Maarten 572e088b8f SDL_IOFromMem/SDL_IOFromConstMem: free userdata on close 2024-03-15 23:55:29 +01:00
Frank Praznik ea60c2079b dialog: Pass the Wayland or X11 parent window handle to the file dialog portal
Pass the Wayland window export string in the form "wayland:<handle string>" or the X11 window XID in the form "x11:<XID in hex>" to the file dialog portal, so that the window manager can associate the dialog with the parent window and position it correctly.
2024-03-15 18:30:05 -04:00
Frank Praznik d523cd069f dialog: Detect if the file chooser portal is available
Use the introspection method to detect if the file chooser portal is available.
2024-03-15 18:30:05 -04:00
Frank Praznik 19764ffcc8 wayland: Add the xdg-foreign-unstable-v2 protocol
Add the xdg-foreign-unstable-v2 protocol and use it to create export handles for toplevel windows, which will be used when an external component, such as the file chooser portal, requires it.
2024-03-15 18:30:05 -04:00
Ryan C. Gordon b7cda16613
iostream: Final fixes before merging.
- SDL_GetRWProperties -> SDL_GetIOProperties
- SDL_GetRWStatus -> SDL_GetIOStatus
- Some documentation corrections and improvements.
2024-03-15 15:37:03 -04:00
Ryan C. Gordon 5a21d87e69
rwops: Changed filenames that reference "rwops" to "iostream". 2024-03-14 23:30:59 -04:00
Ryan C. Gordon 6776b6108a
iostream: "free*" params should be "closeio". 2024-03-14 23:14:46 -04:00
Ryan C. Gordon 3a344cf877
rwops: Fixed some SDL2 symbols that got missed. 2024-03-14 21:57:21 -04:00
Ryan C. Gordon 5f64cc511e
rwops: Fixed build on Android. 2024-03-14 19:38:15 -04:00
Ryan C. Gordon fc7afa9cbf
rwops: Renamed SDL_RWops to SDL_IOStream, and other related symbols. 2024-03-14 19:38:12 -04:00
Ryan C. Gordon fe33b2a81b
rwops: Give implementations access to status value. 2024-03-14 19:37:07 -04:00
Ryan C. Gordon cc58da4c63
rwops: Add SDL_GetRWStatus, make the statuses into an enum. 2024-03-14 19:37:06 -04:00
Ryan C. Gordon e35c304022
rwops: Add properties for some of the internal implementation details. 2024-03-14 19:37:05 -04:00
Ryan C. Gordon 7d4d8ccde0
rwops: Rename everything from SDL_RWxxx to SDL_XxxRW. 2024-03-14 19:37:04 -04:00
Ryan C. Gordon 655ceb3b31
rwops: Renamed SDL_CreateRW and SDL_DestroyRW to SDL_OpenRW and SDL_CloseRW. 2024-03-14 19:37:01 -04:00
Ryan C. Gordon 525919b315
rwops: Reworked RWops for SDL3.
- SDL_RWops is now an opaque struct.
- SDL_AllocRW is gone. If an app is creating a custom RWops, they pass the
  function pointers to SDL_CreateRW(), which are stored internally.
- SDL_RWclose is gone, there is only SDL_DestroyRW(), which calls the
  implementation's `->close` method before freeing other things.
- There is only one path to create and use RWops now, so we don't have to
  worry about whether `->close` will call SDL_DestroyRW, or if this will
  risk any Properties not being released, etc.
- SDL_RWFrom* still works as expected, for getting a RWops without having
  to supply your own implementation. Objects from these functions are also
  destroyed with SDL_DestroyRW.
- Lots of other cleanup and SDL3ization of the library code.
2024-03-14 19:36:08 -04:00
Semphris 70c2e15615 Add file dialogs 2024-03-14 15:40:25 -07:00
Sam Lantinga 30e93b40c2 If a mapping specifies a crc, don't match for controllers that don't have that CRC
The CRC is used to distinguish between different controllers that have the same VID/PID, so if the CRC doesn't match, it's probably a different controller that we don't know about.

Fixes https://github.com/libsdl-org/SDL/issues/9265
2024-03-14 13:26:56 -07:00
Frank Praznik 717f297849 Add 'wl_list_for_each_safe' to the clang-format macro list
...and fix the formatting when it is used.
2024-03-14 10:22:23 -04:00
Frank Praznik 4686a737a9 wayland: Minor cursor code cleanup
Clean up variable declarations and fix some formatting issues.
2024-03-13 12:39:00 -04:00
Dimitriy Ryazantcev 1973edb9b7 WIN_UpdateKeymap: cleanup code a bit 2024-03-13 09:09:59 -07:00
Anthony 0a86f8eb6e
Move some code blocks inside `SDL_VIDEO_RENDER_SW`, where it belongs (#9259)
There was some software renderer specific code that can be excluded with SDL_LEAN_AND_MEAN. This contributes towards #9206
2024-03-12 21:15:46 -07:00
Frank Praznik c2e9693de5 wayland: Add cursor-shape-v1 protocol support 2024-03-12 20:54:55 -04:00
Frank Praznik 9bdb992925 wayland: Allocate the cursor shared memory buffer entirely in memory, if possible.
Use memfd_create() to allocate the temporary SHM backing file in memory, and set the size with posix_fallocate(), which will return an error on insufficient space vs ftruncate(), which will silently succeed and allow a SIGBUS error to occur if the unbacked memory is accessed.

Additionally, make the legacy path more robust by unlinking the temp file, so it won't persist after close, and unmapping the shared memory buffer.
2024-03-12 20:54:55 -04:00
Sam Lantinga d79f865251 Removed incorrect mapping for a HORI controller
This broke support for the Hori Fighting Stick EX2, which gets a good mapping if the automatic mapping is allowed to create one.

If the original controller needs a mapping, it should be added with a crc, since that VID/PID combination is used by several HORI controllers.
2024-03-11 17:11:20 -07:00
Anonymous Maarten bee8a95571 Fix SDL_LEAN_AND_MEAN build 2024-03-11 13:46:16 -07:00
Sam Lantinga d4794cc714 Fix crash in SDL_UpdateFullscreenMode calling SetWindowFullscreen with a null display
- This mirrors the check above for fullscreen=true in the unlikely case where there is no primary display detected
2024-03-11 11:17:45 -07:00
Sam Lantinga ab5351f5d6 Fixed leaving the cursor clip set when changing window focus
While the focus change happens, Windows appears to reset the cursor clip rectangle, and then restore it if the application that has focus has the clip rectangle set.

This fixes resetting the clip rectangle while changing focus between windows in the same application, e.g. the Source 2 editor.
2024-03-11 10:58:40 -07:00
Sam Lantinga efbbafb3f1 Re-added balls to the SDL joystick API
It turns out these were being used on Linux and at least one virtual driver was making use of them (thanks @mrfixit2001!)
2024-03-10 21:30:14 -07:00
Sam Lantinga 53e86be22f Minor cleanup with the new PS3 driver for windows 2024-03-10 20:12:11 -07:00
Riccardo Marcangelo 6534029691
Add DualShock 3 HIDAPI support on Windows (#9144)
This adds HIDAPI support for DualShock 3 controllers on Windows, addressing the current absence of this feature in SDL. To utilize this functionality, the official Sony driver 'sixaxis.sys' must be installed. HID offers several advantages over DirectInput, including rumble support and the ability to control the LED lights that display the controller number.
2024-03-10 20:08:36 -07:00
r4nx feadbffb67 Destroy properties after applying them to avoid memory leakage 2024-03-10 18:16:40 -07:00
Sam Lantinga e3cf2e4794 Turn HIDAPI joystick support off by default on mobile platforms
On Android, HIDAPI prompts for permissions and acquires exclusive access to the device, and on Apple mobile platforms it doesn't do anything except for handling Bluetooth Steam Controllers.

Fixes https://github.com/libsdl-org/SDL/issues/9241
2024-03-10 15:00:49 -07:00
Sam Lantinga ed463b41e1 Unified the software renderer creation path
Previously there were two different paths for renderer creation, and the HDR metadata initialization was missing when creating a software renderer for a surface. Now all the cases are handled in a single path, so regardless of whether you create a software renderer by name, a software renderer for a surface, or fall back to a software renderer, you'll get the correct initialization in all cases.

Fixes https://github.com/libsdl-org/SDL/issues/9221
2024-03-10 11:05:26 -07:00
Anonymous Maarten 3bc27d3856 hidapi_libusb: use SDL_wcscmp and SDL_wcslcpy from SDL 2024-03-10 09:07:33 -07:00
Green Sky 4de30a26a2 x11: workaround issues with primary selection and clipboard temporal ignorance 2024-03-10 08:59:44 -07:00
Simon McVittie 76defc5c82 joystick: Remove redundant CHECK_JOYSTICK_MAGIC in SDL_GetJoystickName
Since commit 0dfdf1f3 "Fixed crash if joystick functions are passed a
NULL joystick", we've already done this check by the time we get to
this point.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-09 08:40:04 -08:00
Sam Lantinga 16e0806ced Note that the cursor clip has been cleared even if we didn't do it
This releases the mouse cursor when bringing up the console on Counter Strike in dev mode.
2024-03-08 15:56:49 -08:00
Mingjie Shen 19b3ddac2f Fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow
an attacker to modify the file between the two operations. (CWE-367)
Fix by using fstat() instead of stat().
2024-03-08 15:52:04 -08:00
Sam Lantinga cde793b0f5 Added support for the 6-button SEGA Mega Drive Control Pad for Nintendo Online
Closes https://github.com/libsdl-org/SDL/pull/9225
2024-03-08 12:33:54 -08:00
Sam Lantinga 790cd395f5 Make sure the type in the SDL_Event aligns properly across the union 2024-03-07 06:58:43 -08:00
Sam Lantinga e9ab2d46de Revert "Change `SDL_Keycode` type to an enum"
SDL_Keycode can actually be any printable character on the keyboard, so isn't limited to the enumerated values of SDL_KeyCode.
2024-03-07 06:58:43 -08:00
Sam Lantinga 33eaddc565 Cleaned up various type conversion issues
This makes sure SDL_PixelFormatEnum flows through the internal code correctly, as well as fixing a number of other minor issues.
2024-03-07 06:58:43 -08:00
Sam Lantinga 57a160c9ab Fixed mapping for the Sanwa Supply JY-P76USV controller 2024-03-06 20:53:48 -08:00
Sam Lantinga c70710cde8 SDL_GetPixelFormatEnumForMasks() returns SDL_PixelFormatEnum 2024-03-06 16:19:08 -08:00
Susko3 01248a99c8 Add `default: break;` to switches on SDL_Event::type
This is just a nice-to-have, as `SDL_Event::type` in an `Uint32`, so there are no
compiler errors about not handling all `SDL_EventType` enum values.
2024-03-06 15:40:05 -08:00
Susko3 722f4104bf Use enums as types in SDL_*Event structures
The main `SDL_Event` union is not using the enum as
valid user events types are not in the enum.
2024-03-06 15:40:05 -08:00
Susko3 641b911d38 Update some internal files to use `SDL_WindowFlags` 2024-03-06 15:08:12 -08:00
Susko3 ce44eff3d2 Use `SDL_WindowFlags` in public headers 2024-03-06 15:08:12 -08:00
Susko3 424616e032 Use SDL_PixelFormatEnum as type 2024-03-06 15:02:13 -08:00
Sam Lantinga 38c54b8e0e More null checks for SDL window operations 2024-03-06 13:33:30 -08:00
Sam Lantinga 6664a089d8 Add missing null check for displaydata during window creation
Found in the wild from minidump reports. Unclear displaydata is null, but according
to the API it is possible for this call to return null so it seems like a valid check.
2024-03-06 13:33:27 -08:00
Sam Lantinga 610e798406 Fix clicking on the titlebar causing mouse input to freeze until esc is pressed
When the titlebar drage region is clicked two actions are triggered:
  * The WM transfers focus to the application
  * The application starts a drag operation because the drag region was clicked

When the drag operation starts before input has been transferred to the application the
window manager gets in a bad state where mouse clicks don't work and the system isn't
actually dragging.

In this CL we delay drag operations until after the application has acquired active focus.
This fixes the problems outlined above.
2024-03-06 13:33:23 -08:00
Sam Lantinga 65a718f8c6 Disable warning C4113 in SDL_windows_gaming_input.c
- A new version of warning C4028 added in VS 2022.
2024-03-06 13:33:20 -08:00
Frank Praznik 53896c9e44 cocoa: Make keyboard grab function return an int 2024-03-06 15:53:24 -05:00
Susko3 f8cb3c742d Change `SDL_Keycode` type to an enum 2024-03-06 12:17:53 -08:00
Sam Lantinga 26b9178e5c Fixed whitespace 2024-03-06 09:57:39 -08:00
Sam Lantinga 860155680d SDL_RegisterEvents() now returns 0 if it couldn't allocate any user events. 2024-03-06 09:51:15 -08:00
Ozkan Sezer 4d20b82850 SDL_RWFromFile, stdio: allow named pipes along with regular files.
Fixes https://github.com/libsdl-org/SDL/issues/9174

(cherry picked from commit 177a836653e0d2690ff8802dade165c392502f81)
2024-03-06 18:51:20 +03:00
Sam Lantinga ee87132385 Make sure fast path RGB <-> YUV conversions are using the same color primaries 2024-03-05 17:43:08 -08:00
Sam Lantinga 4545c77c9e Updated Vita renderer with colorspace clarification 2024-03-05 16:56:58 -08:00
Sam Lantinga db24560387 Additional colorspace clarification
Note that SDL_MATRIX_COEFFICIENTS_BT470BG is functionally equivalent to SDL_MATRIX_COEFFICIENTS_BT601
2024-03-05 16:47:36 -08:00
Sam Lantinga b3858ec5f7 BT2020_CL is very different from BT2020_NCL, and not currently supported 2024-03-05 15:49:17 -08:00
Frank Praznik 4c0601b93f video: Return a failure code if the video driver fails to grab the mouse or keyboard
Alter the video driver grab/confinement function signatures to return an int, set and return an error if the grab request fails, and clear the grab flags from the window if the mouse and/or keyboard wasn't actually grabbed.
2024-03-05 17:59:10 -05:00
Sam Lantinga ae0caeef8d Fixed build 2024-03-05 13:54:17 -08:00
Sam Lantinga 9db68f97f9 Reverted SDL_Vulkan_GetInstanceExtensions() API change
This function is commonly used with Vulkan structures that use uint32_t, so we should keep the Uint32 signature.
2024-03-05 13:39:42 -08:00
Sam Lantinga edbcef11ff Keep track of whether the Android on-screen keyboard was opened by the application
Fixes https://github.com/libsdl-org/SDL/issues/9202
2024-03-05 13:35:17 -08:00
Sylvain cea717e5d3 Removed some uneeded 'unsigned': renderer.num_texture_format and SDL_Vulkan_GetInstanceExtensions() prototype 2024-03-05 13:31:28 -08:00
Sam Lantinga 1e0bac288b Use the hlsli extension for shader includes 2024-03-05 12:46:44 -08:00
Ozkan Sezer 98bec6749f hidapi, windows: sync with mainstream: change MAX_STRING_WCHARS to 126.
This merges mainstream commit
4f2e91bae8
(authored by Vladimir Gladkov) into ours. From the original commit log:

Win32 HID API doc says: For USB devices, the maximum string length is
126 wide characters (not including the terminating NULL character).

For certain USB devices, using a buffer larger or equal to 127 wchars
results in successful completion of HID API functions, but a broken
string is stored in the output buffer. This behaviour persists even if
HID API is bypassed and HID IOCTLs are passed to the HID driver directly
(IOCTL_HID_GET_MANUFACTURER_STRING, IOCTL_HID_GET_PRODUCT_STRING, etc).

So, the buffer MUST NOT exceed 126 wchars.

windows: refactor ULONGLONG hid_internal_get_info(...) ->
 hid_internal_detect_bus_type_result hid_internal_detect_bus_type(...)

hid_internal_detect_bus_type is now only responsible for detection of
the bus type; rename it accordingly. Also, mixing an internal flag and
DEV_INST into an ULONGLONG retval feels kinda hackish; use a cleaner
approach instead (add an internal flag to help distinguishing between
BLUETOOTH and BLE devices, then clear it once we are done).
2024-03-05 14:39:20 +03:00
Ozkan Sezer 26e3ca7387 hidapi: minor sync with mainstream (for sake of symmetry, only.) 2024-03-05 14:33:06 +03:00
Sam Lantinga 759ade8c90 vulkan: enable samplerYcbcrConversion when creating the device 2024-03-04 11:17:42 -08:00
Sam Lantinga 48471f7dbd Added SDL_AddVulkanRenderSemaphores() for external synchronization with SDL rendering 2024-03-04 09:29:36 -08:00
Sam Lantinga 504d8c2fc0 Fixed potential memory leak if vkCreateInstance() fails 2024-03-04 09:29:36 -08:00
Frank Praznik 1e790b20c9 video: Don't overwrite all the pending flags in the OnWindowHidden handler
Other flags may have been set when programmatically hiding a window, so or in the fullscreen and maximized flags to avoid accidentally clearing any others.
2024-03-04 10:30:11 -05:00
Frank Praznik ae4484f4e5 video: Save pending window events when a window is hidden by the window manager
The window manager might hide/unmap the window when it is minimized, in which case the fullscreen and maximized flags must be preserved as pending flags so the window will be restored to the proper state when shown/mapped on restoration.
2024-03-03 18:01:25 -05:00
Sam Lantinga 9be35d4603 Convert mappings using labeled buttons to positional buttons
We were accidentally skipping all of the mappings that used the SDL_GAMECONTROLLER_USE_BUTTON_LABELS hint, because they used the '!' negate operator with a default hint value of 1. Instead we just want to use that hint to determine whether the mapping has positional buttons or not, and swap the buttons as needed.

Fixes https://github.com/libsdl-org/SDL/issues/9190
2024-03-03 14:17:03 -08:00
Sam Lantinga ccd309c433 Added a mapping for the Sanwa Supply JY-P76USV controller
Fixes https://github.com/libsdl-org/SDL/issues/8644
2024-03-03 12:23:00 -08:00
Sam Lantinga 8d8076263e Removed the mapping for the G-Shark GS-GP702
This uses the same chipset as the DragonRise Inc. Generic USB Joystick, which many manufacturers use for different products with different mappings.

In order to add a mapping for a controller using this chipset, we need a unique crc for the device name.
2024-03-03 12:18:57 -08:00
Sam Lantinga 1b86a1c684 SDL_GetGamepadAppleSFSymbolsNameForAxis() returns NULL if the symbol isn't found 2024-03-03 11:55:40 -08:00
Sam Lantinga 5f37242607 Don't clear the clipboard on quit
Fixes https://github.com/libsdl-org/SDL/issues/8830
2024-03-03 11:48:08 -08:00
Sam Lantinga 6e03914375 Fixed signed/unsigned comparison warning 2024-03-03 11:36:23 -08:00
Sam Lantinga e54001b028 Updating the mouse capture should use the mouse focus window
Fixes https://github.com/libsdl-org/SDL/issues/8974
2024-03-03 11:32:17 -08:00
Sam Lantinga c1da39a245 SDL_GetGamepadAppleSFSymbolsNameForButton() returns NULL if the symbol isn't found
Fixes https://github.com/libsdl-org/SDL/issues/9071
2024-03-03 11:07:39 -08:00
Sam Lantinga 74f4614289 Save the native texture parent and return that in SDL_GetRenderTarget()
Fixes https://github.com/libsdl-org/SDL/issues/9176
2024-03-03 09:47:40 -08:00
Sam Lantinga eb5a2e7e7f Fixed building with SDL_LEAN_AND_MEAN
Fixes https://github.com/libsdl-org/SDL/issues/9173
2024-03-03 09:25:02 -08:00
Sam Lantinga 107e06a92a Use a valid finger ID when generating touch events from mouse events
Fixes https://github.com/libsdl-org/SDL/issues/9185
2024-03-03 09:15:07 -08:00
meyraud705 c6ec999869 Set udev class for accelerometer 2024-03-03 08:40:24 -08:00
Sam Lantinga 7f9ff6277c Don't assume HDR headroom for HDR10 surfaces
Applications that support HDR will set the correct values for their content.
2024-03-02 15:02:17 -08:00
Jade Macho c74f273848 d3d12: Move root sigs to D3D12_Shader_Common.hlsli, fix mismatch 2024-03-02 10:30:29 -08:00
Jade Macho e2a8209263 GDK: Use WIN_IsRectEmpty (IsRectEmpty is desktop-only) 2024-03-02 10:30:29 -08:00
Jade Macho 290f64b86c GDK: Windows shape is desktop-only 2024-03-02 10:30:29 -08:00
Jade Macho 794f0f1b42 GDK: Fix SDL_pixels.c/_c.h linking error caused by C / C++ mismatch 2024-03-02 10:30:29 -08:00
Jade Macho 23ace600fc GDK: Remove old shader sources, unify shader compilation .bats 2024-03-02 10:30:29 -08:00
Jade Macho e1e5d33420 GDK: Partially revert 2670eb44af
MsgWaitForMultipleObjects is desktop-only.
2024-03-02 10:30:29 -08:00
Sam Lantinga 2bc2840de5 vulkan: VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 is a 2-plane format 2024-03-01 20:26:52 -08:00
Sam Lantinga 2bedd7f02e Fixed pitch alignment when updating SDL_PIXELFORMAT_P010 textures 2024-03-01 20:26:52 -08:00
Sam Lantinga f2cd361e25 testyuv: added validation of P010 YUV format
Also added conversion between RGB and P010, using XRGB2101010 as a bridging format in PQ space
2024-03-01 20:26:52 -08:00
danginsburg 812e04fb11 Vulkan Renderer - fix validation error with VkSemaphore reused before signaling. Have one semaphore per-submit rather than using the same one. 2024-03-01 06:09:22 -08:00
Ryan C. Gordon 1e8b006d43 stdlib: qsort and bsearch changes.
- Always use internal qsort and bsearch implementation.
- add "_r" reentrant versions.

The reasons for always using the internal versions is that the C runtime
versions' callbacks are not mark STDCALL, so we would have add bridge
functions for them anyhow, The C runtime qsort_r/qsort_s have different
orders of arguments on different platforms, and most importantly: qsort()
isn't a stable sort, and isn't guaranteed to give the same ordering for
two objects marked as equal by the callback...as such, Visual Studio and
glibc can give different sort results for the same data set...in this
sense, having one piece of code shared on all platforms makes sense here,
for reliabillity.

bsearch does not have a standard _r version at all, and suffers from the
same SDLCALL concern. Since the code is simple and we would have to work
around the C runtime, it's easier to just go with the built-in function
and remove all the CMake C runtime tests.

Fixes #9159.
2024-03-01 08:28:12 -05:00
Sam Lantinga 0454e1fdb4 Vulkan: added support for wrapping existing textures 2024-02-29 17:38:10 -08:00
Sam Lantinga 2adbcce864 Vulkan: wait for all queues to be idle before destroying the device 2024-02-29 14:12:09 -08:00
danginsburg 0115027116 Vulkan Renderer - fix validation errors:
* Make sure to always write pointSize in VS (fixes validation error in testsprite)
* Fix validation error from acquiring swapchain semaphore more than once
* Fix validation error from using incorrect framebuffer size in testautomation

Now passes testautomation with validation.
2024-02-29 10:59:47 -08:00
Sam Lantinga 0c6a1b636e Vulkan: added handling for SDL_MATRIX_COEFFICIENTS_UNSPECIFIED 2024-02-28 19:18:37 -08:00
Sam Lantinga 4017e1370d Vulkan: cleaned up error handling 2024-02-28 19:11:33 -08:00
Sam Lantinga 59bbfc1fdd Vulkan: only advertise YUV formats if the VK_KHR_sampler_ycbcr_conversion extension is available
Also check to see if it's available when given an external Vulkan device
2024-02-28 19:04:00 -08:00
Sam Lantinga bf853823a2 Removed unused YCbCr_matrix from Vulkan shaders 2024-02-28 18:38:06 -08:00
Sam Lantinga 4513c32bb3 The ycbcrModel should be based on the transfer matrix, not the color primaries 2024-02-28 16:58:39 -08:00
Sam Lantinga a241cca9e6 Fixed warning C4090: 'function': different 'const' qualifiers 2024-02-28 11:45:24 -08:00
Sam Lantinga 7117d545a3 Fixed crash if the controller product name is NULL
This happens when the Razer Synapse software emulates a controller with a keyboard
2024-02-28 11:43:22 -08:00
Sam Lantinga fc94c3634e Fixed signed/unsigned comparison warning 2024-02-28 09:06:21 -08:00
Sam Lantinga ba34025423 Use direct3d11 as the default renderer on Windows
The D3D12 renderer initializes but has poor performance or graphical issues on older Intel hardware.

Fixes https://github.com/libsdl-org/SDL/issues/7634
Fixes https://github.com/libsdl-org/SDL/issues/9093
2024-02-28 09:00:36 -08:00
Dan Ginsburg ad036d43e9
Vulkan Renderer - implement YcBcCr using VK_KHR_sampler_ycbcr_conversion. (#9169)
* Vulkan Renderer - implement YcBcCr using VK_KHR_sampler_ycbcr_conversion.  This simplifies the shader code and will also allow support for additional formats that we don't yet support (such as SDL_PIXELFORMAT_P010 for ffmpeg). The renderer now queries for VK_KHR_sampler_ycbcr_conversion and dependent extensions and will enable it if it's present. It reimplements YUV/NV12 texture support using this extension (these formats are no longer supported if the extension is not present). For each YUV/NV12 texture, a VkSamplerYcbcrConversion object is created from SDL_Colorspace parameters.  This is passed to the VkImageView and also an additional sampler is created for Ycbcr.  Instead of using 1-3 textures, the shaders now all use 1 texture with a combined image sampler (required by the extension).  Further, when using Ycbcr, a separate descriptor set layout is baked with the Ycbcr sampler as an immutable sampler.  The code to copy the images now copies to the individual image planes.  The swizzling between formats is handled in the VkSamplerYcbcrConversion object.
2024-02-28 08:57:09 -08:00
Frank Praznik 945162c6d9 wayland: Small optimization for output removal function
In the case where an output is being removed, the SDL_DisplayData is already known, so no need to retrieve it from the wl_output user data.
2024-02-28 10:43:06 -05:00
Sam Lantinga e142bb1b0c The extension strings are const and don't need to be duplicated 2024-02-28 07:12:15 -08:00
Sam Lantinga 0997bdd292 Fixed SDL_calloc() calls (should be count, size) 2024-02-28 07:12:15 -08:00
Sam Lantinga 614630df69 Allow using an external Vulkan device with the vulkan renderer 2024-02-28 07:12:15 -08:00
Anonymous Maarten c8372e20d6 SDLTest_CommonEvent: only set done when it is finished 2024-02-28 12:57:30 +01:00
Sam Lantinga 220340e944 Remove SDL_PIXELFORMAT_P010
It's not supported by any renderer or pixel conversion path
2024-02-27 12:48:33 -08:00
Frank Praznik c259a20f96 wayland: Remove all references to destroyed outputs from windows
The removal of a wl_output may not be accompanied by leave events for the surfaces present on it. Ensure that no window continues to hold a reference to a removed output.
2024-02-27 12:18:01 -05:00
Sam Lantinga 81608ad077 Vulkan: fixed creating SDL_PIXELFORMAT_P010 textures 2024-02-26 15:51:13 -08:00
Sam Lantinga 80d2ef7384 Fixed uploading Vulkan texture with w*bpp != pitch 2024-02-26 15:18:23 -08:00
Sam Lantinga 98b1a59a95 Document the HDR tone mapping algorithm 2024-02-26 14:20:34 -08:00
danginsburg 935c197059 Fix testautomation failures (including clip rect) - closes #9145. During merging for prep'ing the final PR for the Vulkan Renderer, I misordered a memcpy that regressed several of the testautomation test. From now on, I will make sure to run testautomation on any future PRs before submitting. 2024-02-26 10:04:10 -08:00
Ryan C. Gordon e61dfe405f
android: Fixed dead URL in comment. 2024-02-26 11:28:32 -05:00
danginsburg 35026cdcba Vulkan Renderer - robustly handle running out of descriptor sets or constant buffer memory. Closes #9131. My previous implementation of descriptor set handling was naive - it attempted to do VULKAN_IssueBatch when running out of descriptor sets or constant buffer space. For one thing, this had a bug and wasn't working (causing the crash), but moreover it would have resulted in having to flush the GPU. Instead, make the descriptor pools and constant buffer mapped buffers be resizeable so that if we need more it will grow to the size that is needed.
# Conflicts:
#	src/render/vulkan/SDL_render_vulkan.c
2024-02-26 08:12:24 -08:00
David Gow f976881651 Vulkan: Don't invalidate internal state in InvalidateCachedState
The VULKAN_InvalidateCachedState() function seems to be meant to
invalidate any _cached_ state, i.e. global state of the API which may
have been modified outside the renderer.

However, at the moment, the Vulkan renderer also resets a number of
internal variables which track buffers, offsets, etc, in use. As a
result, the renderer can get into an inconsistant state and/or lose
data.

For example, if VULKAN_InvalidateCachedState() is called in between two
calls to VULKAN_UpdateVertexBuffer(), the data from the first call will
be overwritten by that from the second, as the number of the next vertex
buffer to use will be reset to 0. This can result in rendering errors,
as the same vertex data is used incorrectly for several calls.

By no longer resetting this 'internal' state here, those glitches
disappear. However, I haven't tested this with any applications which
mix the Vulkan renderer with their own Vulkan code (do any such
applications exist?), so this may be insufficient in case a full flush
of the renderer state  -- and possibly a wait on the appropriate fence
-- could be required.

Signed-off-by: David Gow <david@ingeniumdigital.com>
2024-02-26 07:54:23 -08:00
David Gow c172fb5972 Vulkan: Support 'desired' vs 'required' memory flags (Fix #9310)
When selecting a memory type, there are some property flags we need
(e.g., VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, without which we cannot
vkMapMemory), and others we'd simply prefer (e.g.,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, which may have a performance
impact, but otherwise shouldn't be required).

By specifying these separately, we can fall back to a memory type which
doesn't have everything we want, but which should still work, rather
than giving up.

Signed-off-by: David Gow <david@ingeniumdigital.com>
2024-02-26 07:52:12 -08:00
David Gow 1558d52a0a Vulkan: Only return memory types which are a superset of what we need
VULKAN_FindMemoryTypeIndex() tries first to get a perfectly matching
memory type, then falls back to selecting any memory type which overlaps
with the requested flags.

However, some of the flags requested are actually required, so if -- for
example -- we request a memory type with
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, but get one without it, all future
calls to vkMapMemory() will fail with:

```
vkMapMemory():  Mapping memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set. Memory has type 0 which has properties VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT. The Vulkan spec states:
memory must have been created with a memory type that reports VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT.
```

(This occurs, for instance, on the totally non-conformant hasvk driver
for Intel Haswell integrated GPUs, which otherwise works fine.)

Instead, make sure that any memory type found has a superset of the
requested flags, so it'll always be appropriate.

Of course, this makes it _less_ likely for a memory type to be found, so
it does make #9130 worse in some ways. See the next patch for details.

Signed-off-by: David Gow <david@ingeniumdigital.com>
2024-02-26 07:52:12 -08:00
Sam Lantinga be51b7acea Use the maximum potential headroom if EDR content isn't currently being displayed.
Also document that the HDR properties can change dynamically at runtime.
2024-02-25 15:54:34 -08:00
Sam Lantinga 7a9c6c7ce9 Include SDL_PIXELFORMAT_P010 as a supported format for the metal renderer 2024-02-25 13:55:52 -08:00
Sam Lantinga d211da75ac Fixed crash if app delegate method is called when SDL isn't initialized 2024-02-25 13:38:47 -08:00
Sam Lantinga 9dbbf0a2f7 Implemented clip rect functionality for the Vulkan renderer 2024-02-25 10:13:59 -08:00
Sam Lantinga d0af01e7d4 If the viewport changes the cliprect should be updated
The clip rectangle is defined to be viewport relative, so if the viewport changes we need to update it.

Fixes https://github.com/libsdl-org/SDL/issues/9094
2024-02-25 09:37:56 -08:00
David Gow b8a52c1237 Vulkan: Make sure validation layer name is in-scope
When enabling the Vulkan validation layers, the 'validationLayerName'
variable technically went out of scope before vkCreateInstance() was
called. While most compilers won't clean up stack variables after random
'if' statements, some will, particularly when optimisation or memory
sanitizers are enabled.

This can lead to vkCreateInstance() segfaulting when
SDL_HINT_RENDER_VULKAN_DEBUG is enabled.

Instead, make the validationLayerName visible throughout the entire
VULKAN_CreateDeviceResources() function.

While we're at it, extract the validation layer name out into a
preprocessor #define, so that we are definitely using the same name in
VULKAN_ValidationLayersFound().

Signed-off-by: David Gow <david@ingeniumdigital.com>
2024-02-25 08:24:43 -08:00
Sam Lantinga 276566235c Removed SDL_ClearHints() from the public API
Fixes https://github.com/libsdl-org/SDL/issues/9129
2024-02-24 21:07:50 -08:00
Sam Lantinga a1ea706215 Added names for the newly supported pixel formats 2024-02-24 20:13:59 -08:00
Sam Lantinga f6c42406cd SDL_COLORSPACE_HDR10 is the default colorspace for SDL_PIXELFORMAT_P010 surfaces 2024-02-24 20:04:36 -08:00
Sam Lantinga 4c5584174b Fixed error: declaration shadows a local variable [-Werror,-Wshadow] 2024-02-24 20:04:36 -08:00
Sam Lantinga 2b0e7c40ef Verify that we can create pipeline state objects for the D3D12 renderer
Fixes https://github.com/libsdl-org/SDL/issues/9093
2024-02-24 19:55:10 -08:00
danginsburg 97372b56e8 Vulkan Renderer - handle dynamic resetting of vsync, requires swapchain recreation. 2024-02-23 08:42:04 -08:00
danginsburg b1431e6702 Vulkan Renderer - implement support for vsync disabled. Closes #9116. 2024-02-23 08:42:04 -08:00
Sam Lantinga b9a00aa88e Fixed building the Vulkan renderer on Windows with Visual Studio 2024-02-22 17:18:46 -08:00
Dan Ginsburg cab20117e6
Vulkan Renderer (#9114)
This pull request adds an implementation of a Vulkan Render backend to SDL.  I have so far tested this primarily on Windows, but also smoke tested on Linux and macOS (MoltenVK).  I have not tried it yet on Android, but it should be usable there as well (sans any bugs I missed).  This began as a port of the SDL Direct3D12 Renderer, which is the closest thing to Vulkan as existed in the SDL codebase. The shaders are more or less identical (with the only differences being in descriptor bindings vs root descriptors).  The shaders are built using the HLSL frontend of glslang.

Everything in the code is pure Vulkan 1.0 (no extensions), with the exception of HDR support which requires the Vulkan instance extension `VK_EXT_swapchain_colorspace`.  The code could have been simplified considerably if I used dynamic rendering, push descriptors, extended dynamic state, and other modern Vulkan-isms, but I felt it was more important to make the code as vanilla Vulkan as possible so that it would run on any Vulkan implementation.

The main differences with the Direct3D12 renderer are:
* Having to manage renderpasses for performing clears.  There is likely some optimization that would still remain for more efficient use of TBDR hardware where there might be some unnecessary load/stores, but it does attempt to do clears using renderpasses.
* Constant buffer data couldn't be directly updated in the command buffer since I didn't want to rely on push descriptors, so there is a persistently mapped buffer with increasing offset per swapchain image where CB data gets written.
* Many more resources are dependent on the swapchain resizing due to i.e. Vulkan requiring the VkFramebuffer to reference the VkImageView of the swapchain, so there is a bit more code around handling that than was necessary in D3D12.
* For NV12/NV21 textures, rather than there being plane data in the texture itself, the UV data is placed in a separate `VkImage`/`VkImageView`.

I've verified that `testcolorspace` works with both sRGB and HDR linear.  I've tested `testoverlay` works with the various YUV/NV12/NV21 formats.  I've tested `testsprite`.  I've checked that window resizing and swapchain out-of-date handling when minimizing are working.  I've run through `testautomation` with the render tests.  I also have run several of the tests with Vulkan validation and synchronization validation.  Surely I will have missed some things, but I think it's in a good state to be merged and build out from here.
2024-02-22 14:58:11 -08:00
Sam Lantinga 2f1f55aeb1 Updated default SDR white point and HDR headroom to better match game content 2024-02-22 14:51:23 -08:00
Sam Lantinga 1fb5b9672e Keep SDR white point and HDR headroom defaults in one place 2024-02-22 14:47:58 -08:00
Sam Lantinga aeae202207 Make sure we actually have an HDR10 texture in the HDR10 shader
Some content uses the PQ transfer function but different color primaries
2024-02-22 11:50:58 -08:00
Sam Lantinga f4dd0dbbde Added colorspace conversion from SDL_COLOR_PRIMARIES_SMPTE431 and SDL_COLOR_PRIMARIES_SMPTE432 to SDL_COLOR_PRIMARIES_BT2020 2024-02-22 11:01:03 -08:00
Anonymous Maarten 279a650fae mediafoundation: fix SDL_camera_mediafoundation MinGW compile warnings 2024-02-22 07:18:22 -05:00
Sam Lantinga 78ac14124c Fixed warning C4245: 'function': conversion from 'int' to 'DWORD', signed/unsigned mismatch 2024-02-21 22:21:06 -08:00
Sam Lantinga 0f973f3eb4 Removed SDL_RENDERCMD_SETCOLORSCALE, which ended up being a noop on all renderers 2024-02-21 19:25:49 -08:00
Sam Lantinga 54c2ba6afd Added the Chrome HDR tonemap operator
Also added support for the SDL_PIXELFORMAT_XBGR2101010 pixel format to the D3D12, D3D11, and Metal renderers.
2024-02-21 19:25:49 -08:00
Sam Lantinga 4ba6aeee9d A second take on HDR support with an SDR white point and HDR headroom
This better reflects how HDR content is actually used, e.g. most content is in the SDR range, with specular highlights and bright details beyond the SDR range, in the HDR headroom.

This more closely matches how HDR is handled on Apple platforms, as EDR.

This also greatly simplifies application code which no longer has to think about color scaling. SDR content is rendered at the appropriate brightness automatically, and HDR content is scaled to the correct range for the display HDR headroom.
2024-02-21 19:25:49 -08:00
Ozkan Sezer 3b7533f4a2 SDL_camera_v4l2: allow building against older kernel headers 2024-02-22 00:50:40 +03:00