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