src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 26 Jul 2006 03:12:05 +0000
changeset 1942 4371d679ee12
parent 1941 bf09d535e014
child 1944 91f41fc124a7
permissions -rw-r--r--
Hopefully glSDL has been superceded by the OpenGL render 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 
    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 (*ActivateRenderer) (SDL_Renderer * renderer);
    59     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    60     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    61                                void **pixels, int *pitch);
    62     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    63                               const SDL_Color * colors, int firstcolor,
    64                               int ncolors);
    65     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    66                               SDL_Color * colors, int firstcolor,
    67                               int ncolors);
    68     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    69                           const SDL_Rect * rect, const void *pixels,
    70                           int pitch);
    71     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    72                         const SDL_Rect * rect, int markDirty, void **pixels,
    73                         int *pitch);
    74     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    75     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    76                           int numrects, const SDL_Rect * rects);
    77     int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
    78                        Uint32 color);
    79     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    80                        const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    81                        int blendMode, int scaleMode);
    82     void (*RenderPresent) (SDL_Renderer * renderer);
    83     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    84 
    85     void (*DestroyRenderer) (SDL_Renderer * renderer);
    86 
    87     /* The current renderer info */
    88     SDL_RendererInfo info;
    89 
    90     /* The window associated with the renderer */
    91     SDL_WindowID window;
    92 
    93     void *driverdata;
    94 };
    95 
    96 /* Define the SDL render driver structure */
    97 struct SDL_RenderDriver
    98 {
    99     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   100 
   101     /* Info about the renderer capabilities */
   102     SDL_RendererInfo info;
   103 };
   104 
   105 /* Define the SDL window structure, corresponding to toplevel windows */
   106 struct SDL_Window
   107 {
   108     Uint32 id;
   109 
   110     char *title;
   111     int x, y;
   112     int w, h;
   113     Uint32 flags;
   114 
   115     int display;
   116     SDL_Renderer *renderer;
   117 
   118     void *userdata;
   119     void *driverdata;
   120 };
   121 #define FULLSCREEN_VISIBLE(W) \
   122     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   123      ((W)->flags & SDL_WINDOW_SHOWN) && \
   124      !((W)->flags & SDL_WINDOW_MINIMIZED))
   125 
   126 /* Define the SDL display structure
   127    This corresponds to physical monitors attached to the system.
   128  */
   129 struct SDL_VideoDisplay
   130 {
   131     int max_display_modes;
   132     int num_display_modes;
   133     SDL_DisplayMode *display_modes;
   134     SDL_DisplayMode desktop_mode;
   135     SDL_DisplayMode current_mode;
   136     SDL_DisplayMode desired_mode;
   137     SDL_DisplayMode *fullscreen_mode;
   138     SDL_Palette *palette;
   139 
   140     Uint16 *gamma;
   141     Uint16 *saved_gamma;        /* (just offset into gamma) */
   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     /* Reverse the effects VideoInit() -- called if VideoInit() fails
   177        or if the application is shutting down the video subsystem.
   178      */
   179     void (*VideoQuit) (_THIS);
   180 
   181     /* * * */
   182     /* Display functions
   183      */
   184 
   185     /* Get a list of the available display modes.
   186      * e.g.  SDL_AddDisplayMode(_this->current_display, mode)
   187      */
   188     void (*GetDisplayModes) (_THIS);
   189 
   190     /* Setting the display mode is independent of creating windows,
   191      * so when the display mode is changed, all existing windows
   192      * should have their data updated accordingly, including the
   193      * display surfaces associated with them.
   194      */
   195     int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
   196 
   197     /* Set the color entries of the display palette */
   198     int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   199 
   200     /* Get the color entries of the display palette */
   201     int (*GetDisplayPalette) (_THIS, SDL_Palette * palette);
   202 
   203     /* Set the gamma ramp */
   204     int (*SetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   205 
   206     /* Get the gamma ramp */
   207     int (*GetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   208 
   209     /* * * */
   210     /* Window functions
   211      */
   212     int (*CreateWindow) (_THIS, SDL_Window * window);
   213     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   214     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   215     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   216     void (*SetWindowSize) (_THIS, SDL_Window * window);
   217     void (*ShowWindow) (_THIS, SDL_Window * window);
   218     void (*HideWindow) (_THIS, SDL_Window * window);
   219     void (*RaiseWindow) (_THIS, SDL_Window * window);
   220     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   221     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   222     void (*RestoreWindow) (_THIS, SDL_Window * window);
   223     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   224     void (*DestroyWindow) (_THIS, SDL_Window * window);
   225 
   226     /* Get some platform dependent window information */
   227       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   228                                   struct SDL_SysWMinfo * info);
   229 
   230     /* * * */
   231     /* OpenGL support
   232      */
   233     int (*GL_LoadLibrary) (_THIS, const char *path);
   234     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   235       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   236     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   237     int (*GL_SetSwapInterval) (_THIS, int interval);
   238     int (*GL_GetSwapInterval) (_THIS);
   239     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   240     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   241 
   242     /* * * */
   243     /* Event manager functions
   244      */
   245     void (*PumpEvents) (_THIS);
   246 
   247     /* * * */
   248     /* Data common to all drivers */
   249     int num_displays;
   250     SDL_VideoDisplay *displays;
   251     int current_display;
   252     Uint32 next_object_id;
   253 
   254     /* * * */
   255     /* Data used by the GL drivers */
   256     struct
   257     {
   258         int red_size;
   259         int green_size;
   260         int blue_size;
   261         int alpha_size;
   262         int depth_size;
   263         int buffer_size;
   264         int stencil_size;
   265         int double_buffer;
   266         int accum_red_size;
   267         int accum_green_size;
   268         int accum_blue_size;
   269         int accum_alpha_size;
   270         int stereo;
   271         int multisamplebuffers;
   272         int multisamplesamples;
   273         int accelerated;
   274         int driver_loaded;
   275         char driver_path[256];
   276         void *dll_handle;
   277     } gl_config;
   278 
   279     /* * * */
   280     /* Data private to this driver */
   281     void *driverdata;
   282     struct SDL_GLDriverData *gl_data;
   283 
   284     /* * * */
   285     /* The function used to dispose of this structure */
   286     void (*free) (_THIS);
   287 };
   288 
   289 typedef struct VideoBootStrap
   290 {
   291     const char *name;
   292     const char *desc;
   293     int (*available) (void);
   294     SDL_VideoDevice *(*create) (int devindex);
   295 } VideoBootStrap;
   296 
   297 #if SDL_VIDEO_DRIVER_COCOA
   298 extern VideoBootStrap COCOA_bootstrap;
   299 #endif
   300 #if SDL_VIDEO_DRIVER_X11
   301 extern VideoBootStrap X11_bootstrap;
   302 #endif
   303 #if SDL_VIDEO_DRIVER_NANOX
   304 extern VideoBootStrap NX_bootstrap;
   305 #endif
   306 #if SDL_VIDEO_DRIVER_IPOD
   307 extern VideoBootStrap iPod_bootstrap;
   308 #endif
   309 #if SDL_VIDEO_DRIVER_QTOPIA
   310 extern VideoBootStrap Qtopia_bootstrap;
   311 #endif
   312 #if SDL_VIDEO_DRIVER_WSCONS
   313 extern VideoBootStrap WSCONS_bootstrap;
   314 #endif
   315 #if SDL_VIDEO_DRIVER_FBCON
   316 extern VideoBootStrap FBCON_bootstrap;
   317 #endif
   318 #if SDL_VIDEO_DRIVER_DIRECTFB
   319 extern VideoBootStrap DirectFB_bootstrap;
   320 #endif
   321 #if SDL_VIDEO_DRIVER_PS2GS
   322 extern VideoBootStrap PS2GS_bootstrap;
   323 #endif
   324 #if SDL_VIDEO_DRIVER_GGI
   325 extern VideoBootStrap GGI_bootstrap;
   326 #endif
   327 #if SDL_VIDEO_DRIVER_VGL
   328 extern VideoBootStrap VGL_bootstrap;
   329 #endif
   330 #if SDL_VIDEO_DRIVER_SVGALIB
   331 extern VideoBootStrap SVGALIB_bootstrap;
   332 #endif
   333 #if SDL_VIDEO_DRIVER_GAPI
   334 extern VideoBootStrap GAPI_bootstrap;
   335 #endif
   336 #if SDL_VIDEO_DRIVER_WIN32
   337 extern VideoBootStrap WIN32_bootstrap;
   338 #endif
   339 #if SDL_VIDEO_DRIVER_BWINDOW
   340 extern VideoBootStrap BWINDOW_bootstrap;
   341 #endif
   342 #if SDL_VIDEO_DRIVER_TOOLBOX
   343 extern VideoBootStrap TOOLBOX_bootstrap;
   344 #endif
   345 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   346 extern VideoBootStrap DSp_bootstrap;
   347 #endif
   348 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   349 extern VideoBootStrap CGX_bootstrap;
   350 #endif
   351 #if SDL_VIDEO_DRIVER_PHOTON
   352 extern VideoBootStrap ph_bootstrap;
   353 #endif
   354 #if SDL_VIDEO_DRIVER_EPOC
   355 extern VideoBootStrap EPOC_bootstrap;
   356 #endif
   357 #if SDL_VIDEO_DRIVER_XBIOS
   358 extern VideoBootStrap XBIOS_bootstrap;
   359 #endif
   360 #if SDL_VIDEO_DRIVER_GEM
   361 extern VideoBootStrap GEM_bootstrap;
   362 #endif
   363 #if SDL_VIDEO_DRIVER_PICOGUI
   364 extern VideoBootStrap PG_bootstrap;
   365 #endif
   366 #if SDL_VIDEO_DRIVER_DC
   367 extern VideoBootStrap DC_bootstrap;
   368 #endif
   369 #if SDL_VIDEO_DRIVER_RISCOS
   370 extern VideoBootStrap RISCOS_bootstrap;
   371 #endif
   372 #if SDL_VIDEO_DRIVER_OS2FS
   373 extern VideoBootStrap OS2FSLib_bootstrap;
   374 #endif
   375 #if SDL_VIDEO_DRIVER_AALIB
   376 extern VideoBootStrap AALIB_bootstrap;
   377 #endif
   378 #if SDL_VIDEO_DRIVER_DUMMY
   379 extern VideoBootStrap DUMMY_bootstrap;
   380 #endif
   381 
   382 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   383 
   384 extern SDL_VideoDevice *SDL_GetVideoDevice();
   385 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   386 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   387 extern SDL_bool SDL_AddDisplayMode(int displayIndex,
   388                                    const SDL_DisplayMode * mode);
   389 extern void SDL_AddRenderDriver(int displayIndex,
   390                                 const SDL_RenderDriver * driver);
   391 
   392 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   393 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   394 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   395 
   396 extern void SDL_OnWindowShown(SDL_Window * window);
   397 extern void SDL_OnWindowHidden(SDL_Window * window);
   398 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   399 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   400 extern SDL_WindowID SDL_GetFocusWindow(void);
   401 
   402 #endif /* _SDL_sysvideo_h */
   403 
   404 /* vi: set ts=4 sw=4 expandtab: */