Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
More work in progress integrating SDL_Surface and the new SDL_Texture…
… API
  • Loading branch information
slouken committed Aug 18, 2007
1 parent f9e5abd commit 61f6c3277954961743388c9eb68c837da7e760fd
Showing with 506 additions and 365 deletions.
  1. +4 −0 include/SDL_compat.h
  2. +149 −29 include/SDL_video.h
  3. +18 −11 src/SDL_compat.c
  4. +36 −30 src/video/SDL_RLEaccel.c
  5. +23 −41 src/video/SDL_blit.c
  6. +18 −15 src/video/SDL_blit.h
  7. +231 −158 src/video/SDL_surface.c
  8. +27 −81 src/video/SDL_video.c
@@ -37,6 +37,8 @@ extern "C" {
#endif

#define SDL_SWSURFACE 0x00000000 /* Not used */
//#define SDL_SRCALPHA 0x00010000
//#define SDL_SRCCOLORKEY 0x00020000
#define SDL_ANYFORMAT 0x00100000
#define SDL_HWPALETTE 0x00200000
#define SDL_DOUBLEBUF 0x00400000
@@ -146,6 +148,8 @@ extern DECLSPEC void SDLCALL SDL_UpdateRects(SDL_Surface * screen,
extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen, Sint32 x,
Sint32 y, Uint32 w, Uint32 h);
extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface, Uint32 flag,
Uint8 alpha);
extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
surface);
@@ -265,10 +265,7 @@ typedef void *SDL_GLContext;
/* These are the currently supported flags for the SDL_surface */
/* Used internally (read-only) */
#define SDL_PREALLOC 0x00000001 /* Surface uses preallocated memory */
#define SDL_SRCALPHA 0x00000004 /* Blit uses source alpha blending */
#define SDL_SRCCOLORKEY 0x00000008 /* Blit uses a source color key */
#define SDL_RLEACCELOK 0x00000010 /* Private flag */
#define SDL_RLEACCEL 0x00000020 /* Surface is RLE encoded */
#define SDL_RLEACCEL 0x00000001 /* Surface is RLE encoded */

/* Evaluates to true if the surface needs to be locked before access */
#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
@@ -1401,34 +1398,157 @@ extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)

/*
* Sets the color key (transparent pixel) in a blittable surface.
* If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL),
* 'key' will be the transparent pixel in the source image of a blit.
* SDL_RLEACCEL requests RLE acceleration for the surface if present,
* and removes RLE acceleration if absent.
* If 'flag' is 0, this function clears any current color key.
* This function returns 0, or -1 if there was an error.
* \fn int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
*
* \brief Sets the RLE acceleration hint for a surface.
*
* \return 0 on success, or -1 if the surface is not valid
*
* \note If RLE is enabled, colorkey and alpha blending blits are much faster,
* but the surface must be locked before directly accessing the pixels.
*/
extern DECLSPEC int SDLCALL SDL_SetColorKey
(SDL_Surface * surface, Uint32 flag, Uint32 key);
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag);

/*
* This function sets the alpha value for the entire surface, as opposed to
* using the alpha component of each pixel. This value measures the range
* of transparency of the surface, 0 being completely transparent to 255
* being completely opaque. An 'alpha' value of 255 causes blits to be
* opaque, the source pixels copied to the destination (the default). Note
* that per-surface alpha can be combined with colorkey transparency.
*
* If 'flag' is 0, alpha blending is disabled for the surface.
* If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface.
* OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the
* surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed.
*
* The 'alpha' parameter is ignored for surfaces that have an alpha channel.
*/
extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface, Uint32 flag,
Uint8 alpha);
* \fn int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
*
* \brief Sets the color key (transparent pixel) in a blittable surface.
*
* \param surface The surface to update
* \param flag Non-zero to enable colorkey and 0 to disable colorkey
* \param key The transparent pixel in the native surface format
*
* \return 0 on success, or -1 if the surface is not valid
*/
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);

/**
* \fn int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
*
* \brief Set an additional color value used in blit operations
*
* \param surface The surface to update
* \param r The red source color value multiplied into blit operations
* \param g The green source color value multiplied into blit operations
* \param b The blue source color value multiplied into blit operations
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_GetSurfaceColorMod()
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface,
Uint8 r, Uint8 g, Uint8 b);


/**
* \fn int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
*
* \brief Get the additional color value used in blit operations
*
* \param surface The surface to query
* \param r A pointer filled in with the source red color value
* \param g A pointer filled in with the source green color value
* \param b A pointer filled in with the source blue color value
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_SetSurfaceColorMod()
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface,
Uint8 * r, Uint8 * g,
Uint8 * b);

/**
* \fn int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
*
* \brief Set an additional alpha value used in blit operations
*
* \param surface The surface to update
* \param alpha The source alpha value multiplied into blit operations.
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_GetSurfaceAlphaMod()
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface,
Uint8 alpha);

/**
* \fn int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
*
* \brief Get the additional alpha value used in blit operations
*
* \param surface The surface to query
* \param alpha A pointer filled in with the source alpha value
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_SetSurfaceAlphaMod()
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface,
Uint8 * alpha);

/**
* \fn int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
*
* \brief Set the blend mode used for blit operations
*
* \param surface The surface to update
* \param blendMode SDL_TextureBlendMode to use for blit blending
*
* \return 0 on success, or -1 if the parameters are not valid
*
* \sa SDL_GetSurfaceBlendMode()
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface,
int blendMode);

/**
* \fn int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
*
* \brief Get the blend mode used for blit operations
*
* \param surface The surface to query
* \param blendMode A pointer filled in with the current blend mode
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_SetSurfaceBlendMode()
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface,
int *blendMode);

/**
* \fn int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
*
* \brief Set the scale mode used for blit operations
*
* \param surface The surface to update
* \param scaleMode SDL_TextureScaleMode to use for blit scaling
*
* \return 0 on success, or -1 if the surface is not valid or the scale mode is not supported
*
* \note If the scale mode is not supported, the closest supported mode is chosen. Currently only SDL_TEXTURESCALEMODE_FAST is supported on surfaces.
*
* \sa SDL_GetSurfaceScaleMode()
*/
extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface *surface,
int scaleMode);

/**
* \fn int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
*
* \brief Get the scale mode used for blit operations
*
* \param surface The surface to query
* \param scaleMode A pointer filled in with the current scale mode
*
* \return 0 on success, or -1 if the surface is not valid
*
* \sa SDL_SetSurfaceScaleMode()
*/
extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface *surface,
int *scaleMode);

/*
* Sets the clipping rectangle for the destination surface in a blit.
@@ -589,6 +589,22 @@ SDL_GetVideoSurface(void)
return SDL_PublicSurface;
}

int
SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
{
if (flag & SDL_RLEACCEL) {
SDL_SetSurfaceRLE(surface, 1);
}
if (flag) {
SDL_SetSurfaceAlphaMod(surface, value);
SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
} else {
SDL_SetSurfaceAlphaMod(surface, 0xFF);
SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_NONE);
}
return 0;
}

SDL_Surface *
SDL_DisplayFormat(SDL_Surface * surface)
{
@@ -600,15 +616,7 @@ SDL_DisplayFormat(SDL_Surface * surface)
}

/* Set the flags appropriate for copying to display surface */
flags = SDL_SWSURFACE;
#ifdef AUTORLE_DISPLAYFORMAT
flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
flags |= SDL_RLEACCELOK;
#else
flags |=
surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
#endif
return SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags);
return SDL_ConvertSurface(surface, SDL_PublicSurface->format, SDL_RLEACCELOK);
}

SDL_Surface *
@@ -658,8 +666,7 @@ SDL_DisplayFormatAlpha(SDL_Surface * surface)
break;
}
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
converted = SDL_ConvertSurface(surface, format, flags);
converted = SDL_ConvertSurface(surface, format, SDL_RLEACCELOK);
SDL_FreeFormat(format);
return converted;
}
@@ -905,8 +905,7 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
}
}

alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
? src->map->info.a : 255;
alpha = src->map->info.a;
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != src->w) {
RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
@@ -1803,7 +1802,7 @@ RLEColorkeySurface(SDL_Surface * surface)
int
SDL_RLESurface(SDL_Surface * surface)
{
int retcode;
int flags;

/* Clear any previous RLE conversion */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
@@ -1812,34 +1811,44 @@ SDL_RLESurface(SDL_Surface * surface)

/* We don't support RLE encoding of bitmaps */
if (surface->format->BitsPerPixel < 8) {
return (-1);
return -1;
}

/* Lock the surface if it's in hardware */
if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface) < 0) {
return (-1);
}
/* Make sure the pixels are available */
if (!surface->pixels) {
return -1;
}

/* Encode */
if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
retcode = RLEColorkeySurface(surface);
} else {
if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
&& surface->format->Amask != 0)
retcode = RLEAlphaSurface(surface);
else
retcode = -1; /* no RLE for per-surface alpha sans ckey */
/* If we don't have colorkey or blending, nothing to do... */
flags = surface->map->info.flags;
if(!(flags & (SDL_COPY_COLORKEY|SDL_COPY_BLEND))) {
return -1;
}

/* Unlock the surface if it's in hardware */
if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
/* Pass on combinations not supported */
if ((flags & SDL_COPY_MODULATE_COLOR) ||
(flags & (SDL_COPY_ADD|SDL_COPY_MOD)) ||
(flags & SDL_COPY_NEAREST)) {
return -1;
}

if (retcode < 0)
return -1;
/* Encode and set up the blit */
if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
if (!surface->map->identity) {
return -1;
}
if (RLEColorkeySurface(surface) < 0) {
return -1;
}
surface->map->blit = SDL_RLEBlit;
surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
} else {
if (RLEAlphaSurface(surface) < 0) {
return -1;
}
surface->map->blit = SDL_RLEAlphaBlit;
surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
}

/* The surface is now accelerated */
surface->flags |= SDL_RLEACCEL;
@@ -1931,13 +1940,12 @@ UnRLEAlpha(SDL_Surface * surface)
void
SDL_UnRLESurface(SDL_Surface * surface, int recode)
{
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
if (surface->flags & SDL_RLEACCEL) {
surface->flags &= ~SDL_RLEACCEL;

if (recode && !(surface->flags & SDL_PREALLOC)) {
if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
SDL_Rect full;
unsigned alpha_flag;

/* re-create the original surface */
surface->pixels = SDL_malloc(surface->h * surface->pitch);
@@ -1954,10 +1962,7 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode)
full.x = full.y = 0;
full.w = surface->w;
full.h = surface->h;
alpha_flag = surface->flags & SDL_SRCALPHA;
surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
SDL_RLEBlit(surface, &full, surface, &full);
surface->flags |= alpha_flag;
} else {
if (!UnRLEAlpha(surface)) {
/* Oh crap... */
@@ -1966,8 +1971,9 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode)
}
}
}
surface->map->info.flags &= (SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY);

if (surface->map && surface->map->data) {
if (surface->map->data) {
SDL_free(surface->map->data);
surface->map->data = NULL;
}

0 comments on commit 61f6c32

Please sign in to comment.