include/SDL_video.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 27 Apr 2006 07:59:16 +0000
changeset 1736 3b2a92126f4d
parent 1545 8d9bb0cf2c2a
child 1737 eacc5bc01d1c
permissions -rw-r--r--
Implemented bug #2, 117:

Date: Mon, 21 Mar 2005 12:06:14 +0100
From: Per Inge Mathisen
Subject: Re: [SDL] Outstanding patches?

The patch adds support for setting SDL_GL_SWAP_CONTROL to Windows and
X11. In Windows you can also query this enum to check that it is
working, or see what the default is - such functionality does not
exist in GLX. For more information on the standards implemented:
http://oss.sgi.com/projects/ogl-sample/registry/SGI/swap_control.txt
http://oss.sgi.com/projects/ogl-sample/registry/EXT/wgl_swap_control.txt
     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 /* Header file for access to the SDL raw framebuffer window */
    24 
    25 #ifndef _SDL_video_h
    26 #define _SDL_video_h
    27 
    28 #include "SDL_stdinc.h"
    29 #include "SDL_error.h"
    30 #include "SDL_rwops.h"
    31 
    32 #include "begin_code.h"
    33 /* Set up for C function definitions, even when using C++ */
    34 #ifdef __cplusplus
    35 extern "C" {
    36 #endif
    37 
    38 /* Transparency definitions: These define alpha as the opacity of a surface */
    39 #define SDL_ALPHA_OPAQUE 255
    40 #define SDL_ALPHA_TRANSPARENT 0
    41 
    42 /* Useful data types */
    43 typedef struct SDL_Rect {
    44 	Sint16 x, y;
    45 	Uint16 w, h;
    46 } SDL_Rect;
    47 
    48 typedef struct SDL_Color {
    49 	Uint8 r;
    50 	Uint8 g;
    51 	Uint8 b;
    52 	Uint8 unused;
    53 } SDL_Color;
    54 #define SDL_Colour SDL_Color
    55 
    56 typedef struct SDL_Palette {
    57 	int       ncolors;
    58 	SDL_Color *colors;
    59 } SDL_Palette;
    60 
    61 /* Everything in the pixel format structure is read-only */
    62 typedef struct SDL_PixelFormat {
    63 	SDL_Palette *palette;
    64 	Uint8  BitsPerPixel;
    65 	Uint8  BytesPerPixel;
    66 	Uint8  Rloss;
    67 	Uint8  Gloss;
    68 	Uint8  Bloss;
    69 	Uint8  Aloss;
    70 	Uint8  Rshift;
    71 	Uint8  Gshift;
    72 	Uint8  Bshift;
    73 	Uint8  Ashift;
    74 	Uint32 Rmask;
    75 	Uint32 Gmask;
    76 	Uint32 Bmask;
    77 	Uint32 Amask;
    78 
    79 	/* RGB color key information */
    80 	Uint32 colorkey;
    81 	/* Alpha value information (per-surface alpha) */
    82 	Uint8  alpha;
    83 } SDL_PixelFormat;
    84 
    85 /* This structure should be treated as read-only, except for 'pixels',
    86    which, if not NULL, contains the raw pixel data for the surface.
    87 */
    88 typedef struct SDL_Surface {
    89 	Uint32 flags;				/* Read-only */
    90 	SDL_PixelFormat *format;		/* Read-only */
    91 	int w, h;				/* Read-only */
    92 	Uint16 pitch;				/* Read-only */
    93 	void *pixels;				/* Read-write */
    94 	int offset;				/* Private */
    95 
    96 	/* Hardware-specific surface info */
    97 	struct private_hwdata *hwdata;
    98 
    99 	/* clipping information */
   100 	SDL_Rect clip_rect;			/* Read-only */
   101 	Uint32 unused1;				/* for binary compatibility */
   102 
   103 	/* Allow recursive locks */
   104 	Uint32 locked;				/* Private */
   105 
   106 	/* info for fast blit mapping to other surfaces */
   107 	struct SDL_BlitMap *map;		/* Private */
   108 
   109 	/* format version, bumped at every change to invalidate blit maps */
   110 	unsigned int format_version;		/* Private */
   111 
   112 	/* Reference count -- used when freeing surface */
   113 	int refcount;				/* Read-mostly */
   114 } SDL_Surface;
   115 
   116 /* These are the currently supported flags for the SDL_surface */
   117 /* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */
   118 #define SDL_SWSURFACE	0x00000000	/* Surface is in system memory */
   119 #define SDL_HWSURFACE	0x00000001	/* Surface is in video memory */
   120 #define SDL_ASYNCBLIT	0x00000004	/* Use asynchronous blits if possible */
   121 /* Available for SDL_SetVideoMode() */
   122 #define SDL_ANYFORMAT	0x10000000	/* Allow any video depth/pixel-format */
   123 #define SDL_HWPALETTE	0x20000000	/* Surface has exclusive palette */
   124 #define SDL_DOUBLEBUF	0x40000000	/* Set up double-buffered video mode */
   125 #define SDL_FULLSCREEN	0x80000000	/* Surface is a full screen display */
   126 #define SDL_OPENGL      0x00000002      /* Create an OpenGL rendering context */
   127 #define SDL_OPENGLBLIT	0x0000000A	/* Create an OpenGL rendering context and use it for blitting */
   128 #define SDL_RESIZABLE	0x00000010	/* This video mode may be resized */
   129 #define SDL_NOFRAME	0x00000020	/* No window caption or edge frame */
   130 /* Used internally (read-only) */
   131 #define SDL_HWACCEL	0x00000100	/* Blit uses hardware acceleration */
   132 #define SDL_SRCCOLORKEY	0x00001000	/* Blit uses a source color key */
   133 #define SDL_RLEACCELOK	0x00002000	/* Private flag */
   134 #define SDL_RLEACCEL	0x00004000	/* Surface is RLE encoded */
   135 #define SDL_SRCALPHA	0x00010000	/* Blit uses source alpha blending */
   136 #define SDL_PREALLOC	0x01000000	/* Surface uses preallocated memory */
   137 
   138 /* Evaluates to true if the surface needs to be locked before access */
   139 #define SDL_MUSTLOCK(surface)	\
   140   (surface->offset ||		\
   141   ((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0))
   142 
   143 /* typedef for private surface blitting functions */
   144 typedef int (*SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect,
   145 			struct SDL_Surface *dst, SDL_Rect *dstrect);
   146 
   147 
   148 /* Useful for determining the video hardware capabilities */
   149 typedef struct SDL_VideoInfo {
   150 	Uint32 hw_available :1;	/* Flag: Can you create hardware surfaces? */
   151 	Uint32 wm_available :1;	/* Flag: Can you talk to a window manager? */
   152 	Uint32 UnusedBits1  :6;
   153 	Uint32 UnusedBits2  :1;
   154 	Uint32 blit_hw      :1;	/* Flag: Accelerated blits HW --> HW */
   155 	Uint32 blit_hw_CC   :1;	/* Flag: Accelerated blits with Colorkey */
   156 	Uint32 blit_hw_A    :1;	/* Flag: Accelerated blits with Alpha */
   157 	Uint32 blit_sw      :1;	/* Flag: Accelerated blits SW --> HW */
   158 	Uint32 blit_sw_CC   :1;	/* Flag: Accelerated blits with Colorkey */
   159 	Uint32 blit_sw_A    :1;	/* Flag: Accelerated blits with Alpha */
   160 	Uint32 blit_fill    :1;	/* Flag: Accelerated color fill */
   161 	Uint32 UnusedBits3  :16;
   162 	Uint32 video_mem;	/* The total amount of video memory (in K) */
   163 	SDL_PixelFormat *vfmt;	/* Value: The format of the video surface */
   164 	int    current_w;	/* Value: The current video mode width */
   165 	int    current_h;	/* Value: The current video mode height */
   166 } SDL_VideoInfo;
   167 
   168 
   169 /* The most common video overlay formats.
   170    For an explanation of these pixel formats, see:
   171 	http://www.webartz.com/fourcc/indexyuv.htm
   172 
   173    For information on the relationship between color spaces, see:
   174    http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
   175  */
   176 #define SDL_YV12_OVERLAY  0x32315659	/* Planar mode: Y + V + U  (3 planes) */
   177 #define SDL_IYUV_OVERLAY  0x56555949	/* Planar mode: Y + U + V  (3 planes) */
   178 #define SDL_YUY2_OVERLAY  0x32595559	/* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   179 #define SDL_UYVY_OVERLAY  0x59565955	/* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   180 #define SDL_YVYU_OVERLAY  0x55595659	/* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   181 
   182 /* The YUV hardware video overlay */
   183 typedef struct SDL_Overlay {
   184 	Uint32 format;				/* Read-only */
   185 	int w, h;				/* Read-only */
   186 	int planes;				/* Read-only */
   187 	Uint16 *pitches;			/* Read-only */
   188 	Uint8 **pixels;				/* Read-write */
   189 
   190 	/* Hardware-specific surface info */
   191 	struct private_yuvhwfuncs *hwfuncs;
   192 	struct private_yuvhwdata *hwdata;
   193 
   194 	/* Special flags */
   195 	Uint32 hw_overlay :1;	/* Flag: This overlay hardware accelerated? */
   196 	Uint32 UnusedBits :31;
   197 } SDL_Overlay;
   198 
   199 
   200 /* Public enumeration for setting the OpenGL window attributes. */
   201 typedef enum {
   202     SDL_GL_RED_SIZE,
   203     SDL_GL_GREEN_SIZE,
   204     SDL_GL_BLUE_SIZE,
   205     SDL_GL_ALPHA_SIZE,
   206     SDL_GL_BUFFER_SIZE,
   207     SDL_GL_DOUBLEBUFFER,
   208     SDL_GL_DEPTH_SIZE,
   209     SDL_GL_STENCIL_SIZE,
   210     SDL_GL_ACCUM_RED_SIZE,
   211     SDL_GL_ACCUM_GREEN_SIZE,
   212     SDL_GL_ACCUM_BLUE_SIZE,
   213     SDL_GL_ACCUM_ALPHA_SIZE,
   214     SDL_GL_STEREO,
   215     SDL_GL_MULTISAMPLEBUFFERS,
   216     SDL_GL_MULTISAMPLESAMPLES,
   217     SDL_GL_SWAP_CONTROL
   218 } SDL_GLattr;
   219 
   220 /* flags for SDL_SetPalette() */
   221 #define SDL_LOGPAL 0x01
   222 #define SDL_PHYSPAL 0x02
   223 
   224 /* Function prototypes */
   225 
   226 /* These functions are used internally, and should not be used unless you
   227  * have a specific need to specify the video driver you want to use.
   228  * You should normally use SDL_Init() or SDL_InitSubSystem().
   229  *
   230  * SDL_VideoInit() initializes the video subsystem -- sets up a connection
   231  * to the window manager, etc, and determines the current video mode and
   232  * pixel format, but does not initialize a window or graphics mode.
   233  * Note that event handling is activated by this routine.
   234  *
   235  * If you use both sound and video in your application, you need to call
   236  * SDL_Init() before opening the sound device, otherwise under Win32 DirectX,
   237  * you won't be able to set full-screen display modes.
   238  */
   239 extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags);
   240 extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
   241 
   242 /* This function fills the given character buffer with the name of the
   243  * video driver, and returns a pointer to it if the video driver has
   244  * been initialized.  It returns NULL if no driver has been initialized.
   245  */
   246 extern DECLSPEC char * SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
   247 
   248 /*
   249  * This function returns a pointer to the current display surface.
   250  * If SDL is doing format conversion on the display surface, this
   251  * function returns the publicly visible surface, not the real video
   252  * surface.
   253  */
   254 extern DECLSPEC SDL_Surface * SDLCALL SDL_GetVideoSurface(void);
   255 
   256 /*
   257  * This function returns a read-only pointer to information about the
   258  * video hardware.  If this is called before SDL_SetVideoMode(), the 'vfmt'
   259  * member of the returned structure will contain the pixel format of the
   260  * "best" video mode.
   261  */
   262 extern DECLSPEC const SDL_VideoInfo * SDLCALL SDL_GetVideoInfo(void);
   263 
   264 /* 
   265  * Check to see if a particular video mode is supported.
   266  * It returns 0 if the requested mode is not supported under any bit depth,
   267  * or returns the bits-per-pixel of the closest available mode with the
   268  * given width and height.  If this bits-per-pixel is different from the
   269  * one used when setting the video mode, SDL_SetVideoMode() will succeed,
   270  * but will emulate the requested bits-per-pixel with a shadow surface.
   271  *
   272  * The arguments to SDL_VideoModeOK() are the same ones you would pass to
   273  * SDL_SetVideoMode()
   274  */
   275 extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags);
   276 
   277 /*
   278  * Return a pointer to an array of available screen dimensions for the
   279  * given format and video flags, sorted largest to smallest.  Returns 
   280  * NULL if there are no dimensions available for a particular format, 
   281  * or (SDL_Rect **)-1 if any dimension is okay for the given format.
   282  *
   283  * If 'format' is NULL, the mode list will be for the format given 
   284  * by SDL_GetVideoInfo()->vfmt
   285  */
   286 extern DECLSPEC SDL_Rect ** SDLCALL SDL_ListModes(SDL_PixelFormat *format, Uint32 flags);
   287 
   288 /*
   289  * Set up a video mode with the specified width, height and bits-per-pixel.
   290  *
   291  * If 'bpp' is 0, it is treated as the current display bits per pixel.
   292  *
   293  * If SDL_ANYFORMAT is set in 'flags', the SDL library will try to set the
   294  * requested bits-per-pixel, but will return whatever video pixel format is
   295  * available.  The default is to emulate the requested pixel format if it
   296  * is not natively available.
   297  *
   298  * If SDL_HWSURFACE is set in 'flags', the video surface will be placed in
   299  * video memory, if possible, and you may have to call SDL_LockSurface()
   300  * in order to access the raw framebuffer.  Otherwise, the video surface
   301  * will be created in system memory.
   302  *
   303  * If SDL_ASYNCBLIT is set in 'flags', SDL will try to perform rectangle
   304  * updates asynchronously, but you must always lock before accessing pixels.
   305  * SDL will wait for updates to complete before returning from the lock.
   306  *
   307  * If SDL_HWPALETTE is set in 'flags', the SDL library will guarantee
   308  * that the colors set by SDL_SetColors() will be the colors you get.
   309  * Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all
   310  * of the colors exactly the way they are requested, and you should look
   311  * at the video surface structure to determine the actual palette.
   312  * If SDL cannot guarantee that the colors you request can be set, 
   313  * i.e. if the colormap is shared, then the video surface may be created
   314  * under emulation in system memory, overriding the SDL_HWSURFACE flag.
   315  *
   316  * If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set
   317  * a fullscreen video mode.  The default is to create a windowed mode
   318  * if the current graphics system has a window manager.
   319  * If the SDL library is able to set a fullscreen video mode, this flag 
   320  * will be set in the surface that is returned.
   321  *
   322  * If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up
   323  * two surfaces in video memory and swap between them when you call 
   324  * SDL_Flip().  This is usually slower than the normal single-buffering
   325  * scheme, but prevents "tearing" artifacts caused by modifying video 
   326  * memory while the monitor is refreshing.  It should only be used by 
   327  * applications that redraw the entire screen on every update.
   328  *
   329  * If SDL_RESIZABLE is set in 'flags', the SDL library will allow the
   330  * window manager, if any, to resize the window at runtime.  When this
   331  * occurs, SDL will send a SDL_VIDEORESIZE event to you application,
   332  * and you must respond to the event by re-calling SDL_SetVideoMode()
   333  * with the requested size (or another size that suits the application).
   334  *
   335  * If SDL_NOFRAME is set in 'flags', the SDL library will create a window
   336  * without any title bar or frame decoration.  Fullscreen video modes have
   337  * this flag set automatically.
   338  *
   339  * This function returns the video framebuffer surface, or NULL if it fails.
   340  *
   341  * If you rely on functionality provided by certain video flags, check the
   342  * flags of the returned surface to make sure that functionality is available.
   343  * SDL will fall back to reduced functionality if the exact flags you wanted
   344  * are not available.
   345  */
   346 extern DECLSPEC SDL_Surface * SDLCALL SDL_SetVideoMode
   347 			(int width, int height, int bpp, Uint32 flags);
   348 
   349 /*
   350  * Makes sure the given list of rectangles is updated on the given screen.
   351  * If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire
   352  * screen.
   353  * These functions should not be called while 'screen' is locked.
   354  */
   355 extern DECLSPEC void SDLCALL SDL_UpdateRects
   356 		(SDL_Surface *screen, int numrects, SDL_Rect *rects);
   357 extern DECLSPEC void SDLCALL SDL_UpdateRect
   358 		(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
   359 
   360 /*
   361  * On hardware that supports double-buffering, this function sets up a flip
   362  * and returns.  The hardware will wait for vertical retrace, and then swap
   363  * video buffers before the next video surface blit or lock will return.
   364  * On hardware that doesn not support double-buffering, this is equivalent
   365  * to calling SDL_UpdateRect(screen, 0, 0, 0, 0);
   366  * The SDL_DOUBLEBUF flag must have been passed to SDL_SetVideoMode() when
   367  * setting the video mode for this function to perform hardware flipping.
   368  * This function returns 0 if successful, or -1 if there was an error.
   369  */
   370 extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface *screen);
   371 
   372 /*
   373  * Set the gamma correction for each of the color channels.
   374  * The gamma values range (approximately) between 0.1 and 10.0
   375  * 
   376  * If this function isn't supported directly by the hardware, it will
   377  * be emulated using gamma ramps, if available.  If successful, this
   378  * function returns 0, otherwise it returns -1.
   379  */
   380 extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue);
   381 
   382 /*
   383  * Set the gamma translation table for the red, green, and blue channels
   384  * of the video hardware.  Each table is an array of 256 16-bit quantities,
   385  * representing a mapping between the input and output for that channel.
   386  * The input is the index into the array, and the output is the 16-bit
   387  * gamma value at that index, scaled to the output color precision.
   388  * 
   389  * You may pass NULL for any of the channels to leave it unchanged.
   390  * If the call succeeds, it will return 0.  If the display driver or
   391  * hardware does not support gamma translation, or otherwise fails,
   392  * this function will return -1.
   393  */
   394 extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue);
   395 
   396 /*
   397  * Retrieve the current values of the gamma translation tables.
   398  * 
   399  * You must pass in valid pointers to arrays of 256 16-bit quantities.
   400  * Any of the pointers may be NULL to ignore that channel.
   401  * If the call succeeds, it will return 0.  If the display driver or
   402  * hardware does not support gamma translation, or otherwise fails,
   403  * this function will return -1.
   404  */
   405 extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue);
   406 
   407 /*
   408  * Sets a portion of the colormap for the given 8-bit surface.  If 'surface'
   409  * is not a palettized surface, this function does nothing, returning 0.
   410  * If all of the colors were set as passed to SDL_SetColors(), it will
   411  * return 1.  If not all the color entries were set exactly as given,
   412  * it will return 0, and you should look at the surface palette to
   413  * determine the actual color palette.
   414  *
   415  * When 'surface' is the surface associated with the current display, the
   416  * display colormap will be updated with the requested colors.  If 
   417  * SDL_HWPALETTE was set in SDL_SetVideoMode() flags, SDL_SetColors()
   418  * will always return 1, and the palette is guaranteed to be set the way
   419  * you desire, even if the window colormap has to be warped or run under
   420  * emulation.
   421  */
   422 extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface *surface, 
   423 			SDL_Color *colors, int firstcolor, int ncolors);
   424 
   425 /*
   426  * Sets a portion of the colormap for a given 8-bit surface.
   427  * 'flags' is one or both of:
   428  * SDL_LOGPAL  -- set logical palette, which controls how blits are mapped
   429  *                to/from the surface,
   430  * SDL_PHYSPAL -- set physical palette, which controls how pixels look on
   431  *                the screen
   432  * Only screens have physical palettes. Separate change of physical/logical
   433  * palettes is only possible if the screen has SDL_HWPALETTE set.
   434  *
   435  * The return value is 1 if all colours could be set as requested, and 0
   436  * otherwise.
   437  *
   438  * SDL_SetColors() is equivalent to calling this function with
   439  *     flags = (SDL_LOGPAL|SDL_PHYSPAL).
   440  */
   441 extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags,
   442 				   SDL_Color *colors, int firstcolor,
   443 				   int ncolors);
   444 
   445 /*
   446  * Maps an RGB triple to an opaque pixel value for a given pixel format
   447  */
   448 extern DECLSPEC Uint32 SDLCALL SDL_MapRGB
   449 			(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b);
   450 
   451 /*
   452  * Maps an RGBA quadruple to a pixel value for a given pixel format
   453  */
   454 extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(SDL_PixelFormat *format,
   455 				   Uint8 r, Uint8 g, Uint8 b, Uint8 a);
   456 
   457 /*
   458  * Maps a pixel value into the RGB components for a given pixel format
   459  */
   460 extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt,
   461 				Uint8 *r, Uint8 *g, Uint8 *b);
   462 
   463 /*
   464  * Maps a pixel value into the RGBA components for a given pixel format
   465  */
   466 extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt,
   467 				 Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
   468 
   469 /*
   470  * Allocate and free an RGB surface (must be called after SDL_SetVideoMode)
   471  * If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
   472  * If the depth is greater than 8 bits, the pixel format is set using the
   473  * flags '[RGB]mask'.
   474  * If the function runs out of memory, it will return NULL.
   475  *
   476  * The 'flags' tell what kind of surface to create.
   477  * SDL_SWSURFACE means that the surface should be created in system memory.
   478  * SDL_HWSURFACE means that the surface should be created in video memory,
   479  * with the same format as the display surface.  This is useful for surfaces
   480  * that will not change much, to take advantage of hardware acceleration
   481  * when being blitted to the display surface.
   482  * SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with
   483  * this surface, but you must always lock it before accessing the pixels.
   484  * SDL will wait for current blits to finish before returning from the lock.
   485  * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits.
   486  * If the hardware supports acceleration of colorkey blits between
   487  * two surfaces in video memory, SDL will try to place the surface in
   488  * video memory. If this isn't possible or if there is no hardware
   489  * acceleration available, the surface will be placed in system memory.
   490  * SDL_SRCALPHA means that the surface will be used for alpha blits and 
   491  * if the hardware supports hardware acceleration of alpha blits between
   492  * two surfaces in video memory, to place the surface in video memory
   493  * if possible, otherwise it will be placed in system memory.
   494  * If the surface is created in video memory, blits will be _much_ faster,
   495  * but the surface format must be identical to the video surface format,
   496  * and the only way to access the pixels member of the surface is to use
   497  * the SDL_LockSurface() and SDL_UnlockSurface() calls.
   498  * If the requested surface actually resides in video memory, SDL_HWSURFACE
   499  * will be set in the flags member of the returned surface.  If for some
   500  * reason the surface could not be placed in video memory, it will not have
   501  * the SDL_HWSURFACE flag set, and will be created in system memory instead.
   502  */
   503 #define SDL_AllocSurface    SDL_CreateRGBSurface
   504 extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurface
   505 			(Uint32 flags, int width, int height, int depth, 
   506 			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
   507 extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
   508 			int width, int height, int depth, int pitch,
   509 			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
   510 extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface);
   511 
   512 /*
   513  * SDL_LockSurface() sets up a surface for directly accessing the pixels.
   514  * Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write
   515  * to and read from 'surface->pixels', using the pixel format stored in 
   516  * 'surface->format'.  Once you are done accessing the surface, you should 
   517  * use SDL_UnlockSurface() to release it.
   518  *
   519  * Not all surfaces require locking.  If SDL_MUSTLOCK(surface) evaluates
   520  * to 0, then you can read and write to the surface at any time, and the
   521  * pixel format of the surface will not change.  In particular, if the
   522  * SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you
   523  * will not need to lock the display surface before accessing it.
   524  * 
   525  * No operating system or library calls should be made between lock/unlock
   526  * pairs, as critical system locks may be held during this time.
   527  *
   528  * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
   529  */
   530 extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface);
   531 extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
   532 
   533 /*
   534  * Load a surface from a seekable SDL data source (memory or file.)
   535  * If 'freesrc' is non-zero, the source will be closed after being read.
   536  * Returns the new surface, or NULL if there was an error.
   537  * The new surface should be freed with SDL_FreeSurface().
   538  */
   539 extern DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc);
   540 
   541 /* Convenience macro -- load a surface from a file */
   542 #define SDL_LoadBMP(file)	SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
   543 
   544 /*
   545  * Save a surface to a seekable SDL data source (memory or file.)
   546  * If 'freedst' is non-zero, the source will be closed after being written.
   547  * Returns 0 if successful or -1 if there was an error.
   548  */
   549 extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
   550 		(SDL_Surface *surface, SDL_RWops *dst, int freedst);
   551 
   552 /* Convenience macro -- save a surface to a file */
   553 #define SDL_SaveBMP(surface, file) \
   554 		SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
   555 
   556 /*
   557  * Sets the color key (transparent pixel) in a blittable surface.
   558  * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), 
   559  * 'key' will be the transparent pixel in the source image of a blit.
   560  * SDL_RLEACCEL requests RLE acceleration for the surface if present,
   561  * and removes RLE acceleration if absent.
   562  * If 'flag' is 0, this function clears any current color key.
   563  * This function returns 0, or -1 if there was an error.
   564  */
   565 extern DECLSPEC int SDLCALL SDL_SetColorKey
   566 			(SDL_Surface *surface, Uint32 flag, Uint32 key);
   567 
   568 /*
   569  * This function sets the alpha value for the entire surface, as opposed to
   570  * using the alpha component of each pixel. This value measures the range
   571  * of transparency of the surface, 0 being completely transparent to 255
   572  * being completely opaque. An 'alpha' value of 255 causes blits to be
   573  * opaque, the source pixels copied to the destination (the default). Note
   574  * that per-surface alpha can be combined with colorkey transparency.
   575  *
   576  * If 'flag' is 0, alpha blending is disabled for the surface.
   577  * If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface.
   578  * OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the
   579  * surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed.
   580  *
   581  * The 'alpha' parameter is ignored for surfaces that have an alpha channel.
   582  */
   583 extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
   584 
   585 /*
   586  * Sets the clipping rectangle for the destination surface in a blit.
   587  *
   588  * If the clip rectangle is NULL, clipping will be disabled.
   589  * If the clip rectangle doesn't intersect the surface, the function will
   590  * return SDL_FALSE and blits will be completely clipped.  Otherwise the
   591  * function returns SDL_TRUE and blits to the surface will be clipped to
   592  * the intersection of the surface area and the clipping rectangle.
   593  *
   594  * Note that blits are automatically clipped to the edges of the source
   595  * and destination surfaces.
   596  */
   597 extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect);
   598 
   599 /*
   600  * Gets the clipping rectangle for the destination surface in a blit.
   601  * 'rect' must be a pointer to a valid rectangle which will be filled
   602  * with the correct values.
   603  */
   604 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect);
   605 
   606 /*
   607  * Creates a new surface of the specified format, and then copies and maps 
   608  * the given surface to it so the blit of the converted surface will be as 
   609  * fast as possible.  If this function fails, it returns NULL.
   610  *
   611  * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those 
   612  * semantics.  You can also pass SDL_RLEACCEL in the flags parameter and
   613  * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
   614  * surface.
   615  *
   616  * This function is used internally by SDL_DisplayFormat().
   617  */
   618 extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface
   619 			(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags);
   620 
   621 /*
   622  * This performs a fast blit from the source surface to the destination
   623  * surface.  It assumes that the source and destination rectangles are
   624  * the same size.  If either 'srcrect' or 'dstrect' are NULL, the entire
   625  * surface (src or dst) is copied.  The final blit rectangles are saved
   626  * in 'srcrect' and 'dstrect' after all clipping is performed.
   627  * If the blit is successful, it returns 0, otherwise it returns -1.
   628  *
   629  * The blit function should not be called on a locked surface.
   630  *
   631  * The blit semantics for surfaces with and without alpha and colorkey
   632  * are defined as follows:
   633  *
   634  * RGBA->RGB:
   635  *     SDL_SRCALPHA set:
   636  * 	alpha-blend (using alpha-channel).
   637  * 	SDL_SRCCOLORKEY ignored.
   638  *     SDL_SRCALPHA not set:
   639  * 	copy RGB.
   640  * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
   641  * 	RGB values of the source colour key, ignoring alpha in the
   642  * 	comparison.
   643  * 
   644  * RGB->RGBA:
   645  *     SDL_SRCALPHA set:
   646  * 	alpha-blend (using the source per-surface alpha value);
   647  * 	set destination alpha to opaque.
   648  *     SDL_SRCALPHA not set:
   649  * 	copy RGB, set destination alpha to source per-surface alpha value.
   650  *     both:
   651  * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
   652  * 	source colour key.
   653  * 
   654  * RGBA->RGBA:
   655  *     SDL_SRCALPHA set:
   656  * 	alpha-blend (using the source alpha channel) the RGB values;
   657  * 	leave destination alpha untouched. [Note: is this correct?]
   658  * 	SDL_SRCCOLORKEY ignored.
   659  *     SDL_SRCALPHA not set:
   660  * 	copy all of RGBA to the destination.
   661  * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
   662  * 	RGB values of the source colour key, ignoring alpha in the
   663  * 	comparison.
   664  * 
   665  * RGB->RGB: 
   666  *     SDL_SRCALPHA set:
   667  * 	alpha-blend (using the source per-surface alpha value).
   668  *     SDL_SRCALPHA not set:
   669  * 	copy RGB.
   670  *     both:
   671  * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
   672  * 	source colour key.
   673  *
   674  * If either of the surfaces were in video memory, and the blit returns -2,
   675  * the video memory was lost, so it should be reloaded with artwork and 
   676  * re-blitted:
   677 	while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
   678 		while ( SDL_LockSurface(image) < 0 )
   679 			Sleep(10);
   680 		-- Write image pixels to image->pixels --
   681 		SDL_UnlockSurface(image);
   682 	}
   683  * This happens under DirectX 5.0 when the system switches away from your
   684  * fullscreen application.  The lock will also fail until you have access
   685  * to the video memory again.
   686  */
   687 /* You should call SDL_BlitSurface() unless you know exactly how SDL
   688    blitting works internally and how to use the other blit functions.
   689 */
   690 #define SDL_BlitSurface SDL_UpperBlit
   691 
   692 /* This is the public blit function, SDL_BlitSurface(), and it performs
   693    rectangle validation and clipping before passing it to SDL_LowerBlit()
   694 */
   695 extern DECLSPEC int SDLCALL SDL_UpperBlit
   696 			(SDL_Surface *src, SDL_Rect *srcrect,
   697 			 SDL_Surface *dst, SDL_Rect *dstrect);
   698 /* This is a semi-private blit function and it performs low-level surface
   699    blitting only.
   700 */
   701 extern DECLSPEC int SDLCALL SDL_LowerBlit
   702 			(SDL_Surface *src, SDL_Rect *srcrect,
   703 			 SDL_Surface *dst, SDL_Rect *dstrect);
   704 
   705 /*
   706  * This function performs a fast fill of the given rectangle with 'color'
   707  * The given rectangle is clipped to the destination surface clip area
   708  * and the final fill rectangle is saved in the passed in pointer.
   709  * If 'dstrect' is NULL, the whole surface will be filled with 'color'
   710  * The color should be a pixel of the format used by the surface, and 
   711  * can be generated by the SDL_MapRGB() function.
   712  * This function returns 0 on success, or -1 on error.
   713  */
   714 extern DECLSPEC int SDLCALL SDL_FillRect
   715 		(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
   716 
   717 /* 
   718  * This function takes a surface and copies it to a new surface of the
   719  * pixel format and colors of the video framebuffer, suitable for fast
   720  * blitting onto the display surface.  It calls SDL_ConvertSurface()
   721  *
   722  * If you want to take advantage of hardware colorkey or alpha blit
   723  * acceleration, you should set the colorkey and alpha value before
   724  * calling this function.
   725  *
   726  * If the conversion fails or runs out of memory, it returns NULL
   727  */
   728 extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormat(SDL_Surface *surface);
   729 
   730 /* 
   731  * This function takes a surface and copies it to a new surface of the
   732  * pixel format and colors of the video framebuffer (if possible),
   733  * suitable for fast alpha blitting onto the display surface.
   734  * The new surface will always have an alpha channel.
   735  *
   736  * If you want to take advantage of hardware colorkey or alpha blit
   737  * acceleration, you should set the colorkey and alpha value before
   738  * calling this function.
   739  *
   740  * If the conversion fails or runs out of memory, it returns NULL
   741  */
   742 extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *surface);
   743 
   744 
   745 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   746 /* YUV video surface overlay functions                                       */
   747 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   748 
   749 /* This function creates a video output overlay
   750    Calling the returned surface an overlay is something of a misnomer because
   751    the contents of the display surface underneath the area where the overlay
   752    is shown is undefined - it may be overwritten with the converted YUV data.
   753 */
   754 extern DECLSPEC SDL_Overlay * SDLCALL SDL_CreateYUVOverlay(int width, int height,
   755 				Uint32 format, SDL_Surface *display);
   756 
   757 /* Lock an overlay for direct access, and unlock it when you are done */
   758 extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay *overlay);
   759 extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay *overlay);
   760 
   761 /* Blit a video overlay to the display surface.
   762    The contents of the video surface underneath the blit destination are
   763    not defined.  
   764    The width and height of the destination rectangle may be different from
   765    that of the overlay, but currently only 2x scaling is supported.
   766 */
   767 extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect);
   768 
   769 /* Free a video overlay */
   770 extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay *overlay);
   771 
   772 
   773 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   774 /* OpenGL support functions.                                                 */
   775 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   776 
   777 /*
   778  * Dynamically load an OpenGL library, or the default one if path is NULL
   779  *
   780  * If you do this, you need to retrieve all of the GL functions used in
   781  * your program from the dynamic library using SDL_GL_GetProcAddress().
   782  */
   783 extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
   784 
   785 /*
   786  * Get the address of a GL function
   787  */
   788 extern DECLSPEC void * SDLCALL SDL_GL_GetProcAddress(const char* proc);
   789 
   790 /*
   791  * Set an attribute of the OpenGL subsystem before intialization.
   792  */
   793 extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
   794 
   795 /*
   796  * Get an attribute of the OpenGL subsystem from the windowing
   797  * interface, such as glX. This is of course different from getting
   798  * the values from SDL's internal OpenGL subsystem, which only
   799  * stores the values you request before initialization.
   800  *
   801  * Developers should track the values they pass into SDL_GL_SetAttribute
   802  * themselves if they want to retrieve these values.
   803  */
   804 extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int* value);
   805 
   806 /*
   807  * Swap the OpenGL buffers, if double-buffering is supported.
   808  */
   809 extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
   810 
   811 /*
   812  * Internal functions that should not be called unless you have read
   813  * and understood the source code for these functions.
   814  */
   815 extern DECLSPEC void SDLCALL SDL_GL_UpdateRects(int numrects, SDL_Rect* rects);
   816 extern DECLSPEC void SDLCALL SDL_GL_Lock(void);
   817 extern DECLSPEC void SDLCALL SDL_GL_Unlock(void);
   818 
   819 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   820 /* These functions allow interaction with the window manager, if any.        */
   821 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   822 
   823 /*
   824  * Sets/Gets the title and icon text of the display window (UTF-8 encoded)
   825  */
   826 extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title, const char *icon);
   827 extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon);
   828 
   829 /*
   830  * Sets the icon for the display window.
   831  * This function must be called before the first call to SDL_SetVideoMode().
   832  * It takes an icon surface, and a mask in MSB format.
   833  * If 'mask' is NULL, the entire icon surface will be used as the icon.
   834  */
   835 extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask);
   836 
   837 /*
   838  * This function iconifies the window, and returns 1 if it succeeded.
   839  * If the function succeeds, it generates an SDL_APPACTIVE loss event.
   840  * This function is a noop and returns 0 in non-windowed environments.
   841  */
   842 extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void);
   843 
   844 /*
   845  * Toggle fullscreen mode without changing the contents of the screen.
   846  * If the display surface does not require locking before accessing
   847  * the pixel information, then the memory pointers will not change.
   848  *
   849  * If this function was able to toggle fullscreen mode (change from 
   850  * running in a window to fullscreen, or vice-versa), it will return 1.
   851  * If it is not implemented, or fails, it returns 0.
   852  *
   853  * The next call to SDL_SetVideoMode() will set the mode fullscreen
   854  * attribute based on the flags parameter - if SDL_FULLSCREEN is not
   855  * set, then the display will be windowed by default where supported.
   856  *
   857  * This is currently only implemented in the X11 video driver.
   858  */
   859 extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface *surface);
   860 
   861 /*
   862  * This function allows you to set and query the input grab state of
   863  * the application.  It returns the new input grab state.
   864  */
   865 typedef enum {
   866 	SDL_GRAB_QUERY = -1,
   867 	SDL_GRAB_OFF = 0,
   868 	SDL_GRAB_ON = 1,
   869 	SDL_GRAB_FULLSCREEN	/* Used internally */
   870 } SDL_GrabMode;
   871 /*
   872  * Grabbing means that the mouse is confined to the application window,
   873  * and nearly all keyboard input is passed directly to the application,
   874  * and not interpreted by a window manager, if any.
   875  */
   876 extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
   877 
   878 /* Not in public API at the moment - do not use! */
   879 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
   880                                     SDL_Surface *dst, SDL_Rect *dstrect);
   881                     
   882 /* Ends C function definitions when using C++ */
   883 #ifdef __cplusplus
   884 }
   885 #endif
   886 #include "close_code.h"
   887 
   888 #endif /* _SDL_video_h */