update sdl Merge commit '644725478f4de0f074a6834e8423ac36dce3974f'

This commit is contained in:
2023-09-23 18:53:11 +02:00
172 changed files with 7495 additions and 4062 deletions

View File

@ -64,6 +64,8 @@ assert can have unique static variables associated with it.
#define SDL_TriggerBreakpoint() __builtin_debugtrap()
#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "ebreak\n\t" )
#elif ( defined(__APPLE__) && (defined(__arm64__) || defined(__aarch64__)) ) /* this might work on other ARM targets, but this is a known quantity... */
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
#elif defined(__APPLE__) && defined(__arm__)

View File

@ -80,15 +80,16 @@ typedef Uint16 SDL_AudioFormat;
/* @{ */
#define SDL_AUDIO_MASK_BITSIZE (0xFF)
#define SDL_AUDIO_MASK_DATATYPE (1<<8)
#define SDL_AUDIO_MASK_ENDIAN (1<<12)
#define SDL_AUDIO_MASK_FLOAT (1<<8)
#define SDL_AUDIO_MASK_BIG_ENDIAN (1<<12)
#define SDL_AUDIO_MASK_SIGNED (1<<15)
#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
#define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
#define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
#define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
#define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)
#define SDL_AUDIO_BYTESIZE(x) (SDL_AUDIO_BITSIZE(x) / 8)
#define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)
#define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)
#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
#define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED)
#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
/**
@ -99,27 +100,24 @@ typedef Uint16 SDL_AudioFormat;
/* @{ */
#define SDL_AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
#define SDL_AUDIO_S8 0x8008 /**< Signed 8-bit samples */
#define SDL_AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
#define SDL_AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
#define SDL_AUDIO_S16 SDL_AUDIO_S16LSB
#define SDL_AUDIO_S16LE 0x8010 /**< Signed 16-bit samples */
#define SDL_AUDIO_S16BE 0x9010 /**< As above, but big-endian byte order */
/* @} */
/**
* \name int32 support
*/
/* @{ */
#define SDL_AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
#define SDL_AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
#define SDL_AUDIO_S32 SDL_AUDIO_S32LSB
#define SDL_AUDIO_S32LE 0x8020 /**< 32-bit integer samples */
#define SDL_AUDIO_S32BE 0x9020 /**< As above, but big-endian byte order */
/* @} */
/**
* \name float32 support
*/
/* @{ */
#define SDL_AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
#define SDL_AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
#define SDL_AUDIO_F32 SDL_AUDIO_F32LSB
#define SDL_AUDIO_F32LE 0x8120 /**< 32-bit floating point samples */
#define SDL_AUDIO_F32BE 0x9120 /**< As above, but big-endian byte order */
/* @} */
/**
@ -127,13 +125,13 @@ typedef Uint16 SDL_AudioFormat;
*/
/* @{ */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SDL_AUDIO_S16SYS SDL_AUDIO_S16LSB
#define SDL_AUDIO_S32SYS SDL_AUDIO_S32LSB
#define SDL_AUDIO_F32SYS SDL_AUDIO_F32LSB
#define SDL_AUDIO_S16 SDL_AUDIO_S16LE
#define SDL_AUDIO_S32 SDL_AUDIO_S32LE
#define SDL_AUDIO_F32 SDL_AUDIO_F32LE
#else
#define SDL_AUDIO_S16SYS SDL_AUDIO_S16MSB
#define SDL_AUDIO_S32SYS SDL_AUDIO_S32MSB
#define SDL_AUDIO_F32SYS SDL_AUDIO_F32MSB
#define SDL_AUDIO_S16 SDL_AUDIO_S16BE
#define SDL_AUDIO_S32 SDL_AUDIO_S32BE
#define SDL_AUDIO_F32 SDL_AUDIO_F32BE
#endif
/* @} */
@ -154,6 +152,9 @@ typedef struct SDL_AudioSpec
int freq; /**< sample rate: sample frames per second */
} SDL_AudioSpec;
/* Calculate the size of each audio frame (in bytes) */
#define SDL_AUDIO_FRAMESIZE(x) (SDL_AUDIO_BYTESIZE((x).format) * (x).channels)
/* SDL_AudioStream is an audio conversion interface.
- It can handle resampling data in chunks without generating
artifacts, when it doesn't have the complete buffer available.
@ -308,7 +309,8 @@ extern DECLSPEC SDL_AudioDeviceID *SDLCALL SDL_GetAudioCaptureDevices(int *count
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioOutputDevices
* \sa SDL_GetAudioCaptureDevices
* \sa SDL_GetDefaultAudioInfo
*/
extern DECLSPEC char *SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
@ -325,8 +327,20 @@ extern DECLSPEC char *SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
* reasonable recommendation before opening the system-recommended default
* device.
*
* You can also use this to request the current device buffer size. This is
* specified in sample frames and represents the amount of data SDL will feed
* to the physical hardware in each chunk. This can be converted to
* milliseconds of audio with the following equation:
*
* `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);`
*
* Buffer size is only important if you need low-level control over the audio
* playback timing. Most apps do not need this.
*
* \param devid the instance ID of the device to query.
* \param spec On return, will be filled with device details.
* \param sample_frames Pointer to store device buffer size, in sample frames.
* Can be NULL.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -334,7 +348,7 @@ extern DECLSPEC char *SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec);
extern DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames);
/**
@ -348,9 +362,9 @@ extern DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SD
* An opened audio device starts out with no audio streams bound. To start
* audio playing, bind a stream and supply audio data to it. Unlike SDL2,
* there is no audio callback; you only bind audio streams and make sure they
* have data flowing into them (although, as an optional feature, each audio
* stream may have its own callback, which can be used to simulate SDL2's
* semantics).
* have data flowing into them (however, you can simulate SDL2's semantics
* fairly closely by using SDL_OpenAudioDeviceStream instead of this
* function).
*
* If you don't care about opening a specific device, pass a `devid` of either
* `SDL_AUDIO_DEVICE_DEFAULT_OUTPUT` or `SDL_AUDIO_DEVICE_DEFAULT_CAPTURE`. In
@ -439,7 +453,7 @@ extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDeviceID
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_ResumeAudioDevice
* \sa SDL_IsAudioDevicePaused
* \sa SDL_AudioDevicePaused
*/
extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
@ -466,8 +480,8 @@ extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_ResumeAudioDevice
* \sa SDL_IsAudioDevicePaused
* \sa SDL_AudioDevicePaused
* \sa SDL_PauseAudioDevice
*/
extern DECLSPEC int SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev);
@ -490,9 +504,8 @@ extern DECLSPEC int SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev);
*
* \sa SDL_PauseAudioDevice
* \sa SDL_ResumeAudioDevice
* \sa SDL_IsAudioDevicePaused
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IsAudioDevicePaused(SDL_AudioDeviceID dev);
extern DECLSPEC SDL_bool SDLCALL SDL_AudioDevicePaused(SDL_AudioDeviceID dev);
/**
* Close a previously-opened audio device.
@ -549,7 +562,7 @@ extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);
* \sa SDL_BindAudioStreams
* \sa SDL_UnbindAudioStreams
* \sa SDL_UnbindAudioStream
* \sa SDL_GetAudioStreamBinding
* \sa SDL_GetAudioStreamDevice
*/
extern DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams);
@ -571,7 +584,7 @@ extern DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_Au
* \sa SDL_BindAudioStreams
* \sa SDL_UnbindAudioStreams
* \sa SDL_UnbindAudioStream
* \sa SDL_GetAudioStreamBinding
* \sa SDL_GetAudioStreamDevice
*/
extern DECLSPEC int SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);
@ -595,7 +608,7 @@ extern DECLSPEC int SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_Aud
* \sa SDL_BindAudioStreams
* \sa SDL_BindAudioStream
* \sa SDL_UnbindAudioStream
* \sa SDL_GetAudioStreamBinding
* \sa SDL_GetAudioStreamDevice
*/
extern DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams);
@ -614,7 +627,7 @@ extern DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream **streams, i
* \sa SDL_BindAudioStream
* \sa SDL_BindAudioStreams
* \sa SDL_UnbindAudioStreams
* \sa SDL_GetAudioStreamBinding
* \sa SDL_GetAudioStreamDevice
*/
extern DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
@ -638,7 +651,7 @@ extern DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
* \sa SDL_UnbindAudioStream
* \sa SDL_UnbindAudioStreams
*/
extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamBinding(SDL_AudioStream *stream);
extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_AudioStream *stream);
/**
@ -703,11 +716,54 @@ extern DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream,
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_SetAudioStreamFrequencyRatio
*/
extern DECLSPEC int SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream,
const SDL_AudioSpec *src_spec,
const SDL_AudioSpec *dst_spec);
/**
* Get the frequency ratio of an audio stream.
*
* \param stream the SDL_AudioStream to query.
* \returns the frequency ratio of the stream, or 0.0 on error
*
* \threadsafety It is safe to call this function from any thread, as it holds
* a stream-specific mutex while running.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetAudioStreamFrequencyRatio
*/
extern DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream);
/**
* Change the frequency ratio of an audio stream.
*
* The frequency ratio is used to adjust the rate at which input data is
* consumed. Changing this effectively modifies the speed and pitch of the
* audio. A value greater than 1.0 will play the audio faster, and at a higher
* pitch. A value less than 1.0 will play the audio slower, and at a lower
* pitch.
*
* This is applied during SDL_GetAudioStreamData, and can be continuously
* changed to create various effects.
*
* \param stream The stream the frequency ratio is being changed
* \param ratio The frequency ratio. 1.0 is normal speed. Must be between 0.01
* and 100.
* \returns 0 on success, or -1 on error.
*
* \threadsafety It is safe to call this function from any thread, as it holds
* a stream-specific mutex while running.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetAudioStreamFrequencyRatio
* \sa SDL_SetAudioStreamFormat
*/
extern DECLSPEC int SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);
/**
* Add data to be converted/resampled to the stream.
*
@ -802,6 +858,40 @@ extern DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void
*/
extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);
/**
* Get the number of bytes currently queued.
*
* Note that audio streams can change their input format at any time, even if
* there is still data queued in a different format, so the returned byte
* count will not necessarily match the number of _sample frames_ available.
* Users of this API should be aware of format changes they make when feeding
* a stream and plan accordingly.
*
* Queued data is not converted until it is consumed by
* SDL_GetAudioStreamData, so this value should be representative of the exact
* data that was put into the stream.
*
* If the stream has so much data that it would overflow an int, the return
* value is clamped to a maximum value, but no queued data is lost; if there
* are gigabytes of data queued, the app might need to read some of it with
* SDL_GetAudioStreamData before this function's return value is no longer
* clamped.
*
* \param stream The audio stream to query
* \returns the number of bytes queued.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_ClearAudioStream
*/
extern DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream);
/**
* Tell the stream that you're done sending data, and anything being buffered
* should be converted/resampled and made available immediately.
@ -909,13 +999,22 @@ extern DECLSPEC int SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);
* before your callback is called, so your callback does not need to
* manage the lock explicitly.
*
* Two values are offered here: one is the amount of additional data needed
* to satisfy the immediate request (which might be zero if the stream
* already has enough data queued) and the other is the total amount
* being requested. In a Get call triggering a Put callback, these
* values can be different. In a Put call triggering a Get callback,
* these values are always the same.
*
* Byte counts might be slightly overestimated due to buffering or
* resampling, and may change from call to call.
*
* \param stream The SDL audio stream associated with this callback.
* \param approx_request The _approximate_ amout of data, in bytes, that is requested.
* This might be slightly overestimated due to buffering or
* resampling, and may change from call to call anyhow.
* \param additional_amount The amount of data, in bytes, that is needed right now.
* \param total_amount The total amount of data requested, in bytes, that is requested or available.
* \param userdata An opaque pointer provided by the app for their personal use.
*/
typedef void (SDLCALL *SDL_AudioStreamRequestCallback)(SDL_AudioStream *stream, int approx_request, void *userdata);
typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount);
/**
* Set a callback that runs when data is requested from an audio stream.
@ -960,7 +1059,7 @@ typedef void (SDLCALL *SDL_AudioStreamRequestCallback)(SDL_AudioStream *stream,
*
* \sa SDL_SetAudioStreamPutCallback
*/
extern DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamRequestCallback callback, void *userdata);
extern DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
/**
* Set a callback that runs when data is added to an audio stream.
@ -1008,7 +1107,7 @@ extern DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *strea
*
* \sa SDL_SetAudioStreamGetCallback
*/
extern DECLSPEC int SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamRequestCallback callback, void *userdata);
extern DECLSPEC int SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
/**
@ -1031,32 +1130,125 @@ extern DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);
/**
* Convenience function to create and bind an audio stream in one step.
* Convenience function for straightforward audio init for the common case.
*
* This manages the creation of an audio stream, and setting its format
* correctly to match both the app and the audio device's needs. This is
* optional, but slightly less cumbersome to set up for a common use case.
* If all your app intends to do is provide a single source of PCM audio, this
* function allows you to do all your audio setup in a single call.
*
* This is intended to be a clean means to migrate apps from SDL2.
*
* This function will open an audio device, create a stream and bind it.
* Unlike other methods of setup, the audio device will be closed when this
* stream is destroyed, so the app can treat the returned SDL_AudioStream as
* the only object needed to manage audio playback.
*
* Also unlike other functions, the audio device begins paused. This is to map
* more closely to SDL2-style behavior, and since there is no extra step here
* to bind a stream to begin audio flowing. The audio device should be resumed
* with SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
*
* This function works with both playback and capture devices.
*
* The `spec` parameter represents the app's side of the audio stream. That
* is, for recording audio, this will be the output format, and for playing
* audio, this will be the input format. This function will set the other side
* of the audio stream to the device's format.
* audio, this will be the input format.
*
* \param devid an audio device to bind a stream to. This must be an opened
* device, and can not be zero.
* \param spec the audio stream's input format
* \returns a bound audio stream on success, ready to use. NULL on error; call
* SDL_GetError() for more information.
* If you don't care about opening a specific audio device, you can (and
* probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_OUTPUT for playback and
* SDL_AUDIO_DEVICE_DEFAULT_CAPTURE for recording.
*
* One can optionally provide a callback function; if NULL, the app is
* expected to queue audio data for playback (or unqueue audio data if
* capturing). Otherwise, the callback will begin to fire once the device is
* unpaused.
*
* \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or
* SDL_AUDIO_DEVICE_DEFAULT_CAPTURE.
* \param spec the audio stream's data format. Required.
* \param callback A callback where the app will provide new data for
* playback, or receive new data for capture. Can be NULL, in
* which case the app will need to call SDL_PutAudioStreamData
* or SDL_GetAudioStreamData as necessary.
* \param userdata App-controlled pointer passed to callback. Can be NULL.
* Ignored if callback is NULL.
* \returns an audio stream on success, ready to use. NULL on error; call
* SDL_GetError() for more information. When done with this stream,
* call SDL_DestroyAudioStream to free resources and close the
* device.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_BindAudioStreams
* \sa SDL_UnbindAudioStreams
* \sa SDL_UnbindAudioStream
* \sa SDL_GetAudioStreamDevice
* \sa SDL_ResumeAudioDevice
*/
extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAndBindAudioStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
extern DECLSPEC SDL_AudioStream *SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);
/**
* A callback that fires when data is about to be fed to an audio device.
*
* This is useful for accessing the final mix, perhaps for writing a
* visualizer or applying a final effect to the audio data before playback.
*
* \sa SDL_SetAudioDevicePostmixCallback
*/
typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_AudioSpec *spec, float *buffer, int buflen);
/**
* Set a callback that fires when data is about to be fed to an audio device.
*
* This is useful for accessing the final mix, perhaps for writing a
* visualizer or applying a final effect to the audio data before playback.
*
* The buffer is the final mix of all bound audio streams on an opened device;
* this callback will fire regularly for any device that is both opened and
* unpaused. If there is no new data to mix, either because no streams are
* bound to the device or all the streams are empty, this callback will still
* fire with the entire buffer set to silence.
*
* This callback is allowed to make changes to the data; the contents of the
* buffer after this call is what is ultimately passed along to the hardware.
*
* The callback is always provided the data in float format (values from -1.0f
* to 1.0f), but the number of channels or sample rate may be different than
* the format the app requested when opening the device; SDL might have had to
* manage a conversion behind the scenes, or the playback might have jumped to
* new physical hardware when a system default changed, etc. These details may
* change between calls. Accordingly, the size of the buffer might change
* between calls as well.
*
* This callback can run at any time, and from any thread; if you need to
* serialize access to your app's data, you should provide and use a mutex or
* other synchronization device.
*
* All of this to say: there are specific needs this callback can fulfill, but
* it is not the simplest interface. Apps should generally provide audio in
* their preferred format through an SDL_AudioStream and let SDL handle the
* difference.
*
* This function is extremely time-sensitive; the callback should do the least
* amount of work possible and return as quickly as it can. The longer the
* callback runs, the higher the risk of audio dropouts or other problems.
*
* This function will block until the audio device is in between iterations,
* so any existing callback that might be running will finish before this
* function sets the new callback and returns.
*
* Setting a NULL callback function disables any previously-set callback.
*
* \param devid The ID of an opened audio device.
* \param callback A callback function to be called. Can be NULL.
* \param userdata App-controlled pointer passed to callback. Can be NULL.
* \returns zero on success, -1 on error; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC int SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata);
/**

View File

@ -185,8 +185,9 @@ typedef enum
SDL_EVENT_DROP_POSITION, /**< Position while moving over the window */
/* Audio hotplug events */
SDL_EVENT_AUDIO_DEVICE_ADDED = 0x1100, /**< A new audio device is available */
SDL_EVENT_AUDIO_DEVICE_REMOVED, /**< An audio device has been removed. */
SDL_EVENT_AUDIO_DEVICE_ADDED = 0x1100, /**< A new audio device is available */
SDL_EVENT_AUDIO_DEVICE_REMOVED, /**< An audio device has been removed. */
SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED, /**< An audio device's format has been changed by the system. */
/* Sensor events */
SDL_EVENT_SENSOR_UPDATE = 0x1200, /**< A sensor was updated */
@ -491,9 +492,9 @@ typedef struct SDL_GamepadSensorEvent
*/
typedef struct SDL_AudioDeviceEvent
{
Uint32 type; /**< ::SDL_EVENT_AUDIO_DEVICE_ADDED, or ::SDL_EVENT_AUDIO_DEVICE_REMOVED */
Uint32 type; /**< ::SDL_EVENT_AUDIO_DEVICE_ADDED, or ::SDL_EVENT_AUDIO_DEVICE_REMOVED, or ::SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed */
SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */
Uint8 padding1;
Uint8 padding2;

View File

@ -125,6 +125,53 @@ typedef enum
SDL_GAMEPAD_AXIS_MAX
} SDL_GamepadAxis;
typedef enum
{
SDL_GAMEPAD_BINDTYPE_NONE = 0,
SDL_GAMEPAD_BINDTYPE_BUTTON,
SDL_GAMEPAD_BINDTYPE_AXIS,
SDL_GAMEPAD_BINDTYPE_HAT
} SDL_GamepadBindingType;
typedef struct
{
SDL_GamepadBindingType inputType;
union
{
int button;
struct
{
int axis;
int axis_min;
int axis_max;
} axis;
struct
{
int hat;
int hat_mask;
} hat;
} input;
SDL_GamepadBindingType outputType;
union
{
SDL_GamepadButton button;
struct
{
SDL_GamepadAxis axis;
int axis_min;
int axis_max;
} axis;
} output;
} SDL_GamepadBinding;
/**
* Add support for gamepads that SDL is unaware of or change the binding of an
* existing gamepad.
@ -736,6 +783,19 @@ extern DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
/**
* Get the SDL joystick layer bindings for a gamepad
*
* \param gamepad a gamepad
* \param count a pointer filled in with the number of bindings returned
* \returns a NULL terminated array of pointers to bindings which should be
* freed with SDL_free(), or NULL on error; call SDL_GetError() for
* more details.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC SDL_GamepadBinding **SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
/**
* Manually pump gamepad updates if not using the loop.
*

View File

@ -1488,6 +1488,17 @@ extern "C" {
*/
#define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC"
/**
* \brief A variable controlling whether the Metal render driver select low power device over default one
*
* This variable can be set to the following values:
* "0" - Use the prefered OS device
* "1" - Select a low power one
*
* By default the prefered OS device is used.
*/
#define SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE "SDL_RENDER_METAL_PREFER_LOW_POWER_DEVICE"
/**
* \brief A variable controlling if VSYNC is automatically disable if doesn't reach the enough FPS
*
@ -2499,6 +2510,26 @@ extern "C" {
*/
#define SDL_HINT_GDK_TEXTINPUT_MAX_LENGTH "SDL_GDK_TEXTINPUT_MAX_LENGTH"
/**
* Set the next device open's buffer size.
*
* This hint is an integer > 0, that represents the size of the device's
* buffer in sample frames (stereo audio data in 16-bit format is 4 bytes
* per sample frame, for example).
*
* SDL3 generally decides this value on behalf of the app, but if for some
* reason the app needs to dictate this (because they want either lower
* latency or higher throughput AND ARE WILLING TO DEAL WITH what that
* might require of the app), they can specify it.
*
* SDL will try to accomodate this value, but there is no promise you'll
* get the buffer size requested. Many platforms won't honor this request
* at all, or might adjust it.
*
* This hint is checked when opening an audio device and can be changed
* between calls.
*/
#define SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES "SDL_AUDIO_DEVICE_SAMPLE_FRAMES"
/**
* \brief An enumeration of hint priorities

View File

@ -43,18 +43,18 @@
#define SDL_atomic_t SDL_AtomicInt
/* ##SDL_audio.h */
#define AUDIO_F32 SDL_AUDIO_F32
#define AUDIO_F32LSB SDL_AUDIO_F32LSB
#define AUDIO_F32MSB SDL_AUDIO_F32MSB
#define AUDIO_F32SYS SDL_AUDIO_F32SYS
#define AUDIO_S16 SDL_AUDIO_S16
#define AUDIO_S16LSB SDL_AUDIO_S16LSB
#define AUDIO_S16MSB SDL_AUDIO_S16MSB
#define AUDIO_S16SYS SDL_AUDIO_S16SYS
#define AUDIO_S32 SDL_AUDIO_S32
#define AUDIO_S32LSB SDL_AUDIO_S32LSB
#define AUDIO_S32MSB SDL_AUDIO_S32MSB
#define AUDIO_S32SYS SDL_AUDIO_S32SYS
#define AUDIO_F32 SDL_AUDIO_F32LE
#define AUDIO_F32LSB SDL_AUDIO_F32LE
#define AUDIO_F32MSB SDL_AUDIO_F32BE
#define AUDIO_F32SYS SDL_AUDIO_F32
#define AUDIO_S16 SDL_AUDIO_S16LE
#define AUDIO_S16LSB SDL_AUDIO_S16LE
#define AUDIO_S16MSB SDL_AUDIO_S16BE
#define AUDIO_S16SYS SDL_AUDIO_S16
#define AUDIO_S32 SDL_AUDIO_S32LE
#define AUDIO_S32LSB SDL_AUDIO_S32LE
#define AUDIO_S32MSB SDL_AUDIO_S32BE
#define AUDIO_S32SYS SDL_AUDIO_S32
#define AUDIO_S8 SDL_AUDIO_S8
#define AUDIO_U8 SDL_AUDIO_U8
#define SDL_AudioStreamAvailable SDL_GetAudioStreamAvailable
@ -202,7 +202,6 @@
#define SDL_GameControllerAxis SDL_GamepadAxis
#define SDL_GameControllerBindType SDL_GamepadBindingType
#define SDL_GameControllerButton SDL_GamepadButton
#define SDL_GameControllerButtonBind SDL_GamepadBinding
#define SDL_GameControllerClose SDL_CloseGamepad
#define SDL_GameControllerFromInstanceID SDL_GetGamepadFromInstanceID
#define SDL_GameControllerFromPlayerIndex SDL_GetGamepadFromPlayerIndex
@ -211,8 +210,6 @@
#define SDL_GameControllerGetAttached SDL_GamepadConnected
#define SDL_GameControllerGetAxis SDL_GetGamepadAxis
#define SDL_GameControllerGetAxisFromString SDL_GetGamepadAxisFromString
#define SDL_GameControllerGetBindForAxis SDL_GetGamepadBindForAxis
#define SDL_GameControllerGetBindForButton SDL_GetGamepadBindForButton
#define SDL_GameControllerGetButton SDL_GetGamepadButton
#define SDL_GameControllerGetButtonFromString SDL_GetGamepadButtonFromString
#define SDL_GameControllerGetFirmwareVersion SDL_GetGamepadFirmwareVersion
@ -494,18 +491,18 @@
#elif !defined(SDL_DISABLE_OLD_NAMES)
/* ##SDL_audio.h */
#define AUDIO_F32 AUDIO_F32_renamed_SDL_AUDIO_F32
#define AUDIO_F32LSB AUDIO_F32LSB_renamed_SDL_AUDIO_F32LSB
#define AUDIO_F32MSB AUDIO_F32MSB_renamed_SDL_AUDIO_F32MSB
#define AUDIO_F32SYS AUDIO_F32SYS_renamed_SDL_AUDIO_F32SYS
#define AUDIO_S16 AUDIO_S16_renamed_SDL_AUDIO_S16
#define AUDIO_S16LSB AUDIO_S16LSB_renamed_SDL_AUDIO_S16LSB
#define AUDIO_S16MSB AUDIO_S16MSB_renamed_SDL_AUDIO_S16MSB
#define AUDIO_S16SYS AUDIO_S16SYS_renamed_SDL_AUDIO_S16SYS
#define AUDIO_S32 AUDIO_S32_renamed_SDL_AUDIO_S32
#define AUDIO_S32LSB AUDIO_S32LSB_renamed_SDL_AUDIO_S32LSB
#define AUDIO_S32MSB AUDIO_S32MSB_renamed_SDL_AUDIO_S32MSB
#define AUDIO_S32SYS AUDIO_S32SYS_renamed_SDL_AUDIO_S32SYS
#define AUDIO_F32 AUDIO_F32_renamed_SDL_AUDIO_F32LE
#define AUDIO_F32LSB AUDIO_F32LSB_renamed_SDL_AUDIO_F32LE
#define AUDIO_F32MSB AUDIO_F32MSB_renamed_SDL_AUDIO_F32BE
#define AUDIO_F32SYS AUDIO_F32SYS_renamed_SDL_AUDIO_F32
#define AUDIO_S16 AUDIO_S16_renamed_SDL_AUDIO_S16LE
#define AUDIO_S16LSB AUDIO_S16LSB_renamed_SDL_AUDIO_S16LE
#define AUDIO_S16MSB AUDIO_S16MSB_renamed_SDL_AUDIO_S16BE
#define AUDIO_S16SYS AUDIO_S16SYS_renamed_SDL_AUDIO_S16
#define AUDIO_S32 AUDIO_S32_renamed_SDL_AUDIO_S32LE
#define AUDIO_S32LSB AUDIO_S32LSB_renamed_SDL_AUDIO_S32LE
#define AUDIO_S32MSB AUDIO_S32MSB_renamed_SDL_AUDIO_S32BE
#define AUDIO_S32SYS AUDIO_S32SYS_renamed_SDL_AUDIO_S32
#define AUDIO_S8 AUDIO_S8_renamed_SDL_AUDIO_S8
#define AUDIO_U8 AUDIO_U8_renamed_SDL_AUDIO_U8
#define SDL_AudioStreamAvailable SDL_AudioStreamAvailable_renamed_SDL_GetAudioStreamAvailable
@ -653,7 +650,6 @@
#define SDL_GameControllerAxis SDL_GameControllerAxis_renamed_SDL_GamepadAxis
#define SDL_GameControllerBindType SDL_GameControllerBindType_renamed_SDL_GamepadBindingType
#define SDL_GameControllerButton SDL_GameControllerButton_renamed_SDL_GamepadButton
#define SDL_GameControllerButtonBind SDL_GameControllerButtonBind_renamed_SDL_GamepadBinding
#define SDL_GameControllerClose SDL_GameControllerClose_renamed_SDL_CloseGamepad
#define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_renamed_SDL_GetGamepadFromInstanceID
#define SDL_GameControllerFromPlayerIndex SDL_GameControllerFromPlayerIndex_renamed_SDL_GetGamepadFromPlayerIndex
@ -662,8 +658,6 @@
#define SDL_GameControllerGetAttached SDL_GameControllerGetAttached_renamed_SDL_GamepadConnected
#define SDL_GameControllerGetAxis SDL_GameControllerGetAxis_renamed_SDL_GetGamepadAxis
#define SDL_GameControllerGetAxisFromString SDL_GameControllerGetAxisFromString_renamed_SDL_GetGamepadAxisFromString
#define SDL_GameControllerGetBindForAxis SDL_GameControllerGetBindForAxis_renamed_SDL_GetGamepadBindForAxis
#define SDL_GameControllerGetBindForButton SDL_GameControllerGetBindForButton_renamed_SDL_GetGamepadBindForButton
#define SDL_GameControllerGetButton SDL_GameControllerGetButton_renamed_SDL_GetGamepadButton
#define SDL_GameControllerGetButtonFromString SDL_GameControllerGetButtonFromString_renamed_SDL_GetGamepadButtonFromString
#define SDL_GameControllerGetFirmwareVersion SDL_GameControllerGetFirmwareVersion_renamed_SDL_GetGamepadFirmwareVersion

View File

@ -42,7 +42,7 @@
* of the many good 3D engines.
*
* These functions must be called from the main thread.
* See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995
* See this bug for details: https://github.com/libsdl-org/SDL/issues/986
*/
#ifndef SDL_render_h_

View File

@ -954,7 +954,22 @@ extern DECLSPEC SDL_bool SDLCALL SDL_WriteS64LE(SDL_RWops *dst, Sint64 value);
*/
extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64BE(SDL_RWops *dst, Uint64 value);
extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64BE(SDL_RWops *dst, Uint64 value);
/**
* Use this function to write 64 bits in native format to an SDL_RWops as
* big-endian data.
*
* SDL byteswaps the data only if necessary, so the application always
* specifies native format, and the data written will be in big-endian format.
*
* \param dst the stream to which data will be written
* \param value the data to be written, in native format
* \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_WriteS64BE(SDL_RWops *dst, Sint64 value);
/* @} *//* Write endian functions */
/* Ends C function definitions when using C++ */

View File

@ -778,15 +778,16 @@ extern DECLSPEC int SDLCALL SDL_FillSurfaceRects
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied, or NULL to copy the entire surface
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the target rectangle in
* the destination surface, filled with the actual rectangle
* used after clipping
* \param dstrect the SDL_Rect structure representing the x and y position in
* the destination surface. On input the width and height are
* ignored (taken from srcrect), and on output this is filled
* in with the actual rectangle used after clipping.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_BlitSurface
* \sa SDL_BlitSurfaceScaled
*/
extern DECLSPEC int SDLCALL SDL_BlitSurface
(SDL_Surface *src, const SDL_Rect *srcrect,
@ -815,7 +816,6 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect);
/**
* Perform a fast, low quality, stretch blit between two surfaces of the same
* format.
@ -872,6 +872,8 @@ extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_BlitSurface
*/
extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
(SDL_Surface *src, const SDL_Rect *srcrect,

View File

@ -582,7 +582,16 @@ extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
/* Functions used by iOS application delegates to notify SDL about state changes */
/* Functions used by iOS app delegates to notify SDL about state changes.
*
* These functions allow iOS apps that have their own event handling to hook
* into SDL to generate SDL events. These map directly to iOS-specific
* events, but since they don't do anything iOS-specific internally, they
* are available on all platforms, in case they might be useful for some
* specific paradigm. Most apps do not need to use these directly; SDL's
* internal event code will handle all this for windows created by
* SDL_CreateWindow!
*/
/*
* \since This function is available since SDL 3.0.0.
@ -623,7 +632,8 @@ extern DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void
/* Functions used only by GDK */
#ifdef __GDK__
typedef struct XTaskQueueObject * XTaskQueueHandle;
typedef struct XTaskQueueObject *XTaskQueueHandle;
typedef struct XUser *XUserHandle;
/**
* Gets a reference to the global async task queue handle for GDK,
@ -641,6 +651,20 @@ typedef struct XTaskQueueObject * XTaskQueueHandle;
*/
extern DECLSPEC int SDLCALL SDL_GDKGetTaskQueue(XTaskQueueHandle * outTaskQueue);
/**
* Gets a reference to the default user handle for GDK.
*
* This is effectively a synchronous version of XUserAddAsync, which always
* prefers the default user and allows a sign-in UI.
*
* \param outUserHandle a pointer to be filled in with the default user
* handle.
* \returns 0 if success, -1 if any error occurs.
*
* \since This function is available since SDL 2.28.0.
*/
extern DECLSPEC int SDLCALL SDL_GDKGetDefaultUser(XUserHandle * outUserHandle);
#endif
/* Ends C function definitions when using C++ */

View File

@ -38,7 +38,8 @@ extern "C" {
/* Function prototypes */
#define FONT_CHARACTER_SIZE 8
extern int FONT_CHARACTER_SIZE;
#define FONT_LINE_HEIGHT (FONT_CHARACTER_SIZE + 2)
/**

View File

@ -42,7 +42,14 @@ extern "C" {
*
* \note This should be called before any other SDL functions for complete tracking coverage
*/
int SDLTest_TrackAllocations(void);
void SDLTest_TrackAllocations(void);
/**
* \brief Fill allocations with random data
*
* \note This implicitly calls SDLTest_TrackAllocations()
*/
void SDLTest_RandFillAllocations();
/**
* \brief Print a log of any outstanding allocations

View File

@ -132,7 +132,7 @@ typedef enum
SDL_WINDOW_FULLSCREEN = 0x00000001, /**< window is in fullscreen mode */
SDL_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */
SDL_WINDOW_OCCLUDED = 0x00000004, /**< window is occluded */
SDL_WINDOW_HIDDEN = 0x00000008, /**< window is not visible */
SDL_WINDOW_HIDDEN = 0x00000008, /**< window is neither mapped onto the desktop nor shown in the taskbar/dock/window list; SDL_ShowWindow() is required for it to become visible */
SDL_WINDOW_BORDERLESS = 0x00000010, /**< no window decoration */
SDL_WINDOW_RESIZABLE = 0x00000020, /**< window can be resized */
SDL_WINDOW_MINIMIZED = 0x00000040, /**< window is minimized */
@ -150,7 +150,8 @@ typedef enum
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
SDL_WINDOW_TRANSPARENT = 0x40000000 /**< window with transparent buffer */
SDL_WINDOW_TRANSPARENT = 0x40000000, /**< window with transparent buffer */
SDL_WINDOW_NOT_FOCUSABLE = 0x80000000, /**< window should not be focusable */
} SDL_WindowFlags;
@ -1676,6 +1677,20 @@ extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_
*/
extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window *window);
/**
* Set whether the window may have input focus.
*
* \param window the window to set focusable state
* \param focusable SDL_TRUE to allow input focus, SDL_FALSE to not allow
* input focus
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC int SDLCALL SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable);
/**
* Display the system-level window menu.
*