src/video/SDL_sysvideo.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 15 Jul 2011 17:05:32 -0700
changeset 5563 2a152e7e82f2
parent 5535 96594ac5fd1a
child 6138 4c64952a58fb
permissions -rw-r--r--
Turn SDL_GL_MakeCurrent() into a no-op if setting the same context twice.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #ifndef _SDL_sysvideo_h
    24 #define _SDL_sysvideo_h
    25 
    26 #include "SDL_shape.h"
    27 
    28 /* The SDL video driver */
    29 
    30 typedef struct SDL_WindowShaper SDL_WindowShaper;
    31 typedef struct SDL_ShapeDriver SDL_ShapeDriver;
    32 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    33 typedef struct SDL_VideoDevice SDL_VideoDevice;
    34 
    35 /* Define the SDL window-shaper structure */
    36 struct SDL_WindowShaper
    37 {   
    38     /* The window associated with the shaper */
    39     SDL_Window *window;
    40     
    41     /* The user's specified coordinates for the window, for once we give it a shape. */
    42     Uint32 userx,usery;
    43     
    44     /* The parameters for shape calculation. */
    45     SDL_WindowShapeMode mode;
    46     
    47     /* Has this window been assigned a shape? */
    48     SDL_bool hasshape;
    49     
    50     void *driverdata;
    51 };
    52 
    53 /* Define the SDL shape driver structure */
    54 struct SDL_ShapeDriver
    55 {
    56     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
    57     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
    58     int (*ResizeWindowShape)(SDL_Window *window);
    59 };
    60 
    61 typedef struct SDL_WindowUserData
    62 {
    63     char *name;
    64     void *data;
    65     struct SDL_WindowUserData *next;
    66 } SDL_WindowUserData;
    67 
    68 /* Define the SDL window structure, corresponding to toplevel windows */
    69 struct SDL_Window
    70 {
    71     const void *magic;
    72     Uint32 id;
    73     char *title;
    74     int x, y;
    75     int w, h;
    76     Uint32 flags;
    77 
    78     /* Stored position and size for windowed mode */
    79     SDL_Rect windowed;
    80 
    81     SDL_DisplayMode fullscreen_mode;
    82     
    83     float brightness;
    84     Uint16 *gamma;
    85     Uint16 *saved_gamma;        /* (just offset into gamma) */
    86 
    87     SDL_Surface *surface;
    88     SDL_bool surface_valid;
    89 
    90     SDL_WindowShaper *shaper;
    91 
    92     SDL_WindowUserData *data;
    93 
    94     void *driverdata;
    95 
    96     SDL_Window *prev;
    97     SDL_Window *next;
    98 };
    99 #define FULLSCREEN_VISIBLE(W) \
   100     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   101      ((W)->flags & SDL_WINDOW_SHOWN) && \
   102      !((W)->flags & SDL_WINDOW_MINIMIZED))
   103 
   104 /*
   105  * Define the SDL display structure This corresponds to physical monitors
   106  * attached to the system.
   107  */
   108 struct SDL_VideoDisplay
   109 {
   110     int max_display_modes;
   111     int num_display_modes;
   112     SDL_DisplayMode *display_modes;
   113     SDL_DisplayMode desktop_mode;
   114     SDL_DisplayMode current_mode;
   115 
   116     SDL_Window *fullscreen_window;
   117 
   118     SDL_VideoDevice *device;
   119 
   120     void *driverdata;
   121 };
   122 
   123 /* Forward declaration */
   124 struct SDL_SysWMinfo;
   125 
   126 /* Define the SDL video driver structure */
   127 #define _THIS	SDL_VideoDevice *_this
   128 
   129 struct SDL_VideoDevice
   130 {
   131     /* * * */
   132     /* The name of this video driver */
   133     const char *name;
   134 
   135     /* * * */
   136     /* Initialization/Query functions */
   137 
   138     /*
   139      * Initialize the native video subsystem, filling in the list of
   140      * displays for this driver, returning 0 or -1 if there's an error.
   141      */
   142     int (*VideoInit) (_THIS);
   143 
   144     /*
   145      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   146      * if the application is shutting down the video subsystem.
   147      */
   148     void (*VideoQuit) (_THIS);
   149 
   150     /* * * */
   151     /*
   152      * Display functions
   153      */
   154 
   155     /*
   156      * Get the bounds of a display
   157      */
   158     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   159 
   160     /*
   161      * Get a list of the available display modes for a display.
   162      */
   163     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   164 
   165     /*
   166      * Setting the display mode is independent of creating windows, so
   167      * when the display mode is changed, all existing windows should have
   168      * their data updated accordingly, including the display surfaces
   169      * associated with them.
   170      */
   171     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   172 
   173     /* * * */
   174     /*
   175      * Window functions
   176      */
   177     int (*CreateWindow) (_THIS, SDL_Window * window);
   178     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   179     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   180     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   181     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   182     void (*SetWindowSize) (_THIS, SDL_Window * window);
   183     void (*ShowWindow) (_THIS, SDL_Window * window);
   184     void (*HideWindow) (_THIS, SDL_Window * window);
   185     void (*RaiseWindow) (_THIS, SDL_Window * window);
   186     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   187     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   188     void (*RestoreWindow) (_THIS, SDL_Window * window);
   189     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   190     int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
   191     int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
   192     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   193     void (*DestroyWindow) (_THIS, SDL_Window * window);
   194     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   195     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
   196     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   197 
   198     /* * * */
   199     /*
   200      * Shaped-window functions
   201      */
   202     SDL_ShapeDriver shape_driver;
   203 
   204     /* Get some platform dependent window information */
   205       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   206                                   struct SDL_SysWMinfo * info);
   207 
   208     /* * * */
   209     /*
   210      * OpenGL support
   211      */
   212     int (*GL_LoadLibrary) (_THIS, const char *path);
   213     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   214     void (*GL_UnloadLibrary) (_THIS);
   215       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   216     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   217     int (*GL_SetSwapInterval) (_THIS, int interval);
   218     int (*GL_GetSwapInterval) (_THIS);
   219     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   220     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   221 
   222     /* * * */
   223     /*
   224      * Event manager functions
   225      */
   226     void (*PumpEvents) (_THIS);
   227 
   228     /* Suspend the screensaver */
   229     void (*SuspendScreenSaver) (_THIS);
   230 
   231     /* Text input */
   232     void (*StartTextInput) (_THIS);
   233     void (*StopTextInput) (_THIS);
   234     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   235 
   236     /* Clipboard */
   237     int (*SetClipboardText) (_THIS, const char *text);
   238     char * (*GetClipboardText) (_THIS);
   239     SDL_bool (*HasClipboardText) (_THIS);
   240 
   241     /* * * */
   242     /* Data common to all drivers */
   243     SDL_bool suspend_screensaver;
   244     int num_displays;
   245     SDL_VideoDisplay *displays;
   246     SDL_Window *windows;
   247     Uint8 window_magic;
   248     Uint32 next_object_id;
   249     char * clipboard_text;
   250 
   251     /* * * */
   252     /* Data used by the GL drivers */
   253     struct
   254     {
   255         int red_size;
   256         int green_size;
   257         int blue_size;
   258         int alpha_size;
   259         int depth_size;
   260         int buffer_size;
   261         int stencil_size;
   262         int double_buffer;
   263         int accum_red_size;
   264         int accum_green_size;
   265         int accum_blue_size;
   266         int accum_alpha_size;
   267         int stereo;
   268         int multisamplebuffers;
   269         int multisamplesamples;
   270         int accelerated;
   271         int major_version;
   272         int minor_version;
   273         int retained_backing;
   274         int driver_loaded;
   275         char driver_path[256];
   276         void *dll_handle;
   277     } gl_config;
   278 
   279     /* * * */
   280     /* Cache current GL context; don't call the OS when it hasn't changed. */
   281     SDL_Window *current_glwin;
   282     SDL_GLContext current_glctx;
   283 
   284     /* * * */
   285     /* Data private to this driver */
   286     void *driverdata;
   287     struct SDL_GLDriverData *gl_data;
   288 
   289 #if SDL_VIDEO_DRIVER_PANDORA
   290     struct SDL_PrivateGLESData *gles_data;
   291 #endif
   292 
   293     /* * * */
   294     /* The function used to dispose of this structure */
   295     void (*free) (_THIS);
   296 };
   297 
   298 typedef struct VideoBootStrap
   299 {
   300     const char *name;
   301     const char *desc;
   302     int (*available) (void);
   303     SDL_VideoDevice *(*create) (int devindex);
   304 } VideoBootStrap;
   305 
   306 #if SDL_VIDEO_DRIVER_COCOA
   307 extern VideoBootStrap COCOA_bootstrap;
   308 #endif
   309 #if SDL_VIDEO_DRIVER_X11
   310 extern VideoBootStrap X11_bootstrap;
   311 #endif
   312 #if SDL_VIDEO_DRIVER_DIRECTFB
   313 extern VideoBootStrap DirectFB_bootstrap;
   314 #endif
   315 #if SDL_VIDEO_DRIVER_WINDOWS
   316 extern VideoBootStrap WINDOWS_bootstrap;
   317 #endif
   318 #if SDL_VIDEO_DRIVER_BWINDOW
   319 extern VideoBootStrap BWINDOW_bootstrap;
   320 #endif
   321 #if SDL_VIDEO_DRIVER_PANDORA
   322 extern VideoBootStrap PND_bootstrap;
   323 #endif
   324 #if SDL_VIDEO_DRIVER_NDS
   325 extern VideoBootStrap NDS_bootstrap;
   326 #endif
   327 #if SDL_VIDEO_DRIVER_UIKIT
   328 extern VideoBootStrap UIKIT_bootstrap;
   329 #endif
   330 #if SDL_VIDEO_DRIVER_ANDROID
   331 extern VideoBootStrap Android_bootstrap;
   332 #endif
   333 #if SDL_VIDEO_DRIVER_DUMMY
   334 extern VideoBootStrap DUMMY_bootstrap;
   335 #endif
   336 
   337 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   338 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   339 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   340 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   341 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   342 
   343 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   344 
   345 extern void SDL_OnWindowShown(SDL_Window * window);
   346 extern void SDL_OnWindowHidden(SDL_Window * window);
   347 extern void SDL_OnWindowResized(SDL_Window * window);
   348 extern void SDL_OnWindowMinimized(SDL_Window * window);
   349 extern void SDL_OnWindowRestored(SDL_Window * window);
   350 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   351 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   352 extern SDL_Window * SDL_GetFocusWindow(void);
   353 
   354 #endif /* _SDL_sysvideo_h */
   355 
   356 /* vi: set ts=4 sw=4 expandtab: */