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