src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 30 Jun 2006 05:42:49 +0000
branchSDL-1.3
changeset 1720 a1ebb17f9c52
parent 1712 931d111e737a
child 1725 98a3207ddde8
permissions -rw-r--r--
Cleaned up a bunch of warnings, started adding Win32 event support
     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 
    29 /* The SDL video driver */
    30 
    31 typedef struct SDL_Window SDL_Window;
    32 typedef struct SDL_Texture SDL_Texture;
    33 typedef struct SDL_Renderer SDL_Renderer;
    34 typedef struct SDL_RenderDriver SDL_RenderDriver;
    35 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    36 typedef struct SDL_VideoDevice SDL_VideoDevice;
    37 
    38 /* Define the SDL texture structure */
    39 struct SDL_Texture
    40 {
    41     Uint32 id;
    42 
    43     Uint32 format;      /**< The pixel format of the texture */
    44     int access;         /**< SDL_TextureAccess */
    45     int w;              /**< The width of the texture */
    46     int h;              /**< The height of the texture */
    47 
    48     SDL_Renderer *renderer;
    49 
    50     void *driverdata;   /**< Driver specific texture representation */
    51 
    52     SDL_Texture *next;
    53 };
    54 
    55 /* Define the SDL renderer structure */
    56 struct SDL_Renderer
    57 {
    58     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    59     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    60                                void **pixels, int *pitch);
    61     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    62                               const SDL_Color * colors, int firstcolor,
    63                               int ncolors);
    64     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    65                               SDL_Color * colors, int firstcolor,
    66                               int ncolors);
    67     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    68                           const SDL_Rect * rect, const void *pixels,
    69                           int pitch);
    70     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    71                         const SDL_Rect * rect, int markDirty, void **pixels,
    72                         int *pitch);
    73     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    74     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    75                           int numrects, const SDL_Rect * rects);
    76     void (*SelectRenderTexture) (SDL_Renderer * renderer,
    77                                  SDL_Texture * texture);
    78     int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
    79                        Uint32 color);
    80     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    81                        const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    82                        int blendMode, int scaleMode);
    83     int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    84                              void *pixels, int pitch);
    85     int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    86                               const void *pixels, int pitch);
    87     void (*RenderPresent) (SDL_Renderer * renderer);
    88     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    89 
    90     void (*DestroyRenderer) (SDL_Renderer * renderer);
    91 
    92     /* The current renderer info */
    93     SDL_RendererInfo info;
    94 
    95     /* The window associated with the renderer */
    96     SDL_WindowID window;
    97 
    98     void *driverdata;
    99 };
   100 
   101 /* Define the SDL render driver structure */
   102 struct SDL_RenderDriver
   103 {
   104     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   105 
   106     /* Info about the renderer capabilities */
   107     SDL_RendererInfo info;
   108 };
   109 
   110 /* Define the SDL window structure, corresponding to toplevel windows */
   111 struct SDL_Window
   112 {
   113     Uint32 id;
   114 
   115     char *title;
   116     int x, y;
   117     int w, h;
   118     Uint32 flags;
   119 
   120     Uint16 *gamma;
   121 
   122     int display;
   123     SDL_Renderer *renderer;
   124 
   125     void *userdata;
   126     void *driverdata;
   127 };
   128 
   129 /* Define the SDL display structure
   130    This corresponds to physical monitors attached to the system.
   131  */
   132 struct SDL_VideoDisplay
   133 {
   134     int num_display_modes;
   135     SDL_DisplayMode *display_modes;
   136     SDL_DisplayMode desktop_mode;
   137     SDL_DisplayMode current_mode;
   138     SDL_Palette *palette;
   139 
   140     int num_render_drivers;
   141     SDL_RenderDriver *render_drivers;
   142 
   143     int num_windows;
   144     SDL_Window *windows;
   145 
   146     SDL_Renderer *current_renderer;
   147 
   148     /* The hash list of textures */
   149     SDL_Texture *textures[64];
   150 
   151     SDL_VideoDevice *device;
   152 
   153     void *driverdata;
   154 };
   155 
   156 /* Define the SDL video driver structure */
   157 #define _THIS	SDL_VideoDevice *_this
   158 
   159 struct SDL_VideoDevice
   160 {
   161     /* * * */
   162     /* The name of this video driver */
   163     const char *name;
   164 
   165     /* * * */
   166     /* Initialization/Query functions */
   167 
   168     /* Initialize the native video subsystem, filling in the list
   169        of displays for this driver, returning 0 or -1 if there's an error.
   170      */
   171     int (*VideoInit) (_THIS);
   172 
   173     /* * * */
   174     /* Display functions
   175      */
   176     /* Setting the display mode is independent of creating windows,
   177      * so when the display mode is changed, all existing windows
   178      * should have their data updated accordingly, including the
   179      * display surfaces associated with them.
   180      */
   181     int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
   182 
   183     /* Sets the color entries of the display palette to those in 'colors'.
   184        The return value is 0 if all entries could be set properly or -1
   185        otherwise.
   186      */
   187     int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   188 
   189     /* * * */
   190     /* Window functions
   191      */
   192     int (*CreateWindow) (_THIS, SDL_Window * window);
   193     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   194     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   195     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   196     void (*SetWindowSize) (_THIS, SDL_Window * window);
   197     void (*ShowWindow) (_THIS, SDL_Window * window);
   198     void (*HideWindow) (_THIS, SDL_Window * window);
   199     void (*RaiseWindow) (_THIS, SDL_Window * window);
   200     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   201     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   202     void (*RestoreWindow) (_THIS, SDL_Window * window);
   203     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   204     void (*DestroyWindow) (_THIS, SDL_Window * window);
   205 
   206     /* Get some platform dependent window information */
   207       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   208                                   struct SDL_SysWMinfo * info);
   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     /* Gamma support */
   217 
   218     /* Set the gamma correction directly (emulated with gamma ramps) */
   219     int (*SetGamma) (_THIS, float red, float green, float blue);
   220 
   221     /* Get the gamma correction directly (emulated with gamma ramps) */
   222     int (*GetGamma) (_THIS, float *red, float *green, float *blue);
   223 
   224     /* Set the gamma ramp */
   225     int (*SetGammaRamp) (_THIS, Uint16 * ramp);
   226 
   227     /* Get the gamma ramp */
   228     int (*GetGammaRamp) (_THIS, Uint16 * ramp);
   229 
   230     /* * * */
   231     /* OpenGL support */
   232 
   233     /* Sets the dll to use for OpenGL and loads it */
   234     int (*GL_LoadLibrary) (_THIS, const char *path);
   235 
   236     /* Retrieves the address of a function in the gl library */
   237     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   238 
   239     /* Get attribute information from the windowing system. */
   240     int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
   241 
   242     /* Make the context associated with this driver current */
   243     int (*GL_MakeCurrent) (_THIS);
   244 
   245     /* Swap the current buffers in double buffer mode. */
   246     void (*GL_SwapBuffers) (_THIS);
   247 
   248     /* Determine whether the mouse should be in relative mode or not.
   249        This function is called when the input grab state or cursor
   250        visibility state changes.
   251        If the cursor is not visible, and the input is grabbed, the
   252        driver can place the mouse in relative mode, which may result
   253        in higher accuracy sampling of the pointer motion.
   254      */
   255     void (*CheckMouseMode) (_THIS);
   256 
   257     /* * * */
   258     /* Event manager functions */
   259 
   260     /* Handle any queued OS events */
   261     void (*PumpEvents) (_THIS);
   262 
   263     /* * * */
   264     /* Data common to all drivers */
   265     int num_displays;
   266     SDL_VideoDisplay *displays;
   267     int current_display;
   268     Uint32 next_object_id;
   269 
   270     /* Driver information flags */
   271 
   272     /* * * */
   273     /* Data used by the GL drivers */
   274     struct
   275     {
   276         int red_size;
   277         int green_size;
   278         int blue_size;
   279         int alpha_size;
   280         int depth_size;
   281         int buffer_size;
   282         int stencil_size;
   283         int double_buffer;
   284         int accum_red_size;
   285         int accum_green_size;
   286         int accum_blue_size;
   287         int accum_alpha_size;
   288         int stereo;
   289         int multisamplebuffers;
   290         int multisamplesamples;
   291         int accelerated;
   292         int swap_control;
   293         int driver_loaded;
   294         char driver_path[256];
   295         void *dll_handle;
   296     } gl_config;
   297 
   298     /* * * */
   299     /* Data private to this driver */
   300     void *driverdata;
   301     struct SDL_PrivateGLData *gl_data;
   302 
   303     /* * * */
   304     /* The function used to dispose of this structure */
   305     void (*free) (_THIS);
   306 };
   307 
   308 typedef struct VideoBootStrap
   309 {
   310     const char *name;
   311     const char *desc;
   312     int (*available) (void);
   313     SDL_VideoDevice *(*create) (int devindex);
   314 } VideoBootStrap;
   315 
   316 #if SDL_VIDEO_DRIVER_QUARTZ
   317 extern VideoBootStrap QZ_bootstrap;
   318 #endif
   319 #if SDL_VIDEO_DRIVER_X11
   320 extern VideoBootStrap X11_bootstrap;
   321 #endif
   322 #if SDL_VIDEO_DRIVER_DGA
   323 extern VideoBootStrap DGA_bootstrap;
   324 #endif
   325 #if SDL_VIDEO_DRIVER_NANOX
   326 extern VideoBootStrap NX_bootstrap;
   327 #endif
   328 #if SDL_VIDEO_DRIVER_IPOD
   329 extern VideoBootStrap iPod_bootstrap;
   330 #endif
   331 #if SDL_VIDEO_DRIVER_QTOPIA
   332 extern VideoBootStrap Qtopia_bootstrap;
   333 #endif
   334 #if SDL_VIDEO_DRIVER_WSCONS
   335 extern VideoBootStrap WSCONS_bootstrap;
   336 #endif
   337 #if SDL_VIDEO_DRIVER_FBCON
   338 extern VideoBootStrap FBCON_bootstrap;
   339 #endif
   340 #if SDL_VIDEO_DRIVER_DIRECTFB
   341 extern VideoBootStrap DirectFB_bootstrap;
   342 #endif
   343 #if SDL_VIDEO_DRIVER_PS2GS
   344 extern VideoBootStrap PS2GS_bootstrap;
   345 #endif
   346 #if SDL_VIDEO_DRIVER_GGI
   347 extern VideoBootStrap GGI_bootstrap;
   348 #endif
   349 #if SDL_VIDEO_DRIVER_VGL
   350 extern VideoBootStrap VGL_bootstrap;
   351 #endif
   352 #if SDL_VIDEO_DRIVER_SVGALIB
   353 extern VideoBootStrap SVGALIB_bootstrap;
   354 #endif
   355 #if SDL_VIDEO_DRIVER_GAPI
   356 extern VideoBootStrap GAPI_bootstrap;
   357 #endif
   358 #if SDL_VIDEO_DRIVER_WIN32
   359 extern VideoBootStrap WIN32_bootstrap;
   360 #endif
   361 #if SDL_VIDEO_DRIVER_BWINDOW
   362 extern VideoBootStrap BWINDOW_bootstrap;
   363 #endif
   364 #if SDL_VIDEO_DRIVER_TOOLBOX
   365 extern VideoBootStrap TOOLBOX_bootstrap;
   366 #endif
   367 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   368 extern VideoBootStrap DSp_bootstrap;
   369 #endif
   370 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   371 extern VideoBootStrap CGX_bootstrap;
   372 #endif
   373 #if SDL_VIDEO_DRIVER_PHOTON
   374 extern VideoBootStrap ph_bootstrap;
   375 #endif
   376 #if SDL_VIDEO_DRIVER_EPOC
   377 extern VideoBootStrap EPOC_bootstrap;
   378 #endif
   379 #if SDL_VIDEO_DRIVER_XBIOS
   380 extern VideoBootStrap XBIOS_bootstrap;
   381 #endif
   382 #if SDL_VIDEO_DRIVER_GEM
   383 extern VideoBootStrap GEM_bootstrap;
   384 #endif
   385 #if SDL_VIDEO_DRIVER_PICOGUI
   386 extern VideoBootStrap PG_bootstrap;
   387 #endif
   388 #if SDL_VIDEO_DRIVER_DC
   389 extern VideoBootStrap DC_bootstrap;
   390 #endif
   391 #if SDL_VIDEO_DRIVER_RISCOS
   392 extern VideoBootStrap RISCOS_bootstrap;
   393 #endif
   394 #if SDL_VIDEO_DRIVER_OS2FS
   395 extern VideoBootStrap OS2FSLib_bootstrap;
   396 #endif
   397 #if SDL_VIDEO_DRIVER_AALIB
   398 extern VideoBootStrap AALIB_bootstrap;
   399 #endif
   400 #if SDL_VIDEO_DRIVER_DUMMY
   401 extern VideoBootStrap DUMMY_bootstrap;
   402 #endif
   403 #if SDL_VIDEO_DRIVER_GLSDL
   404 extern VideoBootStrap glSDL_bootstrap;
   405 #endif
   406 
   407 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   408 #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
   409 
   410 extern SDL_VideoDevice *SDL_GetVideoDevice();
   411 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   412 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   413 extern void SDL_AddDisplayMode(int displayIndex,
   414                                const SDL_DisplayMode * mode);
   415 extern void SDL_AddRenderDriver(int displayIndex,
   416                                 const SDL_RenderDriver * driver);
   417 
   418 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   419 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   420 
   421 #endif /* _SDL_sysvideo_h */
   422 
   423 /* vi: set ts=4 sw=4 expandtab: */