src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 10 Feb 2011 14:44:25 -0800
changeset 5246 58265e606e4e
parent 5244 762e40fb8e28
child 5249 7a963be087ef
permissions -rw-r--r--
Window coordinates are in the global space and windows are not tied to a particular display.
Also added Ctrl-Enter keybinding to the test code to toggle fullscreen mode for testing.
     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_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     SDL_bool updating_fullscreen;
   110 
   111     SDL_Window *fullscreen_window;
   112 
   113     SDL_VideoDevice *device;
   114 
   115     void *driverdata;
   116 };
   117 
   118 /* Define the SDL video driver structure */
   119 #define _THIS	SDL_VideoDevice *_this
   120 
   121 struct SDL_VideoDevice
   122 {
   123     /* * * */
   124     /* The name of this video driver */
   125     const char *name;
   126 
   127     /* * * */
   128     /* Initialization/Query functions */
   129 
   130     /*
   131      * Initialize the native video subsystem, filling in the list of
   132      * displays for this driver, returning 0 or -1 if there's an error.
   133      */
   134     int (*VideoInit) (_THIS);
   135 
   136     /*
   137      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   138      * if the application is shutting down the video subsystem.
   139      */
   140     void (*VideoQuit) (_THIS);
   141 
   142     /* * * */
   143     /*
   144      * Display functions
   145      */
   146 
   147     /*
   148      * Get the bounds of a display
   149      */
   150     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   151 
   152     /*
   153      * Get a list of the available display modes for a display.
   154      */
   155     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   156 
   157     /*
   158      * Setting the display mode is independent of creating windows, so
   159      * when the display mode is changed, all existing windows should have
   160      * their data updated accordingly, including the display surfaces
   161      * associated with them.
   162      */
   163     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   164 
   165     /* * * */
   166     /*
   167      * Window functions
   168      */
   169     int (*CreateWindow) (_THIS, SDL_Window * window);
   170     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   171     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   172     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   173     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   174     void (*SetWindowSize) (_THIS, SDL_Window * window);
   175     void (*ShowWindow) (_THIS, SDL_Window * window);
   176     void (*HideWindow) (_THIS, SDL_Window * window);
   177     void (*RaiseWindow) (_THIS, SDL_Window * window);
   178     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   179     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   180     void (*RestoreWindow) (_THIS, SDL_Window * window);
   181     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   182     void (*DestroyWindow) (_THIS, SDL_Window * window);
   183     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   184     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
   185     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   186 
   187     /* * * */
   188     /*
   189      * Shaped-window functions
   190      */
   191     SDL_ShapeDriver shape_driver;
   192 
   193     /* Get some platform dependent window information */
   194       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   195                                   struct SDL_SysWMinfo * info);
   196 
   197     /* * * */
   198     /*
   199      * OpenGL support
   200      */
   201     int (*GL_LoadLibrary) (_THIS, const char *path);
   202     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   203     void (*GL_UnloadLibrary) (_THIS);
   204       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   205     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   206     int (*GL_SetSwapInterval) (_THIS, int interval);
   207     int (*GL_GetSwapInterval) (_THIS);
   208     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   209     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   210 
   211     /* * * */
   212     /*
   213      * Event manager functions
   214      */
   215     void (*PumpEvents) (_THIS);
   216 
   217     /* Suspend the screensaver */
   218     void (*SuspendScreenSaver) (_THIS);
   219 
   220     /* Text input */
   221     void (*StartTextInput) (_THIS);
   222     void (*StopTextInput) (_THIS);
   223     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   224 
   225     /* Clipboard */
   226     int (*SetClipboardText) (_THIS, const char *text);
   227     char * (*GetClipboardText) (_THIS);
   228     SDL_bool (*HasClipboardText) (_THIS);
   229 
   230     /* * * */
   231     /* Data common to all drivers */
   232     SDL_bool suspend_screensaver;
   233     int num_displays;
   234     SDL_VideoDisplay *displays;
   235     SDL_Window *windows;
   236     Uint8 window_magic;
   237     Uint32 next_object_id;
   238     char * clipboard_text;
   239 
   240     /* * * */
   241     /* Data used by the GL drivers */
   242     struct
   243     {
   244         int red_size;
   245         int green_size;
   246         int blue_size;
   247         int alpha_size;
   248         int depth_size;
   249         int buffer_size;
   250         int stencil_size;
   251         int double_buffer;
   252         int accum_red_size;
   253         int accum_green_size;
   254         int accum_blue_size;
   255         int accum_alpha_size;
   256         int stereo;
   257         int multisamplebuffers;
   258         int multisamplesamples;
   259         int accelerated;
   260         int major_version;
   261         int minor_version;
   262         int retained_backing;
   263         int driver_loaded;
   264         char driver_path[256];
   265         void *dll_handle;
   266     } gl_config;
   267 
   268     /* * * */
   269     /* Data private to this driver */
   270     void *driverdata;
   271     struct SDL_GLDriverData *gl_data;
   272 
   273 #if SDL_VIDEO_DRIVER_PANDORA
   274     struct SDL_PrivateGLESData *gles_data;
   275 #endif
   276 
   277     /* * * */
   278     /* The function used to dispose of this structure */
   279     void (*free) (_THIS);
   280 };
   281 
   282 typedef struct VideoBootStrap
   283 {
   284     const char *name;
   285     const char *desc;
   286     int (*available) (void);
   287     SDL_VideoDevice *(*create) (int devindex);
   288 } VideoBootStrap;
   289 
   290 #if SDL_VIDEO_DRIVER_COCOA
   291 extern VideoBootStrap COCOA_bootstrap;
   292 #endif
   293 #if SDL_VIDEO_DRIVER_X11
   294 extern VideoBootStrap X11_bootstrap;
   295 #endif
   296 #if SDL_VIDEO_DRIVER_DIRECTFB
   297 extern VideoBootStrap DirectFB_bootstrap;
   298 #endif
   299 #if SDL_VIDEO_DRIVER_WINDOWS
   300 extern VideoBootStrap WINDOWS_bootstrap;
   301 #endif
   302 #if SDL_VIDEO_DRIVER_BWINDOW
   303 extern VideoBootStrap BWINDOW_bootstrap;
   304 #endif
   305 #if SDL_VIDEO_DRIVER_PANDORA
   306 extern VideoBootStrap PND_bootstrap;
   307 #endif
   308 #if SDL_VIDEO_DRIVER_NDS
   309 extern VideoBootStrap NDS_bootstrap;
   310 #endif
   311 #if SDL_VIDEO_DRIVER_UIKIT
   312 extern VideoBootStrap UIKIT_bootstrap;
   313 #endif
   314 #if SDL_VIDEO_DRIVER_ANDROID
   315 extern VideoBootStrap Android_bootstrap;
   316 #endif
   317 #if SDL_VIDEO_DRIVER_DUMMY
   318 extern VideoBootStrap DUMMY_bootstrap;
   319 #endif
   320 
   321 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   322 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   323 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   324 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   325 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   326 
   327 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   328 
   329 extern void SDL_OnWindowShown(SDL_Window * window);
   330 extern void SDL_OnWindowHidden(SDL_Window * window);
   331 extern void SDL_OnWindowResized(SDL_Window * window);
   332 extern void SDL_OnWindowMinimized(SDL_Window * window);
   333 extern void SDL_OnWindowRestored(SDL_Window * window);
   334 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   335 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   336 extern SDL_Window * SDL_GetFocusWindow(void);
   337 
   338 #endif /* _SDL_sysvideo_h */
   339 
   340 /* vi: set ts=4 sw=4 expandtab: */