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