1 #ifndef _SDL_COMPAT_H
2 #define _SDL_COMPAT_H
3 
4 /*
5  * SDL 1.x/SDL2 compatibility macros.
6  *
7  * Newly written code should use the SDL2 names where they differ,
8  * and define macros here to map them to SDL 1.x names if neccessary.
9  */
10 
11 #if defined(HAVE_STDINT_H)
12 #  define _HAVE_STDINT_H 1 /* SDL2 needs this */
13 #endif
14 #ifndef HAVE_LIBC
15 #  define HAVE_LIBC 1 /* SDL2 does not include system headers without it */
16 #endif
17 
18 /*
19  * workaround for SDL2/SDL_syswm.h:
20  * make sure directfb++.h isn't included, because it is wrapped in extern "C"
21  */
22 #define DIRECTFBPP_H
23 
24 /*
25  * some broken installations of SDL define the PACKAGE_* from
26  * the compilation of SDL itself in SDL_config.h;
27  * just undefine them to avoid redefinitions, we don't need them
28  */
29 #undef PACKAGE_TARNAME
30 #undef PACKAGE_NAME
31 #undef PACKAGE_STRING
32 #undef PACKAGE_BUGREPORT
33 #undef PACKAGE_VERSION
34 #undef PACKAGE_URL
35 
36 #include <SDL.h>
37 
38 #include <SDL_version.h>
39 #include <SDL_endian.h>
40 #include <SDL_keyboard.h>
41 #include <SDL_audio.h>
42 
43 #if defined(__CYGWIN__)
44 /*
45  * HACK: cygwin/mingw32 mix crap
46  *      if not present the SDL_putenv uses cygwin implementation however
47  *       the video driver reading it uses SDL_getenv which comes from the SDL
48  *       build using mingw32...
49  *
50  * SDL2 does not have its own putenv() any longer, but still SDL_getenv()
51  * The places where SDL_putenv was used before, however,
52  * are handled differently now.
53  */
54 #undef SDL_getenv
55 #undef SDL_putenv
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
60 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
61 #ifdef __cplusplus
62 }
63 #endif
64 #else
65 #ifndef SDL_putenv
66 #define SDL_putenv(x) putenv(x)
67 #endif
68 #endif
69 
70 /*
71  * work around inconsistencies between w32api headers
72  * and cygwin headers: both may declare ssize_t/intptr_t
73  * but protect it by different defines
74  */
75 #ifdef _INTPTR_T_DECLARED
76 #define _INTPTR_T_DEFINED
77 #endif
78 #ifdef _UINTPTR_T_DECLARED
79 #define _UINTPTR_T_DEFINED
80 #endif
81 #ifdef _SSIZE_T_DECLARED
82 #define _SSIZE_T_DEFINED
83 #endif
84 
85 #if SDL_VERSION_ATLEAST(2, 0, 0)
86 
87 #define SDL_CreateNamedThread(fn, name, data) SDL_CreateThread(fn, name, data)
88 
89 #define WINDOW_ALPHA 0xff
90 
91 #define SDL_SRCCOLORKEY SDL_TRUE
92 
93 #define SDLK_IS_MODIFIER(sym) \
94 	((sym) == SDLK_NUMLOCKCLEAR || \
95 	 (sym) == SDLK_CAPSLOCK || \
96 	 (sym) == SDLK_SCROLLLOCK || \
97 	 (sym) == SDLK_RSHIFT || \
98 	 (sym) == SDLK_LSHIFT || \
99 	 (sym) == SDLK_RCTRL || \
100 	 (sym) == SDLK_LCTRL || \
101 	 (sym) == SDLK_RALT || \
102 	 (sym) == SDLK_LALT || \
103 	 (sym) == SDLK_RGUI || \
104 	 (sym) == SDLK_LGUI || \
105 	 (sym) == SDLK_MODE)
106 
107 #define SDL_GetVideoDriverName() SDL_GetCurrentVideoDriver()
108 
109 #else
110 
111 #define SDL_CreateNamedThread(fn, name, data) SDL_CreateThread(fn, data)
112 #define SDL_SetMainReady()
113 #define SDL_GetWindowGrab(window) (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ? SDL_TRUE : SDL_FALSE)
114 #define SDL_SetWindowGrab(window, on) SDL_WM_GrabInput((on) ? SDL_GRAB_ON : SDL_GRAB_OFF)
115 
116 typedef SDLMod SDL_Keymod;
117 typedef SDLKey SDL_Keycode;
118 typedef Uint8 SDL_Scancode;
119 typedef SDL_keysym SDL_Keysym;
120 typedef SDL_audiostatus SDL_AudioStatus;
121 
122 #define SDL_GetVersion(v) *(v) = *SDL_Linked_Version()
123 
124 #define KMOD_LGUI KMOD_LMETA
125 #define KMOD_RGUI KMOD_RMETA
126 #define KMOD_GUI KMOD_META
127 
128 #define SDLK_KP_1 SDLK_KP1
129 #define SDLK_KP_2 SDLK_KP2
130 #define SDLK_KP_3 SDLK_KP3
131 #define SDLK_KP_4 SDLK_KP4
132 #define SDLK_KP_5 SDLK_KP5
133 #define SDLK_KP_6 SDLK_KP6
134 #define SDLK_KP_7 SDLK_KP7
135 #define SDLK_KP_8 SDLK_KP8
136 #define SDLK_KP_9 SDLK_KP9
137 #define SDLK_KP_0 SDLK_KP0
138 
139 #define SDLK_SCROLLLOCK SDLK_SCROLLOCK
140 #define SDLK_PRINTSCREEN SDLK_PRINT
141 #define SDLK_NUMLOCKCLEAR SDLK_NUMLOCK
142 
143 #define SDLK_LGUI SDLK_LMETA
144 #define SDLK_RGUI SDLK_RMETA
145 #define SDLK_CANCEL SDLK_BREAK
146 
147 #define SDLK_IS_MODIFIER(sym) ((sym) >= SDLK_NUMLOCK && (sym) <= SDLK_COMPOSE)
148 
SDL_GetVideoDriverName(void)149 static inline const char *SDL_GetVideoDriverName(void)
150 {
151 	static char namebuf[80];
152 	return SDL_VideoDriverName(namebuf, (int)sizeof(namebuf));
153 }
154 
155 typedef void *SDL_GLContext;
156 
157 #if defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
158 
159 extern SDL_GLContext SDL_GL_GetCurrentContext(void);
160 
161 #endif
162 
163 #if defined(SDL_VIDEO_DRIVER_QUARTZ)
164 
165 #ifdef __cplusplus
166 extern "C" {
167 #endif
168 /* returns a NSOpenGLContext and must be implemented in Objc */
169 extern SDL_GLContext SDL_GL_GetCurrentContext(void);
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif
175 
176 #if defined(SDL_VIDEO_DRIVER_X11)
177 
178 /*
179  * SDL_syswm includes <X11/Xlib.h>, but on macOS
180  * These headers are only available if XQuartz was installed
181  */
182 #if !(defined(SDL_VIDEO_DRIVER_QUARTZ) || defined(SDL_VIDEO_DRIVER_COCOA)) || defined(HAVE_X11_XLIB_H)
183 # define HAVE_X11_XLIB_H 1
184 #endif
185 
186 extern SDL_GLContext SDL_GL_GetCurrentContext(void);
187 
188 #endif
189 
190 #endif
191 
192 #if !defined(SDL_VIDEO_DRIVER_WINDOWS) && (defined(SDL_VIDEO_DRIVER_WINRT) || defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI))
193 #  define SDL_VIDEO_DRIVER_WINDOWS 1
194 #endif
195 
196 #ifdef __cplusplus
197 extern "C" {
198 #endif
199 extern void SDL_GL_SetCurrentContext(SDL_GLContext ctx);
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 /*
205  * possible driver names:
206  *
207  * SDL1:
208  * riscos
209  * svgalib
210  * bwindow
211  * qtopia
212  * vgl
213  * wscons
214  * x11
215  * xbios
216  * directfb
217  * aalib
218  * caca
219  * dcvideo
220  * dga
221  * Quartz
222  * DSp (MacOS dspvideo)
223  * toolbox (MacOS romvideo)
224  * windib
225  * directx
226  * epoc
227  * fbcon
228  * gapi (WinCE GAPI)
229  * gem
230  * ggi
231  * ps2gs
232  * ipod
233  * nds
234  * dummy
235  * nanox
236  * os2fslib
237  * picogui
238  * photon
239  * ps3
240  *
241  * SDL2:
242  * PSP
243  * RPI (RaspBery Pi, GLES)
244  * uikit
245  * wayland
246  * windows
247  * winrt (GLES)
248  * x11
249  * directfb
250  * cocoa
251  * Android (GLES)
252  * haiku
253  * mir
254  * dummy
255  * wiz
256  */
257 
SDL_IsVideoDriver(const char * name)258 static inline int SDL_IsVideoDriver(const char *name)
259 {
260 	const char *driver = SDL_GetVideoDriverName();
261 	if (!driver)
262 		return 0;
263 	return strcmp(driver, name) == 0;
264 }
265 
266 SDL_Surface *mySDL_LoadBMP_RW(SDL_RWops * src, int freesrc);
267 
268 #endif /* _SDL_COMPAT_H */
269