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