src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 11 Feb 2011 00:25:44 -0800
changeset 5249 7a963be087ef
parent 5246 58265e606e4e
child 5261 595814f561f7
permissions -rw-r--r--
Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.

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