Home | History | Annotate | Download | only in video
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2012 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 (at) libsdl.org
     21 */
     22 #include "SDL_config.h"
     23 
     24 #ifndef _SDL_sysvideo_h
     25 #define _SDL_sysvideo_h
     26 
     27 #include "SDL_mouse.h"
     28 #define SDL_PROTOTYPES_ONLY
     29 #include "SDL_syswm.h"
     30 #undef SDL_PROTOTYPES_ONLY
     31 
     32 /* This file prototypes the video driver implementation.
     33    This is designed to be easily converted to C++ in the future.
     34  */
     35 
     36 #if SDL_VIDEO_OPENGL
     37 #include "SDL_opengl.h"
     38 #endif /* SDL_VIDEO_OPENGL */
     39 
     40 /* The SDL video driver */
     41 typedef struct SDL_VideoDevice SDL_VideoDevice;
     42 
     43 /* Define the SDL video driver structure */
     44 #define _THIS	SDL_VideoDevice *_this
     45 #ifndef _STATUS
     46 #define _STATUS	SDL_status *status
     47 #endif
     48 struct SDL_VideoDevice {
     49 	/* * * */
     50 	/* The name of this video driver */
     51 	const char *name;
     52 
     53 	/* * * */
     54 	/* Initialization/Query functions */
     55 
     56 	/* Initialize the native video subsystem, filling 'vformat' with the
     57 	   "best" display pixel format, returning 0 or -1 if there's an error.
     58 	 */
     59 	int (*VideoInit)(_THIS, SDL_PixelFormat *vformat);
     60 
     61 	/* List the available video modes for the given pixel format, sorted
     62 	   from largest to smallest.
     63 	 */
     64 	SDL_Rect **(*ListModes)(_THIS, SDL_PixelFormat *format, Uint32 flags);
     65 
     66 	/* Set the requested video mode, returning a surface which will be
     67 	   set to the SDL_VideoSurface.  The width and height will already
     68 	   be verified by ListModes(), and the video subsystem is free to
     69 	   set the mode to a supported bit depth different from the one
     70 	   specified -- the desired bpp will be emulated with a shadow
     71 	   surface if necessary.  If a new mode is returned, this function
     72 	   should take care of cleaning up the current mode.
     73 	 */
     74 	SDL_Surface *(*SetVideoMode)(_THIS, SDL_Surface *current,
     75 				int width, int height, int bpp, Uint32 flags);
     76 
     77 	/* Toggle the fullscreen mode */
     78 	int (*ToggleFullScreen)(_THIS, int on);
     79 
     80 	/* This is called after the video mode has been set, to get the
     81 	   initial mouse state.  It should queue events as necessary to
     82 	   properly represent the current mouse focus and position.
     83 	 */
     84 	void (*UpdateMouse)(_THIS);
     85 
     86 	/* Create a YUV video surface (possibly overlay) of the given
     87 	   format.  The hardware should be able to perform at least 2x
     88 	   scaling on display.
     89 	 */
     90 	SDL_Overlay *(*CreateYUVOverlay)(_THIS, int width, int height,
     91 	                                 Uint32 format, SDL_Surface *display);
     92 
     93         /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
     94 	   of the physical palette to those in 'colors'. If the device is
     95 	   using a software palette (SDL_HWPALETTE not set), then the
     96 	   changes are reflected in the logical palette of the screen
     97 	   as well.
     98 	   The return value is 1 if all entries could be set properly
     99 	   or 0 otherwise.
    100 	*/
    101 	int (*SetColors)(_THIS, int firstcolor, int ncolors,
    102 			 SDL_Color *colors);
    103 
    104 	/* This pointer should exist in the native video subsystem and should
    105 	   point to an appropriate update function for the current video mode
    106 	 */
    107 	void (*UpdateRects)(_THIS, int numrects, SDL_Rect *rects);
    108 
    109 	/* Reverse the effects VideoInit() -- called if VideoInit() fails
    110 	   or if the application is shutting down the video subsystem.
    111 	*/
    112 	void (*VideoQuit)(_THIS);
    113 
    114 	/* * * */
    115 	/* Hardware acceleration functions */
    116 
    117 	/* Information about the video hardware */
    118 	SDL_VideoInfo info;
    119 
    120 	/* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
    121 	SDL_PixelFormat* displayformatalphapixel;
    122 
    123 	/* Allocates a surface in video memory */
    124 	int (*AllocHWSurface)(_THIS, SDL_Surface *surface);
    125 
    126 	/* Sets the hardware accelerated blit function, if any, based
    127 	   on the current flags of the surface (colorkey, alpha, etc.)
    128 	 */
    129 	int (*CheckHWBlit)(_THIS, SDL_Surface *src, SDL_Surface *dst);
    130 
    131 	/* Fills a surface rectangle with the given color */
    132 	int (*FillHWRect)(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
    133 
    134 	/* Sets video mem colorkey and accelerated blit function */
    135 	int (*SetHWColorKey)(_THIS, SDL_Surface *surface, Uint32 key);
    136 
    137 	/* Sets per surface hardware alpha value */
    138 	int (*SetHWAlpha)(_THIS, SDL_Surface *surface, Uint8 value);
    139 
    140 	/* Returns a readable/writable surface */
    141 	int (*LockHWSurface)(_THIS, SDL_Surface *surface);
    142 	void (*UnlockHWSurface)(_THIS, SDL_Surface *surface);
    143 
    144 	/* Performs hardware flipping */
    145 	int (*FlipHWSurface)(_THIS, SDL_Surface *surface);
    146 
    147 	/* Frees a previously allocated video surface */
    148 	void (*FreeHWSurface)(_THIS, SDL_Surface *surface);
    149 
    150 	/* * * */
    151 	/* Gamma support */
    152 
    153 	Uint16 *gamma;
    154 
    155 	/* Set the gamma correction directly (emulated with gamma ramps) */
    156 	int (*SetGamma)(_THIS, float red, float green, float blue);
    157 
    158 	/* Get the gamma correction directly (emulated with gamma ramps) */
    159 	int (*GetGamma)(_THIS, float *red, float *green, float *blue);
    160 
    161 	/* Set the gamma ramp */
    162 	int (*SetGammaRamp)(_THIS, Uint16 *ramp);
    163 
    164 	/* Get the gamma ramp */
    165 	int (*GetGammaRamp)(_THIS, Uint16 *ramp);
    166 
    167 	/* * * */
    168 	/* OpenGL support */
    169 
    170 	/* Sets the dll to use for OpenGL and loads it */
    171 	int (*GL_LoadLibrary)(_THIS, const char *path);
    172 
    173 	/* Retrieves the address of a function in the gl library */
    174 	void* (*GL_GetProcAddress)(_THIS, const char *proc);
    175 
    176 	/* Get attribute information from the windowing system. */
    177 	int (*GL_GetAttribute)(_THIS, SDL_GLattr attrib, int* value);
    178 
    179 	/* Make the context associated with this driver current */
    180 	int (*GL_MakeCurrent)(_THIS);
    181 
    182 	/* Swap the current buffers in double buffer mode. */
    183 	void (*GL_SwapBuffers)(_THIS);
    184 
    185   	/* OpenGL functions for SDL_OPENGLBLIT */
    186 #if SDL_VIDEO_OPENGL
    187 #if !defined(__WIN32__)
    188 #define WINAPI
    189 #endif
    190 #define SDL_PROC(ret,func,params) ret (WINAPI *func) params;
    191 #include "SDL_glfuncs.h"
    192 #undef SDL_PROC
    193 
    194 	/* Texture id */
    195 	GLuint texture;
    196 #endif
    197 	int is_32bit;
    198 
    199 	/* * * */
    200 	/* Window manager functions */
    201 
    202 	/* Set the title and icon text */
    203 	void (*SetCaption)(_THIS, const char *title, const char *icon);
    204 
    205 	/* Set the window icon image */
    206 	void (*SetIcon)(_THIS, SDL_Surface *icon, Uint8 *mask);
    207 
    208 	/* Iconify the window.
    209 	   This function returns 1 if there is a window manager and the
    210 	   window was actually iconified, it returns 0 otherwise.
    211 	*/
    212 	int (*IconifyWindow)(_THIS);
    213 
    214 	/* Grab or ungrab keyboard and mouse input */
    215 	SDL_GrabMode (*GrabInput)(_THIS, SDL_GrabMode mode);
    216 
    217 	/* Get some platform dependent window information */
    218 	int (*GetWMInfo)(_THIS, SDL_SysWMinfo *info);
    219 
    220 	/* set window position */
    221 	void (*SetWindowPos)(_THIS, int x, int y);
    222 
    223 	/* get window position */
    224 	void (*GetWindowPos)(_THIS, int *px, int *py);
    225 
    226 	/* determine if the window is fully visible on screen */
    227 	int (*IsWindowVisible)(_THIS, int recenter);
    228 
    229 	/* get main monitor's resolution */
    230 	int (*GetMonitorDPI)(_THIS, int *xdpi, int *ydpi);
    231 
    232 	/* get nearest monitor's rectangle */
    233 	int (*GetMonitorRect)(_THIS, SDL_Rect* rect);
    234 
    235 	/* * * */
    236 	/* Cursor manager functions */
    237 
    238 	/* Free a window manager cursor
    239 	   This function can be NULL if CreateWMCursor is also NULL.
    240 	 */
    241 	void (*FreeWMCursor)(_THIS, WMcursor *cursor);
    242 
    243 	/* If not NULL, create a black/white window manager cursor */
    244 	WMcursor *(*CreateWMCursor)(_THIS,
    245 		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
    246 
    247 	/* Show the specified cursor, or hide if cursor is NULL */
    248 	int (*ShowWMCursor)(_THIS, WMcursor *cursor);
    249 
    250 	/* Warp the window manager cursor to (x,y)
    251 	   If NULL, a mouse motion event is posted internally.
    252 	 */
    253 	void (*WarpWMCursor)(_THIS, Uint16 x, Uint16 y);
    254 
    255 	/* If not NULL, this is called when a mouse motion event occurs */
    256 	void (*MoveWMCursor)(_THIS, int x, int y);
    257 
    258 	/* Determine whether the mouse should be in relative mode or not.
    259 	   This function is called when the input grab state or cursor
    260 	   visibility state changes.
    261 	   If the cursor is not visible, and the input is grabbed, the
    262 	   driver can place the mouse in relative mode, which may result
    263 	   in higher accuracy sampling of the pointer motion.
    264 	*/
    265 	void (*CheckMouseMode)(_THIS);
    266 
    267 	/* * * */
    268 	/* Event manager functions */
    269 
    270 	/* Initialize keyboard mapping for this driver */
    271 	void (*InitOSKeymap)(_THIS);
    272 
    273 	/* Handle any queued OS events */
    274 	void (*PumpEvents)(_THIS);
    275 
    276 	/* * * */
    277 	/* Data common to all drivers */
    278 	SDL_Surface *screen;
    279 	SDL_Surface *shadow;
    280 	SDL_Surface *visible;
    281         SDL_Palette *physpal;	/* physical palette, if != logical palette */
    282         SDL_Color *gammacols;	/* gamma-corrected colours, or NULL */
    283 	char *wm_title;
    284 	char *wm_icon;
    285 	int offset_x;
    286 	int offset_y;
    287 	SDL_GrabMode input_grab;
    288 
    289 	/* Driver information flags */
    290 	int handles_any_size;	/* Driver handles any size video mode */
    291 
    292 	/* * * */
    293 	/* Data used by the GL drivers */
    294 	struct {
    295 		int red_size;
    296 		int green_size;
    297 		int blue_size;
    298 		int alpha_size;
    299 		int depth_size;
    300 		int buffer_size;
    301 		int stencil_size;
    302 		int double_buffer;
    303 		int accum_red_size;
    304 		int accum_green_size;
    305 		int accum_blue_size;
    306 		int accum_alpha_size;
    307 		int stereo;
    308 		int multisamplebuffers;
    309 		int multisamplesamples;
    310 		int accelerated;
    311 		int swap_control;
    312 		int driver_loaded;
    313 		char driver_path[256];
    314 		void* dll_handle;
    315 	} gl_config;
    316 
    317 	/* * * */
    318 	/* Data private to this driver */
    319 	struct SDL_PrivateVideoData *hidden;
    320 	struct SDL_PrivateGLData *gl_data;
    321 
    322 	/* * * */
    323 	/* The function used to dispose of this structure */
    324 	void (*free)(_THIS);
    325 };
    326 #undef _THIS
    327 
    328 typedef struct VideoBootStrap {
    329 	const char *name;
    330 	const char *desc;
    331 	int (*available)(void);
    332 	SDL_VideoDevice *(*create)(int devindex);
    333 } VideoBootStrap;
    334 
    335 #if SDL_VIDEO_DRIVER_QUARTZ
    336 extern VideoBootStrap QZ_bootstrap;
    337 #endif
    338 #if SDL_VIDEO_DRIVER_X11
    339 extern VideoBootStrap X11_bootstrap;
    340 #endif
    341 #if SDL_VIDEO_DRIVER_DGA
    342 extern VideoBootStrap DGA_bootstrap;
    343 #endif
    344 #if SDL_VIDEO_DRIVER_NANOX
    345 extern VideoBootStrap NX_bootstrap;
    346 #endif
    347 #if SDL_VIDEO_DRIVER_IPOD
    348 extern VideoBootStrap iPod_bootstrap;
    349 #endif
    350 #if SDL_VIDEO_DRIVER_QTOPIA
    351 extern VideoBootStrap Qtopia_bootstrap;
    352 #endif
    353 #if SDL_VIDEO_DRIVER_WSCONS
    354 extern VideoBootStrap WSCONS_bootstrap;
    355 #endif
    356 #if SDL_VIDEO_DRIVER_FBCON
    357 extern VideoBootStrap FBCON_bootstrap;
    358 #endif
    359 #if SDL_VIDEO_DRIVER_DIRECTFB
    360 extern VideoBootStrap DirectFB_bootstrap;
    361 #endif
    362 #if SDL_VIDEO_DRIVER_PS2GS
    363 extern VideoBootStrap PS2GS_bootstrap;
    364 #endif
    365 #if SDL_VIDEO_DRIVER_PS3
    366 extern VideoBootStrap PS3_bootstrap;
    367 #endif
    368 #if SDL_VIDEO_DRIVER_GGI
    369 extern VideoBootStrap GGI_bootstrap;
    370 #endif
    371 #if SDL_VIDEO_DRIVER_VGL
    372 extern VideoBootStrap VGL_bootstrap;
    373 #endif
    374 #if SDL_VIDEO_DRIVER_SVGALIB
    375 extern VideoBootStrap SVGALIB_bootstrap;
    376 #endif
    377 #if SDL_VIDEO_DRIVER_GAPI
    378 extern VideoBootStrap GAPI_bootstrap;
    379 #endif
    380 #if SDL_VIDEO_DRIVER_WINDIB
    381 extern VideoBootStrap WINDIB_bootstrap;
    382 #endif
    383 #if SDL_VIDEO_DRIVER_DDRAW
    384 extern VideoBootStrap DIRECTX_bootstrap;
    385 #endif
    386 #if SDL_VIDEO_DRIVER_BWINDOW
    387 extern VideoBootStrap BWINDOW_bootstrap;
    388 #endif
    389 #if SDL_VIDEO_DRIVER_TOOLBOX
    390 extern VideoBootStrap TOOLBOX_bootstrap;
    391 #endif
    392 #if SDL_VIDEO_DRIVER_DRAWSPROCKET
    393 extern VideoBootStrap DSp_bootstrap;
    394 #endif
    395 #if SDL_VIDEO_DRIVER_PHOTON
    396 extern VideoBootStrap ph_bootstrap;
    397 #endif
    398 #if SDL_VIDEO_DRIVER_EPOC
    399 extern VideoBootStrap EPOC_bootstrap;
    400 #endif
    401 #if SDL_VIDEO_DRIVER_XBIOS
    402 extern VideoBootStrap XBIOS_bootstrap;
    403 #endif
    404 #if SDL_VIDEO_DRIVER_GEM
    405 extern VideoBootStrap GEM_bootstrap;
    406 #endif
    407 #if SDL_VIDEO_DRIVER_PICOGUI
    408 extern VideoBootStrap PG_bootstrap;
    409 #endif
    410 #if SDL_VIDEO_DRIVER_DC
    411 extern VideoBootStrap DC_bootstrap;
    412 #endif
    413 #if SDL_VIDEO_DRIVER_NDS
    414 extern VideoBootStrap NDS_bootstrap;
    415 #endif
    416 #if SDL_VIDEO_DRIVER_RISCOS
    417 extern VideoBootStrap RISCOS_bootstrap;
    418 #endif
    419 #if SDL_VIDEO_DRIVER_OS2FS
    420 extern VideoBootStrap OS2FSLib_bootstrap;
    421 #endif
    422 #if SDL_VIDEO_DRIVER_AALIB
    423 extern VideoBootStrap AALIB_bootstrap;
    424 #endif
    425 #if SDL_VIDEO_DRIVER_CACA
    426 extern VideoBootStrap CACA_bootstrap;
    427 #endif
    428 #if SDL_VIDEO_DRIVER_DUMMY
    429 extern VideoBootStrap DUMMY_bootstrap;
    430 #endif
    431 
    432 /* This is the current video device */
    433 extern SDL_VideoDevice *current_video;
    434 
    435 #define SDL_VideoSurface	(current_video->screen)
    436 #define SDL_ShadowSurface	(current_video->shadow)
    437 #define SDL_PublicSurface	(current_video->visible)
    438 
    439 #endif /* _SDL_sysvideo_h */
    440