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