src/video/SDL_sysvideo.h
author Jørgen P. Tjernø <jorgen@valvesoftware.com>
Wed, 15 Jan 2014 11:17:09 -0800
changeset 8110 98646f687e2b
parent 8093 b43765095a6f
child 8112 257daea8ac11
permissions -rw-r--r--
Allow switching between FS and desktop FS.

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