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