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