src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 15 Jun 2006 07:07:07 +0000
branchSDL-1.3
changeset 1681 80a5e6a4e1e2
parent 1680 9488fca10677
child 1682 7ae8018b2e5d
permissions -rw-r--r--
Working on paletted display and texture support (two different issues)
     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     void *driverdata;
   163 };
   164 
   165 /* Define the SDL video driver structure */
   166 #define _THIS	SDL_VideoDevice *_this
   167 
   168 struct SDL_VideoDevice
   169 {
   170     /* * * */
   171     /* The name of this video driver */
   172     const char *name;
   173 
   174     /* * * */
   175     /* Initialization/Query functions */
   176 
   177     /* Initialize the native video subsystem, filling in the list
   178        of displays for this driver, returning 0 or -1 if there's an error.
   179      */
   180     int (*VideoInit) (_THIS);
   181 
   182     /* * * */
   183     /* Display functions
   184      */
   185     /* Setting the display mode is independent of creating windows,
   186      * so when the display mode is changed, all existing windows
   187      * should have their data updated accordingly, including the
   188      * display surfaces associated with them.
   189      */
   190     int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
   191 
   192     /* Sets the color entries of the display palette to those in 'colors'.
   193        The return value is 0 if all entries could be set properly or -1
   194        otherwise.
   195      */
   196     int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   197 
   198     /* * * */
   199     /* Window functions
   200      */
   201     int (*CreateWindow) (_THIS, SDL_Window * window);
   202     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   203     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   204     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   205     void (*SetWindowSize) (_THIS, SDL_Window * window);
   206     void (*ShowWindow) (_THIS, SDL_Window * window);
   207     void (*HideWindow) (_THIS, SDL_Window * window);
   208     void (*RaiseWindow) (_THIS, SDL_Window * window);
   209     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   210     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   211     void (*RestoreWindow) (_THIS, SDL_Window * window);
   212     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   213     void (*DestroyWindow) (_THIS, SDL_Window * window);
   214 
   215     /* Get some platform dependent window information */
   216       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   217                                   SDL_SysWMinfo * info);
   218 
   219     /* Reverse the effects VideoInit() -- called if VideoInit() fails
   220        or if the application is shutting down the video subsystem.
   221      */
   222     void (*VideoQuit) (_THIS);
   223 
   224     /* * * */
   225     /* Gamma support */
   226 
   227     /* Set the gamma correction directly (emulated with gamma ramps) */
   228     int (*SetGamma) (_THIS, float red, float green, float blue);
   229 
   230     /* Get the gamma correction directly (emulated with gamma ramps) */
   231     int (*GetGamma) (_THIS, float *red, float *green, float *blue);
   232 
   233     /* Set the gamma ramp */
   234     int (*SetGammaRamp) (_THIS, Uint16 * ramp);
   235 
   236     /* Get the gamma ramp */
   237     int (*GetGammaRamp) (_THIS, Uint16 * ramp);
   238 
   239     /* * * */
   240     /* OpenGL support */
   241 
   242     /* Sets the dll to use for OpenGL and loads it */
   243     int (*GL_LoadLibrary) (_THIS, const char *path);
   244 
   245     /* Retrieves the address of a function in the gl library */
   246     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   247 
   248     /* Get attribute information from the windowing system. */
   249     int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
   250 
   251     /* Make the context associated with this driver current */
   252     int (*GL_MakeCurrent) (_THIS);
   253 
   254     /* Swap the current buffers in double buffer mode. */
   255     void (*GL_SwapBuffers) (_THIS);
   256 
   257     /* OpenGL functions for glSDL */
   258 #if SDL_VIDEO_OPENGL
   259 #if !defined(__WIN32__)
   260 #define WINAPI
   261 #endif
   262 #define SDL_PROC(ret,func,params) ret (WINAPI *func) params;
   263 #include "SDL_glfuncs.h"
   264 #undef SDL_PROC
   265 
   266     /* Texture id */
   267     GLuint texture;
   268 
   269     int is_32bit;
   270 #endif
   271 
   272     /* Determine whether the mouse should be in relative mode or not.
   273        This function is called when the input grab state or cursor
   274        visibility state changes.
   275        If the cursor is not visible, and the input is grabbed, the
   276        driver can place the mouse in relative mode, which may result
   277        in higher accuracy sampling of the pointer motion.
   278      */
   279     void (*CheckMouseMode) (_THIS);
   280 
   281     /* * * */
   282     /* Event manager functions */
   283 
   284     /* Handle any queued OS events */
   285     void (*PumpEvents) (_THIS);
   286 
   287     /* * * */
   288     /* Data common to all drivers */
   289     int num_displays;
   290     SDL_VideoDisplay *displays;
   291     int current_display;
   292     Uint32 next_object_id;
   293 
   294     /* Driver information flags */
   295 
   296     /* * * */
   297     /* Data used by the GL drivers */
   298     struct
   299     {
   300         int red_size;
   301         int green_size;
   302         int blue_size;
   303         int alpha_size;
   304         int depth_size;
   305         int buffer_size;
   306         int stencil_size;
   307         int double_buffer;
   308         int accum_red_size;
   309         int accum_green_size;
   310         int accum_blue_size;
   311         int accum_alpha_size;
   312         int stereo;
   313         int multisamplebuffers;
   314         int multisamplesamples;
   315         int accelerated;
   316         int swap_control;
   317         int driver_loaded;
   318         char driver_path[256];
   319         void *dll_handle;
   320     } gl_config;
   321 
   322     /* * * */
   323     /* Data private to this driver */
   324     struct SDL_PrivateVideoData *hidden;
   325     struct SDL_PrivateGLData *gl_data;
   326 
   327     /* * * */
   328     /* The function used to dispose of this structure */
   329     void (*free) (_THIS);
   330 };
   331 #undef _THIS
   332 
   333 typedef struct VideoBootStrap
   334 {
   335     const char *name;
   336     const char *desc;
   337     int (*available) (void);
   338     SDL_VideoDevice *(*create) (int devindex);
   339 } VideoBootStrap;
   340 
   341 #if SDL_VIDEO_DRIVER_QUARTZ
   342 extern VideoBootStrap QZ_bootstrap;
   343 #endif
   344 #if SDL_VIDEO_DRIVER_X11
   345 extern VideoBootStrap X11_bootstrap;
   346 #endif
   347 #if SDL_VIDEO_DRIVER_DGA
   348 extern VideoBootStrap DGA_bootstrap;
   349 #endif
   350 #if SDL_VIDEO_DRIVER_NANOX
   351 extern VideoBootStrap NX_bootstrap;
   352 #endif
   353 #if SDL_VIDEO_DRIVER_IPOD
   354 extern VideoBootStrap iPod_bootstrap;
   355 #endif
   356 #if SDL_VIDEO_DRIVER_QTOPIA
   357 extern VideoBootStrap Qtopia_bootstrap;
   358 #endif
   359 #if SDL_VIDEO_DRIVER_WSCONS
   360 extern VideoBootStrap WSCONS_bootstrap;
   361 #endif
   362 #if SDL_VIDEO_DRIVER_FBCON
   363 extern VideoBootStrap FBCON_bootstrap;
   364 #endif
   365 #if SDL_VIDEO_DRIVER_DIRECTFB
   366 extern VideoBootStrap DirectFB_bootstrap;
   367 #endif
   368 #if SDL_VIDEO_DRIVER_PS2GS
   369 extern VideoBootStrap PS2GS_bootstrap;
   370 #endif
   371 #if SDL_VIDEO_DRIVER_GGI
   372 extern VideoBootStrap GGI_bootstrap;
   373 #endif
   374 #if SDL_VIDEO_DRIVER_VGL
   375 extern VideoBootStrap VGL_bootstrap;
   376 #endif
   377 #if SDL_VIDEO_DRIVER_SVGALIB
   378 extern VideoBootStrap SVGALIB_bootstrap;
   379 #endif
   380 #if SDL_VIDEO_DRIVER_GAPI
   381 extern VideoBootStrap GAPI_bootstrap;
   382 #endif
   383 #if SDL_VIDEO_DRIVER_WINDIB
   384 extern VideoBootStrap WINDIB_bootstrap;
   385 #endif
   386 #if SDL_VIDEO_DRIVER_DDRAW
   387 extern VideoBootStrap DIRECTX_bootstrap;
   388 #endif
   389 #if SDL_VIDEO_DRIVER_BWINDOW
   390 extern VideoBootStrap BWINDOW_bootstrap;
   391 #endif
   392 #if SDL_VIDEO_DRIVER_TOOLBOX
   393 extern VideoBootStrap TOOLBOX_bootstrap;
   394 #endif
   395 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
   396 extern VideoBootStrap DSp_bootstrap;
   397 #endif
   398 #if SDL_VIDEO_DRIVER_CYBERGRAPHICS
   399 extern VideoBootStrap CGX_bootstrap;
   400 #endif
   401 #if SDL_VIDEO_DRIVER_PHOTON
   402 extern VideoBootStrap ph_bootstrap;
   403 #endif
   404 #if SDL_VIDEO_DRIVER_EPOC
   405 extern VideoBootStrap EPOC_bootstrap;
   406 #endif
   407 #if SDL_VIDEO_DRIVER_XBIOS
   408 extern VideoBootStrap XBIOS_bootstrap;
   409 #endif
   410 #if SDL_VIDEO_DRIVER_GEM
   411 extern VideoBootStrap GEM_bootstrap;
   412 #endif
   413 #if SDL_VIDEO_DRIVER_PICOGUI
   414 extern VideoBootStrap PG_bootstrap;
   415 #endif
   416 #if SDL_VIDEO_DRIVER_DC
   417 extern VideoBootStrap DC_bootstrap;
   418 #endif
   419 #if SDL_VIDEO_DRIVER_RISCOS
   420 extern VideoBootStrap RISCOS_bootstrap;
   421 #endif
   422 #if SDL_VIDEO_DRIVER_OS2FS
   423 extern VideoBootStrap OS2FSLib_bootstrap;
   424 #endif
   425 #if SDL_VIDEO_DRIVER_AALIB
   426 extern VideoBootStrap AALIB_bootstrap;
   427 #endif
   428 #if SDL_VIDEO_DRIVER_DUMMY
   429 extern VideoBootStrap DUMMY_bootstrap;
   430 #endif
   431 #if SDL_VIDEO_DRIVER_GLSDL
   432 extern VideoBootStrap glSDL_bootstrap;
   433 #endif
   434 
   435 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   436 #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
   437 
   438 extern SDL_VideoDevice *SDL_GetVideoDevice();
   439 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   440 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   441 extern void SDL_AddDisplayMode(int displayIndex,
   442                                const SDL_DisplayMode * mode);
   443 extern void SDL_AddRenderDriver(int displayIndex,
   444                                 const SDL_RenderDriver * driver);
   445 
   446 #endif /* _SDL_sysvideo_h */
   447 
   448 /* vi: set ts=4 sw=4 expandtab: */