Commit Graph

1313 Commits (main)

Author SHA1 Message Date
Sam Lantinga 141497b14f Added an automated test to verify clip rect functionality 2024-02-25 09:44:41 -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
Anonymous Maarten cbf0b1ce81 testcamera: create window and renderer through test library 2024-02-21 00:49:15 +01:00
Ryan C. Gordon f59c66a97f testcamera: Allow app to flip between a front and back camera. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon b1ed49772c camera: Replace testcamera.c with testcameraminimal.c 2024-02-20 15:56:26 -05:00
Ryan C. Gordon 47313bba32 camera: SDL_GetCameraDevices should not report "no devices" like an error. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon 0b8617f71d test: Fixed CMake to build testcameraminimal correctly on WinRT. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon 67708f9110 camera: Emscripten support!
This also adds code to deal with waiting for the user to approve camera
access, reworks testcameraminimal to use main callbacks, etc.
2024-02-20 15:56:26 -05:00
Ryan C. Gordon 87e7046fca camera: Public API functions should say "Format" not "Spec" to match audio. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon d3e6ef3cc6 camera: Massive code reworking.
- Simplified public API, simplified backend interface.
- Camera device hotplug events.
- Thread code is split up so it backends that provide own threads can use it.
- Added "dummy" backend.

Note that CoreMedia (Apple) and Android backends need to be updated, as does
the testcamera app (testcameraminimal works).
2024-02-20 15:56:26 -05:00
Ryan C. Gordon cb10c80aaf camera: Reworked to operate with a driver interface, like other subsystems. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon 7ae955ce68 camera: Renamed everything from "video capture" to "camera", wired to CMake. 2024-02-20 15:56:26 -05:00
Ryan C. Gordon f49ce4a15d camera: Renamed "video_capture" files to "camera" and moved to own subdir. 2024-02-20 15:56:26 -05:00
Sam Lantinga ed615e92b7 Updated automated test now that getting an invalid property isn't an error 2024-02-17 09:30:50 -08:00
Sam Lantinga 202886f873 Make use of the HDR light range when playing HDR video 2024-02-16 20:05:11 -08:00
Sam Lantinga cb38649490 Added SDL_PROP_DISPLAY_HDR_WHITE_LEVEL_FLOAT 2024-02-16 19:50:41 -08:00
Sam Lantinga d451fcd7a7 Fixed HDR video content being too bright on Apple platforms
This probably isn't the exact formula that we need, but it's much closer to correct.
2024-02-15 16:39:13 -08:00
Sam Lantinga c09daf8388 Removed unused variables 2024-02-15 14:11:04 -08:00
Sam Lantinga 2f7c24e4be Removed SDL_HINT_RENDER_SCALE_QUALITY
Textures now default to linear filtering, use SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST) if you want nearest pixel mode instead.
2024-02-12 09:54:33 -08:00
Sam Lantinga 7cb1ca60ec Removed SDL_HINT_RENDER_OPENGL_SHADERS
Shaders are always used if they are available.
2024-02-12 09:54:33 -08:00
Sam Lantinga a538936821 Renamed SDL_HINT_LINUX_JOYSTICK_DEADZONES to SDL_HINT_JOYSTICK_LINUX_DEADZONES 2024-02-12 09:54:33 -08:00
Sam Lantinga 9ce7fe2848 Removed SDL_HINT_ACCELEROMETER_AS_JOYSTICK
Sensors are a first-class object in SDL and we haven't gotten any feedback that this feature is useful these days.

Closes https://github.com/libsdl-org/SDL/pull/7879
2024-02-12 09:54:33 -08:00
Sam Lantinga cacac6cc34 Updated structure and field names for consistency
Type names are camel case and field names are snake case except for fields ending in id, which are capitalized.

Fixes https://github.com/libsdl-org/SDL/issues/6955
2024-02-11 08:27:56 -08:00
Sam Lantinga f6b92c9b88 Re-added a simplified version of SDL_SetWindowShape()
In order to handle mouse click transparency this needs to be implemented inside SDL
2024-02-09 16:04:46 -08:00
Sam Lantinga 1143bdc351 Greatly simplified the shape example 2024-02-09 03:04:40 -08:00
Sam Lantinga 1c4c29b7ad Fixed a swap chain leak and a double-free in testffmpeg.c
Also added more debug logging to the direct3d11 renderer
2024-02-06 21:33:57 -08:00
Sam Lantinga 3158342441 Use SDL_Color for SDL_RenderGeometryRaw() and add SDL_RenderGeometryRawFloat()
Eventually we can re-add a fast path for that data down to the individual renderers. Setting color scale would still require converting to float, and most hardware accelerated renderers prefer to consume colors as float, so this requires some thought and performance testing.

Fixes https://github.com/libsdl-org/SDL/issues/9009
2024-02-06 18:16:41 -08:00
Sam Lantinga 8afba41aef Added support for HDR10 video on Apple platforms 2024-02-06 15:40:47 -08:00
Sam Lantinga 2039c46d2c Added support for creating an SDL texture from a CVPixelBufferRef 2024-02-06 15:40:47 -08:00
Sam Lantinga ba074acad4 Implemented scRGB colorspace and HDR support on macOS 2024-02-06 12:29:44 -08:00
Sam Lantinga 30e176d6ba Added HDR display properties and related event
Also added an HDR calibration stage to testcolorspace
2024-02-06 02:48:05 -08:00
Sam Lantinga d4caef5b89 Generalize SDR white level handling into a color scale
This gives applications better control over how and when light levels are adjusted when working with HDR content and display.
2024-02-06 02:48:05 -08:00
Sam Lantinga e74171b1ae Added support for HDR10 video playback on direct3d11
Fixes https://github.com/libsdl-org/SDL/issues/8053
2024-02-05 09:45:39 -08:00
meyraud705 f85535b4b6 Use functions from SDL instead of libc 2024-02-05 09:01:28 -05:00
Sam Lantinga ec322bee1c Fixed testyuv help message 2024-02-04 13:09:40 -08:00
Sam Lantinga 327b976bc4 SDL_COLORSPACE_JPEG is the default YUV colorspace 2024-02-04 13:09:40 -08:00
Sam Lantinga 5b8e5f8b9f Fixed accidental changing of All to Allu in previous commit (thanks @zturtleman!) 2024-02-03 23:46:22 -08:00
Sam Lantinga c0b27ccef9 Fixed warning C4701: potentially uninitialized local variable 'drawnTextRect' used 2024-02-03 11:49:15 -08:00
Sam Lantinga 8eba5b75ca Fixed warning C4701: potentially uninitialized local variable 'rndctx' used 2024-02-03 11:49:15 -08:00
Sam Lantinga 445cb42acd Fixed warning C4244: 'function': conversion from 'int' to 'Uint16', possible loss of data 2024-02-03 11:49:15 -08:00
Sam Lantinga 45f936c788 Fixed warning C4245: 'initializing': conversion from '__int64' to 'unsigned __int64', signed/unsigned mismatch 2024-02-03 11:49:15 -08:00
Sam Lantinga 74e85e3a51 Fixed warning C4706: assignment within conditional expression 2024-02-03 11:49:15 -08:00
Sam Lantinga c3e3ad6140 Fixed build warnings 2024-02-03 11:49:15 -08:00
Sam Lantinga c02aaebccc Fixed warning C4245: 'initializing': conversion from 'int' to 'Uint32', signed/unsigned mismatch 2024-02-03 11:49:15 -08:00
Sam Lantinga ff5fdf9f53 Fixed warning C4244: 'initializing': conversion from 'int' to 'const Uint8', possible loss of data 2024-02-03 11:49:15 -08:00
Sam Lantinga 9989f92eee Fixed warning C4245: 'initializing': conversion from 'int' to 'SDL_AudioDeviceID', signed/unsigned mismatch 2024-02-03 11:49:15 -08:00
Sam Lantinga 89b9d6cbdc SDL_RenderReadPixels() now returns a surface
Fixes https://github.com/libsdl-org/SDL/issues/8977
2024-02-03 11:49:15 -08:00
Sam Lantinga 50a805cdd1 Use YUV colorspaces instead of a global YUV conversion mode
Fixes https://github.com/libsdl-org/SDL/issues/8669
2024-02-03 07:36:18 -08:00
Sam Lantinga f9c57e16b0 Don't test 10-bit pixel format conversion
We either need to explicitly test using the sRGB colorspace or update the tests for HDR10 color conversion. We'll just disable them for now, as these formats aren't commonly used in games.
2024-02-02 18:24:15 -08:00
Sam Lantinga b8fe96fa81 Fixed build warning 2024-02-02 18:24:05 -08:00
Sam Lantinga 5d48f9a63a Added SDL_CopyProperties() 2024-02-02 15:09:12 -08:00
Sam Lantinga 9591b2cfb4 Finalized the SDL render API colorspaces
The renderer will always use the sRGB colorspace for drawing, and will default to the sRGB output colorspace. If you want blending in linear space and HDR support, you can select the scRGB output colorspace, which is supported by the direct3d11 and direct3d12
2024-02-02 13:13:53 -08:00
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