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