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