Commit Graph

1311 Commits (d51b53ef8f76ee6dc49115fb7981b84e5b0f02b4)

Author SHA1 Message Date
Simon McVittie 7c089f4e57 testautomation_math: Fix misleading log output
These originally checked for expected ± EPSILON as logged, but since
commit 880c6939 they check for expected ± max_err, where max_err may
need to be greater than EPSILON for very large expected results like
the ones in exp_regularCases().

Also, EPSILON is so small that the default precision of the %f format
(6 decimal places) would never actually have shown its effect, so log
it in scientific notation instead.

Fixes: 880c6939 "testautomation_math: do relative comparison + more precise correct trigonometric values"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-02 07:44:04 -08:00
Simon McVittie b66dba2a9d test: Don't accept results that are much less than expected
While looking at the other tests in this file, I noticed that instead
of checking for a result in the range of expected ± FLT_EPSILON as I
would have expected, these tests would accept any result strictly less
than expected + FLT_EPSILON, for example a wrong result that is very
large and negative. This is presumably not what was intended, so add
the SDL_fabs() that I assume was meant to be here.

Fixes: 474c8d00 "testautomation: don't do float equality tests"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-02 07:44:04 -08:00
Anonymous Maarten f1f9e27128 testautomation_math: do relative comparison + more precise correct trigonometric values
If the magnitude of the expected result is small, then we can safely
assume that the actual calculated result matches it to 10 decimal
places.

However, if the magnitude is very large, as it is for some of our exp()
tests, then 10 decimal places represents an unrealistically high level
of precision, for example 24 decimal digits for the test that is
expected to return approximately 6.6e14. IEEE 754 floating point only
has a precision of about 16 decimal digits, causing test failure on
x86 compilers that use an i387 80-bit extended-precision register for
the result and therefore get a slightly different answer.

To avoid this, scale the required precision with the magnitude of the
expected result, so that we accept a maximum error of either 10 decimal
places or 1 part in 1e10, whichever is greater.

[smcv: Added longer commit message explaining why we need this]
(cherry picked from commit 880c69392ae10c726fc97f17b6e5e2173f70b62f)
2024-02-02 07:44:04 -08:00
Simon McVittie babca704e0 testautomation: Don't expect exp to yield exact floating point results
In the Steam Runtime 1 'scout' environment, when compiling for i386
using the default gcc-4.6, Exp(34.125) matches the desired value to the
precision shown in the log (6 decimal places) but is not an exact match
for the desired value.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-02 07:44:04 -08:00
Sam Lantinga d04fea8b87 Even more miscellaneous gamepad buttons! 2024-02-01 20:34:05 -08:00
Sam Lantinga cb70e972e3 Added miscellaneous gamepad buttons for additional macro buttons on some controllers 2024-02-01 20:15:01 -08:00
Sam Lantinga ea0853d23d Added an HDR gradient test to testcolorspace 2024-02-01 15:36:49 -08:00
Sam Lantinga 90597aeaef HDR10 colorspace isn't currently supported
You can't do blending directly in PQ space, which means you have to create a scene render target in linear space and use shaders to convert PQ texture data to linear, etc. All of this is out of scope for the SDL 2D renderer at the moment.
2024-02-01 12:17:35 -08:00
Sam Lantinga 496ed01bdb Detect blending in HDR10 colorspace 2024-02-01 12:17:35 -08:00
Sam Lantinga 6f443e2aca Added support for the scRGB colorspace on D3D11 and D3D12 2024-01-31 18:07:00 -08:00
Sam Lantinga c1f97c8e07 Fixed testgeometry after color format change (thanks @sezero!) 2024-01-30 23:31:48 -08:00
Sam Lantinga f257eb4481 Added the concept of colorspace to the SDL renderer
This allows color operations to happen in linear space between sRGB input and sRGB output. This is currently supported on the direct3d11, direct3d12 and opengl renderers.

This is a good resource on blending in linear space vs sRGB space:
https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

Also added testcolorspace to verify colorspace changes
2024-01-30 09:48:02 -08:00
Sam Lantinga 554f0625d3 Renderer colors now have floating point precision 2024-01-30 09:48:02 -08:00
Frank Praznik 344ec60f8f tests: Fix window centering test with Wayland display scaling mode
The usable fullscreen bounds need to be queried after window creation, as Wayland can send different usable bounds depending on the focused window's scaling mode.
2024-01-28 13:31:42 -05:00
Sam Lantinga 9f7eb6c4c1 Fixed testautomation log callback calling convention 2024-01-27 22:44:13 -08:00
Sam Lantinga 12bdb2b4d0 Added the environment variable SDL_LOGGING to control default log output 2024-01-27 19:30:22 -08:00
Sam Lantinga f66fe7e221 Replaced SDL_GetJoystickCaps() with joystick properties
Fixes https://github.com/libsdl-org/SDL/issues/8927
2024-01-27 15:11:52 -08:00
Sam Lantinga 3b55c7d1f4 Shortened SDL property names 2024-01-27 13:00:50 -08:00
Sam Lantinga 5ddd97062e Added test code to validate SDL_WaitEventTimeout()
You can enable this by defining TEST_WAITEVENTTIMEOUT
2024-01-25 06:29:15 -08:00
Ozkan Sezer 205c417f74 testgles2.c, testgles2_sdf.c: adjust for new SDL_PLATFORM_WINDOWS meaning. 2024-01-24 21:20:50 +03:00
Anonymous Maarten 31d133db40
Define SDL_PLATFORM_* macros instead of underscored ones (#8875) 2024-01-24 01:40:51 +00:00
Sam Lantinga cd231a65f6 Added SDL_GetJoystickCaps() and SDL_GetGamepadCaps() to get the capabilities of controllers
Also added SDL_GAMEPAD_CAP_PLAYER_LED to let the application know if the controller has a visible player LED
2024-01-22 19:23:42 -08:00
Sam Lantinga 8f20ef5b43 Re-enable C runtime with Mingw, and disable the problematic math test 2024-01-21 06:55:29 -08:00
Sam Lantinga 5e70ee29cc Build SDL with the static C runtime on Visual Studio 2024-01-21 06:55:29 -08:00
Sam Lantinga 8c7f5b73e8 Fixed build
The flip directions aren't 1 and -1, just use SDL_FLIP_NONE for now
2024-01-20 08:42:52 -08:00
Sam Lantinga 308906ba25 Added SDL_FlipSurface() to flip a surface vertically or horizontally
Fixes https://github.com/libsdl-org/SDL/issues/8857
2024-01-20 06:31:37 -08:00
Sam Lantinga 64972b4184 Fixed build 2024-01-19 17:21:05 -08:00
Sam Lantinga 6a00ae7e58 Fixed rendering diagonal lines within a viewport
The drawing uses the origin of the viewport as the coordinate origin, so we only need to clip against the size of the viewport.

Also added a unit test to catch this case in the future
2024-01-19 16:29:38 -08:00
Simon McVittie 81ac656b7c SDL_CalculateRGBSize, SDL_CalculateYUVSize: set the error indicator
These functions historically didn't set the error indicator on overflow.

Before commit 447b508a "error: SDL's allocators now call SDL_OutOfMemory
on error", their callers would call SDL_OutOfMemory() instead, which was
assumed to be close enough in meaning: "that's a silly amount of memory
that would overflow size_t" is similar to "that's more memory than
is available". Now that responsibility for calling SDL_OutOfMemory()
has been pushed down into SDL_calloc() and friends, the functions that
check for overflows might as well set more specific errors.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-18 13:21:50 -08:00
Simon McVittie e9a0edc847 testautomation_surface: Really make width * bpp overflow
A surface of width (0x7fff'ffff) / 2 = 0x3fff'ffff is not quite large
enough to make the pitch overflow in the way we wanted to test here:
with a 32-bit format, that makes each row 0xffff'fffc bytes, which
(just) fits in a 32-bit unsigned size_t. Increasing it to 0x4000'0000
pixels per row is enough to trigger the overflow we intended to test.

In SDL 2, this test bug was hidden by the fact that allocating
0xffff'fffc bytes on a 32-bit platform is very likely to fail, and SDL 2
reported both "malloc() failed" and "this amount of memory is too large
for a size_t" with the same error code.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-18 13:21:50 -08:00
Simon McVittie eb059538f8 testautomation_surface: Really make pitch + alignment overflow
Adding 3 bytes of alignment to 0x7fff'ffff is not enough to make it
overflow a 4-byte unsigned size_t, so this test was not exercising
the intended failure mode. We cannot actually make this overflow
with a signed 32-bit width and an 8-bit format: the maximum width is
not enough to achieve that. However, if we switch to a 24-bit format,
we can make the calculation overflow.

In SDL 2, this test bug was hidden by the fact that allocating
0x7fff'ffff bytes on a 32-bit platform will usually fail, and SDL 2
reported both "malloc() failed" and "this amount of memory is too large
for a size_t" with the same error code.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-18 13:21:50 -08:00
Ozkan Sezer 4fdc291f5d Add spaces around SDL_PRI??? to avoid potential compiler warnings. 2024-01-18 23:41:10 +03:00
Sam Lantinga a31dc6dfcb Switched SDL_TouchID and SDL_FingerID to be Uint64 with 0 being an invalid value 2024-01-18 10:55:24 -08:00
Sam Lantinga cda2bffeee Re-add SDL_HAPTIC_SQUARE for SDL 3.0
Fixes https://github.com/libsdl-org/SDL/issues/8753
Closes https://github.com/libsdl-org/SDL/pull/8831
Closes https://github.com/libsdl-org/SDL/pull/8783
2024-01-18 09:24:03 -08:00
Sam Lantinga fc0c774976 Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()
Also renamed SDL_threadID to SDL_ThreadID and made it Uint64 for consistency with other ID types
2024-01-18 08:18:37 -08:00
Sam Lantinga d6a41f8f31 Updated SDL_TimerID to use the same type as other IDs in SDL 2024-01-18 07:08:15 -08:00
Sam Lantinga f8dfee01bb Made SDL_ReadSurfacePixel a public function
Fixes https://github.com/libsdl-org/SDL/issues/8320
2024-01-18 07:00:10 -08:00
Ozkan Sezer f7ba340999 remove several instances of unnecessary emptry str "" after SDL_PRI??? 2024-01-18 17:25:50 +03:00
Sam Lantinga c540c77756 Removed SDL_INIT_EVERYTHING
Fixes https://github.com/libsdl-org/SDL/issues/8709
2024-01-18 06:17:58 -08:00
Sam Lantinga a2665f54c8 Updated the atomic API for SDL 3.0 naming conventions
Fixes https://github.com/libsdl-org/SDL/issues/7388
2024-01-18 04:41:34 -08:00
Sam Lantinga f224af5ac5 Updated Haptic API for SDL 3.0 conventions
Also removed the XInput haptic support since using the haptic API for rumble is no longer supported.
2024-01-18 03:26:11 -08:00
Frank Praznik 4f3d4bd110 wayland: Add the ability to import and wrap external surfaces
Add the ability to import and wrap external surfaces from external toolkits such as Qt and GTK.

Wayland surfaces and windows are more intrinsically tied to the client library than other windowing systems, so it is necessary to provide a way to initialize SDL with an existing wl_display object, which needs to be set prior to video system initialization, or export the internal SDL wl_display object for use by external applications or toolkits. For this, the global property SDL_PROPERTY_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER is used.

A Wayland example was added to testnative, and a basic example of Qt 6 interoperation is provided in the Wayland readme to demonstrate the use of external windows with both SDL owning the wl_display, and an external toolkit owning it.
2024-01-15 13:54:35 -05:00
Sylvain 101f903bb1 testgeometry: allow to use arrows to move the triangle 2024-01-12 11:53:34 -08:00
Sylvain cf0d1d7234 Fixed ASAN warning, runtime error: left shift of 160 by 24 places cannot be represented in type 'int' 2024-01-11 09:00:19 -08:00
Frank Praznik ec2159d492 tests: Clean up the window creation properties in the Wayland custom surface example 2024-01-10 11:17:06 -05:00
Sam Lantinga ccae9c1ef6 Only initialize audio drivers that have been requested
If testautomation is running with only a specific audio driver enabled, we shouldn't try to open other ones, as they might fail.

Fixes https://github.com/libsdl-org/SDL/issues/8797

(cherry picked from commit 4c11307a4e75fbfde0d8ace6b19d612d2973bf0b)
2024-01-08 14:35:42 -08:00
Frank Praznik f7dd0f9491 wayland: Allow the creation of roleless window surfaces for custom application use
Allow for the creation of SDL windows with a roleless surface that applications can use for their own purposes, such as with a windowing protocol other than XDG toplevel.

The property `wayland.surface_role_custom` will create a window with a surface that SDL can render to and handles input for, but is not associated with a toplevel window, so applications can use it for their own, custom purposes (e.g. wlr_layer_shell).

A test/minimal example is included in tests/testwaylandcustom.c
2024-01-08 14:54:47 -05:00
Simon McVittie 8e7c0b34d7 test: If SDL_CreateRenderer() fails, say why
Helps: https://github.com/libsdl-org/SDL/issues/8799
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-08 11:02:12 -08:00
Simon McVittie 022ff075b9 test: When listing test-cases, say which ones are disabled
When a test has been disabled because it's known not to work reliably
or it's a test for unimplemented functionality, we probably don't want
to encourage developers and testers to run it and report its failures
as a bug.

Helps: #8798, #8800
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-08 09:44:09 -08:00
Sam Lantinga 7eae08cfc4 Removed SDL_GL_BindTexture() and SDL_GL_UnbindTexture()
Now that we have the OpenGL texture properties, you can directly bind them yourself.

Fixes https://github.com/libsdl-org/SDL/issues/2124
2024-01-07 20:19:19 -08:00
Sam Lantinga 1a13dae219 Added constant definitions for SDL properties
Fixes https://github.com/libsdl-org/SDL/issues/8622
2024-01-07 16:59:41 -08:00
Ozkan Sezer b4b5dbd92f testcontroller.c: fixed warnings. 2024-01-03 14:40:20 +03:00
Sam Lantinga 5b3ee51c6c Updated copyright for 2024 2024-01-01 13:15:26 -08:00
Frank Praznik 8f94102b04 tests: Use unsigned format specifiers for printing flags 2023-12-29 14:41:38 -05:00
Sam Lantinga ebd7f9adbd Fixed warning C4245: 'initializing': conversion from 'int' to 'Uint32', signed/unsigned mismatch in SDL_video.c 2023-12-29 10:37:28 -08:00
Sam Lantinga 61704b5862 Removed an assertion it's possible to hit 2023-12-28 15:22:28 -08:00
Susko3 a961066d0b Add basic touch/finger support to `testpen.c`
Reuses the pen code as much as possible.

Seems like the right place, see
https://github.com/libsdl-org/SDL/pull/8749#issuecomment-1869671334.
2023-12-26 13:42:19 -08:00
Sam Lantinga 74418e1aa8 Made the cursor list check a compile time assert instead of a runtime one
This will catch this being out of date more quickly in the future
2023-12-26 09:57:11 -08:00
Susko3 a28ac29aa0 Add missing cursor types
The flowing assert would trip:
    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS)
2023-12-26 09:12:17 -08:00
Sylvain 56f111dffc Fix compilation / same as sdl2-compat
testautomation_platform.c:351:28: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  351 |     result = SDL_SetError("%s", testError);
      |                            ^~
/home/slvn/release/Release_SDL/sdl2-compat/test/testautomation_platform.c:364:64: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  364 |                             "SDL_GetError(): expected message '%s', was message: '%s'",
2023-12-20 22:28:50 +03:00
Sam Lantinga c981a597dc Added Steam Input API support for game controllers
Added support for getting the real controller info, as well as the function SDL_GetGamepadSteamHandle() to get the Steam Input API handle, from the virtual gamepads provided by Steam.

Also added an event SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED which is triggered when a controller's API handle changes, e.g. the controllers were reassigned slots in the Steam UI.
2023-12-20 10:40:28 -08:00
Sam Lantinga 7f75178908 Verify that the %p format specifier works for 64-bit pointers 2023-12-17 08:14:20 -08:00
Sam Lantinga cbf9012c74 Fixed build 2023-12-15 10:03:11 -08:00
Sam Lantinga 5547007915 Added test for inverted cursor 2023-12-15 09:59:50 -08:00
Sam Lantinga 581d1cab25 You should call present when using a software renderer as well.
Fixes https://github.com/libsdl-org/SDL/issues/8676
2023-12-11 08:43:31 -08:00
Sam Lantinga 445f08a0fb Print the gamepad player index when opening a gamepad 2023-12-09 21:00:11 -08:00
Frank Praznik 63ae84e140 x11: Improve sync algorithm
Track and check move and resize requests separately, and consider them done if either the window is already at the expected location, or at least one configure event which moved or resized the window was processed. The avoids a timeout condition if resizing the window caused it to be implicitly moved in order to keep it within desktop bounds.

The automated positioning test now runs on GNOME/X11 without any sync requests timing out.
2023-12-08 13:14:55 -05:00
Anonymous Maarten a197efe3a7 pen: fix leak caused by pen subsystem 2023-12-07 20:38:00 +01:00
Anonymous Maarten 7484d02a2e testshape: use SDL_test to create multiple windows 2023-12-07 20:38:00 +01:00
Frank Praznik 4fd778119b video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.

With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.

The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.

Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.

The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.

Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-12-07 10:26:19 -08:00
Sam Lantinga ac0751a652 Added SDL_strnstr() 2023-12-03 15:06:46 -08:00
Ryan C. Gordon 447b508a77
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.

This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.

The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.

Fixes #8642.
2023-11-30 00:14:27 -05:00
Ryan C. Gordon dd47da8a5c gamepad: Replace GetNumMappings/GetMappingByIndex with a single function.
Now it returns an array and optional count, to match other SDL3 APIs.
2023-11-29 20:50:44 -05:00
Ryan C. Gordon c5daf8adb1 testcontroller: Don't query the mapping list until after they are available.
The included ones need to wait until SDL_Init has run, or you'll get an empty
list, and we might also be adding more from an external gamecontrollerdb.txt
file, too.
2023-11-29 10:33:31 -05:00
Cameron Cawley df05d5eff4 Fix scroll wheel handling in testmouse 2023-11-28 14:41:16 -08:00
Anonymous Maarten fea6e7afb1 cmake: copy sources to binary directory in separate target
Don't do it in POST_BUILD to avoid multiple parallel builds
stepping on each others toes.
Also don't use copy_if_different, but unconditionally copy it.
The build system should take care of dependencies.
2023-11-28 22:16:54 +01:00
Sylvain 6bb40f1d8d SDL_VideoCapture: allow add/remove device at runtime on linux 2023-11-27 16:01:10 -05:00
Ryan C. Gordon 74a2542564
x11: Deal with difference in GLX_EXT_swap_control_tear behavior.
Mesa and Nvidia handle it differently, and one or the other may fix their
implementation in the future, so test which way it works at runtime.

Reference Issue #8004.
2023-11-23 13:56:51 -05:00
Anonymous Maarten a45b371de0 cmake: create and install SDL3::Jar target for Android 2023-11-23 02:13:08 +01:00
Sam Lantinga eca79e38db Removed test shape images 2023-11-22 14:11:10 -08:00
Sam Lantinga 81fc7ded78 Removed the window shape API for SDL 3.0
Fixes https://github.com/libsdl-org/SDL/issues/6654
Fixes https://github.com/libsdl-org/SDL/issues/6897
2023-11-22 14:11:10 -08:00
Zack Middleton 5e9b0820f3 Add cursors for X11/Wayland window resizing 2023-11-21 08:34:13 -08:00
Ryan C. Gordon 5b1c68c2f3
testshader: Don't make local variables with the same name as GL entry points.
Reference Issue #2706.

(cherry picked from commit cb5b8c97472ed1c759bb6934372e3c3ff4aad8f3)
2023-11-20 15:12:37 -05:00
Cameron Cawley 05e7dcf8f8 Support returning <8bpp surfaces in SDL_LoadBMP_RW 2023-11-17 08:45:32 -08:00
Cameron Cawley 753bbd199e Add SDL_PIXELFORMAT_INDEX2LSB and SDL_PIXELFORMAT_INDEX2MSB 2023-11-17 08:45:32 -08:00
Cameron Cawley fda69e5e79 Test both MSB and LSB indexed surfaces in testautomation 2023-11-17 08:45:32 -08:00
Sam Lantinga d4448fe3d2 Update virtual joystick test now that we're just using abxy for mappings, for compatibility 2023-11-16 00:02:47 -08:00
Sam Lantinga f40f272107 Fixed build 2023-11-15 23:58:39 -08:00
Sam Lantinga 34bdd321bf Improved navigation while setting up controller mapping
* Moving forward and backward don't clear the current binding
* Use the tertiary face button to delete the current binding
* More small improvements to make navigation more intuitive
2023-11-15 23:46:31 -08:00
Sam Lantinga 57e5c7f6ee We'll just use the legacy names for face buttons in the mappings
This fixes being able to accidentally rebind the face buttons in testcontroller
2023-11-15 22:09:09 -08:00
Sam Lantinga 2ff9255f29 Print the GUID for controllers that don't have a mapping 2023-11-15 21:04:25 -08:00
Sam Lantinga e0c45c6c98 Renamed SDL_WINDOW_FOREIGN to SDL_WINDOW_EXTERNAL 2023-11-14 06:06:51 -08:00
Sam Lantinga 229b7b9d50 SDL_CreateWindowWithPosition() and SDL_CreateWindowFrom() have been replaced with SDL_CreateWindowWithProperties()
This is a more general interface that can be extended in the future as needed.
2023-11-14 06:06:51 -08:00
Sam Lantinga 1c4723ac66 SDL_CreateWindowFrom() now takes a set of properties that describe the native window and options. 2023-11-12 21:58:58 -08:00
Sam Lantinga 6afae6681b Allow casting properties of different types 2023-11-12 21:58:58 -08:00
Sam Lantinga bd269b0f41 Added SDL_SetBooleanProperty() and SDL_GetBooleanProperty() 2023-11-12 21:58:58 -08:00
Sam Lantinga 0907f345cb Added property types: pointer, string, number, float 2023-11-12 10:48:38 -08:00
Christoph Reichenbach 7c80ac6df7 API for pressure-sensitive pens + XInput2/Wayland
This patch adds an API for querying pressure-
sensitive pens, cf. SDL_pen.h:
- Enumerate all pens
- Get pen capabilities, names, GUIDs
- Distinguishes pens and erasers
- Distinguish attached and detached pens
- Pressure and tilt support
- Rotation, distance, throttle wheel support
  (throttle wheel untested)
- Pen type and meta-information reporting
  (partially tested)

Pen event reporting:
- Three new event structures: PenTip, PenMotion, and
  PenButton
- Report location with sub-pixel precision
- Include axis and button status, is-eraser flag

Internal pen tracker, intended to be independent
of platform APIs, cf. SDL_pen_c.h:
- Track known pens
- Handle pen hotplugging

Automatic test:
- testautomation_pen.c

Other features:
- XInput2 implementation, incl. hotplugging
- Wayland implementation, incl. hotplugging
- Backward compatibility: pen events default to
  emulating pens with mouse ID SDL_PEN_MOUSEID
- Can be toggled via SDL_HINT_PEN_NOT_MOUSE
- Test/demo program (testpen)
- Wacom pen feature identification by pen ID

Acknowledgements:
- Ping Cheng (Wacom) provided extensive feedback
  on Wacom pen features and detection so that
  hopefully untested Wacom devices have a
  realistic chance of working out of the box.
2023-11-12 09:52:02 -08:00
Sam Lantinga f66f61de01 Fixed missing "0" in the button list 2023-11-11 08:30:13 -08:00
Sylvain Becker 04b6b2979f
Re-add SDL_assert() with non boolean ptr syntax (#8530) 2023-11-11 12:28:24 +03:00
Sam Lantinga b374105975 Replaced SDL_GetTextureDXGIResource() with texture properties
Fixes https://github.com/libsdl-org/SDL/issues/8529
2023-11-10 20:38:13 -08:00
Sam Lantinga a5a47d3bee Fixed crash if there is no controller mapping 2023-11-10 16:39:32 -08:00
Sam Lantinga 2991b9f6ac SDL now represents gamepad buttons as positional elements with a separate label
This gives applications and binding systems a clearer view of what the hardware is so they can make intelligent decisions about how to present things to the user.

Gamepad mappings continue to use abxy for the face buttons for simplicity and compatibility with earlier versions of SDL, however the "SDL_GAMECONTROLLER_USE_BUTTON_LABELS" hint no longer has any effect.

Fixes https://github.com/libsdl-org/SDL/issues/6117
2023-11-10 12:21:43 -08:00
Sylvain d8600f717e Pointer as bool (libsdl-org#7214) 2023-11-09 14:18:36 -08:00
Sylvain 59f93e20a7 Add SDL Video Capture, with back-end for linux/macos/ios/android 2023-11-09 08:36:23 -08:00
Anonymous Maarten a6541166bc cmake: also install pdb files of static libraries 2023-11-09 02:17:07 +01:00
Sam Lantinga 1934417b4d Show the existing mapping when a controller is connected 2023-11-08 12:38:54 -08:00
Sam Lantinga fd4a2cce9e SDL_syswm.h has been removed and replaced with window properties 2023-11-08 12:01:48 -08:00
Sam Lantinga aea6e6de6f Simplified SDL_SetProperty() and added SDL_SetPropertyWithCleanup()
Most of the time people won't need to set a cleanup callback, so we can simplify the more commonly used API.
2023-11-08 12:01:48 -08:00
Sam Lantinga a1941fad6c Replaced SDL_RenderGetD3D11Device(), SDL_RenderGetD3D12Device(), and SDL_RenderGetD3D9Device() with renderer properties. 2023-11-08 12:01:48 -08:00
Ryan C. Gordon 2f92807087
vulkan: SDL_Vulkan_CreateSurface now accepts an app-provided allocator.
Fixes #3638.
2023-11-06 13:31:20 -05:00
Ryan C. Gordon c53843a961
docs: Remove Doxygen `\brief` tags.
Doxygen and the wiki bridge don't need them; they'll both just use the first
line/sentence instead.

Fixes #8446.
2023-11-06 10:26:06 -05:00
Sam Lantinga f7d40b7594 Added 10-bit pixel formats in addition to SDL_PIXELFORMAT_ARGB2101010
Added SDL_PIXELFORMAT_XRGB2101010, SDL_PIXELFORMAT_XBGR2101010, SDL_PIXELFORMAT_ABGR2101010

Fixes https://github.com/libsdl-org/SDL/issues/3553
2023-11-06 00:41:09 -08:00
Frank Praznik 21ff699251 test: Fix popup test crash on exit
If the done signal is emitted by the common event handler, the window and all of its children have already been destroyed, so don't try to render with invalid renderer objects.
2023-11-05 12:29:22 -05:00
Sam Lantinga 70c149c88f Automatically clean up memory associated with events 2023-11-05 09:14:11 -08:00
Sam Lantinga 75ea3a8d32 Dynamically allocate long text for SDL_EVENT_TEXT_INPUT events
This prevents input text from being split across Unicode combining or modifier characters, and in practice allocations will rarely happen.
2023-11-04 20:55:10 -07:00
Sam Lantinga f9d11807c0 Added SDL_RWprintf() and SDL_RWvprintf() to do formatted printing to an SDL_rwops stream
Fixes https://github.com/libsdl-org/SDL/issues/2390
2023-11-04 16:46:08 -07:00
Sam Lantinga 7e445da569 Added SDL_CleanupEvent()
This is used to free any dynamically allocated memory in events.
2023-11-04 06:47:24 -07:00
Ivan Mogilko c4bf05fd9d Added subsystem refcount tests to testautomation 2023-11-04 00:52:08 -07:00
Sam Lantinga f3261fedcc Code cleanup now that SDL_bool is equivalent to a C boolean expression 2023-11-03 09:54:04 -07:00
ilyas-taouaou d0d8b28df1 Change SDL_Vulkan_GetInstanceExtensions 2023-11-02 14:27:36 -04:00
Ryan C. Gordon 9c664b0062
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:

First:

    int SDL_AppInit(int argc, char **argv);

This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.

Then:

     int SDL_AppIterate(void);

This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).

Next:

    int SDL_AppEvent(const SDL_Event *event);

This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.

Finally:

    void SDL_AppQuit(void);

This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.

The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.

In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.

On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).

Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.

The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.

Fixes #6785.
Reference PR #8247.
2023-11-01 18:40:41 -04:00
Ryan C. Gordon dcc8805c21
testaudio: Fixed compiler warning on Visual Studio. 2023-10-30 13:09:56 -04:00
Ryan C. Gordon 899eb0d042 thread: Locking mutexes and rwlocks are now void functions.
Almost nothing checks these return values, and there's no reason a valid
lock should fail to operate. The cases where a lock isn't valid (it's a
bogus pointer, it was previously destroyed, a thread is unlocking a lock it
doesn't own, etc) are undefined behavior and always were, and should be
treated as an application bug.

Reference Issue #8096.
2023-10-26 08:57:34 -04:00
Sam Lantinga 39a961ba41 Added support for "%[]" sscanf syntax
Fixes https://github.com/libsdl-org/SDL/issues/8423
2023-10-24 17:28:15 -07:00
Ryan C. Gordon c6f08c2553
testaudio: Removed debugging code. 2023-10-16 15:25:34 -04:00
Ryan C. Gordon d5dac0ad27
testaudio: Deal with a texture being unexpectedly NULL when scaling.
This happens to work because our current textures are all 128x128, but in
theory one shouldn't hit this case anyhow...right?!

Reference Issue #8344.
2023-10-16 14:03:58 -04:00
Ryan C. Gordon b19e68c8ec
testaudio: Properly display playback progress, regardless of data source. 2023-10-16 13:56:43 -04:00
Ryan C. Gordon 354611a0c6
testaudio: Fixed some bugs Valgrind pointed out. 2023-10-16 10:04:02 -04:00
Ryan C. Gordon 1c6d996108
testaudio: if the SDL_Renderer is already gone, don't destroy SDL_Textures. 2023-10-14 23:17:59 -04:00
Ryan C. Gordon b17151eb16
testaudio: Don't crash if renderer is NULL (happens during shutdown). 2023-10-14 13:43:22 -04:00
Anonymous Maarten 382751c4b5 testffmpeg: print usage of options to change audio/video codec 2023-10-13 02:30:14 +02:00
Sam Lantinga f91bde64d5 testffmpeg: Only enable blending if we're using a texture format that supports it 2023-10-12 14:26:46 -07:00
Sam Lantinga 516d6f9efc testffmpeg: added support for YUVA formats using swscale
Fixes https://github.com/libsdl-org/SDL/issues/8377
2023-10-12 14:10:25 -07:00
Sam Lantinga d18f910248 testffmpeg: added the ability to specify audio and video codecs 2023-10-12 11:38:14 -07:00
Sam Lantinga bf64fecf19 testffmpeg: allow resizing of the video window 2023-10-12 00:04:00 -07:00
Sam Lantinga efa9a45048 Clarified that testffmpeg will resize the window to the video size 2023-10-11 23:38:08 -07:00
Sam Lantinga 4368f70ff9 Added properties to various SDL objects
The following objects now have properties that can be user modified:
* SDL_AudioStream
* SDL_Gamepad
* SDL_Joystick
* SDL_RWops
* SDL_Renderer
* SDL_Sensor
* SDL_Surface
* SDL_Texture
* SDL_Window
2023-10-11 22:38:00 -07:00
Sam Lantinga 973c8b3273 Added SDL properties API
Fixes https://github.com/libsdl-org/SDL/issues/7799
2023-10-11 22:38:00 -07:00
Anonymous Maarten 1ae33f6751 cmake: optionally install pdb's 2023-10-12 02:26:48 +02:00
Sam Lantinga c552cc6847 We don't require the audio system to be initialized for audio format conversion
This is helpful for tools pipelines where audio devices are never used.
2023-10-11 09:23:23 -07:00
Ryan C. Gordon bb2f767f5d
testaudio: Make program usable without a 3-button mouse. 2023-10-11 10:02:07 -04:00
Anonymous Maarten ebfbd7327b testffmpeg: use SDL_test to parse arguments and track memory 2023-10-10 21:58:10 +02:00
Anonymous Maarten ee53e4d319 cmake: check ffmpeg capability instead of version 2023-10-10 21:58:10 +02:00
Sam Lantinga adcace6f95 Added a "--software" option to testffmpeg
This allows easy performance comparison between hardware and software decoding
2023-10-10 04:07:22 -07:00
Ozkan Sezer 86ada8a9f0 fix testffmpeg.c build. 2023-10-10 14:02:40 +03:00
Sam Lantinga 303f4e965c testffmpeg works with ffmpeg 5.1.3 and newer 2023-10-10 03:58:57 -07:00
Sam Lantinga 2bd478ae65 Added SDL_GetTextureDXGIResource() to get the DXGI resource associated with a render texture.
Also switched the D3D11 and D3D12 renderers to use real NV12 textures for NV12 data.

The combination of these two changes allows us to implement 0-copy video decode and playback for D3D11 in testffmpeg without any access to the renderer internals.
2023-10-10 03:32:46 -07:00
Sam Lantinga a842446f62 Added support for 0-copy decode and display using D3D11
FIXME: We need a way to do this that doesn't involve reaching into the D3D11 texture internals
2023-10-10 03:32:46 -07:00
Sam Lantinga d830cd140b Added support for 0-copy decode and display using Apple VideoToolbox 2023-10-10 03:32:46 -07:00
Sam Lantinga 1bf913b29a Added support for 0-copy decode and display using VAAPI and EGL 2023-10-10 03:32:46 -07:00
Sam Lantinga ce8161e0cf Make sure we're building with ffmpeg 6.0 or newer 2023-10-10 03:32:46 -07:00
Sam Lantinga ed6381b68d Allow setting any number of sprites over the video
Default to no sprites over the video
2023-10-10 03:32:46 -07:00
Anonymous Maarten ebf5e08fa1 cmake: use *_STATIC_* variables when linking to a static ffmpeg 2023-10-10 03:32:46 -07:00
Sam Lantinga 88f2fb9dcf Added an example of video decoding with ffmpeg 2023-10-10 03:32:46 -07:00
Simon McVittie 04edb38cdf shape: Use SDL[Test]_ReadSurfacePixel
This avoids assuming that the pixels are suitably aligned for direct
access, which there's no guarantee that they are; in particular,
3-bytes-per-pixel RGB images are likely to have 3 out of 4 pixels
misaligned. On x86, dereferencing a misaligned pointer does what you
would expect, but on other architectures it's undefined whether it will
work, crash with SIGBUS, or silently give a wrong answer.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-10 03:23:20 -07:00
Anonymous Maarten 183606d3d4 testdrawchessboard: clean up renderer and window 2023-10-05 13:41:01 +02:00
Frank Praznik 64ec208479 Fix log message spelling 2023-10-02 19:47:39 -04:00
Frank Praznik 9111c5e178 tests: Disable mouse warp test under Wayland
Wayland does not allow warping the mouse pointer, thus these tests are unreliable and should be skipped.
2023-10-02 19:44:02 -04:00
Simon McVittie 6248472c0c test: Accept small numerical differences in more mathematical tests
We can't rely on irrational numbers like pi being represented exactly,
particularly when compiling for i386, where the i387 floating-point
interface carries out calculations in registers that have higher
precision than the actual double-precision variable. The 1980s were a
strange time.

Resolves: https://github.com/libsdl-org/SDL/issues/8311
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-09-28 09:37:12 -07:00
Anonymous Maarten f5886f11d0 cmake: let every test depends on pretest 2023-09-25 18:02:40 +02:00
Anonymous Maarten f45761908a Move check for SDL_Delay upper bounds to testtimer 2023-09-25 18:02:40 +02:00
Anonymous Maarten 474c8d0073 testautomation: don't do float equality tests 2023-09-25 18:02:40 +02:00
Anonymous Maarten 85e3099ba4 testautomation: only require accelated renderer with non-dummy video driver 2023-09-25 18:02:40 +02:00
Anonymous Maarten 0e955a9127 cmake: run testautomation with CTest 2023-09-25 18:02:40 +02:00
Ryan C. Gordon e0b0f9a36e
testaudio: Fix mouseover testing.
Not sure how this line got lost.
2023-09-20 17:02:44 -04:00
Ryan C. Gordon b656720bc6 loopwave: Use SDL_GetAudioStreamQueued() for more accurate results. 2023-09-20 10:15:03 -04:00
Anonymous Maarten 4c3e84897f testspriteminimal: make standalone by embedding icon.bmp 2023-09-19 17:58:25 +02:00
Anonymous Maarten 2a01f9dcb5 tests: plug leaks when running with --trackmem
(using SDL_VIDEO_DRIVER=x11/wayland on Linux)
2023-09-19 17:58:25 +02:00
Brick a62e62f97a Refactored SDL_audiocvt.c 2023-09-17 13:13:23 -07:00
Ryan C. Gordon 2f43f7bc53
audio: Allow querying of device buffer size. 2023-09-13 11:03:17 -04:00
Ryan C. Gordon 8b26e95f91
audio: Change SDL_AudioStreamCallback
Now it offers the total requested bytes in addition to the amount
immediately needed (and immediately needed might be zero if the stream
already has enough queued to satisfy the request.
2023-09-13 10:11:23 -04:00
Sam Lantinga cd633b9a88 Renamed SDL_IsAudioDevicePaused() to SDL_AudioDevicePaused()
This aligns with the SDL3 convention of removing "Is" from self-explanatory function names

Also improved some documentation in SDL_audio.h
2023-09-12 12:11:09 -07:00
Ryan C. Gordon 3a992af446 audio: Added a postmix callback to logical devices.
You can see it in action in testaudio by mousing over a logical device; it
will show a visualizer for the current PCM (whatever is currently being
recorded on a capture device, or whatever is being mixed for output on
playback devices).

Fixes #8122.
2023-09-09 16:26:37 -04:00
Anonymous Maarten a2e17852d9 cmake: make sure SDL_GetPrefPath is run before testfilesystem
60 seconds timeout ought to be sufficient.
2023-09-08 09:05:58 -04:00
Ryan C. Gordon ad1313e751
testaudio: Patched to compile.
(this was a piece of PR #8213 that accidentally creeped into main.)
2023-09-07 16:03:49 -04:00
Ryan C. Gordon 5747ddc012
testaudio: Clean up some messy memory management. 2023-09-07 10:50:11 -04:00
Brick f2ca9a615b Added SDL_AUDIO_FRAMESIZE 2023-09-05 17:56:58 -07:00
Brick 53122593f8 Added SDL_AUDIO_BYTESIZE 2023-09-05 17:56:58 -07:00
Sam Lantinga 3a932141e4 Restore audio format binary compatibility with SDL 2.0 2023-09-04 10:16:53 -07:00
Sam Lantinga 233789b0d1 Audio types have the same naming convention as other SDL endian types, e.g. [S|U][BITS][LE|BE]
Native endian types have no LE/BE suffix
2023-09-04 09:48:44 -07:00
Brick 0e552761b7 Renamed AudioStreamSpeed to AudioStreamFrequencyRatio 2023-09-04 07:46:18 -07:00
Brick 47bcb078f5 Fixed some incorrect SDL_AUDIO_F32 uses 2023-09-04 07:46:18 -07:00
Brick 2833f2e7b5 Fixed OOB access in audio_convertAccuracy test 2023-09-04 07:46:18 -07:00
Brick 28b28bd8f4 Added audio_formatChange test 2023-09-01 14:38:45 -04:00
Brick 5394a805f4 Improved testaudiostreamdynamicresample
Tweaked color palette
2023-09-01 14:38:45 -04:00
Anonymous Maarten 1b03a2430a testsurround: fix order of arguments of callback 2023-08-28 00:12:59 +02:00
Ryan C. Gordon 58c859f64d audio: Rename SDL_GetAudioStreamBinding to SDL_GetAudioStreamDevice. 2023-08-27 16:54:30 -04:00
Ryan C. Gordon 1e775e0eef audio: Replace SDL_CreateAndBindAudioStream with SDL_OpenAudioDeviceStream.
This is meant to offer a simplified API for people that are either migrating
directly from SDL2 with minimal effort or just want to make noise without
any of the fancy new API features.

Users of this API can just deal with a single SDL_AudioStream as their only
object/handle into the audio subsystem.

They are still allowed to open multiple devices (or open the same device
multiple times), but cannot change stream bindings on logical devices opened
through this function.

Destroying the single audio stream will also close the logical device behind
the scenes.
2023-08-27 16:54:30 -04:00
Brick ea68bb8027 Add some additional checks to audio_convertAudio 2023-08-27 13:08:15 -07:00
Brick b1d63be538 Fixed audio_resampleLoss test 2023-08-27 13:08:15 -07:00
Sam Lantinga 34860b932b Fixed testautomation --filter pixels_allocFreeFormat 2023-08-25 08:06:08 -07:00
Brick 958b3cfaea Tweaked and enabled audio_convertAudio test 2023-08-25 08:43:56 -04:00
Brick 7dbb9b65b1 audio_convertAccuracy: Shuffle the data in case of a bad SIMD implementation 2023-08-25 08:43:56 -04:00
Brick f6a4080ff5 audio_resampleLoss: Add support for multiple channels 2023-08-25 08:43:56 -04:00
Brick 4f894e748e audio_resampleLoss: SDL_GetAudioStreamData now returns the correct length 2023-08-25 08:43:56 -04:00
Brick e6c878824c Fixed ResampleAudio interpolation factor calculation 2023-08-22 08:34:22 -04:00
Brick 4983638630 Misc audio tweaks/cleanup 2023-08-21 16:02:54 -04:00
Brick d2b9c8b80d Fixed maths in testaudiostreamdynamicresample (and just show the actual scale) 2023-08-21 16:02:54 -04:00
Brick b9541b9eab Improved ResampleAudio
* filterindex2 was off-by-one
* Generate ResamplerFilter using doubles
* Transpose ResamplerFilter to improve access patterns
2023-08-21 16:02:54 -04:00