src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 09 Jun 2006 06:42:42 +0000
branchSDL-1.3
changeset 1671 89f7510fe17a
parent 1670 eef792d31de8
child 1673 624e1412fbba
permissions -rw-r--r--
Moved the cursor handling into the mouse code.
Added support for multiple mice, potentially dynamically added and removed.
     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     /* Determine whether the mouse should be in relative mode or not.
   295        This function is called when the input grab state or cursor
   296        visibility state changes.
   297        If the cursor is not visible, and the input is grabbed, the
   298        driver can place the mouse in relative mode, which may result
   299        in higher accuracy sampling of the pointer motion.
   300      */
   301     void (*CheckMouseMode) (_THIS);
   302 
   303     /* * * */
   304     /* Event manager functions */
   305 
   306     /* Initialize keyboard mapping for this driver */
   307     void (*InitOSKeymap) (_THIS);
   308 
   309     /* Handle any queued OS events */
   310     void (*PumpEvents) (_THIS);
   311 
   312     /* * * */
   313     /* Data common to all drivers */
   314     int num_displays;
   315     SDL_VideoDisplay *displays;
   316     int current_display;
   317     Uint32 next_object_id;
   318 
   319     /* Driver information flags */
   320 
   321     /* * * */
   322     /* Data used by the GL drivers */
   323     struct
   324     {
   325         int red_size;
   326         int green_size;
   327         int blue_size;
   328         int alpha_size;
   329         int depth_size;
   330         int buffer_size;
   331         int stencil_size;
   332         int double_buffer;
   333         int accum_red_size;
   334         int accum_green_size;
   335         int accum_blue_size;
   336         int accum_alpha_size;
   337         int stereo;
   338         int multisamplebuffers;
   339         int multisamplesamples;
   340         int accelerated;
   341         int swap_control;
   342         int driver_loaded;
   343         char driver_path[256];
   344         void *dll_handle;
   345     } gl_config;
   346 
   347     /* * * */
   348     /* Data private to this driver */
   349     struct SDL_PrivateVideoData *hidden;
   350     struct SDL_PrivateGLData *gl_data;
   351 
   352     /* * * */
   353     /* The function used to dispose of this structure */
   354     void (*free) (_THIS);
   355 };
   356 #undef _THIS
   357 
   358 typedef struct VideoBootStrap
   359 {
   360     const char *name;
   361     const char *desc;
   362     int (*available) (void);
   363     SDL_VideoDevice *(*create) (int devindex);
   364 } VideoBootStrap;
   365 
   366 #if SDL_VIDEO_DRIVER_QUARTZ
   367 extern VideoBootStrap QZ_bootstrap;
   368 #endif
   369 #if SDL_VIDEO_DRIVER_X11
   370 extern VideoBootStrap X11_bootstrap;
   371 #endif
   372 #if SDL_VIDEO_DRIVER_DGA
   373 extern VideoBootStrap DGA_bootstrap;
   374 #endif
   375 #if SDL_VIDEO_DRIVER_NANOX
   376 extern VideoBootStrap NX_bootstrap;
   377 #endif
   378 #if SDL_VIDEO_DRIVER_IPOD
   379 extern VideoBootStrap iPod_bootstrap;
   380 #endif
   381 #if SDL_VIDEO_DRIVER_QTOPIA
   382 extern VideoBootStrap Qtopia_bootstrap;
   383 #endif
   384 #if SDL_VIDEO_DRIVER_WSCONS
   385 extern VideoBootStrap WSCONS_bootstrap;
   386 #endif
   387 #if SDL_VIDEO_DRIVER_FBCON
   388 extern VideoBootStrap FBCON_bootstrap;
   389 #endif
   390 #if SDL_VIDEO_DRIVER_DIRECTFB
   391 extern VideoBootStrap DirectFB_bootstrap;
   392 #endif
   393 #if SDL_VIDEO_DRIVER_PS2GS
   394 extern VideoBootStrap PS2GS_bootstrap;
   395 #endif
   396 #if SDL_VIDEO_DRIVER_GGI
   397 extern VideoBootStrap GGI_bootstrap;
   398 #endif
   399 #if SDL_VIDEO_DRIVER_VGL
   400 extern VideoBootStrap VGL_bootstrap;
   401 #endif
   402 #if SDL_VIDEO_DRIVER_SVGALIB
   403 extern VideoBootStrap SVGALIB_bootstrap;
   404 #endif
   405 #if SDL_VIDEO_DRIVER_GAPI
   406 extern VideoBootStrap GAPI_bootstrap;
   407 #endif
   408 #if SDL_VIDEO_DRIVER_WINDIB
   409 extern VideoBootStrap WINDIB_bootstrap;
   410 #endif
   411 #if SDL_VIDEO_DRIVER_DDRAW
   412 extern VideoBootStrap DIRECTX_bootstrap;
   413 #endif
   414 #if SDL_VIDEO_DRIVER_BWINDOW
   415 extern VideoBootStrap BWINDOW_bootstrap;
   416 #endif
   417 #if SDL_VIDEO_DRIVER_TOOLBOX
   418 extern VideoBootStrap TOOLBOX_bootstrap;
   419 #endif
   420 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   421 extern VideoBootStrap DSp_bootstrap;
   422 #endif
   423 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   424 extern VideoBootStrap CGX_bootstrap;
   425 #endif
   426 #if SDL_VIDEO_DRIVER_PHOTON
   427 extern VideoBootStrap ph_bootstrap;
   428 #endif
   429 #if SDL_VIDEO_DRIVER_EPOC
   430 extern VideoBootStrap EPOC_bootstrap;
   431 #endif
   432 #if SDL_VIDEO_DRIVER_XBIOS
   433 extern VideoBootStrap XBIOS_bootstrap;
   434 #endif
   435 #if SDL_VIDEO_DRIVER_GEM
   436 extern VideoBootStrap GEM_bootstrap;
   437 #endif
   438 #if SDL_VIDEO_DRIVER_PICOGUI
   439 extern VideoBootStrap PG_bootstrap;
   440 #endif
   441 #if SDL_VIDEO_DRIVER_DC
   442 extern VideoBootStrap DC_bootstrap;
   443 #endif
   444 #if SDL_VIDEO_DRIVER_RISCOS
   445 extern VideoBootStrap RISCOS_bootstrap;
   446 #endif
   447 #if SDL_VIDEO_DRIVER_OS2FS
   448 extern VideoBootStrap OS2FSLib_bootstrap;
   449 #endif
   450 #if SDL_VIDEO_DRIVER_AALIB
   451 extern VideoBootStrap AALIB_bootstrap;
   452 #endif
   453 #if SDL_VIDEO_DRIVER_DUMMY
   454 extern VideoBootStrap DUMMY_bootstrap;
   455 #endif
   456 #if SDL_VIDEO_DRIVER_GLSDL
   457 extern VideoBootStrap glSDL_bootstrap;
   458 #endif
   459 
   460 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   461 #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
   462 
   463 extern SDL_VideoDevice *SDL_GetVideoDevice();
   464 extern void SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   465 extern void SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   466 extern void SDL_AddDisplayMode(int displayIndex,
   467                                const SDL_DisplayMode * mode);
   468 extern void SDL_AddRenderDriver(int displayIndex,
   469                                 const SDL_RenderDriver * driver);
   470 
   471 #endif /* _SDL_sysvideo_h */
   472 
   473 /* vi: set ts=4 sw=4 expandtab: */