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