src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Feb 2011 14:34:54 -0800
changeset 5154 fb424691cfc7
parent 5150 1435f8a6425c
child 5165 2b1989f59674
permissions -rw-r--r--
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifndef _SDL_sysvideo_h
    25 #define _SDL_sysvideo_h
    26 
    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 /* Define the SDL window structure, corresponding to toplevel windows */
    63 struct SDL_Window
    64 {
    65     const void *magic;
    66     Uint32 id;
    67     char *title;
    68     int x, y;
    69     int w, h;
    70     Uint32 flags;
    71 
    72     SDL_VideoDisplay *display;
    73 
    74     SDL_DisplayMode fullscreen_mode;
    75     
    76     SDL_WindowShaper *shaper;
    77 
    78     void *userdata;
    79     void *driverdata;
    80 
    81     SDL_Window *prev;
    82     SDL_Window *next;
    83 };
    84 #define FULLSCREEN_VISIBLE(W) \
    85     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
    86      ((W)->flags & SDL_WINDOW_SHOWN) && \
    87      !((W)->flags & SDL_WINDOW_MINIMIZED))
    88 
    89 /*
    90  * Define the SDL display structure This corresponds to physical monitors
    91  * attached to the system.
    92  */
    93 struct SDL_VideoDisplay
    94 {
    95     int max_display_modes;
    96     int num_display_modes;
    97     SDL_DisplayMode *display_modes;
    98     SDL_DisplayMode desktop_mode;
    99     SDL_DisplayMode current_mode;
   100     SDL_bool updating_fullscreen;
   101 
   102     Uint16 *gamma;
   103     Uint16 *saved_gamma;        /* (just offset into gamma) */
   104 
   105     SDL_Window *windows;
   106     SDL_Window *fullscreen_window;
   107 
   108     SDL_VideoDevice *device;
   109 
   110     void *driverdata;
   111 };
   112 
   113 /* Define the SDL video driver structure */
   114 #define _THIS	SDL_VideoDevice *_this
   115 
   116 struct SDL_VideoDevice
   117 {
   118     /* * * */
   119     /* The name of this video driver */
   120     const char *name;
   121 
   122     /* * * */
   123     /* Initialization/Query functions */
   124 
   125     /*
   126      * Initialize the native video subsystem, filling in the list of
   127      * displays for this driver, returning 0 or -1 if there's an error.
   128      */
   129     int (*VideoInit) (_THIS);
   130 
   131     /*
   132      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   133      * if the application is shutting down the video subsystem.
   134      */
   135     void (*VideoQuit) (_THIS);
   136 
   137     /* * * */
   138     /*
   139      * Display functions
   140      */
   141 
   142     /*
   143      * Get the bounds of a display
   144      */
   145     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   146 
   147     /*
   148      * Get a list of the available display modes. e.g.
   149      * SDL_AddDisplayMode(_this->current_display, mode)
   150      */
   151     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   152 
   153     /*
   154      * Setting the display mode is independent of creating windows, so
   155      * when the display mode is changed, all existing windows should have
   156      * their data updated accordingly, including the display surfaces
   157      * associated with them.
   158      */
   159     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   160 
   161     /* Set the gamma ramp */
   162     int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   163 
   164     /* Get the gamma ramp */
   165     int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   166 
   167     /* * * */
   168     /*
   169      * Window functions
   170      */
   171     int (*CreateWindow) (_THIS, SDL_Window * window);
   172     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   173     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   174     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   175     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   176     void (*SetWindowSize) (_THIS, SDL_Window * window);
   177     void (*ShowWindow) (_THIS, SDL_Window * window);
   178     void (*HideWindow) (_THIS, SDL_Window * window);
   179     void (*RaiseWindow) (_THIS, SDL_Window * window);
   180     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   181     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   182     void (*RestoreWindow) (_THIS, SDL_Window * window);
   183     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   184     void (*DestroyWindow) (_THIS, SDL_Window * window);
   185     
   186     /* * * */
   187     /*
   188      * Shaped-window functions
   189      */
   190     SDL_ShapeDriver shape_driver;
   191 
   192     /* Get some platform dependent window information */
   193       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   194                                   struct SDL_SysWMinfo * info);
   195 
   196     /* * * */
   197     /*
   198      * OpenGL support
   199      */
   200     int (*GL_LoadLibrary) (_THIS, const char *path);
   201     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   202     void (*GL_UnloadLibrary) (_THIS);
   203       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   204     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   205     int (*GL_SetSwapInterval) (_THIS, int interval);
   206     int (*GL_GetSwapInterval) (_THIS);
   207     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   208     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   209 
   210     /* * * */
   211     /*
   212      * Event manager functions
   213      */
   214     void (*PumpEvents) (_THIS);
   215 
   216     /* Suspend the screensaver */
   217     void (*SuspendScreenSaver) (_THIS);
   218 
   219     /* Text input */
   220     void (*StartTextInput) (_THIS);
   221     void (*StopTextInput) (_THIS);
   222     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   223 
   224     /* Clipboard */
   225     int (*SetClipboardText) (_THIS, const char *text);
   226     char * (*GetClipboardText) (_THIS);
   227     SDL_bool (*HasClipboardText) (_THIS);
   228 
   229     /* * * */
   230     /* Data common to all drivers */
   231     SDL_bool suspend_screensaver;
   232     int num_displays;
   233     SDL_VideoDisplay *displays;
   234     int current_display;
   235     Uint8 window_magic;
   236     Uint32 next_object_id;
   237     char * clipboard_text;
   238 
   239     /* * * */
   240     /* Data used by the GL drivers */
   241     struct
   242     {
   243         int red_size;
   244         int green_size;
   245         int blue_size;
   246         int alpha_size;
   247         int depth_size;
   248         int buffer_size;
   249         int stencil_size;
   250         int double_buffer;
   251         int accum_red_size;
   252         int accum_green_size;
   253         int accum_blue_size;
   254         int accum_alpha_size;
   255         int stereo;
   256         int multisamplebuffers;
   257         int multisamplesamples;
   258         int accelerated;
   259         int major_version;
   260         int minor_version;
   261         int retained_backing;
   262         int driver_loaded;
   263         char driver_path[256];
   264         void *dll_handle;
   265     } gl_config;
   266 
   267     /* * * */
   268     /* Data private to this driver */
   269     void *driverdata;
   270     struct SDL_GLDriverData *gl_data;
   271 
   272 #if SDL_VIDEO_DRIVER_PANDORA
   273     struct SDL_PrivateGLESData *gles_data;
   274 #endif
   275 
   276     /* * * */
   277     /* The function used to dispose of this structure */
   278     void (*free) (_THIS);
   279 };
   280 
   281 typedef struct VideoBootStrap
   282 {
   283     const char *name;
   284     const char *desc;
   285     int (*available) (void);
   286     SDL_VideoDevice *(*create) (int devindex);
   287 } VideoBootStrap;
   288 
   289 #if SDL_VIDEO_DRIVER_COCOA
   290 extern VideoBootStrap COCOA_bootstrap;
   291 #endif
   292 #if SDL_VIDEO_DRIVER_X11
   293 extern VideoBootStrap X11_bootstrap;
   294 #endif
   295 #if SDL_VIDEO_DRIVER_DIRECTFB
   296 extern VideoBootStrap DirectFB_bootstrap;
   297 #endif
   298 #if SDL_VIDEO_DRIVER_WINDOWS
   299 extern VideoBootStrap WINDOWS_bootstrap;
   300 #endif
   301 #if SDL_VIDEO_DRIVER_BWINDOW
   302 extern VideoBootStrap BWINDOW_bootstrap;
   303 #endif
   304 #if SDL_VIDEO_DRIVER_PANDORA
   305 extern VideoBootStrap PND_bootstrap;
   306 #endif
   307 #if SDL_VIDEO_DRIVER_NDS
   308 extern VideoBootStrap NDS_bootstrap;
   309 #endif
   310 #if SDL_VIDEO_DRIVER_UIKIT
   311 extern VideoBootStrap UIKIT_bootstrap;
   312 #endif
   313 #if SDL_VIDEO_DRIVER_ANDROID
   314 extern VideoBootStrap Android_bootstrap;
   315 #endif
   316 #if SDL_VIDEO_DRIVER_DUMMY
   317 extern VideoBootStrap DUMMY_bootstrap;
   318 #endif
   319 
   320 #define SDL_CurrentDisplay	(&_this->displays[_this->current_display])
   321 
   322 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   323 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   324 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   325 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   326 extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
   327 extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
   328 extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   329 extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   330 extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
   331 extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
   332 extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue);
   333 extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue);
   334 
   335 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   336 
   337 extern void SDL_OnWindowShown(SDL_Window * window);
   338 extern void SDL_OnWindowHidden(SDL_Window * window);
   339 extern void SDL_OnWindowMinimized(SDL_Window * window);
   340 extern void SDL_OnWindowRestored(SDL_Window * window);
   341 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   342 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   343 extern SDL_Window * SDL_GetFocusWindow(void);
   344 
   345 #endif /* _SDL_sysvideo_h */
   346 
   347 /* vi: set ts=4 sw=4 expandtab: */