···156156 #define SDL_TriggerBreakpoint()
157157#endif
158158159159-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
159159+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
160160+/**
161161+ * A macro that reports the current function being compiled.
162162+ *
163163+ * If SDL can't figure how the compiler reports this, it will use "???".
164164+ *
165165+ * \since This macro is available since SDL 3.1.3.
166166+ */
167167+#define SDL_FUNCTION __FUNCTION__
168168+169169+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
160170# define SDL_FUNCTION __func__
161171#elif ((defined(__GNUC__) && (__GNUC__ >= 2)) || defined(_MSC_VER) || defined (__WATCOMC__))
162172# define SDL_FUNCTION __FUNCTION__
163173#else
164174# define SDL_FUNCTION "???"
165175#endif
176176+177177+/**
178178+ * A macro that reports the current file being compiled.
179179+ *
180180+ * \since This macro is available since SDL 3.1.3.
181181+ */
166182#define SDL_FILE __FILE__
183183+184184+/**
185185+ * A macro that reports the current line number of the file being compiled.
186186+ *
187187+ * \since This macro is available since SDL 3.1.3.
188188+ */
167189#define SDL_LINE __LINE__
168190169191/*
···181203disable assertions.
182204*/
183205206206+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
207207+/**
208208+ * A macro for wrapping code in `do {} while (0);` without compiler warnings.
209209+ *
210210+ * Visual Studio with really aggressive warnings enabled needs this to avoid
211211+ * compiler complaints.
212212+ *
213213+ * the `do {} while (0);` trick is useful for wrapping code in a macro that
214214+ * may or may not be a single statement, to avoid various C language accidents.
215215+ *
216216+ * To use:
217217+ *
218218+ * ```c
219219+ * do { SomethingOnce(); } while (SDL_NULL_WHILE_LOOP_CONDITION (0));
220220+ * ```
221221+ *
222222+ * \since This macro is available since SDL 3.1.3.
223223+ */
224224+#define SDL_NULL_WHILE_LOOP_CONDITION (0)
225225+226226+#elif defined _MSC_VER /* Avoid /W4 warnings. */
184227/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
185228 this condition isn't constant. And looks like an owl's face! */
186186-#ifdef _MSC_VER /* stupid /W4 warnings. */
187229#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
188230#else
189231#define SDL_NULL_WHILE_LOOP_CONDITION (0)
190232#endif
191233234234+/**
235235+ * The macro used when an assertion is disabled.
236236+ *
237237+ * This isn't for direct use by apps, but this is the code that is inserted
238238+ * when an SDL_assert is disabled (perhaps in a release build).
239239+ *
240240+ * The code does nothing, but wraps `condition` in a sizeof operator, which
241241+ * generates no code and has no side effects, but avoid compiler warnings
242242+ * about unused variables.
243243+ *
244244+ * \param condition the condition to assert (but not actually run here).
245245+ *
246246+ * \since This macro is available since SDL 3.1.3.
247247+ */
192248#define SDL_disabled_assert(condition) \
193249 do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
194250···237293/**
238294 * Never call this directly.
239295 *
240240- * Use the SDL_assert* macros instead.
296296+ * Use the SDL_assert macros instead.
241297 *
242298 * \param data assert data structure.
243299 * \param func function name.
···253309 const char *func,
254310 const char *file, int line) SDL_ANALYZER_NORETURN;
255311256256-/* Define the trigger breakpoint call used in asserts */
257257-#ifndef SDL_AssertBreakpoint
258258-#if defined(ANDROID) && defined(assert)
259259-/* Define this as empty in case assert() is defined as SDL_assert */
260260-#define SDL_AssertBreakpoint()
261261-#else
312312+313313+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
314314+/**
315315+ * The macro used when an assertion triggers a breakpoint.
316316+ *
317317+ * This isn't for direct use by apps; use SDL_assert or SDL_TriggerBreakpoint
318318+ * instead.
319319+ *
320320+ * \since This macro is available since SDL 3.1.3.
321321+ */
262322#define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
263263-#endif
323323+324324+#elif !defined(SDL_AssertBreakpoint)
325325+# if defined(ANDROID) && defined(assert)
326326+ /* Define this as empty in case assert() is defined as SDL_assert */
327327+# define SDL_AssertBreakpoint()
328328+# else
329329+# define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
330330+# endif
264331#endif /* !SDL_AssertBreakpoint */
265332266266-/* the do {} while(0) avoids dangling else problems:
267267- if (x) SDL_assert(y); else blah();
268268- ... without the do/while, the "else" could attach to this macro's "if".
269269- We try to handle just the minimum we need here in a macro...the loop,
270270- the static vars, and break points. The heavy lifting is handled in
271271- SDL_ReportAssertion(), in SDL_assert.c.
272272-*/
333333+/**
334334+ * The macro used when an assertion is enabled.
335335+ *
336336+ * This isn't for direct use by apps, but this is the code that is inserted
337337+ * when an SDL_assert is enabled.
338338+ *
339339+ * The `do {} while(0)` avoids dangling else problems:
340340+ *
341341+ * ```c
342342+ * if (x) SDL_assert(y); else blah();
343343+ * ```
344344+ *
345345+ * ... without the do/while, the "else" could attach to this macro's "if".
346346+ * We try to handle just the minimum we need here in a macro...the loop,
347347+ * the static vars, and break points. The heavy lifting is handled in
348348+ * SDL_ReportAssertion().
349349+ *
350350+ * \param condition the condition to assert.
351351+ *
352352+ * \since This macro is available since SDL 3.1.3.
353353+ */
273354#define SDL_enabled_assert(condition) \
274355 do { \
275356 while ( !(condition) ) { \
+71-11
include/SDL3/SDL_atomic.h
···155155 * \since This macro is available since SDL 3.1.3.
156156 */
157157#define SDL_CompilerBarrier() DoCompilerSpecificReadWriteBarrier()
158158+158159#elif defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
159160void _ReadWriteBarrier(void);
160161#pragma intrinsic(_ReadWriteBarrier)
···171172#endif
172173173174/**
174174- * Insert a memory release barrier.
175175+ * Insert a memory release barrier (function version).
176176+ *
177177+ * Please refer to SDL_MemoryBarrierRelease for details. This is a function
178178+ * version, which might be useful if you need to use this functionality from
179179+ * a scripting language, etc. Also, some of the macro versions call this
180180+ * function behind the scenes, where more heavy lifting can happen inside
181181+ * of SDL. Generally, though, an app written in C/C++/etc should use the macro
182182+ * version, as it will be more efficient.
183183+ *
184184+ * \threadsafety Obviously this function is safe to use from any thread at any
185185+ * time, but if you find yourself needing this, you are probably
186186+ * dealing with some very sensitive code; be careful!
187187+ *
188188+ * \since This function is available since SDL 3.1.3.
189189+ *
190190+ * \sa SDL_MemoryBarrierRelease
191191+ */
192192+extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
193193+194194+/**
195195+ * Insert a memory acquire barrier (function version).
196196+ *
197197+ * Please refer to SDL_MemoryBarrierRelease for details. This is a function
198198+ * version, which might be useful if you need to use this functionality from
199199+ * a scripting language, etc. Also, some of the macro versions call this
200200+ * function behind the scenes, where more heavy lifting can happen inside
201201+ * of SDL. Generally, though, an app written in C/C++/etc should use the macro
202202+ * version, as it will be more efficient.
203203+ *
204204+ * \threadsafety Obviously this function is safe to use from any thread at any
205205+ * time, but if you find yourself needing this, you are probably
206206+ * dealing with some very sensitive code; be careful!
207207+ *
208208+ * \since This function is available since SDL 3.1.3.
209209+ *
210210+ * \sa SDL_MemoryBarrierAcquire
211211+ */
212212+extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
213213+214214+215215+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
216216+/**
217217+ * Insert a memory release barrier (macro version).
175218 *
176219 * Memory barriers are designed to prevent reads and writes from being
177220 * reordered by the compiler and being seen out of order on multi-core CPUs.
···190233 *
191234 * For more information on these semantics, take a look at the blog post:
192235 * http://preshing.com/20120913/acquire-and-release-semantics
236236+ *
237237+ * This is the macro version of this functionality; if possible, SDL will
238238+ * use compiler intrinsics or inline assembly, but some platforms might
239239+ * need to call the function version of this, SDL_MemoryBarrierReleaseFunction
240240+ * to do the heavy lifting. Apps that can use the macro should favor it over
241241+ * the function.
193242 *
194243 * \threadsafety Obviously this macro is safe to use from any thread at any
195244 * time, but if you find yourself needing this, you are probably
196245 * dealing with some very sensitive code; be careful!
197246 *
198198- * \since This function is available since SDL 3.1.3.
247247+ * \since This macro is available since SDL 3.1.3.
248248+ *
249249+ * \sa SDL_MemoryBarrierAcquire
250250+ * \sa SDL_MemoryBarrierReleaseFunction
199251 */
200200-extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
252252+#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
201253202254/**
203203- * Insert a memory acquire barrier.
255255+ * Insert a memory acquire barrier (macro version).
204256 *
205205- * Please refer to SDL_MemoryBarrierReleaseFunction for the details!
257257+ * Please see SDL_MemoryBarrierRelease for the details on what memory barriers
258258+ * are and when to use them.
206259 *
207207- * \threadsafety Obviously this function is safe to use from any thread at any
260260+ * This is the macro version of this functionality; if possible, SDL will
261261+ * use compiler intrinsics or inline assembly, but some platforms might
262262+ * need to call the function version of this,
263263+ * SDL_MemoryBarrierAcquireFunction, to do the heavy lifting. Apps that can
264264+ * use the macro should favor it over the function.
265265+ *
266266+ * \threadsafety Obviously this macro is safe to use from any thread at any
208267 * time, but if you find yourself needing this, you are probably
209268 * dealing with some very sensitive code; be careful!
210269 *
211211- * \since This function is available since SDL 3.1.3.
270270+ * \since This macro is available since SDL 3.1.3.
212271 *
213213- * \sa SDL_MemoryBarrierReleaseFunction
272272+ * \sa SDL_MemoryBarrierRelease
273273+ * \sa SDL_MemoryBarrierAcquireFunction
214274 */
215215-extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
275275+#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
216276217217-/* !!! FIXME: this should have documentation! */
218218-#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
277277+#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
219278#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
220279#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
221280#elif defined(__GNUC__) && defined(__aarch64__)
···284343 * \since This macro is available since SDL 3.1.3.
285344 */
286345#define SDL_CPUPauseInstruction() DoACPUPauseInACompilerAndArchitectureSpecificWay
346346+287347#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
288348 #define SDL_CPUPauseInstruction() __asm__ __volatile__("pause\n") /* Some assemblers can't do REP NOP, so go with PAUSE. */
289349#elif (defined(__arm__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7) || defined(__aarch64__)
+57-12
include/SDL3/SDL_audio.h
···141141extern "C" {
142142#endif
143143144144-/* masks for different parts of SDL_AudioFormat. */
144144+/**
145145+ * Mask of bits in an SDL_AudioFormat that contains the format bit size.
146146+ *
147147+ * Generally one should use SDL_AUDIO_BITSIZE instead of this macro directly.
148148+ *
149149+ * \since This macro is available since SDL 3.1.3.
150150+ */
145151#define SDL_AUDIO_MASK_BITSIZE (0xFFu)
152152+153153+/**
154154+ * Mask of bits in an SDL_AudioFormat that contain the floating point flag.
155155+ *
156156+ * Generally one should use SDL_AUDIO_ISFLOAT instead of this macro directly.
157157+ *
158158+ * \since This macro is available since SDL 3.1.3.
159159+ */
146160#define SDL_AUDIO_MASK_FLOAT (1u<<8)
161161+162162+/**
163163+ * Mask of bits in an SDL_AudioFormat that contain the bigendian flag.
164164+ *
165165+ * Generally one should use SDL_AUDIO_ISBIGENDIAN or SDL_AUDIO_ISLITTLEENDIAN
166166+ * instead of this macro directly.
167167+ *
168168+ * \since This macro is available since SDL 3.1.3.
169169+ */
147170#define SDL_AUDIO_MASK_BIG_ENDIAN (1u<<12)
171171+172172+/**
173173+ * Mask of bits in an SDL_AudioFormat that contain the signed data flag.
174174+ *
175175+ * Generally one should use SDL_AUDIO_ISSIGNED instead of this macro directly.
176176+ *
177177+ * \since This macro is available since SDL 3.1.3.
178178+ */
148179#define SDL_AUDIO_MASK_SIGNED (1u<<15)
149180150150-#define SDL_DEFINE_AUDIO_FORMAT(signed, bigendian, float, size) \
151151- (((Uint16)(signed) << 15) | ((Uint16)(bigendian) << 12) | ((Uint16)(float) << 8) | ((size) & SDL_AUDIO_MASK_BITSIZE))
181181+/**
182182+ * Define an SDL_AudioFormat value.
183183+ *
184184+ * SDL does not support custom audio formats, so this macro is not of much
185185+ * use externally, but it can be illustrative as to what the various bits of
186186+ * an SDL_AudioFormat mean.
187187+ *
188188+ * For example, SDL_AUDIO_S32LE looks like this:
189189+ *
190190+ * ```c
191191+ * SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32)
192192+ * ```
193193+ *
194194+ * \param signed 1 for signed data, 0 for unsigned data.
195195+ * \param bigendian 1 for bigendian data, 0 for littleendian data.
196196+ * \param flt 1 for floating point data, 0 for integer data.
197197+ * \param size number of bits per sample.
198198+ * \returns a format value in the style of SDL_AudioFormat.
199199+ *
200200+ * \threadsafety It is safe to call this macro from any thread.
201201+ *
202202+ * \since This macro is available since SDL 3.1.3.
203203+ */
204204+#define SDL_DEFINE_AUDIO_FORMAT(signed, bigendian, flt, size) \
205205+ (((Uint16)(signed) << 15) | ((Uint16)(bigendian) << 12) | ((Uint16)(flt) << 8) | ((size) & SDL_AUDIO_MASK_BITSIZE))
152206153207/**
154208 * Audio format.
···400454/* Function prototypes */
401455402456/**
403403- * \name Driver discovery functions
404404- *
405405- * These functions return the list of built in audio drivers, in the
406406- * order that they are normally initialized by default.
407407- */
408408-/* @{ */
409409-410410-/**
411457 * Use this function to get the number of built-in audio drivers.
412458 *
413459 * This function returns a hardcoded number. This never returns a negative
···453499 * \sa SDL_GetNumAudioDrivers
454500 */
455501extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
456456-/* @} */
457502458503/**
459504 * Get the name of the current audio driver.
+6-3
include/SDL3/SDL_begin_code.h
···2222/* WIKI CATEGORY: BeginCode */
23232424/**
2525- * SDL_begin_code.h sets things up for C dynamic library function definitions,
2626- * static inlined functions, and structures aligned at 4-byte alignment.
2727- * If you don't like ugly C preprocessor code, don't look at this file. :)
2525+ * # CategoryBeginCode
2626+ *
2727+ * `SDL_begin_code.h` sets things up for C dynamic library function
2828+ * definitions, static inlined functions, and structures aligned at 4-byte
2929+ * alignment. If you don't like ugly C preprocessor code, don't look at this
3030+ * file. :)
2831 *
2932 * SDL's headers use this; applications generally should not include this
3033 * header directly.
+33-7
include/SDL3/SDL_gpu.h
···15041504 SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
15051505} SDL_GPUTextureCreateInfo;
1506150615071507-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT "SDL.gpu.createtexture.d3d12.clear.r"
15081508-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT "SDL.gpu.createtexture.d3d12.clear.g"
15091509-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT "SDL.gpu.createtexture.d3d12.clear.b"
15101510-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT "SDL.gpu.createtexture.d3d12.clear.a"
15111511-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT "SDL.gpu.createtexture.d3d12.clear.depth"
15121512-#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 "SDL.gpu.createtexture.d3d12.clear.stencil"
15131513-15141507/**
15151508 * A structure specifying the parameters of a buffer.
15161509 *
···22392232 * implementation will automatically fall back to the highest available sample
22402233 * count.
22412234 *
22352235+ * There are optional properties that can be provided through
22362236+ * SDL_GPUTextureCreateInfo's `props`. These are the supported properties:
22372237+ *
22382238+ * - `SDL_PROP_PROCESS_CREATE_ARGS_POINTER`: an array of strings containing
22392239+ * the program to run, any arguments, and a NULL pointer, e.g. const char
22402240+ * *args[] = { "myprogram", "argument", NULL }. This is a required property.
22412241+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT`: (Direct3D 12 only)
22422242+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the
22432243+ * texture to a color with this red intensity. Defaults to zero.
22442244+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT`: (Direct3D 12 only)
22452245+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the
22462246+ * texture to a color with this green intensity. Defaults to zero.
22472247+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT`: (Direct3D 12 only)
22482248+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the
22492249+ * texture to a color with this blue intensity. Defaults to zero.
22502250+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT`: (Direct3D 12 only)
22512251+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the
22522252+ * texture to a color with this alpha intensity. Defaults to zero.
22532253+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT`: (Direct3D 12 only)
22542254+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, clear
22552255+ * the texture to a depth of this value. Defaults to zero.
22562256+ * - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8`: (Direct3D 12 only)
22572257+ * if the texture usage is SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, clear
22582258+ * the texture to a stencil of this value. Defaults to zero.
22592259+ *
22422260 * \param device a GPU Context.
22432261 * \param createinfo a struct describing the state of the texture to create.
22442262 * \returns a texture object on success, or NULL on failure; call
···22602278extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_CreateGPUTexture(
22612279 SDL_GPUDevice *device,
22622280 const SDL_GPUTextureCreateInfo *createinfo);
22812281+22822282+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT "SDL.gpu.createtexture.d3d12.clear.r"
22832283+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT "SDL.gpu.createtexture.d3d12.clear.g"
22842284+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT "SDL.gpu.createtexture.d3d12.clear.b"
22852285+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT "SDL.gpu.createtexture.d3d12.clear.a"
22862286+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT "SDL.gpu.createtexture.d3d12.clear.depth"
22872287+#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 "SDL.gpu.createtexture.d3d12.clear.stencil"
22882288+2263228922642290/**
22652291 * Creates a buffer object to be used in graphics or compute workflows.
+13-1
include/SDL3/SDL_haptic.h
···299299#define SDL_HAPTIC_LEFTRIGHT (1u<<11)
300300301301/**
302302- * Reserved for future use
302302+ * Reserved for future use.
303303 *
304304 * \since This macro is available since SDL 3.1.3.
305305 */
306306#define SDL_HAPTIC_RESERVED1 (1u<<12)
307307+308308+/**
309309+ * Reserved for future use.
310310+ *
311311+ * \since This macro is available since SDL 3.1.3.
312312+ */
307313#define SDL_HAPTIC_RESERVED2 (1u<<13)
314314+315315+/**
316316+ * Reserved for future use.
317317+ *
318318+ * \since This macro is available since SDL 3.1.3.
319319+ */
308320#define SDL_HAPTIC_RESERVED3 (1u<<14)
309321310322/**
+9
include/SDL3/SDL_hints.h
···40214021 * \since This hint is available since SDL 3.1.3.
40224022 */
40234023#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
40244024+40254025+/**
40264026+ * A variable to specify custom icon resource id from RC file on Windows
40274027+ * platform.
40284028+ *
40294029+ * This hint should be set before SDL is initialized.
40304030+ *
40314031+ * \since This hint is available since SDL 3.1.3.
40324032+ */
40244033#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"
4025403440264035/**
+60
include/SDL3/SDL_init.h
···113113 SDL_APP_FAILURE /**< Value that requests termination with error from the main callbacks. */
114114} SDL_AppResult;
115115116116+/**
117117+ * Function pointer typedef for SDL_AppInit.
118118+ *
119119+ * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
120120+ * the scenes for apps using the optional main callbacks. Apps that want to use
121121+ * this should just implement SDL_AppInit directly.
122122+ *
123123+ * \param appstate a place where the app can optionally store a pointer for
124124+ * future use.
125125+ * \param argc the standard ANSI C main's argc; number of elements in `argv`.
126126+ * \param argv the standard ANSI C main's argv; array of command line
127127+ * arguments.
128128+ * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
129129+ * terminate with success, SDL_APP_CONTINUE to continue.
130130+ *
131131+ * \since This datatype is available since SDL 3.1.3.
132132+ */
116133typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]);
134134+135135+/**
136136+ * Function pointer typedef for SDL_AppIterate.
137137+ *
138138+ * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
139139+ * the scenes for apps using the optional main callbacks. Apps that want to use
140140+ * this should just implement SDL_AppIterate directly.
141141+ *
142142+ * \param appstate an optional pointer, provided by the app in SDL_AppInit.
143143+ * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
144144+ * terminate with success, SDL_APP_CONTINUE to continue.
145145+ *
146146+ * \since This datatype is available since SDL 3.1.3.
147147+ */
117148typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate);
149149+150150+/**
151151+ * Function pointer typedef for SDL_AppEvent.
152152+ *
153153+ * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
154154+ * the scenes for apps using the optional main callbacks. Apps that want to use
155155+ * this should just implement SDL_AppEvent directly.
156156+ *
157157+ * \param appstate an optional pointer, provided by the app in SDL_AppInit.
158158+ * \param event the new event for the app to examine.
159159+ * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
160160+ * terminate with success, SDL_APP_CONTINUE to continue.
161161+ *
162162+ * \since This datatype is available since SDL 3.1.3.
163163+ */
118164typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, SDL_Event *event);
165165+166166+/**
167167+ * Function pointer typedef for SDL_AppQuit.
168168+ *
169169+ * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
170170+ * the scenes for apps using the optional main callbacks. Apps that want to use
171171+ * this should just implement SDL_AppEvent directly.
172172+ *
173173+ * \param appstate an optional pointer, provided by the app in SDL_AppInit.
174174+ * \param result the result code that terminated the app (success or failure).
175175+ *
176176+ * \since This datatype is available since SDL 3.1.3.
177177+ */
119178typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate, SDL_AppResult result);
179179+120180121181/**
122182 * Initialize the SDL library.
+64-2
include/SDL3/SDL_intrin.h
···267267#endif
268268#endif /* compiler version */
269269270270-#if defined(__clang__) && defined(__has_attribute)
270270+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
271271+/**
272272+ * A macro to decide if the compiler supports `__attribute__((target))`.
273273+ *
274274+ * Even though this is defined in SDL's public headers, it is generally not
275275+ * used directly by apps. Apps should probably just use SDL_TARGETING
276276+ * directly, instead.
277277+ *
278278+ * \since This macro is available since SDL 3.1.3.
279279+ *
280280+ * \sa SDL_TARGETING
281281+ */
282282+#define SDL_HAS_TARGET_ATTRIBS
283283+284284+#elif defined(__clang__) && defined(__has_attribute)
271285# if __has_attribute(target)
272286# define SDL_HAS_TARGET_ATTRIBS
273287# endif
···277291# define SDL_HAS_TARGET_ATTRIBS
278292#endif
279293280280-#ifdef SDL_HAS_TARGET_ATTRIBS
294294+295295+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
296296+297297+/**
298298+ * A macro to tag a function as targeting a specific CPU architecture.
299299+ *
300300+ * This is a hint to the compiler that a function should be built with support
301301+ * for a CPU instruction set that might be different than the rest of the
302302+ * program.
303303+ *
304304+ * The particulars of this are explained in the GCC documentation:
305305+ *
306306+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-target-function-attribute
307307+ *
308308+ * An example of using this feature is to turn on SSE2 support for a specific
309309+ * function, even if the rest of the source code is not compiled to use SSE2
310310+ * code:
311311+ *
312312+ * ```c
313313+ * #ifdef SDL_SSE2_INTRINSICS
314314+ * static void SDL_TARGETING("sse2") DoSomethingWithSSE2(char *x) {
315315+ * ...use SSE2 intrinsic functions, etc...
316316+ * }
317317+ * #endif
318318+ *
319319+ * // later...
320320+ * #ifdef SDL_SSE2_INTRINSICS
321321+ * if (SDL_HasSSE2()) {
322322+ * DoSomethingWithSSE2(str);
323323+ * }
324324+ * #endif
325325+ * ```
326326+ *
327327+ * The application is, on a whole, built without SSE2 instructions, so it
328328+ * will run on Intel machines that don't support SSE2. But then at runtime,
329329+ * it checks if the system supports the instructions, and then calls into a
330330+ * function that uses SSE2 opcodes. The ifdefs make sure that this code isn't
331331+ * used on platforms that don't have SSE2 at all.
332332+ *
333333+ * On compilers without target support, this is defined to nothing.
334334+ *
335335+ * This symbol is used by SDL internally, but apps and other libraries are
336336+ * welcome to use it for their own interfaces as well.
337337+ *
338338+ * \since This macro is available since SDL 3.1.3.
339339+ */
340340+#define SDL_TARGETING(x) __attribute__((target(x)))
341341+342342+#elif defined(SDL_HAS_TARGET_ATTRIBS)
281343# define SDL_TARGETING(x) __attribute__((target(x)))
282344#else
283345# define SDL_TARGETING(x)
+99-27
include/SDL3/SDL_main.h
···2828 * should look like this:
2929 *
3030 * ```c
3131- * int main(int argc, char *argv[])
3232- * {
3333- * }
3131+ * int main(int argc, char *argv[])
3232+ * {
3333+ * }
3434 * ```
3535 *
3636 * SDL will take care of platform specific details on how it gets called.
···5555#include <SDL3/SDL_error.h>
5656#include <SDL3/SDL_events.h>
57575858+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
5959+6060+/**
6161+ * Inform SDL that the app is providing an entry point instead of SDL.
6262+ *
6363+ * SDL does not define this macro, but will check if it is defined when
6464+ * including `SDL_main.h`. If defined, SDL will expect the app to provide the
6565+ * proper entry point for the platform, and all the other magic details
6666+ * needed, like manually calling SDL_SetMainReady.
6767+ *
6868+ * Please see [README/main-functions](README/main-functions), (or
6969+ * docs/README-main-functions.md in the source tree) for a more detailed
7070+ * explanation.
7171+ *
7272+ * \since This macro is used by the headers since SDL 3.1.3.
7373+ */
7474+#define SDL_MAIN_HANDLED 1
7575+7676+/**
7777+ * Inform SDL to use the main callbacks instead of main.
7878+ *
7979+ * SDL does not define this macro, but will check if it is defined when
8080+ * including `SDL_main.h`. If defined, SDL will expect the app to provide
8181+ * several functions: SDL_AppInit, SDL_AppEvent, SDL_AppIterate, and
8282+ * SDL_AppQuit. The app should not provide a `main` function in this case, and
8383+ * doing so will likely cause the build to fail.
8484+ *
8585+ * Please see [README/main-functions](README/main-functions), (or
8686+ * docs/README-main-functions.md in the source tree) for a more detailed
8787+ * explanation.
8888+ *
8989+ * \since This macro is used by the headers since SDL 3.1.3.
9090+ *
9191+ * \sa SDL_AppInit
9292+ * \sa SDL_AppEvent
9393+ * \sa SDL_AppIterate
9494+ * \sa SDL_AppQuit
9595+ */
9696+#define SDL_MAIN_USE_CALLBACKS 1
9797+9898+/**
9999+ * Defined if the target platform offers a special mainline through SDL.
100100+ *
101101+ * This won't be defined otherwise. If defined, SDL's headers will redefine
102102+ * `main` to `SDL_main`.
103103+ *
104104+ * This macro is defined by `SDL_main.h`, which is not automatically included
105105+ * by `SDL.h`.
106106+ *
107107+ * Even if available, an app can define SDL_MAIN_HANDLED and provide their
108108+ * own, if they know what they're doing.
109109+ *
110110+ * This macro is used internally by SDL, and apps probably shouldn't rely on it.
111111+ *
112112+ * \since This macro is available since SDL 3.1.3.
113113+ */
114114+#define SDL_MAIN_AVAILABLE
115115+116116+/**
117117+ * Defined if the target platform _requires_ a special mainline through SDL.
118118+ *
119119+ * This won't be defined otherwise. If defined, SDL's headers will redefine
120120+ * `main` to `SDL_main`.
121121+ *
122122+ * This macro is defined by `SDL_main.h`, which is not automatically included
123123+ * by `SDL.h`.
124124+ *
125125+ * Even if required, an app can define SDL_MAIN_HANDLED and provide their
126126+ * own, if they know what they're doing.
127127+ *
128128+ * This macro is used internally by SDL, and apps probably shouldn't rely on it.
129129+ *
130130+ * \since This macro is available since SDL 3.1.3.
131131+ */
132132+#define SDL_MAIN_NEEDED
133133+134134+#endif
135135+58136#ifndef SDL_MAIN_HANDLED
59137 #if defined(SDL_PLATFORM_PRIVATE_MAIN)
60138 /* Private platforms may have their own ideas about entry points. */
···144222 #endif
145223#endif /* SDL_MAIN_HANDLED */
146224147147-#ifdef SDL_MAIN_EXPORTED
148148-/* We need to export SDL_main so it can be launched from external code,
149149- like SDLActivity.java on Android */
150150-#define SDLMAIN_DECLSPEC SDL_DECLSPEC
151151-#else
152152-/* usually this is empty */
153153-#define SDLMAIN_DECLSPEC
154154-#endif /* SDL_MAIN_EXPORTED */
155225156226#ifdef SDL_WIKI_DOCUMENTATION_SECTION
157227158228/**
159159- * Inform SDL to use the main callbacks instead of main.
229229+ * A macro to tag a main entry point function as exported.
160230 *
161161- * SDL does not define this macro, but will check if it is defined when
162162- * including `SDL_main.h`. If defined, SDL will expect the app to provide
163163- * several functions: SDL_AppInit, SDL_AppEvent, SDL_AppIterate, and
164164- * SDL_AppQuit. The app should not provide a `main` function in this case, and
165165- * doing so will likely cause the build to fail.
231231+ * Most platforms don't need this, and the macro will be defined to nothing.
232232+ * Some, like Android, keep the entry points in a shared library and need to
233233+ * explicitly export the symbols.
166234 *
167167- * Please see [README/main-functions](README/main-functions), (or
168168- * docs/README-main-functions.md in the source tree) for a more detailed
169169- * explanation.
235235+ * External code rarely needs this, and if it needs something, it's almost
236236+ * always SDL_DECLSPEC instead.
170237 *
171171- * \since This macro is used by the headers since SDL 3.1.3.
238238+ * \since This macro is available since SDL 3.1.3.
172239 *
173173- * \sa SDL_AppInit
174174- * \sa SDL_AppEvent
175175- * \sa SDL_AppIterate
176176- * \sa SDL_AppQuit
240240+ * \sa SDL_DECLSPEC
177241 */
178178-#define SDL_MAIN_USE_CALLBACKS 1
179179-#endif
242242+#define SDLMAIN_DECLSPEC
243243+244244+#elif defined(SDL_MAIN_EXPORTED)
245245+/* We need to export SDL_main so it can be launched from external code,
246246+ like SDLActivity.java on Android */
247247+#define SDLMAIN_DECLSPEC SDL_DECLSPEC
248248+#else
249249+/* usually this is empty */
250250+#define SDLMAIN_DECLSPEC
251251+#endif /* SDL_MAIN_EXPORTED */
180252181253#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) || defined(SDL_MAIN_USE_CALLBACKS)
182254#define main SDL_main
+152-6
include/SDL3/SDL_mutex.h
···3333#include <SDL3/SDL_error.h>
3434#include <SDL3/SDL_thread.h>
35353636-/******************************************************************************/
3737-/* Enable thread safety attributes only with clang.
3636+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
3737+/**
3838+ * Enable thread safety attributes, only with clang.
3939+ *
3840 * The attributes can be safely erased when compiling with other compilers.
3941 *
4042 * To enable analysis, set these environment variables before running cmake:
4141- * export CC=clang
4242- * export CFLAGS="-DSDL_THREAD_SAFETY_ANALYSIS -Wthread-safety"
4343+ *
4444+ * ```bash
4545+ * export CC=clang
4646+ * export CFLAGS="-DSDL_THREAD_SAFETY_ANALYSIS -Wthread-safety"
4747+ * ```
4348 */
4444-#if defined(SDL_THREAD_SAFETY_ANALYSIS) && \
4545- defined(__clang__) && (!defined(SWIG))
4949+#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
5050+5151+#elif defined(SDL_THREAD_SAFETY_ANALYSIS) && defined(__clang__) && (!defined(SWIG))
4652#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
4753#else
4854#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) /* no-op */
4955#endif
50565757+/**
5858+ * Wrapper around Clang thread safety analysis annotations.
5959+ *
6060+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
6161+ *
6262+ * \since This macro is available since SDL 3.1.3.
6363+ */
5164#define SDL_CAPABILITY(x) \
5265 SDL_THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
53666767+/**
6868+ * Wrapper around Clang thread safety analysis annotations.
6969+ *
7070+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
7171+ *
7272+ * \since This macro is available since SDL 3.1.3.
7373+ */
5474#define SDL_SCOPED_CAPABILITY \
5575 SDL_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
56767777+/**
7878+ * Wrapper around Clang thread safety analysis annotations.
7979+ *
8080+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
8181+ *
8282+ * \since This macro is available since SDL 3.1.3.
8383+ */
5784#define SDL_GUARDED_BY(x) \
5885 SDL_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
59868787+/**
8888+ * Wrapper around Clang thread safety analysis annotations.
8989+ *
9090+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
9191+ *
9292+ * \since This macro is available since SDL 3.1.3.
9393+ */
6094#define SDL_PT_GUARDED_BY(x) \
6195 SDL_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
62969797+/**
9898+ * Wrapper around Clang thread safety analysis annotations.
9999+ *
100100+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
101101+ *
102102+ * \since This macro is available since SDL 3.1.3.
103103+ */
63104#define SDL_ACQUIRED_BEFORE(x) \
64105 SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
65106107107+/**
108108+ * Wrapper around Clang thread safety analysis annotations.
109109+ *
110110+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
111111+ *
112112+ * \since This macro is available since SDL 3.1.3.
113113+ */
66114#define SDL_ACQUIRED_AFTER(x) \
67115 SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x))
68116117117+/**
118118+ * Wrapper around Clang thread safety analysis annotations.
119119+ *
120120+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
121121+ *
122122+ * \since This macro is available since SDL 3.1.3.
123123+ */
69124#define SDL_REQUIRES(x) \
70125 SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(x))
71126127127+/**
128128+ * Wrapper around Clang thread safety analysis annotations.
129129+ *
130130+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
131131+ *
132132+ * \since This macro is available since SDL 3.1.3.
133133+ */
72134#define SDL_REQUIRES_SHARED(x) \
73135 SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(x))
74136137137+/**
138138+ * Wrapper around Clang thread safety analysis annotations.
139139+ *
140140+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
141141+ *
142142+ * \since This macro is available since SDL 3.1.3.
143143+ */
75144#define SDL_ACQUIRE(x) \
76145 SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(x))
77146147147+/**
148148+ * Wrapper around Clang thread safety analysis annotations.
149149+ *
150150+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
151151+ *
152152+ * \since This macro is available since SDL 3.1.3.
153153+ */
78154#define SDL_ACQUIRE_SHARED(x) \
79155 SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(x))
80156157157+/**
158158+ * Wrapper around Clang thread safety analysis annotations.
159159+ *
160160+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
161161+ *
162162+ * \since This macro is available since SDL 3.1.3.
163163+ */
81164#define SDL_RELEASE(x) \
82165 SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(x))
83166167167+/**
168168+ * Wrapper around Clang thread safety analysis annotations.
169169+ *
170170+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
171171+ *
172172+ * \since This macro is available since SDL 3.1.3.
173173+ */
84174#define SDL_RELEASE_SHARED(x) \
85175 SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(x))
86176177177+/**
178178+ * Wrapper around Clang thread safety analysis annotations.
179179+ *
180180+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
181181+ *
182182+ * \since This macro is available since SDL 3.1.3.
183183+ */
87184#define SDL_RELEASE_GENERIC(x) \
88185 SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(x))
89186187187+/**
188188+ * Wrapper around Clang thread safety analysis annotations.
189189+ *
190190+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
191191+ *
192192+ * \since This macro is available since SDL 3.1.3.
193193+ */
90194#define SDL_TRY_ACQUIRE(x, y) \
91195 SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(x, y))
92196197197+/**
198198+ * Wrapper around Clang thread safety analysis annotations.
199199+ *
200200+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
201201+ *
202202+ * \since This macro is available since SDL 3.1.3.
203203+ */
93204#define SDL_TRY_ACQUIRE_SHARED(x, y) \
94205 SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(x, y))
95206207207+/**
208208+ * Wrapper around Clang thread safety analysis annotations.
209209+ *
210210+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
211211+ *
212212+ * \since This macro is available since SDL 3.1.3.
213213+ */
96214#define SDL_EXCLUDES(x) \
97215 SDL_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x))
98216217217+/**
218218+ * Wrapper around Clang thread safety analysis annotations.
219219+ *
220220+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
221221+ *
222222+ * \since This macro is available since SDL 3.1.3.
223223+ */
99224#define SDL_ASSERT_CAPABILITY(x) \
100225 SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
101226227227+/**
228228+ * Wrapper around Clang thread safety analysis annotations.
229229+ *
230230+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
231231+ *
232232+ * \since This macro is available since SDL 3.1.3.
233233+ */
102234#define SDL_ASSERT_SHARED_CAPABILITY(x) \
103235 SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
104236237237+/**
238238+ * Wrapper around Clang thread safety analysis annotations.
239239+ *
240240+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
241241+ *
242242+ * \since This macro is available since SDL 3.1.3.
243243+ */
105244#define SDL_RETURN_CAPABILITY(x) \
106245 SDL_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
107246247247+/**
248248+ * Wrapper around Clang thread safety analysis annotations.
249249+ *
250250+ * Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
251251+ *
252252+ * \since This macro is available since SDL 3.1.3.
253253+ */
108254#define SDL_NO_THREAD_SAFETY_ANALYSIS \
109255 SDL_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
110256
+399-25
include/SDL3/SDL_pixels.h
···213213 SDL_PACKEDLAYOUT_1010102
214214} SDL_PackedLayout;
215215216216+/**
217217+ * A macro for defining custom FourCC pixel formats.
218218+ *
219219+ * For example, defining SDL_PIXELFORMAT_YV12 looks like this:
220220+ *
221221+ * ```c
222222+ * SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')
223223+ * ```
224224+ *
225225+ * \param A the first character of the FourCC code.
226226+ * \param B the second character of the FourCC code.
227227+ * \param C the third character of the FourCC code.
228228+ * \param D the fourth character of the FourCC code.
229229+ * \returns a format value in the style of SDL_PixelFormat.
230230+ *
231231+ * \threadsafety It is safe to call this macro from any thread.
232232+ *
233233+ * \since This macro is available since SDL 3.1.3.
234234+ */
216235#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
217236237237+/**
238238+ * A macro for defining custom non-FourCC pixel formats.
239239+ *
240240+ * For example, defining SDL_PIXELFORMAT_RGBA8888 looks like this:
241241+ *
242242+ * ```c
243243+ * SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4)
244244+ * ```
245245+ *
246246+ * \param type the type of the new format, probably a SDL_PixelType value.
247247+ * \param order the order of the new format, probably a SDL_BitmapOrder, SDL_PackedOrder, or SDL_ArrayOrder value.
248248+ * \param layout the layout of the new format, probably an SDL_PackedLayout value or zero.
249249+ * \param bits the number of bits per pixel of the new format.
250250+ * \param bytes the number of bytes per pixel of the new format.
251251+ * \returns a format value in the style of SDL_PixelFormat.
252252+ *
253253+ * \threadsafety It is safe to call this macro from any thread.
254254+ *
255255+ * \since This macro is available since SDL 3.1.3.
256256+ */
218257#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
219258 ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
220259 ((bits) << 8) | ((bytes) << 0))
221260222222-#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
223223-#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
224224-#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
225225-#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
226226-#define SDL_BITSPERPIXEL(X) \
227227- (SDL_ISPIXELFORMAT_FOURCC(X) ? 0 : (((X) >> 8) & 0xFF))
228228-#define SDL_BYTESPERPIXEL(X) \
229229- (SDL_ISPIXELFORMAT_FOURCC(X) ? \
230230- ((((X) == SDL_PIXELFORMAT_YUY2) || \
231231- ((X) == SDL_PIXELFORMAT_UYVY) || \
232232- ((X) == SDL_PIXELFORMAT_YVYU) || \
233233- ((X) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((X) >> 0) & 0xFF))
261261+/**
262262+ * A macro to retrieve the flags of an SDL_PixelFormat.
263263+ *
264264+ * This macro is generally not needed directly by an app, which should use
265265+ * specific tests, like SDL_ISPIXELFORMAT_FOURCC, instead.
266266+ *
267267+ * \param format an SDL_PixelFormat to check.
268268+ * \returns the flags of `format`.
269269+ *
270270+ * \threadsafety It is safe to call this macro from any thread.
271271+ *
272272+ * \since This macro is available since SDL 3.1.3.
273273+ */
274274+#define SDL_PIXELFLAG(format) (((format) >> 28) & 0x0F)
234275276276+/**
277277+ * A macro to retrieve the type of an SDL_PixelFormat.
278278+ *
279279+ * This is usually a value from the SDL_PixelType enumeration.
280280+ *
281281+ * \param format an SDL_PixelFormat to check.
282282+ * \returns the type of `format`.
283283+ *
284284+ * \threadsafety It is safe to call this macro from any thread.
285285+ *
286286+ * \since This macro is available since SDL 3.1.3.
287287+ */
288288+#define SDL_PIXELTYPE(format) (((format) >> 24) & 0x0F)
289289+290290+/**
291291+ * A macro to retrieve the order of an SDL_PixelFormat.
292292+ *
293293+ * This is usually a value from the SDL_BitmapOrder, SDL_PackedOrder, or
294294+ * SDL_ArrayOrder enumerations, depending on the format type.
295295+ *
296296+ * \param format an SDL_PixelFormat to check.
297297+ * \returns the order of `format`.
298298+ *
299299+ * \threadsafety It is safe to call this macro from any thread.
300300+ *
301301+ * \since This macro is available since SDL 3.1.3.
302302+ */
303303+#define SDL_PIXELORDER(format) (((format) >> 20) & 0x0F)
304304+305305+/**
306306+ * A macro to retrieve the layout of an SDL_PixelFormat.
307307+ *
308308+ * This is usually a value from the SDL_PackedLayout enumeration, or zero if
309309+ * a layout doesn't make sense for the format type.
310310+ *
311311+ * \param format an SDL_PixelFormat to check.
312312+ * \returns the layout of `format`.
313313+ *
314314+ * \threadsafety It is safe to call this macro from any thread.
315315+ *
316316+ * \since This macro is available since SDL 3.1.3.
317317+ */
318318+#define SDL_PIXELLAYOUT(format) (((format) >> 16) & 0x0F)
319319+320320+/**
321321+ * A macro to determine an SDL_PixelFormat's bits per pixel.
322322+ *
323323+ * Note that this macro double-evaluates its parameter, so do not use
324324+ * expressions with side-effects here.
325325+ *
326326+ * FourCC formats will report zero here, as it rarely makes sense to measure
327327+ * them per-pixel.
328328+ *
329329+ * \param format an SDL_PixelFormat to check.
330330+ * \returns the bits-per-pixel of `format`.
331331+ *
332332+ * \threadsafety It is safe to call this macro from any thread.
333333+ *
334334+ * \since This macro is available since SDL 3.1.3.
335335+ *
336336+ * \sa SDL_BYTESPERPIXEL
337337+ */
338338+#define SDL_BITSPERPIXEL(format) \
339339+ (SDL_ISPIXELFORMAT_FOURCC(format) ? 0 : (((format) >> 8) & 0xFF))
340340+341341+/**
342342+ * A macro to determine an SDL_PixelFormat's bytes per pixel.
343343+ *
344344+ * Note that this macro double-evaluates its parameter, so do not use
345345+ * expressions with side-effects here.
346346+ *
347347+ * FourCC formats do their best here, but many of them don't have a meaningful
348348+ * measurement of bytes per pixel.
349349+ *
350350+ * \param format an SDL_PixelFormat to check.
351351+ * \returns the bytes-per-pixel of `format`.
352352+ *
353353+ * \threadsafety It is safe to call this macro from any thread.
354354+ *
355355+ * \since This macro is available since SDL 3.1.3.
356356+ *
357357+ * \sa SDL_BITSPERPIXEL
358358+ */
359359+#define SDL_BYTESPERPIXEL(format) \
360360+ (SDL_ISPIXELFORMAT_FOURCC(format) ? \
361361+ ((((format) == SDL_PIXELFORMAT_YUY2) || \
362362+ ((format) == SDL_PIXELFORMAT_UYVY) || \
363363+ ((format) == SDL_PIXELFORMAT_YVYU) || \
364364+ ((format) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((format) >> 0) & 0xFF))
365365+366366+367367+/**
368368+ * A macro to determine if an SDL_PixelFormat is an indexed format.
369369+ *
370370+ * Note that this macro double-evaluates its parameter, so do not use
371371+ * expressions with side-effects here.
372372+ *
373373+ * \param format an SDL_PixelFormat to check.
374374+ * \returns true if the format is indexed, false otherwise.
375375+ *
376376+ * \threadsafety It is safe to call this macro from any thread.
377377+ *
378378+ * \since This macro is available since SDL 3.1.3.
379379+ */
235380#define SDL_ISPIXELFORMAT_INDEXED(format) \
236381 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
237382 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
···239384 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
240385 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
241386387387+/**
388388+ * A macro to determine if an SDL_PixelFormat is a packed format.
389389+ *
390390+ * Note that this macro double-evaluates its parameter, so do not use
391391+ * expressions with side-effects here.
392392+ *
393393+ * \param format an SDL_PixelFormat to check.
394394+ * \returns true if the format is packed, false otherwise.
395395+ *
396396+ * \threadsafety It is safe to call this macro from any thread.
397397+ *
398398+ * \since This macro is available since SDL 3.1.3.
399399+ */
242400#define SDL_ISPIXELFORMAT_PACKED(format) \
243401 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
244402 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
245403 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
246404 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
247405406406+/**
407407+ * A macro to determine if an SDL_PixelFormat is an array format.
408408+ *
409409+ * Note that this macro double-evaluates its parameter, so do not use
410410+ * expressions with side-effects here.
411411+ *
412412+ * \param format an SDL_PixelFormat to check.
413413+ * \returns true if the format is an array, false otherwise.
414414+ *
415415+ * \threadsafety It is safe to call this macro from any thread.
416416+ *
417417+ * \since This macro is available since SDL 3.1.3.
418418+ */
248419#define SDL_ISPIXELFORMAT_ARRAY(format) \
249420 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
250421 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
···253424 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
254425 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
255426427427+/**
428428+ * A macro to determine if an SDL_PixelFormat is a 10-bit format.
429429+ *
430430+ * Note that this macro double-evaluates its parameter, so do not use
431431+ * expressions with side-effects here.
432432+ *
433433+ * \param format an SDL_PixelFormat to check.
434434+ * \returns true if the format is 10-bit, false otherwise.
435435+ *
436436+ * \threadsafety It is safe to call this macro from any thread.
437437+ *
438438+ * \since This macro is available since SDL 3.1.3.
439439+ */
256440#define SDL_ISPIXELFORMAT_10BIT(format) \
257441 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
258442 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
259443 (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
260444445445+/**
446446+ * A macro to determine if an SDL_PixelFormat is a floating point format.
447447+ *
448448+ * Note that this macro double-evaluates its parameter, so do not use
449449+ * expressions with side-effects here.
450450+ *
451451+ * \param format an SDL_PixelFormat to check.
452452+ * \returns true if the format is 10-bit, false otherwise.
453453+ *
454454+ * \threadsafety It is safe to call this macro from any thread.
455455+ *
456456+ * \since This macro is available since SDL 3.1.3.
457457+ */
261458#define SDL_ISPIXELFORMAT_FLOAT(format) \
262459 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
263460 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
264461 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
265462463463+/**
464464+ * A macro to determine if an SDL_PixelFormat has an alpha channel.
465465+ *
466466+ * Note that this macro double-evaluates its parameter, so do not use
467467+ * expressions with side-effects here.
468468+ *
469469+ * \param format an SDL_PixelFormat to check.
470470+ * \returns true if the format has alpha, false otherwise.
471471+ *
472472+ * \threadsafety It is safe to call this macro from any thread.
473473+ *
474474+ * \since This macro is available since SDL 3.1.3.
475475+ */
266476#define SDL_ISPIXELFORMAT_ALPHA(format) \
267477 ((SDL_ISPIXELFORMAT_PACKED(format) && \
268478 ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
···275485 (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
276486 (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
277487278278-/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
279279-#define SDL_ISPIXELFORMAT_FOURCC(format) \
488488+489489+/**
490490+ * A macro to determine if an SDL_PixelFormat is a "FourCC" format.
491491+ *
492492+ * This covers custom and other unusual formats.
493493+ *
494494+ * Note that this macro double-evaluates its parameter, so do not use
495495+ * expressions with side-effects here.
496496+ *
497497+ * \param format an SDL_PixelFormat to check.
498498+ * \returns true if the format has alpha, false otherwise.
499499+ *
500500+ * \threadsafety It is safe to call this macro from any thread.
501501+ *
502502+ * \since This macro is available since SDL 3.1.3.
503503+ */
504504+#define SDL_ISPIXELFORMAT_FOURCC(format) /* The flag is set to 1 because 0x1? is not in the printable ASCII range */ \
280505 ((format) && (SDL_PIXELFLAG(format) != 1))
281506282507/* Note: If you modify this enum, update SDL_GetPixelFormatName() */
···591816592817593818/* Colorspace definition */
819819+820820+/**
821821+ * A macro for defining custom SDL_Colorspace formats.
822822+ *
823823+ * For example, defining SDL_COLORSPACE_SRGB looks like this:
824824+ *
825825+ * ```c
826826+ * SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
827827+ * SDL_COLOR_RANGE_FULL,
828828+ * SDL_COLOR_PRIMARIES_BT709,
829829+ * SDL_TRANSFER_CHARACTERISTICS_SRGB,
830830+ * SDL_MATRIX_COEFFICIENTS_IDENTITY,
831831+ * SDL_CHROMA_LOCATION_NONE)
832832+ * ```
833833+ *
834834+ * \param type the type of the new format, probably an SDL_ColorType value.
835835+ * \param range the range of the new format, probably a SDL_ColorRange value.
836836+ * \param primaries the primaries of the new format, probably an SDL_ColorPrimaries value.
837837+ * \param transfer the transfer characteristics of the new format, probably an SDL_TransferCharacteristics value.
838838+ * \param matrix the matrix coefficients of the new format, probably an SDL_MatrixCoefficients value.
839839+ * \param chroma the chroma sample location of the new format, probably an SDL_ChromaLocation value.
840840+ * \returns a format value in the style of SDL_Colorspace.
841841+ *
842842+ * \threadsafety It is safe to call this macro from any thread.
843843+ *
844844+ * \since This macro is available since SDL 3.1.3.
845845+ */
594846#define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
595847 (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
596848 ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
597849598598-#define SDL_COLORSPACETYPE(X) (SDL_ColorType)(((X) >> 28) & 0x0F)
599599-#define SDL_COLORSPACERANGE(X) (SDL_ColorRange)(((X) >> 24) & 0x0F)
600600-#define SDL_COLORSPACECHROMA(X) (SDL_ChromaLocation)(((X) >> 20) & 0x0F)
601601-#define SDL_COLORSPACEPRIMARIES(X) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F)
602602-#define SDL_COLORSPACETRANSFER(X) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F)
603603-#define SDL_COLORSPACEMATRIX(X) (SDL_MatrixCoefficients)((X) & 0x1F)
850850+/**
851851+ * A macro to retrieve the type of an SDL_Colorspace.
852852+ *
853853+ * \param cspace an SDL_Colorspace to check.
854854+ * \returns the SDL_ColorType for `cspace`.
855855+ *
856856+ * \threadsafety It is safe to call this macro from any thread.
857857+ *
858858+ * \since This macro is available since SDL 3.1.3.
859859+ */
860860+#define SDL_COLORSPACETYPE(cspace) (SDL_ColorType)(((cspace) >> 28) & 0x0F)
861861+862862+/**
863863+ * A macro to retrieve the range of an SDL_Colorspace.
864864+ *
865865+ * \param cspace an SDL_Colorspace to check.
866866+ * \returns the SDL_ColorRange of `cspace`.
867867+ *
868868+ * \threadsafety It is safe to call this macro from any thread.
869869+ *
870870+ * \since This macro is available since SDL 3.1.3.
871871+ */
872872+#define SDL_COLORSPACERANGE(cspace) (SDL_ColorRange)(((cspace) >> 24) & 0x0F)
873873+874874+/**
875875+ * A macro to retrieve the chroma sample location of an SDL_Colorspace.
876876+ *
877877+ * \param cspace an SDL_Colorspace to check.
878878+ * \returns the SDL_ChromaLocation of `cspace`.
879879+ *
880880+ * \threadsafety It is safe to call this macro from any thread.
881881+ *
882882+ * \since This macro is available since SDL 3.1.3.
883883+ */
884884+#define SDL_COLORSPACECHROMA(cspace) (SDL_ChromaLocation)(((cspace) >> 20) & 0x0F)
885885+886886+/**
887887+ * A macro to retrieve the primaries of an SDL_Colorspace.
888888+ *
889889+ * \param cspace an SDL_Colorspace to check.
890890+ * \returns the SDL_ColorPrimaries of `cspace`.
891891+ *
892892+ * \threadsafety It is safe to call this macro from any thread.
893893+ *
894894+ * \since This macro is available since SDL 3.1.3.
895895+ */
896896+#define SDL_COLORSPACEPRIMARIES(cspace) (SDL_ColorPrimaries)(((cspace) >> 10) & 0x1F)
897897+898898+/**
899899+ * A macro to retrieve the transfer characteristics of an SDL_Colorspace.
900900+ *
901901+ * \param cspace an SDL_Colorspace to check.
902902+ * \returns the SDL_TransferCharacteristics of `cspace`.
903903+ *
904904+ * \threadsafety It is safe to call this macro from any thread.
905905+ *
906906+ * \since This macro is available since SDL 3.1.3.
907907+ */
908908+#define SDL_COLORSPACETRANSFER(cspace) (SDL_TransferCharacteristics)(((cspace) >> 5) & 0x1F)
909909+910910+/**
911911+ * A macro to retrieve the matrix coefficients of an SDL_Colorspace.
912912+ *
913913+ * \param cspace an SDL_Colorspace to check.
914914+ * \returns the SDL_MatrixCoefficients of `cspace`.
915915+ *
916916+ * \threadsafety It is safe to call this macro from any thread.
917917+ *
918918+ * \since This macro is available since SDL 3.1.3.
919919+ */
920920+#define SDL_COLORSPACEMATRIX(cspace) (SDL_MatrixCoefficients)((cspace) & 0x1F)
921921+922922+/**
923923+ * A macro to determine if an SDL_Colorspace uses BT601 (or BT470BG) matrix coefficients.
924924+ *
925925+ * Note that this macro double-evaluates its parameter, so do not use
926926+ * expressions with side-effects here.
927927+ *
928928+ * \param cspace an SDL_Colorspace to check.
929929+ * \returns true if BT601 or BT470BG, false otherwise.
930930+ *
931931+ * \threadsafety It is safe to call this macro from any thread.
932932+ *
933933+ * \since This macro is available since SDL 3.1.3.
934934+ */
935935+#define SDL_ISCOLORSPACE_MATRIX_BT601(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT470BG)
936936+937937+/**
938938+ * A macro to determine if an SDL_Colorspace uses BT709 matrix coefficients.
939939+ *
940940+ * \param cspace an SDL_Colorspace to check.
941941+ * \returns true if BT709, false otherwise.
942942+ *
943943+ * \threadsafety It is safe to call this macro from any thread.
944944+ *
945945+ * \since This macro is available since SDL 3.1.3.
946946+ */
947947+#define SDL_ISCOLORSPACE_MATRIX_BT709(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT709)
948948+949949+/**
950950+ * A macro to determine if an SDL_Colorspace uses BT2020_NCL matrix coefficients.
951951+ *
952952+ * \param cspace an SDL_Colorspace to check.
953953+ * \returns true if BT709, false otherwise.
954954+ *
955955+ * \threadsafety It is safe to call this macro from any thread.
956956+ *
957957+ * \since This macro is available since SDL 3.1.3.
958958+ */
959959+#define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
604960605605-#define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG)
606606-#define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709)
607607-#define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
608608-#define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL)
609609-#define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL)
961961+/**
962962+ * A macro to determine if an SDL_Colorspace has a limited range.
963963+ *
964964+ * \param cspace an SDL_Colorspace to check.
965965+ * \returns true if limited range, false otherwise.
966966+ *
967967+ * \threadsafety It is safe to call this macro from any thread.
968968+ *
969969+ * \since This macro is available since SDL 3.1.3.
970970+ */
971971+#define SDL_ISCOLORSPACE_LIMITED_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) != SDL_COLOR_RANGE_FULL)
972972+973973+/**
974974+ * A macro to determine if an SDL_Colorspace has a full range.
975975+ *
976976+ * \param cspace an SDL_Colorspace to check.
977977+ * \returns true if full range, false otherwise.
978978+ *
979979+ * \threadsafety It is safe to call this macro from any thread.
980980+ *
981981+ * \since This macro is available since SDL 3.1.3.
982982+ */
983983+#define SDL_ISCOLORSPACE_FULL_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) == SDL_COLOR_RANGE_FULL)
610984611985/**
612986 * Colorspace definitions.
+9-1
include/SDL3/SDL_platform_defines.h
···357357 #define WINAPI_FAMILY_WINRT 0
358358#endif /* HAVE_WINAPIFAMILY_H */
359359360360-#if HAVE_WINAPIFAMILY_H && HAVE_WINAPIFAMILY_H
360360+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
361361+/**
362362+ * A preprocessor macro that defined to 1 if compiling for Windows Phone.
363363+ *
364364+ * \since This macro is available since SDL 3.1.3.
365365+ */
366366+#define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
367367+368368+#elif HAVE_WINAPIFAMILY_H && HAVE_WINAPIFAMILY_H
361369 #define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
362370#else
363371 #define SDL_WINAPI_FAMILY_PHONE 0
+7
include/SDL3/SDL_process.h
···5454extern "C" {
5555#endif
56565757+/**
5858+ * An opaque handle representing a system process.
5959+ *
6060+ * \since This datatype is available since SDL 3.1.3.
6161+ *
6262+ * \sa SDL_CreateProcess
6363+ */
5764typedef struct SDL_Process SDL_Process;
58655966/**
+655-19
include/SDL3/SDL_stdinc.h
···753753#endif
754754755755/* Annotations to help code analysis tools */
756756-#ifdef SDL_DISABLE_ANALYZE_MACROS
756756+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
757757+758758+/**
759759+ * Macro that annotates function params with input buffer size.
760760+ *
761761+ * If we were to annotate `memcpy`:
762762+ *
763763+ * ```c
764764+ * void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
765765+ * ```
766766+ *
767767+ * This notes that `src` should be `len` bytes in size and is only read by the
768768+ * function. The compiler or other analysis tools can warn when this doesn't
769769+ * appear to be the case.
770770+ *
771771+ * On compilers without this annotation mechanism, this is defined to nothing.
772772+ *
773773+ * \since This macro is available since SDL 3.1.3.
774774+ */
775775+#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
776776+777777+/**
778778+ * Macro that annotates function params with input/output string buffer size.
779779+ *
780780+ * If we were to annotate `strlcat`:
781781+ *
782782+ * ```c
783783+ * size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
784784+ * ```
785785+ *
786786+ * This notes that `dst` is a null-terminated C string, should be `maxlen`
787787+ * bytes in size, and is both read from and written to by the function. The
788788+ * compiler or other analysis tools can warn when this doesn't appear to be
789789+ * the case.
790790+ *
791791+ * On compilers without this annotation mechanism, this is defined to nothing.
792792+ *
793793+ * \since This macro is available since SDL 3.1.3.
794794+ */
795795+#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
796796+797797+/**
798798+ * Macro that annotates function params with output string buffer size.
799799+ *
800800+ * If we were to annotate `snprintf`:
801801+ *
802802+ * ```c
803803+ * int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...);
804804+ * ```
805805+ *
806806+ * This notes that `text` is a null-terminated C string, should be `maxlen`
807807+ * bytes in size, and is only written to by the function. The compiler or
808808+ * other analysis tools can warn when this doesn't appear to be the case.
809809+ *
810810+ * On compilers without this annotation mechanism, this is defined to nothing.
811811+ *
812812+ * \since This macro is available since SDL 3.1.3.
813813+ */
814814+#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
815815+816816+/**
817817+ * Macro that annotates function params with output buffer size.
818818+ *
819819+ * If we were to annotate `wcsncpy`:
820820+ *
821821+ * ```c
822822+ * char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize);
823823+ * ```
824824+ *
825825+ * This notes that `dst` should have a capacity of `bufsize` wchar_t in size,
826826+ * and is only written to by the function. The compiler or other analysis
827827+ * tools can warn when this doesn't appear to be the case.
828828+ *
829829+ * This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for bytes.
830830+ *
831831+ * On compilers without this annotation mechanism, this is defined to nothing.
832832+ *
833833+ * \since This macro is available since SDL 3.1.3.
834834+ */
835835+#define SDL_OUT_CAP(x) _Out_cap_(x)
836836+837837+/**
838838+ * Macro that annotates function params with output buffer size.
839839+ *
840840+ * If we were to annotate `memcpy`:
841841+ *
842842+ * ```c
843843+ * void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize);
844844+ * ```
845845+ *
846846+ * This notes that `dst` should have a capacity of `bufsize` bytes in size,
847847+ * and is only written to by the function. The compiler or other analysis
848848+ * tools can warn when this doesn't appear to be the case.
849849+ *
850850+ * On compilers without this annotation mechanism, this is defined to nothing.
851851+ *
852852+ * \since This macro is available since SDL 3.1.3.
853853+ */
854854+#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
855855+856856+/**
857857+ * Macro that annotates function params with output buffer string size.
858858+ *
859859+ * If we were to annotate `strcpy`:
860860+ *
861861+ * ```c
862862+ * char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize);
863863+ * ```
864864+ *
865865+ * This notes that `dst` should have a capacity of `bufsize` bytes in size,
866866+ * and a zero-terminated string is written to it by the function. The compiler
867867+ * or other analysis tools can warn when this doesn't appear to be the case.
868868+ *
869869+ * On compilers without this annotation mechanism, this is defined to nothing.
870870+ *
871871+ * \since This macro is available since SDL 3.1.3.
872872+ */
873873+#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
874874+875875+/**
876876+ * Macro that annotates function params as printf-style format strings.
877877+ *
878878+ * If we were to annotate `fprintf`:
879879+ *
880880+ * ```c
881881+ * int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
882882+ * ```
883883+ *
884884+ * This notes that `fmt` should be a printf-style format string. The compiler
885885+ * or other analysis tools can warn when this doesn't appear to be the case.
886886+ *
887887+ * On compilers without this annotation mechanism, this is defined to nothing.
888888+ *
889889+ * \since This macro is available since SDL 3.1.3.
890890+ */
891891+#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
892892+893893+/**
894894+ * Macro that annotates function params as scanf-style format strings.
895895+ *
896896+ * If we were to annotate `fscanf`:
897897+ *
898898+ * ```c
899899+ * int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...);
900900+ * ```
901901+ *
902902+ * This notes that `fmt` should be a scanf-style format string. The compiler
903903+ * or other analysis tools can warn when this doesn't appear to be the case.
904904+ *
905905+ * On compilers without this annotation mechanism, this is defined to nothing.
906906+ *
907907+ * \since This macro is available since SDL 3.1.3.
908908+ */
909909+#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
910910+911911+/**
912912+ * Macro that annotates a vararg function that operates like printf.
913913+ *
914914+ * If we were to annotate `fprintf`:
915915+ *
916916+ * ```c
917917+ * int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
918918+ * ```
919919+ *
920920+ * This notes that the second parameter should be a printf-style format string, followed by `...`.
921921+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
922922+ *
923923+ * On compilers without this annotation mechanism, this is defined to nothing.
924924+ *
925925+ * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which between them
926926+ * will cover at least Visual Studio, GCC, and Clang.
927927+ *
928928+ * \since This macro is available since SDL 3.1.3.
929929+ */
930930+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
931931+932932+/**
933933+ * Macro that annotates a va_list function that operates like printf.
934934+ *
935935+ * If we were to annotate `vfprintf`:
936936+ *
937937+ * ```c
938938+ * int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
939939+ * ```
940940+ *
941941+ * This notes that the second parameter should be a printf-style format string, followed by a va_list.
942942+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
943943+ *
944944+ * On compilers without this annotation mechanism, this is defined to nothing.
945945+ *
946946+ * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which between them
947947+ * will cover at least Visual Studio, GCC, and Clang.
948948+ *
949949+ * \since This macro is available since SDL 3.1.3.
950950+ */
951951+#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
952952+953953+/**
954954+ * Macro that annotates a vararg function that operates like scanf.
955955+ *
956956+ * If we were to annotate `fscanf`:
957957+ *
958958+ * ```c
959959+ * int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2);
960960+ * ```
961961+ *
962962+ * This notes that the second parameter should be a scanf-style format string, followed by `...`.
963963+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
964964+ *
965965+ * On compilers without this annotation mechanism, this is defined to nothing.
966966+ *
967967+ * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which between them
968968+ * will cover at least Visual Studio, GCC, and Clang.
969969+ *
970970+ * \since This macro is available since SDL 3.1.3.
971971+ */
972972+#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
973973+974974+/**
975975+ * Macro that annotates a va_list function that operates like scanf.
976976+ *
977977+ * If we were to annotate `vfscanf`:
978978+ *
979979+ * ```c
980980+ * int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
981981+ * ```
982982+ *
983983+ * This notes that the second parameter should be a scanf-style format string, followed by a va_list.
984984+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
985985+ *
986986+ * On compilers without this annotation mechanism, this is defined to nothing.
987987+ *
988988+ * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which between them
989989+ * will cover at least Visual Studio, GCC, and Clang.
990990+ *
991991+ * \since This macro is available since SDL 3.1.3.
992992+ */
993993+#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
994994+995995+/**
996996+ * Macro that annotates a vararg function that operates like wprintf.
997997+ *
998998+ * If we were to annotate `fwprintf`:
999999+ *
10001000+ * ```c
10011001+ * int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2);
10021002+ * ```
10031003+ *
10041004+ * This notes that the second parameter should be a wprintf-style format wide string, followed by `...`.
10051005+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
10061006+ *
10071007+ * On compilers without this annotation mechanism, this is defined to nothing.
10081008+ *
10091009+ * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which between them
10101010+ * will cover at least Visual Studio, GCC, and Clang.
10111011+ *
10121012+ * \since This macro is available since SDL 3.1.3.
10131013+ */
10141014+#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
10151015+10161016+/**
10171017+ * Macro that annotates a va_list function that operates like wprintf.
10181018+ *
10191019+ * If we were to annotate `vfwprintf`:
10201020+ *
10211021+ * ```c
10221022+ * int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2);
10231023+ * ```
10241024+ *
10251025+ * This notes that the second parameter should be a wprintf-style format wide string, followed by a va_list.
10261026+ * The compiler or other analysis tools can warn when this doesn't appear to be the case.
10271027+ *
10281028+ * On compilers without this annotation mechanism, this is defined to nothing.
10291029+ *
10301030+ * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which between them
10311031+ * will cover at least Visual Studio, GCC, and Clang.
10321032+ *
10331033+ * \since This macro is available since SDL 3.1.3.
10341034+ */
10351035+#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
10361036+10371037+#elif defined(SDL_DISABLE_ANALYZE_MACROS)
7571038#define SDL_IN_BYTECAP(x)
7581039#define SDL_INOUT_Z_CAP(x)
7591040#define SDL_OUT_Z_CAP(x)
···22952576#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
229625772297257825792579+/**
25802580+ * Compare two buffers of memory.
25812581+ *
25822582+ * \param s1 the first buffer to compare. NULL is not permitted!
25832583+ * \param s2 the second buffer to compare. NULL is not permitted!
25842584+ * \param len the number of bytes to compare between the buffers.
25852585+ * \returns less than zero if s1 is "less than" s2, greater than zero if
25862586+ * s1 is "greater than" s2, and zero if the buffers match
25872587+ * exactly for `len` bytes.
25882588+ *
25892589+ * \threadsafety It is safe to call this function from any thread.
25902590+ *
25912591+ * \since This function is available since SDL 3.1.3.
25922592+ */
22982593extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
2299259425952595+/**
25962596+ * This works exactly like wcslen() but doesn't require access to a C runtime.
25972597+ *
25982598+ * Counts the number of wchar_t values in `wstr`, excluding the null
25992599+ * terminator.
26002600+ *
26012601+ * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
26022602+ * this counts wchar_t values in a string, even if the string's encoding is of
26032603+ * variable width, like UTF-16.
26042604+ *
26052605+ * Also be aware that wchar_t is different sizes on different platforms (4
26062606+ * bytes on Linux, 2 on Windows, etc).
26072607+ *
26082608+ * \param wstr The null-terminated wide string to read. Must not be NULL.
26092609+ * \returns the length (in wchar_t values, excluding the null terminator) of `wstr`.
26102610+ *
26112611+ * \threadsafety It is safe to call this function from any thread.
26122612+ *
26132613+ * \since This function is available since SDL 3.1.3.
26142614+ *
26152615+ * \sa SDL_wcsnlen
26162616+ * \sa SDL_utf8strlen
26172617+ * \sa SDL_utf8strnlen
26182618+ */
23002619extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
26202620+26212621+/**
26222622+ * This works exactly like wcsnlen() but doesn't require access to a C
26232623+ * runtime.
26242624+ *
26252625+ * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
26262626+ * null terminator.
26272627+ *
26282628+ * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
26292629+ * this counts wchar_t values in a string, even if the string's encoding is of
26302630+ * variable width, like UTF-16.
26312631+ *
26322632+ * Also be aware that wchar_t is different sizes on different platforms (4
26332633+ * bytes on Linux, 2 on Windows, etc).
26342634+ *
26352635+ * Also, `maxlen` is a count of wide characters, not bytes!
26362636+ *
26372637+ * \param wstr The null-terminated wide string to read. Must not be NULL.
26382638+ * \param maxlen The maximum amount of wide characters to count.
26392639+ * \returns the length (in wide characters, excluding the null terminator) of
26402640+ * `wstr` but never more than `maxlen`.
26412641+ *
26422642+ * \threadsafety It is safe to call this function from any thread.
26432643+ *
26442644+ * \since This function is available since SDL 3.1.3.
26452645+ *
26462646+ * \sa SDL_wcslen
26472647+ * \sa SDL_utf8strlen
26482648+ * \sa SDL_utf8strnlen
26492649+ */
23012650extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
2302265123032652/**
···23162665 * \param src The null-terminated wide string to copy. Must not be NULL, and
23172666 * must not overlap with `dst`.
23182667 * \param maxlen The length (in wide characters) of the destination buffer.
23192319- * \returns The length (in wide characters, excluding the null terminator) of
26682668+ * \returns the length (in wide characters, excluding the null terminator) of
23202669 * `src`.
23212670 *
23222671 * \threadsafety It is safe to call this function from any thread.
···23452694 * \param src The second null-terminated wide string. Must not be NULL, and
23462695 * must not overlap with `dst`.
23472696 * \param maxlen The length (in wide characters) of the destination buffer.
23482348- * \returns The length (in wide characters, excluding the null terminator) of
26972697+ * \returns the length (in wide characters, excluding the null terminator) of
23492698 * the string in `dst` plus the length of `src`.
23502699 *
23512700 * \threadsafety It is safe to call this function from any thread.
···23562705 */
23572706extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
2358270727082708+/**
27092709+ * Allocate a copy of a wide string.
27102710+ *
27112711+ * This allocates enough space for a null-terminated copy of `wstr`, using
27122712+ * SDL_malloc, and then makes a copy of the string into this space.
27132713+ *
27142714+ * The returned string is owned by the caller, and should be passed to
27152715+ * SDL_free when no longer needed.
27162716+ *
27172717+ * \param wstr the string to copy.
27182718+ * \returns a pointer to the newly-allocated wide string.
27192719+ *
27202720+ * \threadsafety It is safe to call this function from any thread.
27212721+ *
27222722+ * \since This function is available since SDL 3.1.3.
27232723+ */
23592724extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
27252725+27262726+/**
27272727+ * Search a wide string for the first instance of a specific substring.
27282728+ *
27292729+ * The search ends once it finds the requested substring, or a null
27302730+ * terminator byte to end the string.
27312731+ *
27322732+ * Note that this looks for strings of _wide characters_, not _codepoints_, so
27332733+ * it's legal to search for malformed and incomplete UTF-16 sequences.
27342734+ *
27352735+ * \param haystack the wide string to search. Must not be NULL.
27362736+ * \param needle the wide string to search for. Must not be NULL.
27372737+ * \returns a pointer to the first instance of `needle` in the string, or NULL if not found.
27382738+ *
27392739+ * \threadsafety It is safe to call this function from any thread.
27402740+ *
27412741+ * \since This function is available since SDL 3.1.3.
27422742+ */
23602743extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
27442744+27452745+/**
27462746+ * Search a wide string, up to n wide chars, for the first instance of a specific substring.
27472747+ *
27482748+ * The search ends once it finds the requested substring, or a null
27492749+ * terminator value to end the string, or `maxlen` wide character have been
27502750+ * examined. It is possible to use this function on a wide string without a
27512751+ * null terminator.
27522752+ *
27532753+ * Note that this looks for strings of _wide characters_, not _codepoints_, so
27542754+ * it's legal to search for malformed and incomplete UTF-16 sequences.
27552755+ *
27562756+ * \param haystack the wide string to search. Must not be NULL.
27572757+ * \param needle the wide string to search for. Must not be NULL.
27582758+ * \param maxlen the maximum number of wide characters to search in `haystack`.
27592759+ * \returns a pointer to the first instance of `needle` in the string, or NULL if not found.
27602760+ *
27612761+ * \threadsafety It is safe to call this function from any thread.
27622762+ *
27632763+ * \since This function is available since SDL 3.1.3.
27642764+ */
23612765extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
2362276623632767/**
···24992903 * to 36 inclusive. If 0, the base will be inferred from the
25002904 * number's prefix (0x for hexadecimal, 0 for octal, decimal
25012905 * otherwise).
25022502- * \returns The parsed `long`, or 0 if no number could be parsed.
29062906+ * \returns the parsed `long`, or 0 if no number could be parsed.
25032907 *
25042908 * \threadsafety It is safe to call this function from any thread.
25052909 *
···25172921 * If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
25182922 *
25192923 * \param str The null-terminated string to read. Must not be NULL.
25202520- * \returns The length (in bytes, excluding the null terminator) of `src`.
29242924+ * \returns the length (in bytes, excluding the null terminator) of `src`.
25212925 *
25222926 * \threadsafety It is safe to call this function from any thread.
25232927 *
···25402944 *
25412945 * \param str The null-terminated string to read. Must not be NULL.
25422946 * \param maxlen The maximum amount of bytes to count.
25432543- * \returns The length (in bytes, excluding the null terminator) of `src` but
29472947+ * \returns the length (in bytes, excluding the null terminator) of `src` but
25442948 * never more than `maxlen`.
25452949 *
25462950 * \threadsafety It is safe to call this function from any thread.
···25702974 * \param src The null-terminated string to copy. Must not be NULL, and must
25712975 * not overlap with `dst`.
25722976 * \param maxlen The length (in characters) of the destination buffer.
25732573- * \returns The length (in characters, excluding the null terminator) of
29772977+ * \returns the length (in characters, excluding the null terminator) of
25742978 * `src`.
25752979 *
25762980 * \threadsafety It is safe to call this function from any thread.
···26003004 * must not overlap with `dst`.
26013005 * \param dst_bytes The length (in bytes) of the destination buffer. Must not
26023006 * be 0.
26032603- * \returns The number of bytes written, excluding the null terminator.
30073007+ * \returns the number of bytes written, excluding the null terminator.
26043008 *
26053009 * \threadsafety It is safe to call this function from any thread.
26063010 *
···26273031 * \param src The second null-terminated string. Must not be NULL, and must
26283032 * not overlap with `dst`.
26293033 * \param maxlen The length (in characters) of the destination buffer.
26302630- * \returns The length (in characters, excluding the null terminator) of the
30343034+ * \returns the length (in characters, excluding the null terminator) of the
26313035 * string in `dst` plus the length of `src`.
26323036 *
26333037 * \threadsafety It is safe to call this function from any thread.
···26383042 */
26393043extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
2640304430453045+/**
30463046+ * Allocate a copy of a string.
30473047+ *
30483048+ * This allocates enough space for a null-terminated copy of `str`, using
30493049+ * SDL_malloc, and then makes a copy of the string into this space.
30503050+ *
30513051+ * The returned string is owned by the caller, and should be passed to
30523052+ * SDL_free when no longer needed.
30533053+ *
30543054+ * \param str the string to copy.
30553055+ * \returns a pointer to the newly-allocated string.
30563056+ *
30573057+ * \threadsafety It is safe to call this function from any thread.
30583058+ *
30593059+ * \since This function is available since SDL 3.1.3.
30603060+ */
26413061extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
30623062+30633063+/**
30643064+ * Allocate a copy of a string, up to n characters.
30653065+ *
30663066+ * This allocates enough space for a null-terminated copy of `str`, up to
30673067+ * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string
30683068+ * into this space.
30693069+ *
30703070+ * If the string is longer than `maxlen` bytes, the returned string will
30713071+ * be `maxlen` bytes long, plus a null-terminator character that isn't
30723072+ * included in the count.
30733073+ *
30743074+ * The returned string is owned by the caller, and should be passed to
30753075+ * SDL_free when no longer needed.
30763076+ *
30773077+ * \param str the string to copy.
30783078+ * \param maxlen the maximum length of the copied string, not counting
30793079+ * the null-terminator character.
30803080+ * \returns a pointer to the newly-allocated string.
30813081+ *
30823082+ * \threadsafety It is safe to call this function from any thread.
30833083+ *
30843084+ * \since This function is available since SDL 3.1.3.
30853085+ */
26423086extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
30873087+30883088+/**
30893089+ * Reverse a string's contents.
30903090+ *
30913091+ * This reverses a null-terminated string in-place. Only the content of the
30923092+ * string is reversed; the null-terminator character remains at the end of the
30933093+ * reversed string.
30943094+ *
30953095+ * **WARNING**: This function reverses the _bytes_ of the string, not the
30963096+ * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
30973097+ * will ruin the string data. You should only use this function on strings
30983098+ * that are completely comprised of low ASCII characters.
30993099+ *
31003100+ * \param str the string to reverse.
31013101+ * \returns `str`.
31023102+ *
31033103+ * \threadsafety It is safe to call this function from any thread.
31043104+ *
31053105+ * \since This function is available since SDL 3.1.3.
31063106+ */
26433107extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
2644310826453109/**
···30593523 * `(int)SDL_strtol(str, NULL, 10)`.
30603524 *
30613525 * \param str The null-terminated string to read. Must not be NULL.
30623062- * \returns The parsed `int`.
35263526+ * \returns the parsed `int`.
30633527 *
30643528 * \threadsafety It is safe to call this function from any thread.
30653529 *
···30823546 * NULL)`.
30833547 *
30843548 * \param str The null-terminated string to read. Must not be NULL.
30853085- * \returns The parsed `double`.
35493549+ * \returns the parsed `double`.
30863550 *
30873551 * \threadsafety It is safe to call this function from any thread.
30883552 *
···31143578 * to 36 inclusive. If 0, the base will be inferred from the
31153579 * number's prefix (0x for hexadecimal, 0 for octal, decimal
31163580 * otherwise).
31173117- * \returns The parsed `long`, or 0 if no number could be parsed.
35813581+ * \returns the parsed `long`, or 0 if no number could be parsed.
31183582 *
31193583 * \threadsafety It is safe to call this function from any thread.
31203584 *
···31483612 * to 36 inclusive. If 0, the base will be inferred from the
31493613 * number's prefix (0x for hexadecimal, 0 for octal, decimal
31503614 * otherwise).
31513151- * \returns The parsed `unsigned long`, or 0 if no number could be parsed.
36153615+ * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
31523616 *
31533617 * \threadsafety It is safe to call this function from any thread.
31543618 *
···31813645 * to 36 inclusive. If 0, the base will be inferred from the
31823646 * number's prefix (0x for hexadecimal, 0 for octal, decimal
31833647 * otherwise).
31843184- * \returns The parsed `long long`, or 0 if no number could be parsed.
36483648+ * \returns the parsed `long long`, or 0 if no number could be parsed.
31853649 *
31863650 * \threadsafety It is safe to call this function from any thread.
31873651 *
···32143678 * to 36 inclusive. If 0, the base will be inferred from the
32153679 * number's prefix (0x for hexadecimal, 0 for octal, decimal
32163680 * otherwise).
32173217- * \returns The parsed `unsigned long long`, or 0 if no number could be
36813681+ * \returns the parsed `unsigned long long`, or 0 if no number could be
32183682 * parsed.
32193683 *
32203684 * \threadsafety It is safe to call this function from any thread.
···32413705 * - Whether or not INF and NAN can be parsed is unspecified.
32423706 * - The precision of the result is unspecified.
32433707 *
32443244- * \param str The null-terminated string to read. Must not be NULL.
32453245- * \param endp If not NULL, the address of the first invalid character (i.e.
37083708+ * \param str the null-terminated string to read. Must not be NULL.
37093709+ * \param endp if not NULL, the address of the first invalid character (i.e.
32463710 * the next character after the parsed number) will be written to
32473711 * this pointer.
32483248- * \returns The parsed `double`, or 0 if no number could be parsed.
37123712+ * \returns the parsed `double`, or 0 if no number could be parsed.
32493713 *
32503714 * \threadsafety It is safe to call this function from any thread.
32513715 *
···35163980 */
35173981extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
3518398239833983+/**
39843984+ * This works exactly like sscanf() but doesn't require access to a C runtime.
39853985+ *
39863986+ * Scan a string, matching a format string, converting each '%' item and
39873987+ * storing it to pointers provided through variable arguments.
39883988+ *
39893989+ * \param text the string to scan. Must not be NULL.
39903990+ * \param fmt a printf-style format string. Must not be NULL.
39913991+ * \param ... a list of pointers to values to be filled in with scanned items.
39923992+ * \returns the number of items that matched the format string.
39933993+ *
39943994+ * \threadsafety It is safe to call this function from any thread.
39953995+ *
39963996+ * \since This function is available since SDL 3.1.3.
39973997+ */
39983998+extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
3519399935203520-extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
40004000+/**
40014001+ * This works exactly like vsscanf() but doesn't require access to a C runtime.
40024002+ *
40034003+ * Functions identically to SDL_sscanf(), except it takes a `va_list`
40044004+ * instead of using `...` variable arguments.
40054005+ *
40064006+ * \param text the string to scan. Must not be NULL.
40074007+ * \param fmt a printf-style format string. Must not be NULL.
40084008+ * \param ap a `va_list` of pointers to values to be filled in with scanned items.
40094009+ * \returns the number of items that matched the format string.
40104010+ *
40114011+ * \threadsafety It is safe to call this function from any thread.
40124012+ *
40134013+ * \since This function is available since SDL 3.1.3.
40144014+ */
35214015extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
40164016+40174017+/**
40184018+ * This works exactly like snprintf() but doesn't require access to a C runtime.
40194019+ *
40204020+ * Format a string of up to `maxlen`-1 bytes, converting each '%' item with
40214021+ * values provided through variable arguments.
40224022+ *
40234023+ * While some C runtimes differ on how to deal with too-large strings,
40244024+ * this function null-terminates the output, by treating the null-terminator
40254025+ * as part of the `maxlen` count. Note that if `maxlen` is zero, however, no
40264026+ * bytes will be written at all.
40274027+ *
40284028+ * This function returns the number of _bytes_ (not _characters_) that should
40294029+ * be written, excluding the null-terminator character. If this returns a
40304030+ * number >= `maxlen`, it means the output string was truncated. A negative
40314031+ * return value means an error occurred.
40324032+ *
40334033+ * Referencing the output string's pointer with a format item is undefined
40344034+ * behavior.
40354035+ *
40364036+ * \param text the buffer to write the string into. Must not be NULL.
40374037+ * \param maxlen the maximum bytes to write, including the null-terminator.
40384038+ * \param fmt a printf-style format string. Must not be NULL.
40394039+ * \param ... a list of values to be used with the format string.
40404040+ * \returns the number of bytes that should be written, not counting the
40414041+ * null-terminator char, or a negative value on error.
40424042+ *
40434043+ * \threadsafety It is safe to call this function from any thread.
40444044+ *
40454045+ * \since This function is available since SDL 3.1.3.
40464046+ */
35224047extern SDL_DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
40484048+40494049+/**
40504050+ * This works exactly like swprintf() but doesn't require access to a C runtime.
40514051+ *
40524052+ * Format a wide string of up to `maxlen`-1 wchar_t values, converting each '%'
40534053+ * item with values provided through variable arguments.
40544054+ *
40554055+ * While some C runtimes differ on how to deal with too-large strings,
40564056+ * this function null-terminates the output, by treating the null-terminator
40574057+ * as part of the `maxlen` count. Note that if `maxlen` is zero, however, no
40584058+ * wide characters will be written at all.
40594059+ *
40604060+ * This function returns the number of _wide characters_ (not _codepoints_)
40614061+ * that should be written, excluding the null-terminator character. If this
40624062+ * returns a number >= `maxlen`, it means the output string was truncated. A
40634063+ * negative return value means an error occurred.
40644064+ *
40654065+ * Referencing the output string's pointer with a format item is undefined
40664066+ * behavior.
40674067+ *
40684068+ * \param text the buffer to write the wide string into. Must not be NULL.
40694069+ * \param maxlen the maximum wchar_t values to write, including the null-terminator.
40704070+ * \param fmt a printf-style format string. Must not be NULL.
40714071+ * \param ... a list of values to be used with the format string.
40724072+ * \returns the number of wide characters that should be written, not counting
40734073+ * the null-terminator char, or a negative value on error.
40744074+ *
40754075+ * \threadsafety It is safe to call this function from any thread.
40764076+ *
40774077+ * \since This function is available since SDL 3.1.3.
40784078+ */
35234079extern SDL_DECLSPEC int SDLCALL SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(3);
40804080+40814081+/**
40824082+ * This works exactly like vsnprintf() but doesn't require access to a C runtime.
40834083+ *
40844084+ * Functions identically to SDL_snprintf(), except it takes a `va_list`
40854085+ * instead of using `...` variable arguments.
40864086+ *
40874087+ * \param text the buffer to write the string into. Must not be NULL.
40884088+ * \param maxlen the maximum bytes to write, including the null-terminator.
40894089+ * \param fmt a printf-style format string. Must not be NULL.
40904090+ * \param ap a `va_list` values to be used with the format string.
40914091+ * \returns the number of bytes that should be written, not counting the
40924092+ * null-terminator char, or a negative value on error.
40934093+ *
40944094+ * \threadsafety It is safe to call this function from any thread.
40954095+ *
40964096+ * \since This function is available since SDL 3.1.3.
40974097+ */
35244098extern SDL_DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
40994099+41004100+/**
41014101+ * This works exactly like vswprintf() but doesn't require access to a C runtime.
41024102+ *
41034103+ * Functions identically to SDL_swprintf(), except it takes a `va_list`
41044104+ * instead of using `...` variable arguments.
41054105+ *
41064106+ * \param text the buffer to write the string into. Must not be NULL.
41074107+ * \param maxlen the maximum wide characters to write, including the null-terminator.
41084108+ * \param fmt a printf-style format wide string. Must not be NULL.
41094109+ * \param ap a `va_list` values to be used with the format string.
41104110+ * \returns the number of wide characters that should be written, not counting
41114111+ * the null-terminator char, or a negative value on error.
41124112+ *
41134113+ * \threadsafety It is safe to call this function from any thread.
41144114+ *
41154115+ * \since This function is available since SDL 3.1.3.
41164116+ */
35254117extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3);
41184118+41194119+/**
41204120+ * This works exactly like asprintf() but doesn't require access to a C runtime.
41214121+ *
41224122+ * Functions identically to SDL_snprintf(), except it allocates a buffer large
41234123+ * enough to hold the output string on behalf of the caller.
41244124+ *
41254125+ * On success, this function returns the number of bytes (not characters)
41264126+ * comprising the output string, not counting the null-terminator character,
41274127+ * and sets `*strp` to the newly-allocated string.
41284128+ *
41294129+ * On error, this function returns a negative number, and the value of `*strp`
41304130+ * is undefined.
41314131+ *
41324132+ * The returned string is owned by the caller, and should be passed to
41334133+ * SDL_free when no longer needed.
41344134+ *
41354135+ * \param strp on output, is set to the new string. Must not be NULL.
41364136+ * \param fmt a printf-style format string. Must not be NULL.
41374137+ * \param ... a list of values to be used with the format string.
41384138+ * \returns the number of bytes in the newly-allocated string, not counting
41394139+ * the null-terminator char, or a negative value on error.
41404140+ *
41414141+ * \threadsafety It is safe to call this function from any thread.
41424142+ *
41434143+ * \since This function is available since SDL 3.1.3.
41444144+ */
35264145extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
41464146+41474147+/**
41484148+ * This works exactly like vasprintf() but doesn't require access to a C runtime.
41494149+ *
41504150+ * Functions identically to SDL_asprintf(), except it takes a `va_list`
41514151+ * instead of using `...` variable arguments.
41524152+ *
41534153+ * \param strp on output, is set to the new string. Must not be NULL.
41544154+ * \param fmt a printf-style format string. Must not be NULL.
41554155+ * \param ap a `va_list` values to be used with the format string.
41564156+ * \returns the number of bytes in the newly-allocated string, not counting
41574157+ * the null-terminator char, or a negative value on error.
41584158+ *
41594159+ * \threadsafety It is safe to call this function from any thread.
41604160+ *
41614161+ * \since This function is available since SDL 3.1.3.
41624162+ */
35274163extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
3528416435294165/**
+40-1
include/SDL3/SDL_system.h
···129129 * Platform specific functions for UNIX
130130 */
131131132132+/* this is defined in Xlib's headers, just need a simple declaration here. */
132133typedef union _XEvent XEvent;
134134+135135+/**
136136+ * A callback to be used with SDL_SetX11EventHook.
137137+ *
138138+ * This callback may modify the event, and should return true if the event
139139+ * should continue to be processed, or false to prevent further processing.
140140+ *
141141+ * As this is processing an event directly from the X11 event loop, this
142142+ * callback should do the minimum required work and return quickly.
143143+ *
144144+ * \param userdata the app-defined pointer provided to SDL_SetX11EventHook.
145145+ * \param xevent a pointer to an Xlib XEvent union to process.
146146+ * \returns true to let event continue on, false to drop it.
147147+ *
148148+ * \threadsafety This may only be called (by SDL) from the thread handling the
149149+ * X11 event loop.
150150+ *
151151+ * \since This datatype is available since SDL 3.1.3.
152152+ *
153153+ * \sa SDL_SetX11EventHook
154154+ */
133155typedef bool (SDLCALL *SDL_X11EventHook)(void *userdata, XEvent *xevent);
134156135157/**
···380402 * \since This macro is available since SDL 3.1.3.
381403 */
382404#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
405405+406406+/**
407407+ * See the official Android developer guide for more information:
408408+ * http://developer.android.com/guide/topics/data/data-storage.html
409409+ *
410410+ * \since This macro is available since SDL 3.1.3.
411411+ */
383412#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
384413385414/**
···468497 */
469498extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidCachePath(void);
470499471471-500500+/**
501501+ * Callback that presents a response from a SDL_RequestAndroidPermission call.
502502+ *
503503+ * \param userdata an app-controlled pointer that is passed to the callback.
504504+ * \param permission the Android-specific permission name that was requested.
505505+ * \param granted true if permission is granted, false if denied.
506506+ *
507507+ * \since This datatype is available since SDL 3.1.3.
508508+ *
509509+ * \sa SDL_RequestAndroidPermission
510510+ */
472511typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, bool granted);
473512474513/**
+98-6
include/SDL3/SDL_video.h
···112112 SDL_SYSTEM_THEME_DARK /**< Dark colored system theme */
113113} SDL_SystemTheme;
114114115115-/* Internal display mode data */
115115+/**
116116+ * Internal display mode data.
117117+ *
118118+ * This lives as a field in SDL_DisplayMode, as opaque data.
119119+ *
120120+ * \since This struct is available since SDL 3.1.3.
121121+ *
122122+ * \sa SDL_DisplayMode
123123+ */
116124typedef struct SDL_DisplayModeData SDL_DisplayModeData;
117125118126/**
···206214207215208216/**
217217+ * A magic value used with SDL_WINDOWPOS_UNDEFINED.
218218+ *
219219+ * Generally this macro isn't used directly, but rather through
220220+ * SDL_WINDOWPOS_UNDEFINED or SDL_WINDOWPOS_UNDEFINED_DISPLAY.
221221+ *
222222+ * \since This macro is available since SDL 3.1.3.
223223+ */
224224+#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
225225+226226+/**
209227 * Used to indicate that you don't care what the window position is.
210228 *
229229+ * If you _really_ don't care, SDL_WINDOWPOS_UNDEFINED is the same, but always
230230+ * uses the primary display instead of specifying one.
231231+ *
232232+ * \param X the SDL_DisplayID of the display to use.
233233+ *
211234 * \since This macro is available since SDL 3.1.3.
212235 */
213213-#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
214236#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
237237+238238+/**
239239+ * Used to indicate that you don't care what the window position/display is.
240240+ *
241241+ * This always uses the primary display.
242242+ *
243243+ * \since This macro is available since SDL 3.1.3.
244244+ */
215245#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
216216-#define SDL_WINDOWPOS_ISUNDEFINED(X) \
217217- (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
246246+247247+/**
248248+ * A macro to test if the window position is marked as "undefined."
249249+ *
250250+ * \param X the window position value.
251251+ *
252252+ * \since This macro is available since SDL 3.1.3.
253253+ */
254254+#define SDL_WINDOWPOS_ISUNDEFINED(X) (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
218255219256/**
220220- * Used to indicate that the window position should be centered.
257257+ * A magic value used with SDL_WINDOWPOS_CENTERED.
258258+ *
259259+ * Generally this macro isn't used directly, but rather through
260260+ * SDL_WINDOWPOS_CENTERED or SDL_WINDOWPOS_CENTERED_DISPLAY.
221261 *
222262 * \since This macro is available since SDL 3.1.3.
223263 */
224264#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000u
265265+266266+/**
267267+ * Used to indicate that the window position should be centered.
268268+ *
269269+ * SDL_WINDOWPOS_CENTERED is the same, but always uses the primary display
270270+ * instead of specifying one.
271271+ *
272272+ * \param X the SDL_DisplayID of the display to use.
273273+ *
274274+ * \since This macro is available since SDL 3.1.3.
275275+ */
225276#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
277277+278278+/**
279279+ * Used to indicate that the window position should be centered.
280280+ *
281281+ * This always uses the primary display.
282282+ *
283283+ * \since This macro is available since SDL 3.1.3.
284284+ */
226285#define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
286286+287287+/**
288288+ * A macro to test if the window position is marked as "centered."
289289+ *
290290+ * \param X the window position value.
291291+ *
292292+ * \since This macro is available since SDL 3.1.3.
293293+ */
227294#define SDL_WINDOWPOS_ISCENTERED(X) \
228295 (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
296296+229297230298/**
231299 * Window flash operation.
···249317typedef struct SDL_GLContextState *SDL_GLContext;
250318251319/**
252252- * Opaque EGL types.
320320+ * Opaque type for an EGL display.
253321 *
254322 * \since This datatype is available since SDL 3.1.3.
255323 */
256324typedef void *SDL_EGLDisplay;
325325+326326+/**
327327+ * Opaque type for an EGL config.
328328+ *
329329+ * \since This datatype is available since SDL 3.1.3.
330330+ */
257331typedef void *SDL_EGLConfig;
332332+333333+/**
334334+ * Opaque type for an EGL surface.
335335+ *
336336+ * \since This datatype is available since SDL 3.1.3.
337337+ */
258338typedef void *SDL_EGLSurface;
339339+340340+/**
341341+ * An EGL attribute, used when creating an EGL context.
342342+ *
343343+ * \since This datatype is available since SDL 3.1.3.
344344+ */
259345typedef intptr_t SDL_EGLAttrib;
346346+347347+/**
348348+ * An EGL integer attribute, used when creating an EGL surface.
349349+ *
350350+ * \since This datatype is available since SDL 3.1.3.
351351+ */
260352typedef int SDL_EGLint;
261353262354/**