src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 23 Jul 2006 00:19:12 +0000
changeset 1928 861bc36f0ab3
parent 1924 69217fdd2c0a
child 1931 103c6fec2a60
permissions -rw-r--r--
Fixed crash with multiple windows
     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     int (*GL_GetWindowAttribute) (_THIS, SDL_Window * window,
   236                                   SDL_GLattr attrib, int *value);
   237       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   238     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   239     int (*GL_SetSwapInterval) (_THIS, int interval);
   240     int (*GL_GetSwapInterval) (_THIS);
   241     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   242     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   243 
   244     /* * * */
   245     /* Event manager functions
   246      */
   247     void (*PumpEvents) (_THIS);
   248 
   249     /* * * */
   250     /* Data common to all drivers */
   251     int num_displays;
   252     SDL_VideoDisplay *displays;
   253     int current_display;
   254     Uint32 next_object_id;
   255 
   256     /* * * */
   257     /* Data used by the GL drivers */
   258     struct
   259     {
   260         int red_size;
   261         int green_size;
   262         int blue_size;
   263         int alpha_size;
   264         int depth_size;
   265         int buffer_size;
   266         int stencil_size;
   267         int double_buffer;
   268         int accum_red_size;
   269         int accum_green_size;
   270         int accum_blue_size;
   271         int accum_alpha_size;
   272         int stereo;
   273         int multisamplebuffers;
   274         int multisamplesamples;
   275         int accelerated;
   276         int driver_loaded;
   277         char driver_path[256];
   278         void *dll_handle;
   279     } gl_config;
   280 
   281     /* * * */
   282     /* Data private to this driver */
   283     void *driverdata;
   284     struct SDL_GLDriverData *gl_data;
   285 
   286     /* * * */
   287     /* The function used to dispose of this structure */
   288     void (*free) (_THIS);
   289 };
   290 
   291 typedef struct VideoBootStrap
   292 {
   293     const char *name;
   294     const char *desc;
   295     int (*available) (void);
   296     SDL_VideoDevice *(*create) (int devindex);
   297 } VideoBootStrap;
   298 
   299 #if SDL_VIDEO_DRIVER_QUARTZ
   300 extern VideoBootStrap QZ_bootstrap;
   301 #endif
   302 #if SDL_VIDEO_DRIVER_X11
   303 extern VideoBootStrap X11_bootstrap;
   304 #endif
   305 #if SDL_VIDEO_DRIVER_DGA
   306 extern VideoBootStrap DGA_bootstrap;
   307 #endif
   308 #if SDL_VIDEO_DRIVER_NANOX
   309 extern VideoBootStrap NX_bootstrap;
   310 #endif
   311 #if SDL_VIDEO_DRIVER_IPOD
   312 extern VideoBootStrap iPod_bootstrap;
   313 #endif
   314 #if SDL_VIDEO_DRIVER_QTOPIA
   315 extern VideoBootStrap Qtopia_bootstrap;
   316 #endif
   317 #if SDL_VIDEO_DRIVER_WSCONS
   318 extern VideoBootStrap WSCONS_bootstrap;
   319 #endif
   320 #if SDL_VIDEO_DRIVER_FBCON
   321 extern VideoBootStrap FBCON_bootstrap;
   322 #endif
   323 #if SDL_VIDEO_DRIVER_DIRECTFB
   324 extern VideoBootStrap DirectFB_bootstrap;
   325 #endif
   326 #if SDL_VIDEO_DRIVER_PS2GS
   327 extern VideoBootStrap PS2GS_bootstrap;
   328 #endif
   329 #if SDL_VIDEO_DRIVER_GGI
   330 extern VideoBootStrap GGI_bootstrap;
   331 #endif
   332 #if SDL_VIDEO_DRIVER_VGL
   333 extern VideoBootStrap VGL_bootstrap;
   334 #endif
   335 #if SDL_VIDEO_DRIVER_SVGALIB
   336 extern VideoBootStrap SVGALIB_bootstrap;
   337 #endif
   338 #if SDL_VIDEO_DRIVER_GAPI
   339 extern VideoBootStrap GAPI_bootstrap;
   340 #endif
   341 #if SDL_VIDEO_DRIVER_WIN32
   342 extern VideoBootStrap WIN32_bootstrap;
   343 #endif
   344 #if SDL_VIDEO_DRIVER_BWINDOW
   345 extern VideoBootStrap BWINDOW_bootstrap;
   346 #endif
   347 #if SDL_VIDEO_DRIVER_TOOLBOX
   348 extern VideoBootStrap TOOLBOX_bootstrap;
   349 #endif
   350 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   351 extern VideoBootStrap DSp_bootstrap;
   352 #endif
   353 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   354 extern VideoBootStrap CGX_bootstrap;
   355 #endif
   356 #if SDL_VIDEO_DRIVER_PHOTON
   357 extern VideoBootStrap ph_bootstrap;
   358 #endif
   359 #if SDL_VIDEO_DRIVER_EPOC
   360 extern VideoBootStrap EPOC_bootstrap;
   361 #endif
   362 #if SDL_VIDEO_DRIVER_XBIOS
   363 extern VideoBootStrap XBIOS_bootstrap;
   364 #endif
   365 #if SDL_VIDEO_DRIVER_GEM
   366 extern VideoBootStrap GEM_bootstrap;
   367 #endif
   368 #if SDL_VIDEO_DRIVER_PICOGUI
   369 extern VideoBootStrap PG_bootstrap;
   370 #endif
   371 #if SDL_VIDEO_DRIVER_DC
   372 extern VideoBootStrap DC_bootstrap;
   373 #endif
   374 #if SDL_VIDEO_DRIVER_RISCOS
   375 extern VideoBootStrap RISCOS_bootstrap;
   376 #endif
   377 #if SDL_VIDEO_DRIVER_OS2FS
   378 extern VideoBootStrap OS2FSLib_bootstrap;
   379 #endif
   380 #if SDL_VIDEO_DRIVER_AALIB
   381 extern VideoBootStrap AALIB_bootstrap;
   382 #endif
   383 #if SDL_VIDEO_DRIVER_DUMMY
   384 extern VideoBootStrap DUMMY_bootstrap;
   385 #endif
   386 #if SDL_VIDEO_DRIVER_GLSDL
   387 extern VideoBootStrap glSDL_bootstrap;
   388 #endif
   389 
   390 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   391 
   392 extern SDL_VideoDevice *SDL_GetVideoDevice();
   393 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   394 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   395 extern SDL_bool SDL_AddDisplayMode(int displayIndex,
   396                                    const SDL_DisplayMode * mode);
   397 extern void SDL_AddRenderDriver(int displayIndex,
   398                                 const SDL_RenderDriver * driver);
   399 
   400 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   401 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   402 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   403 
   404 extern void SDL_OnWindowShown(SDL_Window * window);
   405 extern void SDL_OnWindowHidden(SDL_Window * window);
   406 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   407 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   408 extern SDL_WindowID SDL_GetFocusWindow(void);
   409 
   410 #endif /* _SDL_sysvideo_h */
   411 
   412 /* vi: set ts=4 sw=4 expandtab: */