src/video/SDL_sysvideo.h
author David Ludwig <dludwig@pobox.com>
Sat, 27 Oct 2012 22:48:04 -0400
changeset 8327 bc51589f33dc
parent 6422 fd0ac1b56115
child 8337 4a67a3cca43d
permissions -rw-r--r--
WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 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 (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
   190     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   191     int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
   192     int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
   193     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   194     void (*DestroyWindow) (_THIS, SDL_Window * window);
   195     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   196     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
   197     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   198 
   199     /* * * */
   200     /*
   201      * Shaped-window functions
   202      */
   203     SDL_ShapeDriver shape_driver;
   204 
   205     /* Get some platform dependent window information */
   206       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   207                                   struct SDL_SysWMinfo * info);
   208 
   209     /* * * */
   210     /*
   211      * OpenGL support
   212      */
   213     int (*GL_LoadLibrary) (_THIS, const char *path);
   214     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   215     void (*GL_UnloadLibrary) (_THIS);
   216       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   217     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   218     int (*GL_SetSwapInterval) (_THIS, int interval);
   219     int (*GL_GetSwapInterval) (_THIS);
   220     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   221     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   222 
   223     /* * * */
   224     /*
   225      * Event manager functions
   226      */
   227     void (*PumpEvents) (_THIS);
   228 
   229     /* Suspend the screensaver */
   230     void (*SuspendScreenSaver) (_THIS);
   231 
   232     /* Text input */
   233     void (*StartTextInput) (_THIS);
   234     void (*StopTextInput) (_THIS);
   235     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   236 
   237     /* Screen keyboard */
   238     SDL_bool (*SDL_HasScreenKeyboardSupport) (_THIS, SDL_Window *window);
   239     int (*SDL_ShowScreenKeyboard) (_THIS, SDL_Window *window);
   240     int (*SDL_HideScreenKeyboard) (_THIS, SDL_Window *window);
   241     int (*SDL_ToggleScreenKeyboard) (_THIS, SDL_Window *window);
   242     SDL_bool (*SDL_IsScreenKeyboardShown) (_THIS, SDL_Window *window);
   243 
   244     /* Clipboard */
   245     int (*SetClipboardText) (_THIS, const char *text);
   246     char * (*GetClipboardText) (_THIS);
   247     SDL_bool (*HasClipboardText) (_THIS);
   248 
   249     /* * * */
   250     /* Data common to all drivers */
   251     SDL_bool suspend_screensaver;
   252     int num_displays;
   253     SDL_VideoDisplay *displays;
   254     SDL_Window *windows;
   255     Uint8 window_magic;
   256     Uint32 next_object_id;
   257     char * clipboard_text;
   258 
   259     /* * * */
   260     /* Data used by the GL drivers */
   261     struct
   262     {
   263         int red_size;
   264         int green_size;
   265         int blue_size;
   266         int alpha_size;
   267         int depth_size;
   268         int buffer_size;
   269         int stencil_size;
   270         int double_buffer;
   271         int accum_red_size;
   272         int accum_green_size;
   273         int accum_blue_size;
   274         int accum_alpha_size;
   275         int stereo;
   276         int multisamplebuffers;
   277         int multisamplesamples;
   278         int accelerated;
   279         int major_version;
   280         int minor_version;
   281         int flags;
   282         int profile_mask;
   283         int use_egl;
   284         int share_with_current_context;
   285         int retained_backing;
   286         int driver_loaded;
   287         char driver_path[256];
   288         void *dll_handle;
   289     } gl_config;
   290 
   291     /* * * */
   292     /* Cache current GL context; don't call the OS when it hasn't changed. */
   293     SDL_Window *current_glwin;
   294     SDL_GLContext current_glctx;
   295 
   296     /* * * */
   297     /* Data private to this driver */
   298     void *driverdata;
   299     struct SDL_GLDriverData *gl_data;
   300 
   301 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   302     struct SDL_PrivateGLESData *gles_data;
   303 #endif
   304 
   305     /* * * */
   306     /* The function used to dispose of this structure */
   307     void (*free) (_THIS);
   308 };
   309 
   310 typedef struct VideoBootStrap
   311 {
   312     const char *name;
   313     const char *desc;
   314     int (*available) (void);
   315     SDL_VideoDevice *(*create) (int devindex);
   316 } VideoBootStrap;
   317 
   318 #if SDL_VIDEO_DRIVER_COCOA
   319 extern VideoBootStrap COCOA_bootstrap;
   320 #endif
   321 #if SDL_VIDEO_DRIVER_X11
   322 extern VideoBootStrap X11_bootstrap;
   323 #endif
   324 #if SDL_VIDEO_DRIVER_DIRECTFB
   325 extern VideoBootStrap DirectFB_bootstrap;
   326 #endif
   327 #if SDL_VIDEO_DRIVER_WINDOWS
   328 extern VideoBootStrap WINDOWS_bootstrap;
   329 #endif
   330 #if SDL_VIDEO_DRIVER_WINRT
   331 extern VideoBootStrap WINRT_bootstrap;
   332 #endif
   333 #if SDL_VIDEO_DRIVER_BWINDOW
   334 extern VideoBootStrap BWINDOW_bootstrap;
   335 #endif
   336 #if SDL_VIDEO_DRIVER_PANDORA
   337 extern VideoBootStrap PND_bootstrap;
   338 #endif
   339 #if SDL_VIDEO_DRIVER_NDS
   340 extern VideoBootStrap NDS_bootstrap;
   341 #endif
   342 #if SDL_VIDEO_DRIVER_UIKIT
   343 extern VideoBootStrap UIKIT_bootstrap;
   344 #endif
   345 #if SDL_VIDEO_DRIVER_ANDROID
   346 extern VideoBootStrap Android_bootstrap;
   347 #endif
   348 #if SDL_VIDEO_DRIVER_DUMMY
   349 extern VideoBootStrap DUMMY_bootstrap;
   350 #endif
   351 
   352 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   353 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   354 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   355 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   356 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   357 
   358 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   359 
   360 extern void SDL_OnWindowShown(SDL_Window * window);
   361 extern void SDL_OnWindowHidden(SDL_Window * window);
   362 extern void SDL_OnWindowResized(SDL_Window * window);
   363 extern void SDL_OnWindowMinimized(SDL_Window * window);
   364 extern void SDL_OnWindowRestored(SDL_Window * window);
   365 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   366 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   367 extern SDL_Window * SDL_GetFocusWindow(void);
   368 
   369 #endif /* _SDL_sysvideo_h */
   370 
   371 /* vi: set ts=4 sw=4 expandtab: */