SDL_internal.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_internal_h_
  19. #define SDL_internal_h_
  20. /* Many of SDL's features require _GNU_SOURCE on various platforms */
  21. #ifndef _GNU_SOURCE
  22. #define _GNU_SOURCE
  23. #endif
  24. /* Need this so Linux systems define fseek64o, ftell64o and off64_t */
  25. #ifndef _LARGEFILE64_SOURCE
  26. #define _LARGEFILE64_SOURCE 1
  27. #endif
  28. /* This is for a variable-length array at the end of a struct:
  29. struct x { int y; char z[SDL_VARIABLE_LENGTH_ARRAY]; };
  30. Use this because GCC 2 needs different magic than other compilers. */
  31. #if (defined(__GNUC__) && (__GNUC__ <= 2)) || defined(__CC_ARM) || defined(__cplusplus)
  32. #define SDL_VARIABLE_LENGTH_ARRAY 1
  33. #else
  34. #define SDL_VARIABLE_LENGTH_ARRAY
  35. #endif
  36. #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))) || defined(__clang__)
  37. #define HAVE_GCC_DIAGNOSTIC_PRAGMA 1
  38. #endif
  39. #ifdef _MSC_VER /* We use constant comparison for generated code */
  40. #pragma warning(disable : 6326)
  41. #endif
  42. #ifdef _MSC_VER /* SDL_MAX_SMALL_ALLOC_STACKSIZE is smaller than _ALLOCA_S_THRESHOLD and should be generally safe */
  43. #pragma warning(disable : 6255)
  44. #endif
  45. #define SDL_MAX_SMALL_ALLOC_STACKSIZE 128
  46. #define SDL_small_alloc(type, count, pisstack) ((*(pisstack) = ((sizeof(type) * (count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type *)SDL_malloc(sizeof(type) * (count))))
  47. #define SDL_small_free(ptr, isstack) \
  48. if ((isstack)) { \
  49. SDL_stack_free(ptr); \
  50. } else { \
  51. SDL_free(ptr); \
  52. }
  53. #include "build_config/SDL_build_config.h"
  54. #include "dynapi/SDL_dynapi.h"
  55. #if SDL_DYNAMIC_API
  56. #include "dynapi/SDL_dynapi_overrides.h"
  57. /* force SDL_DECLSPEC off...it's all internal symbols now.
  58. These will have actual #defines during SDL_dynapi.c only */
  59. #ifdef SDL_DECLSPEC
  60. #undef SDL_DECLSPEC
  61. #endif
  62. #define SDL_DECLSPEC
  63. #endif
  64. #ifdef SDL_PLATFORM_APPLE
  65. #ifndef _DARWIN_C_SOURCE
  66. #define _DARWIN_C_SOURCE 1 /* for memset_pattern4() */
  67. #endif
  68. #endif
  69. #ifdef HAVE_SYS_TYPES_H
  70. #include <sys/types.h>
  71. #endif
  72. #ifdef HAVE_STDIO_H
  73. #include <stdio.h>
  74. #endif
  75. #ifdef HAVE_STDLIB_H
  76. #include <stdlib.h>
  77. #elif defined(HAVE_MALLOC_H)
  78. #include <malloc.h>
  79. #endif
  80. #ifdef HAVE_STDDEF_H
  81. #include <stddef.h>
  82. #endif
  83. #ifdef HAVE_STDARG_H
  84. #include <stdarg.h>
  85. #endif
  86. #ifdef HAVE_STRING_H
  87. #ifdef HAVE_MEMORY_H
  88. #include <memory.h>
  89. #endif
  90. #include <string.h>
  91. #endif
  92. #ifdef HAVE_STRINGS_H
  93. #include <strings.h>
  94. #endif
  95. #ifdef HAVE_WCHAR_H
  96. #include <wchar.h>
  97. #endif
  98. #ifdef HAVE_INTTYPES_H
  99. #include <inttypes.h>
  100. #elif defined(HAVE_STDINT_H)
  101. #include <stdint.h>
  102. #endif
  103. #ifdef HAVE_MATH_H
  104. #include <math.h>
  105. #endif
  106. #ifdef HAVE_FLOAT_H
  107. #include <float.h>
  108. #endif
  109. /* If you run into a warning that O_CLOEXEC is redefined, update the SDL configuration header for your platform to add HAVE_O_CLOEXEC */
  110. #ifndef HAVE_O_CLOEXEC
  111. #define O_CLOEXEC 0
  112. #endif
  113. /* A few #defines to reduce SDL footprint.
  114. Only effective when library is statically linked.
  115. You have to manually edit this file. */
  116. #ifndef SDL_LEAN_AND_MEAN
  117. #define SDL_LEAN_AND_MEAN 0
  118. #endif
  119. /* Optimized functions from 'SDL_blit_0.c'
  120. - blit with source bits_per_pixel < 8, palette */
  121. #ifndef SDL_HAVE_BLIT_0
  122. #define SDL_HAVE_BLIT_0 !SDL_LEAN_AND_MEAN
  123. #endif
  124. /* Optimized functions from 'SDL_blit_1.c'
  125. - blit with source bytes_per_pixel == 1, palette */
  126. #ifndef SDL_HAVE_BLIT_1
  127. #define SDL_HAVE_BLIT_1 !SDL_LEAN_AND_MEAN
  128. #endif
  129. /* Optimized functions from 'SDL_blit_A.c'
  130. - blit with 'SDL_BLENDMODE_BLEND' blending mode */
  131. #ifndef SDL_HAVE_BLIT_A
  132. #define SDL_HAVE_BLIT_A !SDL_LEAN_AND_MEAN
  133. #endif
  134. /* Optimized functions from 'SDL_blit_N.c'
  135. - blit with COLORKEY mode, or nothing */
  136. #ifndef SDL_HAVE_BLIT_N
  137. #define SDL_HAVE_BLIT_N !SDL_LEAN_AND_MEAN
  138. #endif
  139. /* Optimized functions from 'SDL_blit_N.c'
  140. - RGB565 conversion with Lookup tables */
  141. #ifndef SDL_HAVE_BLIT_N_RGB565
  142. #define SDL_HAVE_BLIT_N_RGB565 !SDL_LEAN_AND_MEAN
  143. #endif
  144. /* Optimized functions from 'SDL_blit_AUTO.c'
  145. - blit with modulate color, modulate alpha, any blending mode
  146. - scaling or not */
  147. #ifndef SDL_HAVE_BLIT_AUTO
  148. #define SDL_HAVE_BLIT_AUTO !SDL_LEAN_AND_MEAN
  149. #endif
  150. /* Run-Length-Encoding
  151. - SDL_SetSurfaceColorKey() called with SDL_RLEACCEL flag */
  152. #ifndef SDL_HAVE_RLE
  153. #define SDL_HAVE_RLE !SDL_LEAN_AND_MEAN
  154. #endif
  155. /* Software SDL_Renderer
  156. - creation of software renderer
  157. - *not* general blitting functions
  158. - {blend,draw}{fillrect,line,point} internal functions */
  159. #ifndef SDL_VIDEO_RENDER_SW
  160. #define SDL_VIDEO_RENDER_SW !SDL_LEAN_AND_MEAN
  161. #endif
  162. /* YUV formats
  163. - handling of YUV surfaces
  164. - blitting and conversion functions */
  165. #ifndef SDL_HAVE_YUV
  166. #define SDL_HAVE_YUV !SDL_LEAN_AND_MEAN
  167. #endif
  168. #ifndef SDL_RENDER_DISABLED
  169. /* define the not defined ones as 0 */
  170. #ifndef SDL_VIDEO_RENDER_D3D
  171. #define SDL_VIDEO_RENDER_D3D 0
  172. #endif
  173. #ifndef SDL_VIDEO_RENDER_D3D11
  174. #define SDL_VIDEO_RENDER_D3D11 0
  175. #endif
  176. #ifndef SDL_VIDEO_RENDER_D3D12
  177. #define SDL_VIDEO_RENDER_D3D12 0
  178. #endif
  179. #ifndef SDL_VIDEO_RENDER_METAL
  180. #define SDL_VIDEO_RENDER_METAL 0
  181. #endif
  182. #ifndef SDL_VIDEO_RENDER_OGL
  183. #define SDL_VIDEO_RENDER_OGL 0
  184. #endif
  185. #ifndef SDL_VIDEO_RENDER_OGL_ES2
  186. #define SDL_VIDEO_RENDER_OGL_ES2 0
  187. #endif
  188. #ifndef SDL_VIDEO_RENDER_PS2
  189. #define SDL_VIDEO_RENDER_PS2 0
  190. #endif
  191. #ifndef SDL_VIDEO_RENDER_PSP
  192. #define SDL_VIDEO_RENDER_PSP 0
  193. #endif
  194. #ifndef SDL_VIDEO_RENDER_VITA_GXM
  195. #define SDL_VIDEO_RENDER_VITA_GXM 0
  196. #endif
  197. #ifndef SDL_VIDEO_RENDER_VULKAN
  198. #define SDL_VIDEO_RENDER_VULKAN 0
  199. #endif
  200. #else /* define all as 0 */
  201. #undef SDL_VIDEO_RENDER_SW
  202. #define SDL_VIDEO_RENDER_SW 0
  203. #undef SDL_VIDEO_RENDER_D3D
  204. #define SDL_VIDEO_RENDER_D3D 0
  205. #undef SDL_VIDEO_RENDER_D3D11
  206. #define SDL_VIDEO_RENDER_D3D11 0
  207. #undef SDL_VIDEO_RENDER_D3D12
  208. #define SDL_VIDEO_RENDER_D3D12 0
  209. #undef SDL_VIDEO_RENDER_METAL
  210. #define SDL_VIDEO_RENDER_METAL 0
  211. #undef SDL_VIDEO_RENDER_OGL
  212. #define SDL_VIDEO_RENDER_OGL 0
  213. #undef SDL_VIDEO_RENDER_OGL_ES2
  214. #define SDL_VIDEO_RENDER_OGL_ES2 0
  215. #undef SDL_VIDEO_RENDER_PS2
  216. #define SDL_VIDEO_RENDER_PS2 0
  217. #undef SDL_VIDEO_RENDER_PSP
  218. #define SDL_VIDEO_RENDER_PSP 0
  219. #undef SDL_VIDEO_RENDER_VITA_GXM
  220. #define SDL_VIDEO_RENDER_VITA_GXM 0
  221. #undef SDL_VIDEO_RENDER_VULKAN
  222. #define SDL_VIDEO_RENDER_VULKAN 0
  223. #endif /* SDL_RENDER_DISABLED */
  224. #define SDL_HAS_RENDER_DRIVER \
  225. (SDL_VIDEO_RENDER_SW | \
  226. SDL_VIDEO_RENDER_D3D | \
  227. SDL_VIDEO_RENDER_D3D11 | \
  228. SDL_VIDEO_RENDER_D3D12 | \
  229. SDL_VIDEO_RENDER_METAL | \
  230. SDL_VIDEO_RENDER_OGL | \
  231. SDL_VIDEO_RENDER_OGL_ES2 | \
  232. SDL_VIDEO_RENDER_PS2 | \
  233. SDL_VIDEO_RENDER_PSP | \
  234. SDL_VIDEO_RENDER_VITA_GXM | \
  235. SDL_VIDEO_RENDER_VULKAN )
  236. #if !defined(SDL_RENDER_DISABLED) && !SDL_HAS_RENDER_DRIVER
  237. #error SDL_RENDER enabled without any backend drivers.
  238. #endif
  239. #if !defined(HAVE_LIBC)
  240. // If not using _any_ C runtime, these have to be defined before SDL_thread.h
  241. // gets included, so internal SDL_CreateThread calls will not try to reference
  242. // the (unavailable and unneeded) _beginthreadex/_endthreadex functions.
  243. #define SDL_BeginThreadFunction NULL
  244. #define SDL_EndThreadFunction NULL
  245. #endif
  246. #include <SDL3/SDL.h>
  247. #include <SDL3/SDL_intrin.h>
  248. #define SDL_MAIN_NOIMPL /* don't drag in header-only implementation of SDL_main */
  249. #include <SDL3/SDL_main.h>
  250. #include "SDL_utils_c.h"
  251. /* The internal implementations of these functions have up to nanosecond precision.
  252. We can expose these functions as part of the API if we want to later.
  253. */
  254. /* Set up for C function definitions, even when using C++ */
  255. #ifdef __cplusplus
  256. extern "C" {
  257. #endif
  258. extern int SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS);
  259. extern int SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS);
  260. extern SDL_bool SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS);
  261. /* Queue `memory` to be passed to SDL_free once the event queue is emptied.
  262. this manages the list of pointers to SDL_AllocateEventMemory, but you
  263. can use it to queue pointers from other subsystems that can die at any
  264. moment but definitely need to live long enough for the app to copy them
  265. if they happened to query them in their last moments. */
  266. extern void *SDL_FreeLater(void *memory);
  267. /* Ends C function definitions when using C++ */
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271. #endif /* SDL_internal_h_ */