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