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