src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Dec 2008 22:37:40 +0000
changeset 2853 6258fa7cd300
parent 2753 0969758c8809
child 2859 99210400e8b9
permissions -rw-r--r--
Fixed picking blit function when RLE fails
     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 #include "SDL_keysym.h"
    29 
    30 /* The SDL video driver */
    31 
    32 typedef struct SDL_Window SDL_Window;
    33 typedef struct SDL_Texture SDL_Texture;
    34 typedef struct SDL_Renderer SDL_Renderer;
    35 typedef struct SDL_RenderDriver SDL_RenderDriver;
    36 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    37 typedef struct SDL_VideoDevice SDL_VideoDevice;
    38 
    39 /* Define the SDL texture structure */
    40 struct SDL_Texture
    41 {
    42     Uint32 id;
    43 
    44     Uint32 format;              /**< The pixel format of the texture */
    45     int access;                 /**< SDL_TextureAccess */
    46     int w;                      /**< The width of the texture */
    47     int h;                      /**< The height of the texture */
    48     int modMode;                /**< The texture modulation mode */
    49     int blendMode;                      /**< The texture blend mode */
    50     int scaleMode;                      /**< The texture scale mode */
    51     Uint8 r, g, b, a;                   /**< Texture modulation values */
    52 
    53     SDL_Renderer *renderer;
    54 
    55     void *driverdata;                   /**< Driver specific texture representation */
    56 
    57     SDL_Texture *next;
    58 };
    59 
    60 /* Define the SDL renderer structure */
    61 struct SDL_Renderer
    62 {
    63     int (*ActivateRenderer) (SDL_Renderer * renderer);
    64     int (*DisplayModeChanged) (SDL_Renderer * renderer);
    65     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    66     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    67                                void **pixels, int *pitch);
    68     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    69                               const SDL_Color * colors, int firstcolor,
    70                               int ncolors);
    71     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    72                               SDL_Color * colors, int firstcolor,
    73                               int ncolors);
    74     int (*SetTextureColorMod) (SDL_Renderer * renderer,
    75                                SDL_Texture * texture);
    76     int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
    77                                SDL_Texture * texture);
    78     int (*SetTextureBlendMode) (SDL_Renderer * renderer,
    79                                 SDL_Texture * texture);
    80     int (*SetTextureScaleMode) (SDL_Renderer * renderer,
    81                                 SDL_Texture * texture);
    82     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    83                           const SDL_Rect * rect, const void *pixels,
    84                           int pitch);
    85     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    86                         const SDL_Rect * rect, int markDirty, void **pixels,
    87                         int *pitch);
    88     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    89     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    90                           int numrects, const SDL_Rect * rects);
    91     int (*RenderFill) (SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    92                        Uint8 a, const SDL_Rect * rect);
    93     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    94                        const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    95     void (*RenderPresent) (SDL_Renderer * renderer);
    96     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    97 
    98     void (*DestroyRenderer) (SDL_Renderer * renderer);
    99 
   100     /* The current renderer info */
   101     SDL_RendererInfo info;
   102 
   103     /* The window associated with the renderer */
   104     SDL_WindowID window;
   105 
   106     void *driverdata;
   107 };
   108 
   109 /* Define the SDL render driver structure */
   110 struct SDL_RenderDriver
   111 {
   112     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   113 
   114     /* Info about the renderer capabilities */
   115     SDL_RendererInfo info;
   116 };
   117 
   118 /* Define the SDL window structure, corresponding to toplevel windows */
   119 struct SDL_Window
   120 {
   121     Uint32 id;
   122 
   123     char *title;
   124     int x, y;
   125     int w, h;
   126     Uint32 flags;
   127 
   128     int display;
   129     SDL_Renderer *renderer;
   130 
   131     void *userdata;
   132     void *driverdata;
   133 };
   134 #define FULLSCREEN_VISIBLE(W) \
   135     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   136      ((W)->flags & SDL_WINDOW_SHOWN) && \
   137      !((W)->flags & SDL_WINDOW_MINIMIZED))
   138 
   139 /*
   140  * Define the SDL display structure This corresponds to physical monitors
   141  * attached to the system.
   142  */
   143 struct SDL_VideoDisplay
   144 {
   145     int max_display_modes;
   146     int num_display_modes;
   147     SDL_DisplayMode *display_modes;
   148     SDL_DisplayMode desktop_mode;
   149     SDL_DisplayMode current_mode;
   150     SDL_DisplayMode fullscreen_mode;
   151     SDL_Palette *palette;
   152 
   153     Uint16 *gamma;
   154     Uint16 *saved_gamma;        /* (just offset into gamma) */
   155 
   156     int num_render_drivers;
   157     SDL_RenderDriver *render_drivers;
   158 
   159     int num_windows;
   160     SDL_Window *windows;
   161 
   162     SDL_Renderer *current_renderer;
   163 
   164     /* The hash list of textures */
   165     SDL_Texture *textures[64];
   166 
   167     SDL_VideoDevice *device;
   168 
   169     void *driverdata;
   170 };
   171 
   172 /* Define the SDL video driver structure */
   173 #define _THIS	SDL_VideoDevice *_this
   174 
   175 struct SDL_VideoDevice
   176 {
   177     /* * * */
   178     /* The name of this video driver */
   179     const char *name;
   180 
   181     /* * * */
   182     /* Initialization/Query functions */
   183 
   184     /*
   185      * Initialize the native video subsystem, filling in the list of
   186      * displays for this driver, returning 0 or -1 if there's an error.
   187      */
   188     int (*VideoInit) (_THIS);
   189 
   190     /*
   191      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   192      * if the application is shutting down the video subsystem.
   193      */
   194     void (*VideoQuit) (_THIS);
   195 
   196     /* * * */
   197     /*
   198      * Display functions
   199      */
   200 
   201     /*
   202      * Get a list of the available display modes. e.g.
   203      * SDL_AddDisplayMode(_this->current_display, mode)
   204      */
   205     void (*GetDisplayModes) (_THIS);
   206 
   207     /*
   208      * Setting the display mode is independent of creating windows, so
   209      * when the display mode is changed, all existing windows should have
   210      * their data updated accordingly, including the display surfaces
   211      * associated with them.
   212      */
   213     int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
   214 
   215     /* Set the color entries of the display palette */
   216     int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   217 
   218     /* Get the color entries of the display palette */
   219     int (*GetDisplayPalette) (_THIS, SDL_Palette * palette);
   220 
   221     /* Set the gamma ramp */
   222     int (*SetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   223 
   224     /* Get the gamma ramp */
   225     int (*GetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   226 
   227     /* * * */
   228     /*
   229      * Window functions
   230      */
   231     int (*CreateWindow) (_THIS, SDL_Window * window);
   232     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   233     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   234     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   235     void (*SetWindowSize) (_THIS, SDL_Window * window);
   236     void (*ShowWindow) (_THIS, SDL_Window * window);
   237     void (*HideWindow) (_THIS, SDL_Window * window);
   238     void (*RaiseWindow) (_THIS, SDL_Window * window);
   239     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   240     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   241     void (*RestoreWindow) (_THIS, SDL_Window * window);
   242     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   243     void (*DestroyWindow) (_THIS, SDL_Window * window);
   244 
   245     /* Get some platform dependent window information */
   246       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   247                                   struct SDL_SysWMinfo * info);
   248 
   249     /* * * */
   250     /*
   251      * OpenGL support
   252      */
   253     int (*GL_LoadLibrary) (_THIS, const char *path);
   254     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   255       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   256     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   257     int (*GL_SetSwapInterval) (_THIS, int interval);
   258     int (*GL_GetSwapInterval) (_THIS);
   259     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   260     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   261 
   262     /* * * */
   263     /*
   264      * Event manager functions
   265      */
   266     void (*PumpEvents) (_THIS);
   267 
   268     /* * * */
   269     /* Data common to all drivers */
   270     int num_displays;
   271     SDL_VideoDisplay *displays;
   272     int current_display;
   273     Uint32 next_object_id;
   274 
   275     /* * * */
   276     /* Data used by the GL drivers */
   277     struct
   278     {
   279         int red_size;
   280         int green_size;
   281         int blue_size;
   282         int alpha_size;
   283         int depth_size;
   284         int buffer_size;
   285         int stencil_size;
   286         int double_buffer;
   287         int accum_red_size;
   288         int accum_green_size;
   289         int accum_blue_size;
   290         int accum_alpha_size;
   291         int stereo;
   292         int multisamplebuffers;
   293         int multisamplesamples;
   294         int accelerated;
   295         int retained_backing;
   296         int driver_loaded;
   297         char driver_path[256];
   298         void *dll_handle;
   299     } gl_config;
   300 
   301     /* * * */
   302     /* Data private to this driver */
   303     void *driverdata;
   304     struct SDL_GLDriverData *gl_data;
   305 
   306     /* * * */
   307     /* The function used to dispose of this structure */
   308     void (*free) (_THIS);
   309 };
   310 
   311 typedef struct VideoBootStrap
   312 {
   313     const char *name;
   314     const char *desc;
   315     int (*available) (void);
   316     SDL_VideoDevice *(*create) (int devindex);
   317 } VideoBootStrap;
   318 
   319 #if SDL_VIDEO_DRIVER_COCOA
   320 extern VideoBootStrap COCOA_bootstrap;
   321 #endif
   322 #if SDL_VIDEO_DRIVER_X11
   323 extern VideoBootStrap X11_bootstrap;
   324 #endif
   325 #if SDL_VIDEO_DRIVER_NANOX
   326 extern VideoBootStrap NX_bootstrap;
   327 #endif
   328 #if SDL_VIDEO_DRIVER_IPOD
   329 extern VideoBootStrap iPod_bootstrap;
   330 #endif
   331 #if SDL_VIDEO_DRIVER_WSCONS
   332 extern VideoBootStrap WSCONS_bootstrap;
   333 #endif
   334 #if SDL_VIDEO_DRIVER_FBCON
   335 extern VideoBootStrap FBCON_bootstrap;
   336 #endif
   337 #if SDL_VIDEO_DRIVER_DIRECTFB
   338 extern VideoBootStrap DirectFB_bootstrap;
   339 #endif
   340 #if SDL_VIDEO_DRIVER_PS2GS
   341 extern VideoBootStrap PS2GS_bootstrap;
   342 #endif
   343 #if SDL_VIDEO_DRIVER_VGL
   344 extern VideoBootStrap VGL_bootstrap;
   345 #endif
   346 #if SDL_VIDEO_DRIVER_SVGALIB
   347 extern VideoBootStrap SVGALIB_bootstrap;
   348 #endif
   349 #if SDL_VIDEO_DRIVER_GAPI
   350 extern VideoBootStrap GAPI_bootstrap;
   351 #endif
   352 #if SDL_VIDEO_DRIVER_WIN32
   353 extern VideoBootStrap WIN32_bootstrap;
   354 #endif
   355 #if SDL_VIDEO_DRIVER_BWINDOW
   356 extern VideoBootStrap BWINDOW_bootstrap;
   357 #endif
   358 #if SDL_VIDEO_DRIVER_PHOTON
   359 extern VideoBootStrap ph_bootstrap;
   360 #endif
   361 #if SDL_VIDEO_DRIVER_EPOC
   362 extern VideoBootStrap EPOC_bootstrap;
   363 #endif
   364 #if SDL_VIDEO_DRIVER_XBIOS
   365 extern VideoBootStrap XBIOS_bootstrap;
   366 #endif
   367 #if SDL_VIDEO_DRIVER_GEM
   368 extern VideoBootStrap GEM_bootstrap;
   369 #endif
   370 #if SDL_VIDEO_DRIVER_DC
   371 extern VideoBootStrap DC_bootstrap;
   372 #endif
   373 #if SDL_VIDEO_DRIVER_RISCOS
   374 extern VideoBootStrap RISCOS_bootstrap;
   375 #endif
   376 #if SDL_VIDEO_DRIVER_OS2FS
   377 extern VideoBootStrap OS2FSLib_bootstrap;
   378 #endif
   379 #if SDL_VIDEO_DRIVER_UIKIT
   380 extern VideoBootStrap UIKIT_bootstrap;
   381 #endif
   382 #if SDL_VIDEO_DRIVER_DUMMY
   383 extern VideoBootStrap DUMMY_bootstrap;
   384 #endif
   385 #if SDL_VIDEO_DRIVER_NDS
   386 extern VideoBootStrap NDS_bootstrap;
   387 #endif
   388 
   389 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   390 
   391 extern SDL_VideoDevice *SDL_GetVideoDevice();
   392 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   393 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   394 extern SDL_bool
   395 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode);
   396 extern void
   397 SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver);
   398 
   399 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   400 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   401 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   402 
   403 extern void SDL_OnWindowShown(SDL_Window * window);
   404 extern void SDL_OnWindowHidden(SDL_Window * window);
   405 extern void SDL_OnWindowResized(SDL_Window * window);
   406 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   407 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   408 extern SDL_WindowID SDL_GetFocusWindow(void);
   409 
   410 #endif /* _SDL_sysvideo_h */
   411 
   412 /* vi: set ts=4 sw=4 expandtab: */