src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 12 Dec 2010 15:19:05 -0800
changeset 4929 aa8888658021
parent 4862 7b1d35d98294
child 5045 1cee937d9fcc
permissions -rw-r--r--
Use the enumerated type for blend and scale mode instead of int
Renamed SDL_TextureScaleMode to SDL_ScaleMode
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 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 #include "SDL_shape.h"
    30 
    31 /* The SDL video driver */
    32 
    33 typedef struct SDL_Renderer SDL_Renderer;
    34 typedef struct SDL_RenderDriver SDL_RenderDriver;
    35 typedef struct SDL_WindowShaper SDL_WindowShaper;
    36 typedef struct SDL_ShapeDriver SDL_ShapeDriver;
    37 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    38 typedef struct SDL_VideoDevice SDL_VideoDevice;
    39 
    40 /* Define the SDL texture structure */
    41 struct SDL_Texture
    42 {
    43     const void *magic;
    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     SDL_BlendMode blendMode;    /**< The texture blend mode */
    50     SDL_ScaleMode 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 *prev;
    58     SDL_Texture *next;
    59 };
    60 
    61 /* Define the SDL renderer structure */
    62 struct SDL_Renderer
    63 {
    64     int (*ActivateRenderer) (SDL_Renderer * renderer);
    65     int (*DisplayModeChanged) (SDL_Renderer * renderer);
    66     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    67     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    68                                void **pixels, int *pitch);
    69     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    70                               const SDL_Color * colors, int firstcolor,
    71                               int ncolors);
    72     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    73                               SDL_Color * colors, int firstcolor,
    74                               int ncolors);
    75     int (*SetTextureColorMod) (SDL_Renderer * renderer,
    76                                SDL_Texture * texture);
    77     int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
    78                                SDL_Texture * texture);
    79     int (*SetTextureBlendMode) (SDL_Renderer * renderer,
    80                                 SDL_Texture * texture);
    81     int (*SetTextureScaleMode) (SDL_Renderer * renderer,
    82                                 SDL_Texture * texture);
    83     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    84                           const SDL_Rect * rect, const void *pixels,
    85                           int pitch);
    86     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    87                         const SDL_Rect * rect, int markDirty, void **pixels,
    88                         int *pitch);
    89     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    90     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    91                           int numrects, const SDL_Rect * rects);
    92     int (*SetDrawColor) (SDL_Renderer * renderer);
    93     int (*SetDrawBlendMode) (SDL_Renderer * renderer);
    94     int (*RenderClear) (SDL_Renderer * renderer);
    95     int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points,
    96                              int count);
    97     int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
    98                             int count);
    99     int (*RenderDrawRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
   100                             int count);
   101     int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
   102                             int count);
   103     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
   104                        const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   105     int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   106                              Uint32 format, void * pixels, int pitch);
   107     int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   108                               Uint32 format, const void * pixels, int pitch);
   109     void (*RenderPresent) (SDL_Renderer * renderer);
   110     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   111 
   112     void (*DestroyRenderer) (SDL_Renderer * renderer);
   113 
   114     /* The current renderer info */
   115     SDL_RendererInfo info;
   116 
   117     /* The window associated with the renderer */
   118     SDL_Window *window;
   119 
   120     /* The list of textures */
   121     SDL_Texture *textures;
   122 
   123     Uint8 r, g, b, a;                   /**< Color for drawing operations values */
   124     SDL_BlendMode blendMode;            /**< The drawing blend mode */
   125 
   126     void *driverdata;
   127 };
   128 
   129 /* Define the SDL render driver structure */
   130 struct SDL_RenderDriver
   131 {
   132     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   133 
   134     /* Info about the renderer capabilities */
   135     SDL_RendererInfo info;
   136 };
   137 
   138 /* Define the SDL window-shaper structure */
   139 struct SDL_WindowShaper
   140 {   
   141     /* The window associated with the shaper */
   142     SDL_Window *window;
   143     
   144     /* The user's specified coordinates for the window, for once we give it a shape. */
   145     Uint32 userx,usery;
   146     
   147     /* The parameters for shape calculation. */
   148     SDL_WindowShapeMode mode;
   149     
   150     /* Has this window been assigned a shape? */
   151     SDL_bool hasshape;
   152     
   153     void *driverdata;
   154 };
   155 
   156 /* Define the SDL shape driver structure */
   157 struct SDL_ShapeDriver
   158 {
   159     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
   160     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
   161     int (*ResizeWindowShape)(SDL_Window *window);
   162 };
   163 
   164 /* Define the SDL window structure, corresponding to toplevel windows */
   165 struct SDL_Window
   166 {
   167     const void *magic;
   168     Uint32 id;
   169     char *title;
   170     int x, y;
   171     int w, h;
   172     Uint32 flags;
   173 
   174     SDL_VideoDisplay *display;
   175     SDL_Renderer *renderer;
   176 
   177     SDL_DisplayMode fullscreen_mode;
   178     
   179     SDL_WindowShaper *shaper;
   180 
   181     void *userdata;
   182     void *driverdata;
   183 
   184     SDL_Window *prev;
   185     SDL_Window *next;
   186 };
   187 #define FULLSCREEN_VISIBLE(W) \
   188     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   189      ((W)->flags & SDL_WINDOW_SHOWN) && \
   190      !((W)->flags & SDL_WINDOW_MINIMIZED))
   191 
   192 /*
   193  * Define the SDL display structure This corresponds to physical monitors
   194  * attached to the system.
   195  */
   196 struct SDL_VideoDisplay
   197 {
   198     int max_display_modes;
   199     int num_display_modes;
   200     SDL_DisplayMode *display_modes;
   201     SDL_DisplayMode desktop_mode;
   202     SDL_DisplayMode current_mode;
   203     SDL_bool updating_fullscreen;
   204     SDL_Palette *palette;
   205 
   206     Uint16 *gamma;
   207     Uint16 *saved_gamma;        /* (just offset into gamma) */
   208 
   209     int num_render_drivers;
   210     SDL_RenderDriver *render_drivers;
   211 
   212     SDL_Window *windows;
   213     SDL_Window *fullscreen_window;
   214 
   215     SDL_Renderer *current_renderer;
   216 
   217     SDL_VideoDevice *device;
   218 
   219     void *driverdata;
   220 };
   221 
   222 /* Define the SDL video driver structure */
   223 #define _THIS	SDL_VideoDevice *_this
   224 
   225 struct SDL_VideoDevice
   226 {
   227     /* * * */
   228     /* The name of this video driver */
   229     const char *name;
   230 
   231     /* * * */
   232     /* Initialization/Query functions */
   233 
   234     /*
   235      * Initialize the native video subsystem, filling in the list of
   236      * displays for this driver, returning 0 or -1 if there's an error.
   237      */
   238     int (*VideoInit) (_THIS);
   239 
   240     /*
   241      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   242      * if the application is shutting down the video subsystem.
   243      */
   244     void (*VideoQuit) (_THIS);
   245 
   246     /* * * */
   247     /*
   248      * Display functions
   249      */
   250 
   251     /*
   252      * Get the bounds of a display
   253      */
   254     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   255 
   256     /*
   257      * Get a list of the available display modes. e.g.
   258      * SDL_AddDisplayMode(_this->current_display, mode)
   259      */
   260     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   261 
   262     /*
   263      * Setting the display mode is independent of creating windows, so
   264      * when the display mode is changed, all existing windows should have
   265      * their data updated accordingly, including the display surfaces
   266      * associated with them.
   267      */
   268     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   269 
   270     /* Set the color entries of the display palette */
   271     int (*SetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   272 
   273     /* Get the color entries of the display palette */
   274     int (*GetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   275 
   276     /* Set the gamma ramp */
   277     int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   278 
   279     /* Get the gamma ramp */
   280     int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   281 
   282     /* * * */
   283     /*
   284      * Window functions
   285      */
   286     int (*CreateWindow) (_THIS, SDL_Window * window);
   287     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   288     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   289     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   290     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   291     void (*SetWindowSize) (_THIS, SDL_Window * window);
   292     void (*ShowWindow) (_THIS, SDL_Window * window);
   293     void (*HideWindow) (_THIS, SDL_Window * window);
   294     void (*RaiseWindow) (_THIS, SDL_Window * window);
   295     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   296     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   297     void (*RestoreWindow) (_THIS, SDL_Window * window);
   298     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   299     void (*DestroyWindow) (_THIS, SDL_Window * window);
   300     
   301     /* * * */
   302     /*
   303      * Shaped-window functions
   304      */
   305     SDL_ShapeDriver shape_driver;
   306 
   307     /* Get some platform dependent window information */
   308       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   309                                   struct SDL_SysWMinfo * info);
   310 
   311     /* * * */
   312     /*
   313      * OpenGL support
   314      */
   315     int (*GL_LoadLibrary) (_THIS, const char *path);
   316     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   317     void (*GL_UnloadLibrary) (_THIS);
   318       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   319     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   320     int (*GL_SetSwapInterval) (_THIS, int interval);
   321     int (*GL_GetSwapInterval) (_THIS);
   322     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   323     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   324 
   325     /* * * */
   326     /*
   327      * Event manager functions
   328      */
   329     void (*PumpEvents) (_THIS);
   330 
   331     /* Suspend the screensaver */
   332     void (*SuspendScreenSaver) (_THIS);
   333 
   334     /* Text input */
   335     void (*StartTextInput) (_THIS);
   336     void (*StopTextInput) (_THIS);
   337     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   338 
   339     /* Clipboard */
   340     int (*SetClipboardText) (_THIS, const char *text);
   341     char * (*GetClipboardText) (_THIS);
   342     SDL_bool (*HasClipboardText) (_THIS);
   343 
   344     /* * * */
   345     /* Data common to all drivers */
   346     SDL_bool suspend_screensaver;
   347     int num_displays;
   348     SDL_VideoDisplay *displays;
   349     int current_display;
   350     Uint8 window_magic;
   351     Uint8 texture_magic;
   352     Uint32 next_object_id;
   353     char * clipboard_text;
   354 
   355     /* * * */
   356     /* Data used by the GL drivers */
   357     struct
   358     {
   359         int red_size;
   360         int green_size;
   361         int blue_size;
   362         int alpha_size;
   363         int depth_size;
   364         int buffer_size;
   365         int stencil_size;
   366         int double_buffer;
   367         int accum_red_size;
   368         int accum_green_size;
   369         int accum_blue_size;
   370         int accum_alpha_size;
   371         int stereo;
   372         int multisamplebuffers;
   373         int multisamplesamples;
   374         int accelerated;
   375         int major_version;
   376         int minor_version;
   377         int retained_backing;
   378         int driver_loaded;
   379         char driver_path[256];
   380         void *dll_handle;
   381     } gl_config;
   382 
   383     /* * * */
   384     /* Data private to this driver */
   385     void *driverdata;
   386     struct SDL_GLDriverData *gl_data;
   387 
   388 #if SDL_VIDEO_DRIVER_PANDORA
   389     struct SDL_PrivateGLESData *gles_data;
   390 #endif
   391 
   392     /* * * */
   393     /* The function used to dispose of this structure */
   394     void (*free) (_THIS);
   395 };
   396 
   397 typedef struct VideoBootStrap
   398 {
   399     const char *name;
   400     const char *desc;
   401     int (*available) (void);
   402     SDL_VideoDevice *(*create) (int devindex);
   403 } VideoBootStrap;
   404 
   405 #if SDL_VIDEO_DRIVER_COCOA
   406 extern VideoBootStrap COCOA_bootstrap;
   407 #endif
   408 #if SDL_VIDEO_DRIVER_X11
   409 extern VideoBootStrap X11_bootstrap;
   410 #endif
   411 #if SDL_VIDEO_DRIVER_FBCON
   412 extern VideoBootStrap FBCON_bootstrap;
   413 #endif
   414 #if SDL_VIDEO_DRIVER_DIRECTFB
   415 extern VideoBootStrap DirectFB_bootstrap;
   416 #endif
   417 #if SDL_VIDEO_DRIVER_PS3
   418 extern VideoBootStrap PS3_bootstrap;
   419 #endif
   420 #if SDL_VIDEO_DRIVER_SVGALIB
   421 extern VideoBootStrap SVGALIB_bootstrap;
   422 #endif
   423 #if SDL_VIDEO_DRIVER_WIN32
   424 extern VideoBootStrap WIN32_bootstrap;
   425 #endif
   426 #if SDL_VIDEO_DRIVER_BWINDOW
   427 extern VideoBootStrap BWINDOW_bootstrap;
   428 #endif
   429 #if SDL_VIDEO_DRIVER_PHOTON
   430 extern VideoBootStrap photon_bootstrap;
   431 #endif
   432 #if SDL_VIDEO_DRIVER_QNXGF
   433 extern VideoBootStrap qnxgf_bootstrap;
   434 #endif
   435 #if SDL_VIDEO_DRIVER_EPOC
   436 extern VideoBootStrap EPOC_bootstrap;
   437 #endif
   438 #if SDL_VIDEO_DRIVER_RISCOS
   439 extern VideoBootStrap RISCOS_bootstrap;
   440 #endif
   441 #if SDL_VIDEO_DRIVER_UIKIT
   442 extern VideoBootStrap UIKIT_bootstrap;
   443 #endif
   444 #if SDL_VIDEO_DRIVER_DUMMY
   445 extern VideoBootStrap DUMMY_bootstrap;
   446 #endif
   447 #if SDL_VIDEO_DRIVER_NDS
   448 extern VideoBootStrap NDS_bootstrap;
   449 #endif
   450 #if SDL_VIDEO_DRIVER_PANDORA
   451 extern VideoBootStrap PND_bootstrap;
   452 #endif
   453 #if SDL_VIDEO_DRIVER_ANDROID
   454 extern VideoBootStrap Android_bootstrap;
   455 #endif
   456 
   457 #define SDL_CurrentDisplay	(&_this->displays[_this->current_display])
   458 #define SDL_CurrentRenderer	(SDL_CurrentDisplay->current_renderer)
   459 
   460 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   461 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   462 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   463 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   464 extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
   465 extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
   466 extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   467 extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   468 extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
   469 extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
   470 extern int SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors);
   471 extern int SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors);
   472 extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue);
   473 extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue);
   474 extern void SDL_AddRenderDriver(SDL_VideoDisplay *display, const SDL_RenderDriver * driver);
   475 
   476 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   477 
   478 extern void SDL_OnWindowShown(SDL_Window * window);
   479 extern void SDL_OnWindowHidden(SDL_Window * window);
   480 extern void SDL_OnWindowResized(SDL_Window * window);
   481 extern void SDL_OnWindowMinimized(SDL_Window * window);
   482 extern void SDL_OnWindowRestored(SDL_Window * window);
   483 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   484 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   485 extern SDL_Window * SDL_GetFocusWindow(void);
   486 
   487 #endif /* _SDL_sysvideo_h */
   488 
   489 /* vi: set ts=4 sw=4 expandtab: */