1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 */ 21 #include "../SDL_internal.h" 22 23 #ifndef SDL_sysvideo_h_ 24 #define SDL_sysvideo_h_ 25 26 #include "SDL_messagebox.h" 27 #include "SDL_shape.h" 28 #include "SDL_thread.h" 29 #include "SDL_metal.h" 30 31 #include "SDL_vulkan_internal.h" 32 33 /* The SDL video driver */ 34 35 typedef struct SDL_WindowShaper SDL_WindowShaper; 36 typedef struct SDL_ShapeDriver SDL_ShapeDriver; 37 typedef struct SDL_VideoDisplay SDL_VideoDisplay; 38 typedef struct SDL_VideoDevice SDL_VideoDevice; 39 40 /* Define the SDL window-shaper structure */ 41 struct SDL_WindowShaper 42 { 43 /* The window associated with the shaper */ 44 SDL_Window *window; 45 46 /* The user's specified coordinates for the window, for once we give it a shape. */ 47 Uint32 userx,usery; 48 49 /* The parameters for shape calculation. */ 50 SDL_WindowShapeMode mode; 51 52 /* Has this window been assigned a shape? */ 53 SDL_bool hasshape; 54 55 void *driverdata; 56 }; 57 58 /* Define the SDL shape driver structure */ 59 struct SDL_ShapeDriver 60 { 61 SDL_WindowShaper *(*CreateShaper)(SDL_Window * window); 62 int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode); 63 int (*ResizeWindowShape)(SDL_Window *window); 64 }; 65 66 typedef struct SDL_WindowUserData 67 { 68 char *name; 69 void *data; 70 struct SDL_WindowUserData *next; 71 } SDL_WindowUserData; 72 73 /* Define the SDL window structure, corresponding to toplevel windows */ 74 struct SDL_Window 75 { 76 const void *magic; 77 Uint32 id; 78 char *title; 79 SDL_Surface *icon; 80 int x, y; 81 int w, h; 82 int min_w, min_h; 83 int max_w, max_h; 84 Uint32 flags; 85 Uint32 last_fullscreen_flags; 86 87 /* Stored position and size for windowed mode */ 88 SDL_Rect windowed; 89 90 SDL_DisplayMode fullscreen_mode; 91 92 float opacity; 93 94 float brightness; 95 Uint16 *gamma; 96 Uint16 *saved_gamma; /* (just offset into gamma) */ 97 98 SDL_Surface *surface; 99 SDL_bool surface_valid; 100 101 SDL_bool is_hiding; 102 SDL_bool is_destroying; 103 SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */ 104 105 SDL_WindowShaper *shaper; 106 107 SDL_HitTest hit_test; 108 void *hit_test_data; 109 110 SDL_WindowUserData *data; 111 112 void *driverdata; 113 114 SDL_Window *prev; 115 SDL_Window *next; 116 }; 117 #define FULLSCREEN_VISIBLE(W) \ 118 (((W)->flags & SDL_WINDOW_FULLSCREEN) && \ 119 ((W)->flags & SDL_WINDOW_SHOWN) && \ 120 !((W)->flags & SDL_WINDOW_MINIMIZED)) 121 122 /* 123 * Define the SDL display structure. 124 * This corresponds to physical monitors attached to the system. 125 */ 126 struct SDL_VideoDisplay 127 { 128 char *name; 129 int max_display_modes; 130 int num_display_modes; 131 SDL_DisplayMode *display_modes; 132 SDL_DisplayMode desktop_mode; 133 SDL_DisplayMode current_mode; 134 SDL_DisplayOrientation orientation; 135 136 SDL_Window *fullscreen_window; 137 138 SDL_VideoDevice *device; 139 140 void *driverdata; 141 }; 142 143 /* Forward declaration */ 144 struct SDL_SysWMinfo; 145 146 /* Define the SDL video driver structure */ 147 #define _THIS SDL_VideoDevice *_this 148 149 struct SDL_VideoDevice 150 { 151 /* * * */ 152 /* The name of this video driver */ 153 const char *name; 154 155 /* * * */ 156 /* Initialization/Query functions */ 157 158 /* 159 * Initialize the native video subsystem, filling in the list of 160 * displays for this driver, returning 0 or -1 if there's an error. 161 */ 162 int (*VideoInit) (_THIS); 163 164 /* 165 * Reverse the effects VideoInit() -- called if VideoInit() fails or 166 * if the application is shutting down the video subsystem. 167 */ 168 void (*VideoQuit) (_THIS); 169 170 /* 171 * Reinitialize the touch devices -- called if an unknown touch ID occurs. 172 */ 173 void (*ResetTouch) (_THIS); 174 175 /* * * */ 176 /* 177 * Display functions 178 */ 179 180 /* 181 * Get the bounds of a display 182 */ 183 int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); 184 185 /* 186 * Get the usable bounds of a display (bounds minus menubar or whatever) 187 */ 188 int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); 189 190 /* 191 * Get the dots/pixels-per-inch of a display 192 */ 193 int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi); 194 195 /* 196 * Get a list of the available display modes for a display. 197 */ 198 void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display); 199 200 /* 201 * Setting the display mode is independent of creating windows, so 202 * when the display mode is changed, all existing windows should have 203 * their data updated accordingly, including the display surfaces 204 * associated with them. 205 */ 206 int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); 207 208 /* * * */ 209 /* 210 * Window functions 211 */ 212 int (*CreateSDLWindow) (_THIS, SDL_Window * window); 213 int (*CreateSDLWindowFrom) (_THIS, SDL_Window * window, const void *data); 214 void (*SetWindowTitle) (_THIS, SDL_Window * window); 215 void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon); 216 void (*SetWindowPosition) (_THIS, SDL_Window * window); 217 void (*SetWindowSize) (_THIS, SDL_Window * window); 218 void (*SetWindowMinimumSize) (_THIS, SDL_Window * window); 219 void (*SetWindowMaximumSize) (_THIS, SDL_Window * window); 220 int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right); 221 int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity); 222 int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window); 223 int (*SetWindowInputFocus) (_THIS, SDL_Window * window); 224 void (*ShowWindow) (_THIS, SDL_Window * window); 225 void (*HideWindow) (_THIS, SDL_Window * window); 226 void (*RaiseWindow) (_THIS, SDL_Window * window); 227 void (*MaximizeWindow) (_THIS, SDL_Window * window); 228 void (*MinimizeWindow) (_THIS, SDL_Window * window); 229 void (*RestoreWindow) (_THIS, SDL_Window * window); 230 void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered); 231 void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable); 232 void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen); 233 int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp); 234 int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp); 235 void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); 236 void (*DestroyWindow) (_THIS, SDL_Window * window); 237 int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); 238 int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); 239 void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window); 240 void (*OnWindowEnter) (_THIS, SDL_Window * window); 241 242 /* * * */ 243 /* 244 * Shaped-window functions 245 */ 246 SDL_ShapeDriver shape_driver; 247 248 /* Get some platform dependent window information */ 249 SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window, 250 struct SDL_SysWMinfo * info); 251 252 /* * * */ 253 /* 254 * OpenGL support 255 */ 256 int (*GL_LoadLibrary) (_THIS, const char *path); 257 void *(*GL_GetProcAddress) (_THIS, const char *proc); 258 void (*GL_UnloadLibrary) (_THIS); 259 SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window); 260 int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context); 261 void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h); 262 int (*GL_SetSwapInterval) (_THIS, int interval); 263 int (*GL_GetSwapInterval) (_THIS); 264 int (*GL_SwapWindow) (_THIS, SDL_Window * window); 265 void (*GL_DeleteContext) (_THIS, SDL_GLContext context); 266 void (*GL_DefaultProfileConfig) (_THIS, int *mask, int *major, int *minor); 267 268 /* * * */ 269 /* 270 * Vulkan support 271 */ 272 int (*Vulkan_LoadLibrary) (_THIS, const char *path); 273 void (*Vulkan_UnloadLibrary) (_THIS); 274 SDL_bool (*Vulkan_GetInstanceExtensions) (_THIS, SDL_Window *window, unsigned *count, const char **names); 275 SDL_bool (*Vulkan_CreateSurface) (_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface); 276 void (*Vulkan_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h); 277 278 /* * * */ 279 /* 280 * Metal support 281 */ 282 SDL_MetalView (*Metal_CreateView) (_THIS, SDL_Window * window); 283 void (*Metal_DestroyView) (_THIS, SDL_MetalView view); 284 void *(*Metal_GetLayer) (_THIS, SDL_MetalView view); 285 void (*Metal_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h); 286 287 /* * * */ 288 /* 289 * Event manager functions 290 */ 291 void (*PumpEvents) (_THIS); 292 293 /* Suspend the screensaver */ 294 void (*SuspendScreenSaver) (_THIS); 295 296 /* Text input */ 297 void (*StartTextInput) (_THIS); 298 void (*StopTextInput) (_THIS); 299 void (*SetTextInputRect) (_THIS, SDL_Rect *rect); 300 301 /* Screen keyboard */ 302 SDL_bool (*HasScreenKeyboardSupport) (_THIS); 303 void (*ShowScreenKeyboard) (_THIS, SDL_Window *window); 304 void (*HideScreenKeyboard) (_THIS, SDL_Window *window); 305 SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window); 306 307 /* Clipboard */ 308 int (*SetClipboardText) (_THIS, const char *text); 309 char * (*GetClipboardText) (_THIS); 310 SDL_bool (*HasClipboardText) (_THIS); 311 312 /* MessageBox */ 313 int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid); 314 315 /* Hit-testing */ 316 int (*SetWindowHitTest)(SDL_Window * window, SDL_bool enabled); 317 318 /* Tell window that app enabled drag'n'drop events */ 319 void (*AcceptDragAndDrop)(SDL_Window * window, SDL_bool accept); 320 321 /* * * */ 322 /* Data common to all drivers */ 323 SDL_bool is_dummy; 324 SDL_bool suspend_screensaver; 325 int num_displays; 326 SDL_VideoDisplay *displays; 327 SDL_Window *windows; 328 SDL_Window *grabbed_window; 329 Uint8 window_magic; 330 Uint32 next_object_id; 331 char *clipboard_text; 332 333 /* * * */ 334 /* Data used by the GL drivers */ 335 struct 336 { 337 int red_size; 338 int green_size; 339 int blue_size; 340 int alpha_size; 341 int depth_size; 342 int buffer_size; 343 int stencil_size; 344 int double_buffer; 345 int accum_red_size; 346 int accum_green_size; 347 int accum_blue_size; 348 int accum_alpha_size; 349 int stereo; 350 int multisamplebuffers; 351 int multisamplesamples; 352 int accelerated; 353 int major_version; 354 int minor_version; 355 int flags; 356 int profile_mask; 357 int share_with_current_context; 358 int release_behavior; 359 int reset_notification; 360 int framebuffer_srgb_capable; 361 int no_error; 362 int retained_backing; 363 int driver_loaded; 364 char driver_path[256]; 365 void *dll_handle; 366 } gl_config; 367 368 /* * * */ 369 /* Cache current GL context; don't call the OS when it hasn't changed. */ 370 /* We have the global pointers here so Cocoa continues to work the way 371 it always has, and the thread-local storage for the general case. 372 */ 373 SDL_Window *current_glwin; 374 SDL_GLContext current_glctx; 375 SDL_TLSID current_glwin_tls; 376 SDL_TLSID current_glctx_tls; 377 378 /* Flag that stores whether it's allowed to call SDL_GL_MakeCurrent() 379 * with a NULL window, but a non-NULL context. (Not allowed in most cases, 380 * except on EGL under some circumstances.) */ 381 SDL_bool gl_allow_no_surface; 382 383 /* * * */ 384 /* Data used by the Vulkan drivers */ 385 struct 386 { 387 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; 388 PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties; 389 int loader_loaded; 390 char loader_path[256]; 391 void *loader_handle; 392 } vulkan_config; 393 394 /* * * */ 395 /* Data private to this driver */ 396 void *driverdata; 397 struct SDL_GLDriverData *gl_data; 398 399 #if SDL_VIDEO_OPENGL_EGL 400 struct SDL_EGL_VideoData *egl_data; 401 #endif 402 403 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 404 struct SDL_PrivateGLESData *gles_data; 405 #endif 406 407 /* * * */ 408 /* The function used to dispose of this structure */ 409 void (*free) (_THIS); 410 }; 411 412 typedef struct VideoBootStrap 413 { 414 const char *name; 415 const char *desc; 416 int (*available) (void); 417 SDL_VideoDevice *(*create) (int devindex); 418 } VideoBootStrap; 419 420 /* Not all of these are available in a given build. Use #ifdefs, etc. */ 421 extern VideoBootStrap COCOA_bootstrap; 422 extern VideoBootStrap X11_bootstrap; 423 extern VideoBootStrap DirectFB_bootstrap; 424 extern VideoBootStrap WINDOWS_bootstrap; 425 extern VideoBootStrap WINRT_bootstrap; 426 extern VideoBootStrap HAIKU_bootstrap; 427 extern VideoBootStrap PND_bootstrap; 428 extern VideoBootStrap UIKIT_bootstrap; 429 extern VideoBootStrap Android_bootstrap; 430 extern VideoBootStrap PSP_bootstrap; 431 extern VideoBootStrap RPI_bootstrap; 432 extern VideoBootStrap KMSDRM_bootstrap; 433 extern VideoBootStrap DUMMY_bootstrap; 434 extern VideoBootStrap Wayland_bootstrap; 435 extern VideoBootStrap NACL_bootstrap; 436 extern VideoBootStrap VIVANTE_bootstrap; 437 extern VideoBootStrap Emscripten_bootstrap; 438 extern VideoBootStrap QNX_bootstrap; 439 extern VideoBootStrap OFFSCREEN_bootstrap; 440 extern VideoBootStrap AliOS_bootstrap; 441 442 extern SDL_VideoDevice *SDL_GetVideoDevice(void); 443 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); 444 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); 445 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode); 446 extern int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display); 447 extern SDL_VideoDisplay *SDL_GetDisplay(int displayIndex); 448 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window); 449 extern void *SDL_GetDisplayDriverData( int displayIndex ); 450 extern SDL_bool SDL_IsVideoContextExternal(void); 451 452 extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor); 453 454 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); 455 extern SDL_bool SDL_HasWindows(void); 456 457 extern void SDL_OnWindowShown(SDL_Window * window); 458 extern void SDL_OnWindowHidden(SDL_Window * window); 459 extern void SDL_OnWindowResized(SDL_Window * window); 460 extern void SDL_OnWindowMinimized(SDL_Window * window); 461 extern void SDL_OnWindowRestored(SDL_Window * window); 462 extern void SDL_OnWindowEnter(SDL_Window * window); 463 extern void SDL_OnWindowLeave(SDL_Window * window); 464 extern void SDL_OnWindowFocusGained(SDL_Window * window); 465 extern void SDL_OnWindowFocusLost(SDL_Window * window); 466 extern void SDL_UpdateWindowGrab(SDL_Window * window); 467 extern SDL_Window * SDL_GetFocusWindow(void); 468 469 extern SDL_bool SDL_ShouldAllowTopmost(void); 470 471 extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches); 472 473 extern void SDL_ToggleDragAndDropSupport(void); 474 475 #endif /* SDL_sysvideo_h_ */ 476 477 /* vi: set ts=4 sw=4 expandtab: */ 478