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