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