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