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