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