src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 15 Feb 2011 13:59:59 -0800
changeset 5297 1800dc39b74c
parent 5272 3c94c559f5c2
child 5305 75f5ff92ad08
permissions -rw-r--r--
Changed the concept of a render clip rect to a render viewport.
The render viewport is automatically re-centered when the window changes size, so applications that don't care will not have to handle recalculating their rendering coordinates.

Fixed API for drawing and filling multiple rectangles - the parameter should be an array of rects, not an array of pointers to rects.

Fixed API for updating window rects for consistency with other APIs - the order is pointer to array followed by count in array.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 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_shape.h"
    28 
    29 /* The SDL video driver */
    30 
    31 typedef struct SDL_WindowShaper SDL_WindowShaper;
    32 typedef struct SDL_ShapeDriver SDL_ShapeDriver;
    33 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    34 typedef struct SDL_VideoDevice SDL_VideoDevice;
    35 
    36 /* Define the SDL window-shaper structure */
    37 struct SDL_WindowShaper
    38 {   
    39     /* The window associated with the shaper */
    40     SDL_Window *window;
    41     
    42     /* The user's specified coordinates for the window, for once we give it a shape. */
    43     Uint32 userx,usery;
    44     
    45     /* The parameters for shape calculation. */
    46     SDL_WindowShapeMode mode;
    47     
    48     /* Has this window been assigned a shape? */
    49     SDL_bool hasshape;
    50     
    51     void *driverdata;
    52 };
    53 
    54 /* Define the SDL shape driver structure */
    55 struct SDL_ShapeDriver
    56 {
    57     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
    58     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
    59     int (*ResizeWindowShape)(SDL_Window *window);
    60 };
    61 
    62 typedef struct SDL_WindowUserData
    63 {
    64     char *name;
    65     void *data;
    66     struct SDL_WindowUserData *next;
    67 } SDL_WindowUserData;
    68 
    69 /* Define the SDL window structure, corresponding to toplevel windows */
    70 struct SDL_Window
    71 {
    72     const void *magic;
    73     Uint32 id;
    74     char *title;
    75     int x, y;
    76     int w, h;
    77     Uint32 flags;
    78 
    79     SDL_DisplayMode fullscreen_mode;
    80     
    81     SDL_Surface *surface;
    82     SDL_bool surface_valid;
    83 
    84     SDL_WindowShaper *shaper;
    85 
    86     SDL_WindowUserData *data;
    87 
    88     void *driverdata;
    89 
    90     SDL_Window *prev;
    91     SDL_Window *next;
    92 };
    93 #define FULLSCREEN_VISIBLE(W) \
    94     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
    95      ((W)->flags & SDL_WINDOW_SHOWN) && \
    96      !((W)->flags & SDL_WINDOW_MINIMIZED))
    97 
    98 /*
    99  * Define the SDL display structure This corresponds to physical monitors
   100  * attached to the system.
   101  */
   102 struct SDL_VideoDisplay
   103 {
   104     int max_display_modes;
   105     int num_display_modes;
   106     SDL_DisplayMode *display_modes;
   107     SDL_DisplayMode desktop_mode;
   108     SDL_DisplayMode current_mode;
   109 
   110     SDL_Window *fullscreen_window;
   111 
   112     SDL_VideoDevice *device;
   113 
   114     void *driverdata;
   115 };
   116 
   117 /* Forward declaration */
   118 struct SDL_SysWMinfo;
   119 
   120 /* Define the SDL video driver structure */
   121 #define _THIS	SDL_VideoDevice *_this
   122 
   123 struct SDL_VideoDevice
   124 {
   125     /* * * */
   126     /* The name of this video driver */
   127     const char *name;
   128 
   129     /* * * */
   130     /* Initialization/Query functions */
   131 
   132     /*
   133      * Initialize the native video subsystem, filling in the list of
   134      * displays for this driver, returning 0 or -1 if there's an error.
   135      */
   136     int (*VideoInit) (_THIS);
   137 
   138     /*
   139      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   140      * if the application is shutting down the video subsystem.
   141      */
   142     void (*VideoQuit) (_THIS);
   143 
   144     /* * * */
   145     /*
   146      * Display functions
   147      */
   148 
   149     /*
   150      * Get the bounds of a display
   151      */
   152     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   153 
   154     /*
   155      * Get a list of the available display modes for a display.
   156      */
   157     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   158 
   159     /*
   160      * Setting the display mode is independent of creating windows, so
   161      * when the display mode is changed, all existing windows should have
   162      * their data updated accordingly, including the display surfaces
   163      * associated with them.
   164      */
   165     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   166 
   167     /* * * */
   168     /*
   169      * Window functions
   170      */
   171     int (*CreateWindow) (_THIS, SDL_Window * window);
   172     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   173     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   174     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   175     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   176     void (*SetWindowSize) (_THIS, SDL_Window * window);
   177     void (*ShowWindow) (_THIS, SDL_Window * window);
   178     void (*HideWindow) (_THIS, SDL_Window * window);
   179     void (*RaiseWindow) (_THIS, SDL_Window * window);
   180     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   181     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   182     void (*RestoreWindow) (_THIS, SDL_Window * window);
   183     void (*PrepWindowFullscreen) (_THIS, SDL_Window * window);
   184     void (*SetWindowFullscreen) (_THIS, SDL_Window * window);
   185     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   186     void (*DestroyWindow) (_THIS, SDL_Window * window);
   187     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   188     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
   189     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   190 
   191     /* * * */
   192     /*
   193      * Shaped-window functions
   194      */
   195     SDL_ShapeDriver shape_driver;
   196 
   197     /* Get some platform dependent window information */
   198       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   199                                   struct SDL_SysWMinfo * info);
   200 
   201     /* * * */
   202     /*
   203      * OpenGL support
   204      */
   205     int (*GL_LoadLibrary) (_THIS, const char *path);
   206     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   207     void (*GL_UnloadLibrary) (_THIS);
   208       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   209     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   210     int (*GL_SetSwapInterval) (_THIS, int interval);
   211     int (*GL_GetSwapInterval) (_THIS);
   212     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   213     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   214 
   215     /* * * */
   216     /*
   217      * Event manager functions
   218      */
   219     void (*PumpEvents) (_THIS);
   220 
   221     /* Suspend the screensaver */
   222     void (*SuspendScreenSaver) (_THIS);
   223 
   224     /* Text input */
   225     void (*StartTextInput) (_THIS);
   226     void (*StopTextInput) (_THIS);
   227     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   228 
   229     /* Clipboard */
   230     int (*SetClipboardText) (_THIS, const char *text);
   231     char * (*GetClipboardText) (_THIS);
   232     SDL_bool (*HasClipboardText) (_THIS);
   233 
   234     /* * * */
   235     /* Data common to all drivers */
   236     SDL_bool suspend_screensaver;
   237     int num_displays;
   238     SDL_VideoDisplay *displays;
   239     SDL_Window *windows;
   240     Uint8 window_magic;
   241     Uint32 next_object_id;
   242     char * clipboard_text;
   243 
   244     /* * * */
   245     /* Data used by the GL drivers */
   246     struct
   247     {
   248         int red_size;
   249         int green_size;
   250         int blue_size;
   251         int alpha_size;
   252         int depth_size;
   253         int buffer_size;
   254         int stencil_size;
   255         int double_buffer;
   256         int accum_red_size;
   257         int accum_green_size;
   258         int accum_blue_size;
   259         int accum_alpha_size;
   260         int stereo;
   261         int multisamplebuffers;
   262         int multisamplesamples;
   263         int accelerated;
   264         int major_version;
   265         int minor_version;
   266         int retained_backing;
   267         int driver_loaded;
   268         char driver_path[256];
   269         void *dll_handle;
   270     } gl_config;
   271 
   272     /* * * */
   273     /* Data private to this driver */
   274     void *driverdata;
   275     struct SDL_GLDriverData *gl_data;
   276 
   277 #if SDL_VIDEO_DRIVER_PANDORA
   278     struct SDL_PrivateGLESData *gles_data;
   279 #endif
   280 
   281     /* * * */
   282     /* The function used to dispose of this structure */
   283     void (*free) (_THIS);
   284 };
   285 
   286 typedef struct VideoBootStrap
   287 {
   288     const char *name;
   289     const char *desc;
   290     int (*available) (void);
   291     SDL_VideoDevice *(*create) (int devindex);
   292 } VideoBootStrap;
   293 
   294 #if SDL_VIDEO_DRIVER_COCOA
   295 extern VideoBootStrap COCOA_bootstrap;
   296 #endif
   297 #if SDL_VIDEO_DRIVER_X11
   298 extern VideoBootStrap X11_bootstrap;
   299 #endif
   300 #if SDL_VIDEO_DRIVER_DIRECTFB
   301 extern VideoBootStrap DirectFB_bootstrap;
   302 #endif
   303 #if SDL_VIDEO_DRIVER_WINDOWS
   304 extern VideoBootStrap WINDOWS_bootstrap;
   305 #endif
   306 #if SDL_VIDEO_DRIVER_BWINDOW
   307 extern VideoBootStrap BWINDOW_bootstrap;
   308 #endif
   309 #if SDL_VIDEO_DRIVER_PANDORA
   310 extern VideoBootStrap PND_bootstrap;
   311 #endif
   312 #if SDL_VIDEO_DRIVER_NDS
   313 extern VideoBootStrap NDS_bootstrap;
   314 #endif
   315 #if SDL_VIDEO_DRIVER_UIKIT
   316 extern VideoBootStrap UIKIT_bootstrap;
   317 #endif
   318 #if SDL_VIDEO_DRIVER_ANDROID
   319 extern VideoBootStrap Android_bootstrap;
   320 #endif
   321 #if SDL_VIDEO_DRIVER_DUMMY
   322 extern VideoBootStrap DUMMY_bootstrap;
   323 #endif
   324 
   325 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   326 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   327 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   328 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   329 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   330 
   331 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   332 
   333 extern void SDL_OnWindowShown(SDL_Window * window);
   334 extern void SDL_OnWindowHidden(SDL_Window * window);
   335 extern void SDL_OnWindowResized(SDL_Window * window);
   336 extern void SDL_OnWindowMinimized(SDL_Window * window);
   337 extern void SDL_OnWindowRestored(SDL_Window * window);
   338 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   339 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   340 extern SDL_Window * SDL_GetFocusWindow(void);
   341 
   342 #endif /* _SDL_sysvideo_h */
   343 
   344 /* vi: set ts=4 sw=4 expandtab: */