src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1658 e49147870aac
child 1666 6e7ec5cb83c3
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 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_mouse.h"
    28 #define SDL_PROTOTYPES_ONLY
    29 #include "SDL_syswm.h"
    30 #undef SDL_PROTOTYPES_ONLY
    31 
    32 /* This file prototypes the video driver implementation.
    33    This is designed to be easily converted to C++ in the future.
    34  */
    35 
    36 #if SDL_VIDEO_OPENGL
    37 #include "SDL_opengl.h"
    38 #endif /* SDL_VIDEO_OPENGL */
    39 
    40 /* The SDL video driver */
    41 
    42 /* Define the SDL window structure, corresponding to toplevel windows */
    43 typedef struct SDL_Window SDL_Window;
    44 
    45 struct SDL_Window
    46 {
    47     Uint32 id;
    48 
    49     char *title;
    50     int x, y;
    51     int w, h;
    52     Uint32 flags;
    53 
    54     SDL_Surface *surface;
    55     SDL_Surface *shadow;
    56     Uint16 *gamma;
    57 
    58     void *userdata;
    59     void *driverdata;
    60 };
    61 
    62 /* Define the SDL display structure
    63    This corresponds to physical monitors attached to the system.
    64  */
    65 typedef struct SDL_VideoDisplay
    66 {
    67     int num_display_modes;
    68     SDL_DisplayMode *display_modes;
    69     SDL_DisplayMode desktop_mode;
    70     SDL_DisplayMode current_mode;
    71 
    72     int max_windows;
    73     int num_windows;
    74     SDL_Window *windows;
    75 
    76     void *driverdata;
    77 } SDL_VideoDisplay;
    78 
    79 typedef struct SDL_VideoDevice SDL_VideoDevice;
    80 
    81 /* Define the SDL video driver structure */
    82 #define _THIS	SDL_VideoDevice *_this
    83 
    84 struct SDL_VideoDevice
    85 {
    86     /* * * */
    87     /* The name of this video driver */
    88     const char *name;
    89 
    90     /* * * */
    91     /* Initialization/Query functions */
    92 
    93     /* Initialize the native video subsystem, filling in the list
    94        of displays for this driver, returning 0 or -1 if there's an error.
    95      */
    96     int (*VideoInit) (_THIS);
    97 
    98     /* * * */
    99     /* Display functions
   100      */
   101     /* Setting the display mode is independent of creating windows,
   102      * so when the display mode is changed, all existing windows
   103      * should have their data updated accordingly, including the
   104      * display surfaces associated with them.
   105      */
   106     int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
   107 
   108     /* * * */
   109     /* Window functions
   110      */
   111     int (*CreateWindow) (_THIS, SDL_Window * window);
   112     int (*CreateWindowFrom) (_THIS, SDL_Window * window, void *data);
   113     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   114     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   115     void (*SetWindowSize) (_THIS, SDL_Window * window);
   116     void (*ShowWindow) (_THIS, SDL_Window * window);
   117     void (*HideWindow) (_THIS, SDL_Window * window);
   118     void (*RaiseWindow) (_THIS, SDL_Window * window);
   119     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   120     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   121     void (*RestoreWindow) (_THIS, SDL_Window * window);
   122     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   123     void (*DestroyWindow) (_THIS, SDL_Window * window);
   124 
   125     SDL_Surface *(*CreateWindowSurface) (_THIS, SDL_Window * window);
   126     void (*UpdateWindowSurface) (_THIS, SDL_Window * window, int numrects,
   127                                  SDL_Rect * rects);
   128     void (*FlipWindowSurface) (_THIS, SDL_Window * window);
   129 
   130     /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
   131        of the physical palette to those in 'colors'. If the device is
   132        using a software palette (SDL_HWPALETTE not set), then the
   133        changes are reflected in the logical palette of the screen
   134        as well.
   135        The return value is 1 if all entries could be set properly
   136        or 0 otherwise.
   137      */
   138     int (*SetWindowColors) (_THIS, SDL_Window * window,
   139                             int firstcolor, int ncolors, SDL_Color * colors);
   140 
   141     /* Get some platform dependent window information */
   142       SDL_bool (*GetWindowWMInfo) (_THIS, SDL_Window * window,
   143                                    SDL_SysWMinfo * info);
   144 
   145     /* Create a YUV video surface (possibly overlay) of the given
   146        format.  The hardware should be able to perform at least 2x
   147        scaling on display.
   148      */
   149     SDL_Overlay *(*CreateYUVOverlay) (_THIS, int width, int height,
   150                                       Uint32 format, SDL_Surface * display);
   151 
   152     /* Reverse the effects VideoInit() -- called if VideoInit() fails
   153        or if the application is shutting down the video subsystem.
   154      */
   155     void (*VideoQuit) (_THIS);
   156 
   157     /* * * */
   158     /* Hardware acceleration functions */
   159 
   160     /* Information about the video hardware */
   161     SDL_VideoInfo info;
   162 
   163     /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
   164     SDL_PixelFormat *displayformatalphapixel;
   165 
   166     /* Allocates a surface in video memory */
   167     int (*AllocHWSurface) (_THIS, SDL_Surface * surface);
   168 
   169     /* Sets the hardware accelerated blit function, if any, based
   170        on the current flags of the surface (colorkey, alpha, etc.)
   171      */
   172     int (*CheckHWBlit) (_THIS, SDL_Surface * src, SDL_Surface * dst);
   173 
   174     /* Fills a surface rectangle with the given color */
   175     int (*FillHWRect) (_THIS, SDL_Surface * dst, SDL_Rect * rect,
   176                        Uint32 color);
   177 
   178     /* Sets video mem colorkey and accelerated blit function */
   179     int (*SetHWColorKey) (_THIS, SDL_Surface * surface, Uint32 key);
   180 
   181     /* Sets per surface hardware alpha value */
   182     int (*SetHWAlpha) (_THIS, SDL_Surface * surface, Uint8 value);
   183 
   184     /* Returns a readable/writable surface */
   185     int (*LockHWSurface) (_THIS, SDL_Surface * surface);
   186     void (*UnlockHWSurface) (_THIS, SDL_Surface * surface);
   187 
   188     /* Frees a previously allocated video surface */
   189     void (*FreeHWSurface) (_THIS, SDL_Surface * surface);
   190 
   191     /* * * */
   192     /* Gamma support */
   193 
   194     /* Set the gamma correction directly (emulated with gamma ramps) */
   195     int (*SetGamma) (_THIS, float red, float green, float blue);
   196 
   197     /* Get the gamma correction directly (emulated with gamma ramps) */
   198     int (*GetGamma) (_THIS, float *red, float *green, float *blue);
   199 
   200     /* Set the gamma ramp */
   201     int (*SetGammaRamp) (_THIS, Uint16 * ramp);
   202 
   203     /* Get the gamma ramp */
   204     int (*GetGammaRamp) (_THIS, Uint16 * ramp);
   205 
   206     /* * * */
   207     /* OpenGL support */
   208 
   209     /* Sets the dll to use for OpenGL and loads it */
   210     int (*GL_LoadLibrary) (_THIS, const char *path);
   211 
   212     /* Retrieves the address of a function in the gl library */
   213     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   214 
   215     /* Get attribute information from the windowing system. */
   216     int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
   217 
   218     /* Make the context associated with this driver current */
   219     int (*GL_MakeCurrent) (_THIS);
   220 
   221     /* Swap the current buffers in double buffer mode. */
   222     void (*GL_SwapBuffers) (_THIS);
   223 
   224     /* OpenGL functions for glSDL */
   225 #if SDL_VIDEO_OPENGL
   226 #if !defined(__WIN32__)
   227 #define WINAPI
   228 #endif
   229 #define SDL_PROC(ret,func,params) ret (WINAPI *func) params;
   230 #include "SDL_glfuncs.h"
   231 #undef SDL_PROC
   232 
   233     /* Texture id */
   234     GLuint texture;
   235 
   236     int is_32bit;
   237 #endif
   238 
   239     /* * * */
   240     /* Cursor manager functions */
   241 
   242     /* Free a window manager cursor
   243        This function can be NULL if CreateWMCursor is also NULL.
   244      */
   245     void (*FreeWMCursor) (_THIS, WMcursor * cursor);
   246 
   247     /* If not NULL, create a black/white window manager cursor */
   248     WMcursor *(*CreateWMCursor) (_THIS,
   249                                  Uint8 * data, Uint8 * mask, int w, int h,
   250                                  int hot_x, int hot_y);
   251 
   252     /* Show the specified cursor, or hide if cursor is NULL */
   253     int (*ShowWMCursor) (_THIS, WMcursor * cursor);
   254 
   255     /* Warp the window manager cursor to (x,y)
   256        If NULL, a mouse motion event is posted internally.
   257      */
   258     void (*WarpWMCursor) (_THIS, Uint16 x, Uint16 y);
   259 
   260     /* If not NULL, this is called when a mouse motion event occurs */
   261     void (*MoveWMCursor) (_THIS, int x, int y);
   262 
   263     /* Determine whether the mouse should be in relative mode or not.
   264        This function is called when the input grab state or cursor
   265        visibility state changes.
   266        If the cursor is not visible, and the input is grabbed, the
   267        driver can place the mouse in relative mode, which may result
   268        in higher accuracy sampling of the pointer motion.
   269      */
   270     void (*CheckMouseMode) (_THIS);
   271 
   272     /* * * */
   273     /* Event manager functions */
   274 
   275     /* Initialize keyboard mapping for this driver */
   276     void (*InitOSKeymap) (_THIS);
   277 
   278     /* Handle any queued OS events */
   279     void (*PumpEvents) (_THIS);
   280 
   281     /* * * */
   282     /* Data common to all drivers */
   283     int num_displays;
   284     SDL_VideoDisplay *displays;
   285     int current_display;
   286     Uint32 next_window_id;
   287 
   288     /* Driver information flags */
   289 
   290     /* * * */
   291     /* Data used by the GL drivers */
   292     struct
   293     {
   294         int red_size;
   295         int green_size;
   296         int blue_size;
   297         int alpha_size;
   298         int depth_size;
   299         int buffer_size;
   300         int stencil_size;
   301         int double_buffer;
   302         int accum_red_size;
   303         int accum_green_size;
   304         int accum_blue_size;
   305         int accum_alpha_size;
   306         int stereo;
   307         int multisamplebuffers;
   308         int multisamplesamples;
   309         int accelerated;
   310         int swap_control;
   311         int driver_loaded;
   312         char driver_path[256];
   313         void *dll_handle;
   314     } gl_config;
   315 
   316     /* * * */
   317     /* Data private to this driver */
   318     struct SDL_PrivateVideoData *hidden;
   319     struct SDL_PrivateGLData *gl_data;
   320 
   321     /* * * */
   322     /* The function used to dispose of this structure */
   323     void (*free) (_THIS);
   324 };
   325 #undef _THIS
   326 
   327 typedef struct VideoBootStrap
   328 {
   329     const char *name;
   330     const char *desc;
   331     int (*available) (void);
   332     SDL_VideoDevice *(*create) (int devindex);
   333 } VideoBootStrap;
   334 
   335 #if SDL_VIDEO_DRIVER_QUARTZ
   336 extern VideoBootStrap QZ_bootstrap;
   337 #endif
   338 #if SDL_VIDEO_DRIVER_X11
   339 extern VideoBootStrap X11_bootstrap;
   340 #endif
   341 #if SDL_VIDEO_DRIVER_DGA
   342 extern VideoBootStrap DGA_bootstrap;
   343 #endif
   344 #if SDL_VIDEO_DRIVER_NANOX
   345 extern VideoBootStrap NX_bootstrap;
   346 #endif
   347 #if SDL_VIDEO_DRIVER_IPOD
   348 extern VideoBootStrap iPod_bootstrap;
   349 #endif
   350 #if SDL_VIDEO_DRIVER_QTOPIA
   351 extern VideoBootStrap Qtopia_bootstrap;
   352 #endif
   353 #if SDL_VIDEO_DRIVER_WSCONS
   354 extern VideoBootStrap WSCONS_bootstrap;
   355 #endif
   356 #if SDL_VIDEO_DRIVER_FBCON
   357 extern VideoBootStrap FBCON_bootstrap;
   358 #endif
   359 #if SDL_VIDEO_DRIVER_DIRECTFB
   360 extern VideoBootStrap DirectFB_bootstrap;
   361 #endif
   362 #if SDL_VIDEO_DRIVER_PS2GS
   363 extern VideoBootStrap PS2GS_bootstrap;
   364 #endif
   365 #if SDL_VIDEO_DRIVER_GGI
   366 extern VideoBootStrap GGI_bootstrap;
   367 #endif
   368 #if SDL_VIDEO_DRIVER_VGL
   369 extern VideoBootStrap VGL_bootstrap;
   370 #endif
   371 #if SDL_VIDEO_DRIVER_SVGALIB
   372 extern VideoBootStrap SVGALIB_bootstrap;
   373 #endif
   374 #if SDL_VIDEO_DRIVER_GAPI
   375 extern VideoBootStrap GAPI_bootstrap;
   376 #endif
   377 #if SDL_VIDEO_DRIVER_WINDIB
   378 extern VideoBootStrap WINDIB_bootstrap;
   379 #endif
   380 #if SDL_VIDEO_DRIVER_DDRAW
   381 extern VideoBootStrap DIRECTX_bootstrap;
   382 #endif
   383 #if SDL_VIDEO_DRIVER_BWINDOW
   384 extern VideoBootStrap BWINDOW_bootstrap;
   385 #endif
   386 #if SDL_VIDEO_DRIVER_TOOLBOX
   387 extern VideoBootStrap TOOLBOX_bootstrap;
   388 #endif
   389 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   390 extern VideoBootStrap DSp_bootstrap;
   391 #endif
   392 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   393 extern VideoBootStrap CGX_bootstrap;
   394 #endif
   395 #if SDL_VIDEO_DRIVER_PHOTON
   396 extern VideoBootStrap ph_bootstrap;
   397 #endif
   398 #if SDL_VIDEO_DRIVER_EPOC
   399 extern VideoBootStrap EPOC_bootstrap;
   400 #endif
   401 #if SDL_VIDEO_DRIVER_XBIOS
   402 extern VideoBootStrap XBIOS_bootstrap;
   403 #endif
   404 #if SDL_VIDEO_DRIVER_GEM
   405 extern VideoBootStrap GEM_bootstrap;
   406 #endif
   407 #if SDL_VIDEO_DRIVER_PICOGUI
   408 extern VideoBootStrap PG_bootstrap;
   409 #endif
   410 #if SDL_VIDEO_DRIVER_DC
   411 extern VideoBootStrap DC_bootstrap;
   412 #endif
   413 #if SDL_VIDEO_DRIVER_RISCOS
   414 extern VideoBootStrap RISCOS_bootstrap;
   415 #endif
   416 #if SDL_VIDEO_DRIVER_OS2FS
   417 extern VideoBootStrap OS2FSLib_bootstrap;
   418 #endif
   419 #if SDL_VIDEO_DRIVER_AALIB
   420 extern VideoBootStrap AALIB_bootstrap;
   421 #endif
   422 #if SDL_VIDEO_DRIVER_DUMMY
   423 extern VideoBootStrap DUMMY_bootstrap;
   424 #endif
   425 #if SDL_VIDEO_DRIVER_GLSDL
   426 extern VideoBootStrap glSDL_bootstrap;
   427 #endif
   428 
   429 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   430 #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
   431 #define SDL_VideoSurface	((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.surface : NULL)
   432 #define SDL_ShadowSurface	((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.shadow : NULL)
   433 #define SDL_PublicSurface	(SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface)
   434 
   435 extern SDL_VideoDevice *SDL_GetVideoDevice ();
   436 extern void SDL_AddBasicVideoDisplay (const SDL_DisplayMode * desktop_mode);
   437 extern void SDL_AddVideoDisplay (SDL_VideoDisplay * display);
   438 extern void SDL_AddDisplayMode (int display, const SDL_DisplayMode * mode);
   439 extern SDL_Window *SDL_GetWindowFromSurface (SDL_Surface * surface);
   440 
   441 #endif /* _SDL_sysvideo_h */
   442 
   443 /* vi: set ts=4 sw=4 expandtab: */