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