src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 01 Dec 2009 05:57:15 +0000
changeset 3500 4b594623401b
parent 3435 9f62f47d989b
child 3501 467e67d301f3
permissions -rw-r--r--
Work in progress on multi-display support:
* Added display parameter to many internal functions so video modes can be set on displays that aren't the public current one.
* The fullscreen mode is associated with fullscreen windows - not displays, so different windows more naturally have a mode associated with them based on their width and height. It's no longer necessary to specify a fullscreen mode, a default one will be picked automatically for fullscreen windows.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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 (*SetDrawColor) (SDL_Renderer * renderer);
    92     int (*SetDrawBlendMode) (SDL_Renderer * renderer);
    93     int (*RenderPoint) (SDL_Renderer * renderer, int x, int y);
    94     int (*RenderLine) (SDL_Renderer * renderer, int x1, int y1, int x2,
    95                        int y2);
    96     int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect);
    97     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    98                        const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    99     int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   100                              Uint32 format, void * pixels, int pitch);
   101     int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   102                               Uint32 format, const void * pixels, int pitch);
   103     void (*RenderPresent) (SDL_Renderer * renderer);
   104     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   105 
   106     void (*DestroyRenderer) (SDL_Renderer * renderer);
   107 
   108     /* The current renderer info */
   109     SDL_RendererInfo info;
   110 
   111     /* The window associated with the renderer */
   112     SDL_WindowID window;
   113 
   114     Uint8 r, g, b, a;                   /**< Color for drawing operations values */
   115     int blendMode;                      /**< The drawing blend mode */
   116 
   117     void *driverdata;
   118 };
   119 
   120 /* Define the SDL render driver structure */
   121 struct SDL_RenderDriver
   122 {
   123     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   124 
   125     /* Info about the renderer capabilities */
   126     SDL_RendererInfo info;
   127 };
   128 
   129 /* Define the SDL window structure, corresponding to toplevel windows */
   130 struct SDL_Window
   131 {
   132     Uint32 id;
   133 
   134     char *title;
   135     int x, y;
   136     int w, h;
   137     Uint32 flags;
   138 
   139     int display;
   140     SDL_Renderer *renderer;
   141 
   142     SDL_DisplayMode fullscreen_mode;
   143 
   144     void *userdata;
   145     void *driverdata;
   146 };
   147 #define FULLSCREEN_VISIBLE(W) \
   148     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   149      ((W)->flags & SDL_WINDOW_SHOWN) && \
   150      !((W)->flags & SDL_WINDOW_MINIMIZED))
   151 
   152 /*
   153  * Define the SDL display structure This corresponds to physical monitors
   154  * attached to the system.
   155  */
   156 struct SDL_VideoDisplay
   157 {
   158     int max_display_modes;
   159     int num_display_modes;
   160     SDL_DisplayMode *display_modes;
   161     SDL_DisplayMode desktop_mode;
   162     SDL_DisplayMode current_mode;
   163     SDL_Palette *palette;
   164 
   165     Uint16 *gamma;
   166     Uint16 *saved_gamma;        /* (just offset into gamma) */
   167 
   168     int num_render_drivers;
   169     SDL_RenderDriver *render_drivers;
   170 
   171     int num_windows;
   172     SDL_Window *windows;
   173 
   174     SDL_Renderer *current_renderer;
   175 
   176     /* The hash list of textures */
   177     SDL_Texture *textures[64];
   178 
   179     SDL_VideoDevice *device;
   180 
   181     void *driverdata;
   182 };
   183 
   184 /* Define the SDL video driver structure */
   185 #define _THIS	SDL_VideoDevice *_this
   186 
   187 struct SDL_VideoDevice
   188 {
   189     /* * * */
   190     /* The name of this video driver */
   191     const char *name;
   192 
   193     /* * * */
   194     /* Initialization/Query functions */
   195 
   196     /*
   197      * Initialize the native video subsystem, filling in the list of
   198      * displays for this driver, returning 0 or -1 if there's an error.
   199      */
   200     int (*VideoInit) (_THIS);
   201 
   202     /*
   203      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   204      * if the application is shutting down the video subsystem.
   205      */
   206     void (*VideoQuit) (_THIS);
   207 
   208     /* * * */
   209     /*
   210      * Display functions
   211      */
   212 
   213     /*
   214      * Get a list of the available display modes. e.g.
   215      * SDL_AddDisplayMode(_this->current_display, mode)
   216      */
   217     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   218 
   219     /*
   220      * Setting the display mode is independent of creating windows, so
   221      * when the display mode is changed, all existing windows should have
   222      * their data updated accordingly, including the display surfaces
   223      * associated with them.
   224      */
   225     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   226 
   227     /* Set the color entries of the display palette */
   228     int (*SetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   229 
   230     /* Get the color entries of the display palette */
   231     int (*GetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   232 
   233     /* Set the gamma ramp */
   234     int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   235 
   236     /* Get the gamma ramp */
   237     int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   238 
   239     /* * * */
   240     /*
   241      * Window functions
   242      */
   243     int (*CreateWindow) (_THIS, SDL_Window * window);
   244     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   245     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   246     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   247     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   248     void (*SetWindowSize) (_THIS, SDL_Window * window);
   249     void (*ShowWindow) (_THIS, SDL_Window * window);
   250     void (*HideWindow) (_THIS, SDL_Window * window);
   251     void (*RaiseWindow) (_THIS, SDL_Window * window);
   252     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   253     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   254     void (*RestoreWindow) (_THIS, SDL_Window * window);
   255     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   256     void (*DestroyWindow) (_THIS, SDL_Window * window);
   257 
   258     /* Get some platform dependent window information */
   259       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   260                                   struct SDL_SysWMinfo * info);
   261 
   262     /* * * */
   263     /*
   264      * OpenGL support
   265      */
   266     int (*GL_LoadLibrary) (_THIS, const char *path);
   267     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   268     void (*GL_UnloadLibrary) (_THIS);
   269       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   270     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   271     int (*GL_SetSwapInterval) (_THIS, int interval);
   272     int (*GL_GetSwapInterval) (_THIS);
   273     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   274     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   275 
   276     /* * * */
   277     /*
   278      * Event manager functions
   279      */
   280     void (*PumpEvents) (_THIS);
   281 
   282     /* Suspend the screensaver */
   283     void (*SuspendScreenSaver) (_THIS);
   284 
   285     /* Text input */
   286     void (*StartTextInput) (_THIS);
   287     void (*StopTextInput) (_THIS);
   288     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   289 
   290     /* * * */
   291     /* Data common to all drivers */
   292     SDL_bool suspend_screensaver;
   293     int num_displays;
   294     SDL_VideoDisplay *displays;
   295     int current_display;
   296     Uint32 next_object_id;
   297 
   298     /* * * */
   299     /* Data used by the GL drivers */
   300     struct
   301     {
   302         int red_size;
   303         int green_size;
   304         int blue_size;
   305         int alpha_size;
   306         int depth_size;
   307         int buffer_size;
   308         int stencil_size;
   309         int double_buffer;
   310         int accum_red_size;
   311         int accum_green_size;
   312         int accum_blue_size;
   313         int accum_alpha_size;
   314         int stereo;
   315         int multisamplebuffers;
   316         int multisamplesamples;
   317         int accelerated;
   318         int major_version;
   319         int minor_version;
   320         int retained_backing;
   321         int driver_loaded;
   322         char driver_path[256];
   323         void *dll_handle;
   324     } gl_config;
   325 
   326     /* * * */
   327     /* Data private to this driver */
   328     void *driverdata;
   329     struct SDL_GLDriverData *gl_data;
   330 
   331 #if SDL_VIDEO_DRIVER_PANDORA
   332     struct SDL_PrivateGLESData *gles_data;
   333 #endif
   334 
   335     /* * * */
   336     /* The function used to dispose of this structure */
   337     void (*free) (_THIS);
   338 };
   339 
   340 typedef struct VideoBootStrap
   341 {
   342     const char *name;
   343     const char *desc;
   344     int (*available) (void);
   345     SDL_VideoDevice *(*create) (int devindex);
   346 } VideoBootStrap;
   347 
   348 #if SDL_VIDEO_DRIVER_COCOA
   349 extern VideoBootStrap COCOA_bootstrap;
   350 #endif
   351 #if SDL_VIDEO_DRIVER_X11
   352 extern VideoBootStrap X11_bootstrap;
   353 #endif
   354 #if SDL_VIDEO_DRIVER_FBCON
   355 extern VideoBootStrap FBCON_bootstrap;
   356 #endif
   357 #if SDL_VIDEO_DRIVER_DIRECTFB
   358 extern VideoBootStrap DirectFB_bootstrap;
   359 #endif
   360 #if SDL_VIDEO_DRIVER_PS2GS
   361 extern VideoBootStrap PS2GS_bootstrap;
   362 #endif
   363 #if SDL_VIDEO_DRIVER_PS3
   364 extern VideoBootStrap PS3_bootstrap;
   365 #endif
   366 #if SDL_VIDEO_DRIVER_SVGALIB
   367 extern VideoBootStrap SVGALIB_bootstrap;
   368 #endif
   369 #if SDL_VIDEO_DRIVER_GAPI
   370 extern VideoBootStrap GAPI_bootstrap;
   371 #endif
   372 #if SDL_VIDEO_DRIVER_WIN32
   373 extern VideoBootStrap WIN32_bootstrap;
   374 #endif
   375 #if SDL_VIDEO_DRIVER_BWINDOW
   376 extern VideoBootStrap BWINDOW_bootstrap;
   377 #endif
   378 #if SDL_VIDEO_DRIVER_PHOTON
   379 extern VideoBootStrap photon_bootstrap;
   380 #endif
   381 #if SDL_VIDEO_DRIVER_QNXGF
   382 extern VideoBootStrap qnxgf_bootstrap;
   383 #endif
   384 #if SDL_VIDEO_DRIVER_EPOC
   385 extern VideoBootStrap EPOC_bootstrap;
   386 #endif
   387 #if SDL_VIDEO_DRIVER_RISCOS
   388 extern VideoBootStrap RISCOS_bootstrap;
   389 #endif
   390 #if SDL_VIDEO_DRIVER_UIKIT
   391 extern VideoBootStrap UIKIT_bootstrap;
   392 #endif
   393 #if SDL_VIDEO_DRIVER_DUMMY
   394 extern VideoBootStrap DUMMY_bootstrap;
   395 #endif
   396 #if SDL_VIDEO_DRIVER_NDS
   397 extern VideoBootStrap NDS_bootstrap;
   398 #endif
   399 #if SDL_VIDEO_DRIVER_PANDORA
   400 extern VideoBootStrap PND_bootstrap;
   401 #endif
   402 
   403 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   404 #define SDL_CurrentRenderer	(SDL_CurrentDisplay.current_renderer)
   405 
   406 extern SDL_VideoDevice *SDL_GetVideoDevice();
   407 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   408 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   409 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   410 extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
   411 extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
   412 extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   413 extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   414 extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
   415 extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
   416 extern int SDL_SetDisplayPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors);
   417 extern int SDL_GetDisplayPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors);
   418 extern void SDL_AddRenderDriver(SDL_VideoDisplay *display, const SDL_RenderDriver * driver);
   419 
   420 extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue);
   421 extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue);
   422 
   423 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   424 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   425 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   426 
   427 extern void SDL_OnWindowShown(SDL_Window * window);
   428 extern void SDL_OnWindowHidden(SDL_Window * window);
   429 extern void SDL_OnWindowResized(SDL_Window * window);
   430 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   431 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   432 extern SDL_WindowID SDL_GetFocusWindow(void);
   433 
   434 #endif /* _SDL_sysvideo_h */
   435 
   436 /* vi: set ts=4 sw=4 expandtab: */