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