SDL_sysvideo.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 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. #include "../SDL_internal.h"
  19. #ifndef _SDL_sysvideo_h
  20. #define _SDL_sysvideo_h
  21. #include "SDL_messagebox.h"
  22. #include "SDL_shape.h"
  23. #include "SDL_thread.h"
  24. /* The SDL video driver */
  25. typedef struct SDL_WindowShaper SDL_WindowShaper;
  26. typedef struct SDL_ShapeDriver SDL_ShapeDriver;
  27. typedef struct SDL_VideoDisplay SDL_VideoDisplay;
  28. typedef struct SDL_VideoDevice SDL_VideoDevice;
  29. /* Define the SDL window-shaper structure */
  30. struct SDL_WindowShaper
  31. {
  32. /* The window associated with the shaper */
  33. SDL_Window *window;
  34. /* The user's specified coordinates for the window, for once we give it a shape. */
  35. Uint32 userx,usery;
  36. /* The parameters for shape calculation. */
  37. SDL_WindowShapeMode mode;
  38. /* Has this window been assigned a shape? */
  39. SDL_bool hasshape;
  40. void *driverdata;
  41. };
  42. /* Define the SDL shape driver structure */
  43. struct SDL_ShapeDriver
  44. {
  45. SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
  46. int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
  47. int (*ResizeWindowShape)(SDL_Window *window);
  48. };
  49. typedef struct SDL_WindowUserData
  50. {
  51. char *name;
  52. void *data;
  53. struct SDL_WindowUserData *next;
  54. } SDL_WindowUserData;
  55. /* Define the SDL window structure, corresponding to toplevel windows */
  56. struct SDL_Window
  57. {
  58. const void *magic;
  59. Uint32 id;
  60. char *title;
  61. SDL_Surface *icon;
  62. int x, y;
  63. int w, h;
  64. int min_w, min_h;
  65. int max_w, max_h;
  66. Uint32 flags;
  67. Uint32 last_fullscreen_flags;
  68. /* Stored position and size for windowed mode */
  69. SDL_Rect windowed;
  70. SDL_DisplayMode fullscreen_mode;
  71. float brightness;
  72. Uint16 *gamma;
  73. Uint16 *saved_gamma; /* (just offset into gamma) */
  74. SDL_Surface *surface;
  75. SDL_bool surface_valid;
  76. SDL_bool is_destroying;
  77. SDL_WindowShaper *shaper;
  78. SDL_WindowUserData *data;
  79. void *driverdata;
  80. SDL_Window *prev;
  81. SDL_Window *next;
  82. };
  83. #define FULLSCREEN_VISIBLE(W) \
  84. (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
  85. ((W)->flags & SDL_WINDOW_SHOWN) && \
  86. !((W)->flags & SDL_WINDOW_MINIMIZED))
  87. /*
  88. * Define the SDL display structure This corresponds to physical monitors
  89. * attached to the system.
  90. */
  91. struct SDL_VideoDisplay
  92. {
  93. char *name;
  94. int max_display_modes;
  95. int num_display_modes;
  96. SDL_DisplayMode *display_modes;
  97. SDL_DisplayMode desktop_mode;
  98. SDL_DisplayMode current_mode;
  99. SDL_Window *fullscreen_window;
  100. SDL_VideoDevice *device;
  101. void *driverdata;
  102. };
  103. /* Forward declaration */
  104. struct SDL_SysWMinfo;
  105. /* Define the SDL video driver structure */
  106. #define _THIS SDL_VideoDevice *_this
  107. struct SDL_VideoDevice
  108. {
  109. /* * * */
  110. /* The name of this video driver */
  111. const char *name;
  112. /* * * */
  113. /* Initialization/Query functions */
  114. /*
  115. * Initialize the native video subsystem, filling in the list of
  116. * displays for this driver, returning 0 or -1 if there's an error.
  117. */
  118. int (*VideoInit) (_THIS);
  119. /*
  120. * Reverse the effects VideoInit() -- called if VideoInit() fails or
  121. * if the application is shutting down the video subsystem.
  122. */
  123. void (*VideoQuit) (_THIS);
  124. /* * * */
  125. /*
  126. * Display functions
  127. */
  128. /*
  129. * Get the bounds of a display
  130. */
  131. int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
  132. /*
  133. * Get a list of the available display modes for a display.
  134. */
  135. void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
  136. /*
  137. * Setting the display mode is independent of creating windows, so
  138. * when the display mode is changed, all existing windows should have
  139. * their data updated accordingly, including the display surfaces
  140. * associated with them.
  141. */
  142. int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
  143. /* * * */
  144. /*
  145. * Window functions
  146. */
  147. int (*CreateWindow) (_THIS, SDL_Window * window);
  148. int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
  149. void (*SetWindowTitle) (_THIS, SDL_Window * window);
  150. void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
  151. void (*SetWindowPosition) (_THIS, SDL_Window * window);
  152. void (*SetWindowSize) (_THIS, SDL_Window * window);
  153. void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
  154. void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
  155. void (*ShowWindow) (_THIS, SDL_Window * window);
  156. void (*HideWindow) (_THIS, SDL_Window * window);
  157. void (*RaiseWindow) (_THIS, SDL_Window * window);
  158. void (*MaximizeWindow) (_THIS, SDL_Window * window);
  159. void (*MinimizeWindow) (_THIS, SDL_Window * window);
  160. void (*RestoreWindow) (_THIS, SDL_Window * window);
  161. void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
  162. void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
  163. int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
  164. int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
  165. void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
  166. void (*DestroyWindow) (_THIS, SDL_Window * window);
  167. int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
  168. int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
  169. void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
  170. void (*OnWindowEnter) (_THIS, SDL_Window * window);
  171. /* * * */
  172. /*
  173. * Shaped-window functions
  174. */
  175. SDL_ShapeDriver shape_driver;
  176. /* Get some platform dependent window information */
  177. SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
  178. struct SDL_SysWMinfo * info);
  179. /* * * */
  180. /*
  181. * OpenGL support
  182. */
  183. int (*GL_LoadLibrary) (_THIS, const char *path);
  184. void *(*GL_GetProcAddress) (_THIS, const char *proc);
  185. void (*GL_UnloadLibrary) (_THIS);
  186. SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
  187. int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
  188. void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
  189. int (*GL_SetSwapInterval) (_THIS, int interval);
  190. int (*GL_GetSwapInterval) (_THIS);
  191. void (*GL_SwapWindow) (_THIS, SDL_Window * window);
  192. void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
  193. /* * * */
  194. /*
  195. * Event manager functions
  196. */
  197. void (*PumpEvents) (_THIS);
  198. /* Suspend the screensaver */
  199. void (*SuspendScreenSaver) (_THIS);
  200. /* Text input */
  201. void (*StartTextInput) (_THIS);
  202. void (*StopTextInput) (_THIS);
  203. void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
  204. /* Screen keyboard */
  205. SDL_bool (*HasScreenKeyboardSupport) (_THIS);
  206. void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
  207. void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
  208. SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
  209. /* Clipboard */
  210. int (*SetClipboardText) (_THIS, const char *text);
  211. char * (*GetClipboardText) (_THIS);
  212. SDL_bool (*HasClipboardText) (_THIS);
  213. /* MessageBox */
  214. int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
  215. /* * * */
  216. /* Data common to all drivers */
  217. SDL_bool suspend_screensaver;
  218. int num_displays;
  219. SDL_VideoDisplay *displays;
  220. SDL_Window *windows;
  221. Uint8 window_magic;
  222. Uint32 next_object_id;
  223. char * clipboard_text;
  224. /* * * */
  225. /* Data used by the GL drivers */
  226. struct
  227. {
  228. int red_size;
  229. int green_size;
  230. int blue_size;
  231. int alpha_size;
  232. int depth_size;
  233. int buffer_size;
  234. int stencil_size;
  235. int double_buffer;
  236. int accum_red_size;
  237. int accum_green_size;
  238. int accum_blue_size;
  239. int accum_alpha_size;
  240. int stereo;
  241. int multisamplebuffers;
  242. int multisamplesamples;
  243. int accelerated;
  244. int major_version;
  245. int minor_version;
  246. int flags;
  247. int profile_mask;
  248. int share_with_current_context;
  249. int framebuffer_srgb_capable;
  250. int retained_backing;
  251. int driver_loaded;
  252. char driver_path[256];
  253. void *dll_handle;
  254. } gl_config;
  255. /* * * */
  256. /* Cache current GL context; don't call the OS when it hasn't changed. */
  257. /* We have the global pointers here so Cocoa continues to work the way
  258. it always has, and the thread-local storage for the general case.
  259. */
  260. SDL_Window *current_glwin;
  261. SDL_GLContext current_glctx;
  262. SDL_TLSID current_glwin_tls;
  263. SDL_TLSID current_glctx_tls;
  264. /* * * */
  265. /* Data private to this driver */
  266. void *driverdata;
  267. struct SDL_GLDriverData *gl_data;
  268. #if SDL_VIDEO_OPENGL_EGL
  269. struct SDL_EGL_VideoData *egl_data;
  270. #endif
  271. #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
  272. struct SDL_PrivateGLESData *gles_data;
  273. #endif
  274. /* * * */
  275. /* The function used to dispose of this structure */
  276. void (*free) (_THIS);
  277. };
  278. typedef struct VideoBootStrap
  279. {
  280. const char *name;
  281. const char *desc;
  282. int (*available) (void);
  283. SDL_VideoDevice *(*create) (int devindex);
  284. } VideoBootStrap;
  285. #if SDL_VIDEO_DRIVER_COCOA
  286. extern VideoBootStrap COCOA_bootstrap;
  287. #endif
  288. #if SDL_VIDEO_DRIVER_X11
  289. extern VideoBootStrap X11_bootstrap;
  290. #endif
  291. #if SDL_VIDEO_DRIVER_MIR
  292. extern VideoBootStrap MIR_bootstrap;
  293. #endif
  294. #if SDL_VIDEO_DRIVER_DIRECTFB
  295. extern VideoBootStrap DirectFB_bootstrap;
  296. #endif
  297. #if SDL_VIDEO_DRIVER_WINDOWS
  298. extern VideoBootStrap WINDOWS_bootstrap;
  299. #endif
  300. #if SDL_VIDEO_DRIVER_WINRT
  301. extern VideoBootStrap WINRT_bootstrap;
  302. #endif
  303. #if SDL_VIDEO_DRIVER_HAIKU
  304. extern VideoBootStrap HAIKU_bootstrap;
  305. #endif
  306. #if SDL_VIDEO_DRIVER_PANDORA
  307. extern VideoBootStrap PND_bootstrap;
  308. #endif
  309. #if SDL_VIDEO_DRIVER_UIKIT
  310. extern VideoBootStrap UIKIT_bootstrap;
  311. #endif
  312. #if SDL_VIDEO_DRIVER_ANDROID
  313. extern VideoBootStrap Android_bootstrap;
  314. #endif
  315. #if SDL_VIDEO_DRIVER_PSP
  316. extern VideoBootStrap PSP_bootstrap;
  317. #endif
  318. #if SDL_VIDEO_DRIVER_RPI
  319. extern VideoBootStrap RPI_bootstrap;
  320. #endif
  321. #if SDL_VIDEO_DRIVER_DUMMY
  322. extern VideoBootStrap DUMMY_bootstrap;
  323. #endif
  324. #if SDL_VIDEO_DRIVER_WAYLAND
  325. extern VideoBootStrap Wayland_bootstrap;
  326. #endif
  327. #if SDL_VIDEO_DRIVER_NACL
  328. extern VideoBootStrap NACL_bootstrap;
  329. #endif
  330. extern SDL_VideoDevice *SDL_GetVideoDevice(void);
  331. extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
  332. extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
  333. extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
  334. extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
  335. extern void *SDL_GetDisplayDriverData( int displayIndex );
  336. extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
  337. extern void SDL_OnWindowShown(SDL_Window * window);
  338. extern void SDL_OnWindowHidden(SDL_Window * window);
  339. extern void SDL_OnWindowResized(SDL_Window * window);
  340. extern void SDL_OnWindowMinimized(SDL_Window * window);
  341. extern void SDL_OnWindowRestored(SDL_Window * window);
  342. extern void SDL_OnWindowEnter(SDL_Window * window);
  343. extern void SDL_OnWindowLeave(SDL_Window * window);
  344. extern void SDL_OnWindowFocusGained(SDL_Window * window);
  345. extern void SDL_OnWindowFocusLost(SDL_Window * window);
  346. extern void SDL_UpdateWindowGrab(SDL_Window * window);
  347. extern SDL_Window * SDL_GetFocusWindow(void);
  348. extern SDL_bool SDL_ShouldAllowTopmost(void);
  349. #endif /* _SDL_sysvideo_h */
  350. /* vi: set ts=4 sw=4 expandtab: */