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