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