SDL_sysvideo.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2016 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 opacity;
  72. float brightness;
  73. Uint16 *gamma;
  74. Uint16 *saved_gamma; /* (just offset into gamma) */
  75. SDL_Surface *surface;
  76. SDL_bool surface_valid;
  77. SDL_bool is_hiding;
  78. SDL_bool is_destroying;
  79. SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
  80. SDL_WindowShaper *shaper;
  81. SDL_HitTest hit_test;
  82. void *hit_test_data;
  83. SDL_WindowUserData *data;
  84. void *driverdata;
  85. SDL_Window *prev;
  86. SDL_Window *next;
  87. };
  88. #define FULLSCREEN_VISIBLE(W) \
  89. (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
  90. ((W)->flags & SDL_WINDOW_SHOWN) && \
  91. !((W)->flags & SDL_WINDOW_MINIMIZED))
  92. /*
  93. * Define the SDL display structure This corresponds to physical monitors
  94. * attached to the system.
  95. */
  96. struct SDL_VideoDisplay
  97. {
  98. char *name;
  99. int max_display_modes;
  100. int num_display_modes;
  101. SDL_DisplayMode *display_modes;
  102. SDL_DisplayMode desktop_mode;
  103. SDL_DisplayMode current_mode;
  104. SDL_Window *fullscreen_window;
  105. SDL_VideoDevice *device;
  106. void *driverdata;
  107. };
  108. /* Forward declaration */
  109. struct SDL_SysWMinfo;
  110. /* Define the SDL video driver structure */
  111. #define _THIS SDL_VideoDevice *_this
  112. struct SDL_VideoDevice
  113. {
  114. /* * * */
  115. /* The name of this video driver */
  116. const char *name;
  117. /* * * */
  118. /* Initialization/Query functions */
  119. /*
  120. * Initialize the native video subsystem, filling in the list of
  121. * displays for this driver, returning 0 or -1 if there's an error.
  122. */
  123. int (*VideoInit) (_THIS);
  124. /*
  125. * Reverse the effects VideoInit() -- called if VideoInit() fails or
  126. * if the application is shutting down the video subsystem.
  127. */
  128. void (*VideoQuit) (_THIS);
  129. /* * * */
  130. /*
  131. * Display functions
  132. */
  133. /*
  134. * Get the bounds of a display
  135. */
  136. int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
  137. /*
  138. * Get the dots/pixels-per-inch of a display
  139. */
  140. int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
  141. /*
  142. * Get the usable bounds of a display (bounds minus menubar or whatever)
  143. */
  144. int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
  145. /*
  146. * Get a list of the available display modes for a display.
  147. */
  148. void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
  149. /*
  150. * Setting the display mode is independent of creating windows, so
  151. * when the display mode is changed, all existing windows should have
  152. * their data updated accordingly, including the display surfaces
  153. * associated with them.
  154. */
  155. int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
  156. /* * * */
  157. /*
  158. * Window functions
  159. */
  160. int (*CreateWindow) (_THIS, SDL_Window * window);
  161. int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
  162. void (*SetWindowTitle) (_THIS, SDL_Window * window);
  163. void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
  164. void (*SetWindowPosition) (_THIS, SDL_Window * window);
  165. void (*SetWindowSize) (_THIS, SDL_Window * window);
  166. void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
  167. void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
  168. int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
  169. int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
  170. int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
  171. int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
  172. void (*ShowWindow) (_THIS, SDL_Window * window);
  173. void (*HideWindow) (_THIS, SDL_Window * window);
  174. void (*RaiseWindow) (_THIS, SDL_Window * window);
  175. void (*MaximizeWindow) (_THIS, SDL_Window * window);
  176. void (*MinimizeWindow) (_THIS, SDL_Window * window);
  177. void (*RestoreWindow) (_THIS, SDL_Window * window);
  178. void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
  179. void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
  180. int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
  181. int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
  182. void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
  183. void (*DestroyWindow) (_THIS, SDL_Window * window);
  184. int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
  185. int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
  186. void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
  187. void (*OnWindowEnter) (_THIS, SDL_Window * window);
  188. /* * * */
  189. /*
  190. * Shaped-window functions
  191. */
  192. SDL_ShapeDriver shape_driver;
  193. /* Get some platform dependent window information */
  194. SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
  195. struct SDL_SysWMinfo * info);
  196. /* * * */
  197. /*
  198. * OpenGL support
  199. */
  200. int (*GL_LoadLibrary) (_THIS, const char *path);
  201. void *(*GL_GetProcAddress) (_THIS, const char *proc);
  202. void (*GL_UnloadLibrary) (_THIS);
  203. SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
  204. int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
  205. void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
  206. int (*GL_SetSwapInterval) (_THIS, int interval);
  207. int (*GL_GetSwapInterval) (_THIS);
  208. void (*GL_SwapWindow) (_THIS, SDL_Window * window);
  209. void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
  210. /* * * */
  211. /*
  212. * Event manager functions
  213. */
  214. void (*PumpEvents) (_THIS);
  215. /* Suspend the screensaver */
  216. void (*SuspendScreenSaver) (_THIS);
  217. /* Text input */
  218. void (*StartTextInput) (_THIS);
  219. void (*StopTextInput) (_THIS);
  220. void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
  221. /* Screen keyboard */
  222. SDL_bool (*HasScreenKeyboardSupport) (_THIS);
  223. void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
  224. void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
  225. SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
  226. /* Clipboard */
  227. int (*SetClipboardText) (_THIS, const char *text);
  228. char * (*GetClipboardText) (_THIS);
  229. SDL_bool (*HasClipboardText) (_THIS);
  230. /* MessageBox */
  231. int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
  232. /* Hit-testing */
  233. int (*SetWindowHitTest)(SDL_Window * window, SDL_bool enabled);
  234. /* * * */
  235. /* Data common to all drivers */
  236. SDL_bool suspend_screensaver;
  237. int num_displays;
  238. SDL_VideoDisplay *displays;
  239. SDL_Window *windows;
  240. SDL_Window *grabbed_window;
  241. Uint8 window_magic;
  242. Uint32 next_object_id;
  243. char * clipboard_text;
  244. /* * * */
  245. /* Data used by the GL drivers */
  246. struct
  247. {
  248. int red_size;
  249. int green_size;
  250. int blue_size;
  251. int alpha_size;
  252. int depth_size;
  253. int buffer_size;
  254. int stencil_size;
  255. int double_buffer;
  256. int accum_red_size;
  257. int accum_green_size;
  258. int accum_blue_size;
  259. int accum_alpha_size;
  260. int stereo;
  261. int multisamplebuffers;
  262. int multisamplesamples;
  263. int accelerated;
  264. int major_version;
  265. int minor_version;
  266. int flags;
  267. int profile_mask;
  268. int share_with_current_context;
  269. int release_behavior;
  270. int framebuffer_srgb_capable;
  271. int retained_backing;
  272. int driver_loaded;
  273. char driver_path[256];
  274. void *dll_handle;
  275. } gl_config;
  276. /* * * */
  277. /* Cache current GL context; don't call the OS when it hasn't changed. */
  278. /* We have the global pointers here so Cocoa continues to work the way
  279. it always has, and the thread-local storage for the general case.
  280. */
  281. SDL_Window *current_glwin;
  282. SDL_GLContext current_glctx;
  283. SDL_TLSID current_glwin_tls;
  284. SDL_TLSID current_glctx_tls;
  285. /* * * */
  286. /* Data private to this driver */
  287. void *driverdata;
  288. struct SDL_GLDriverData *gl_data;
  289. #if SDL_VIDEO_OPENGL_EGL
  290. struct SDL_EGL_VideoData *egl_data;
  291. #endif
  292. #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
  293. struct SDL_PrivateGLESData *gles_data;
  294. #endif
  295. /* * * */
  296. /* The function used to dispose of this structure */
  297. void (*free) (_THIS);
  298. };
  299. typedef struct VideoBootStrap
  300. {
  301. const char *name;
  302. const char *desc;
  303. int (*available) (void);
  304. SDL_VideoDevice *(*create) (int devindex);
  305. } VideoBootStrap;
  306. #if SDL_VIDEO_DRIVER_COCOA
  307. extern VideoBootStrap COCOA_bootstrap;
  308. #endif
  309. #if SDL_VIDEO_DRIVER_X11
  310. extern VideoBootStrap X11_bootstrap;
  311. #endif
  312. #if SDL_VIDEO_DRIVER_MIR
  313. extern VideoBootStrap MIR_bootstrap;
  314. #endif
  315. #if SDL_VIDEO_DRIVER_DIRECTFB
  316. extern VideoBootStrap DirectFB_bootstrap;
  317. #endif
  318. #if SDL_VIDEO_DRIVER_WINDOWS
  319. extern VideoBootStrap WINDOWS_bootstrap;
  320. #endif
  321. #if SDL_VIDEO_DRIVER_WINRT
  322. extern VideoBootStrap WINRT_bootstrap;
  323. #endif
  324. #if SDL_VIDEO_DRIVER_HAIKU
  325. extern VideoBootStrap HAIKU_bootstrap;
  326. #endif
  327. #if SDL_VIDEO_DRIVER_PANDORA
  328. extern VideoBootStrap PND_bootstrap;
  329. #endif
  330. #if SDL_VIDEO_DRIVER_UIKIT
  331. extern VideoBootStrap UIKIT_bootstrap;
  332. #endif
  333. #if SDL_VIDEO_DRIVER_ANDROID
  334. extern VideoBootStrap Android_bootstrap;
  335. #endif
  336. #if SDL_VIDEO_DRIVER_PSP
  337. extern VideoBootStrap PSP_bootstrap;
  338. #endif
  339. #if SDL_VIDEO_DRIVER_RPI
  340. extern VideoBootStrap RPI_bootstrap;
  341. #endif
  342. #if SDL_VIDEO_DRIVER_DUMMY
  343. extern VideoBootStrap DUMMY_bootstrap;
  344. #endif
  345. #if SDL_VIDEO_DRIVER_WAYLAND
  346. extern VideoBootStrap Wayland_bootstrap;
  347. #endif
  348. #if SDL_VIDEO_DRIVER_NACL
  349. extern VideoBootStrap NACL_bootstrap;
  350. #endif
  351. #if SDL_VIDEO_DRIVER_VIVANTE
  352. extern VideoBootStrap VIVANTE_bootstrap;
  353. #endif
  354. #if SDL_VIDEO_DRIVER_EMSCRIPTEN
  355. extern VideoBootStrap Emscripten_bootstrap;
  356. #endif
  357. extern SDL_VideoDevice *SDL_GetVideoDevice(void);
  358. extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
  359. extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
  360. extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
  361. extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
  362. extern void *SDL_GetDisplayDriverData( int displayIndex );
  363. extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
  364. extern void SDL_OnWindowShown(SDL_Window * window);
  365. extern void SDL_OnWindowHidden(SDL_Window * window);
  366. extern void SDL_OnWindowResized(SDL_Window * window);
  367. extern void SDL_OnWindowMinimized(SDL_Window * window);
  368. extern void SDL_OnWindowRestored(SDL_Window * window);
  369. extern void SDL_OnWindowEnter(SDL_Window * window);
  370. extern void SDL_OnWindowLeave(SDL_Window * window);
  371. extern void SDL_OnWindowFocusGained(SDL_Window * window);
  372. extern void SDL_OnWindowFocusLost(SDL_Window * window);
  373. extern void SDL_UpdateWindowGrab(SDL_Window * window);
  374. extern SDL_Window * SDL_GetFocusWindow(void);
  375. extern SDL_bool SDL_ShouldAllowTopmost(void);
  376. extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
  377. #endif /* _SDL_sysvideo_h */
  378. /* vi: set ts=4 sw=4 expandtab: */