From ec2a2efc9ae9ad5dd9ad4c954015e012dd06efde Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 18 Aug 2007 05:39:09 +0000 Subject: [PATCH] Okay, still some bugs, but everything builds again... --- include/SDL_compat.h | 5 +- include/SDL_video.h | 24 +-- src/SDL_compat.c | 10 +- src/video/SDL_RLEaccel.c | 7 +- src/video/SDL_blit.c | 50 +++-- src/video/SDL_blit.h | 19 +- src/video/SDL_blit_0.c | 80 ++++---- src/video/SDL_blit_1.c | 83 ++++---- src/video/SDL_blit_A.c | 328 ++++++++++++++++--------------- src/video/SDL_blit_N.c | 264 ++++++++++++------------- src/video/SDL_blit_auto.c | 2 +- src/video/SDL_blit_copy.c | 10 +- src/video/SDL_pixels.c | 40 ++-- src/video/SDL_renderer_sw.c | 133 ++----------- src/video/SDL_surface.c | 91 ++++++--- src/video/SDL_video.c | 39 ++-- src/video/dummy/SDL_nullrender.c | 52 +---- src/video/sdlgenblit.pl | 2 +- test/testalpha.c | 8 +- test/testblitspeed.c | 25 ++- test/testgl.c | 2 +- test/testoverlay.c | 2 - test/testoverlay2.c | 2 - 23 files changed, 603 insertions(+), 675 deletions(-) diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 184754e6e..a62f314b5 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -37,8 +37,8 @@ extern "C" { #endif #define SDL_SWSURFACE 0x00000000 /* Not used */ -//#define SDL_SRCALPHA 0x00010000 -//#define SDL_SRCCOLORKEY 0x00020000 +#define SDL_SRCALPHA 0x00010000 +#define SDL_SRCCOLORKEY 0x00020000 #define SDL_ANYFORMAT 0x00100000 #define SDL_HWPALETTE 0x00200000 #define SDL_DOUBLEBUF 0x00400000 @@ -48,6 +48,7 @@ extern "C" { #define SDL_OPENGL 0x04000000 #define SDL_HWSURFACE 0x08000001 /* Not used */ #define SDL_ASYNCBLIT 0x08000000 /* Not used */ +#define SDL_RLEACCELOK 0x08000000 /* Not used */ #define SDL_HWACCEL 0x08000000 /* Not used */ #define SDL_APPMOUSEFOCUS 0x01 diff --git a/include/SDL_video.h b/include/SDL_video.h index 12a85e8ba..6554e71e6 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -265,7 +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_RLEACCEL 0x00000001 /* Surface is RLE encoded */ +#define SDL_RLEACCEL 0x00000002 /* 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) @@ -1407,7 +1407,8 @@ extern DECLSPEC int SDLCALL SDL_SaveBMP_RW * \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_SetSurfaceRLE(SDL_Surface *surface, int flag); +extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface, + int flag); /* * \fn int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) @@ -1420,7 +1421,8 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag); * * \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); +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) @@ -1436,7 +1438,7 @@ extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, U * * \sa SDL_GetSurfaceColorMod() */ -extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b); @@ -1454,7 +1456,7 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, * * \sa SDL_SetSurfaceColorMod() */ -extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b); @@ -1470,7 +1472,7 @@ extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, * * \sa SDL_GetSurfaceAlphaMod() */ -extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha); /** @@ -1485,7 +1487,7 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, * * \sa SDL_SetSurfaceAlphaMod() */ -extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha); /** @@ -1500,7 +1502,7 @@ extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, * * \sa SDL_GetSurfaceBlendMode() */ -extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface, int blendMode); /** @@ -1515,7 +1517,7 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, * * \sa SDL_SetSurfaceBlendMode() */ -extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface, int *blendMode); /** @@ -1532,7 +1534,7 @@ extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, * * \sa SDL_GetSurfaceScaleMode() */ -extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface * surface, int scaleMode); /** @@ -1547,7 +1549,7 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface *surface, * * \sa SDL_SetSurfaceScaleMode() */ -extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface *surface, +extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface * surface, int *scaleMode); /* diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 1c564418f..33b0093cc 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -608,7 +608,7 @@ SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value) SDL_Surface * SDL_DisplayFormat(SDL_Surface * surface) { - Uint32 flags; + SDL_Surface *converted; if (!SDL_PublicSurface) { SDL_SetError("No video mode has been set"); @@ -616,7 +616,9 @@ SDL_DisplayFormat(SDL_Surface * surface) } /* Set the flags appropriate for copying to display surface */ - return SDL_ConvertSurface(surface, SDL_PublicSurface->format, SDL_RLEACCELOK); + converted = SDL_ConvertSurface(surface, SDL_PublicSurface->format, 0); + SDL_SetSurfaceRLE(converted, 1); + return converted; } SDL_Surface * @@ -625,7 +627,6 @@ SDL_DisplayFormatAlpha(SDL_Surface * surface) SDL_PixelFormat *vf; SDL_PixelFormat *format; SDL_Surface *converted; - Uint32 flags; /* default to ARGB8888 */ Uint32 amask = 0xff000000; Uint32 rmask = 0x00ff0000; @@ -666,7 +667,8 @@ SDL_DisplayFormatAlpha(SDL_Surface * surface) break; } format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); - converted = SDL_ConvertSurface(surface, format, SDL_RLEACCELOK); + converted = SDL_ConvertSurface(surface, format, 0); + SDL_SetSurfaceRLE(converted, 1); SDL_FreeFormat(format); return converted; } diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index c5c3e2a83..b5f9e3ab6 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1821,13 +1821,13 @@ SDL_RLESurface(SDL_Surface * surface) /* If we don't have colorkey or blending, nothing to do... */ flags = surface->map->info.flags; - if(!(flags & (SDL_COPY_COLORKEY|SDL_COPY_BLEND))) { + if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) { return -1; } /* Pass on combinations not supported */ if ((flags & SDL_COPY_MODULATE_COLOR) || - (flags & (SDL_COPY_ADD|SDL_COPY_MOD)) || + (flags & (SDL_COPY_ADD | SDL_COPY_MOD)) || (flags & SDL_COPY_NEAREST)) { return -1; } @@ -1971,7 +1971,8 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode) } } } - surface->map->info.flags &= (SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY); + surface->map->info.flags &= + (SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY); if (surface->map->data) { SDL_free(surface->map->data); diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index 2b48a43c6..45504ab99 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -71,11 +71,15 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect, (Uint16) srcrect->x * info->src_fmt->BytesPerPixel; info->src_w = srcrect->w; info->src_h = srcrect->h; - info->dst = (Uint8 *) dst->pixels + - (Uint16) dstrect->y * dst->pitch + + info->src_skip = + info->src_pitch - info->src_w * info->src_fmt->BytesPerPixel; + info->dst = + (Uint8 *) dst->pixels + (Uint16) dstrect->y * dst->pitch + (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel; info->dst_w = dstrect->w; info->dst_h = dstrect->h; + info->dst_skip = + info->dst_pitch - info->dst_w * info->dst_fmt->BytesPerPixel; RunBlit = (SDL_BlitFunc) src->map->data; /* Run the actual software blit */ @@ -119,7 +123,8 @@ SDL_UseAltivecPrefetch() #endif /* __MACOSX__ */ static SDL_BlitFunc -SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitFuncEntry * entries) +SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, + SDL_BlitFuncEntry * entries) { int i, flagcheck; static Uint32 features = 0xffffffff; @@ -166,13 +171,16 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitFunc } /* Check modulation flags */ - flagcheck = (flags & (SDL_COPY_MODULATE_COLOR|SDL_COPY_MODULATE_COLOR)); + flagcheck = + (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_COLOR)); if ((flagcheck & entries[i].flags) != flagcheck) { continue; } /* Check blend flags */ - flagcheck = (flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)); + flagcheck = + (flags & + (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)); if ((flagcheck & entries[i].flags) != flagcheck) { continue; } @@ -208,8 +216,6 @@ SDL_CalculateBlit(SDL_Surface * surface) SDL_BlitFunc blit = NULL; SDL_BlitMap *map = surface->map; SDL_Surface *dst = map->dst; - Uint32 src_format; - Uint32 dst_format; /* Clean everything out to start */ if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { @@ -222,16 +228,13 @@ SDL_CalculateBlit(SDL_Surface * surface) map->info.dst_pitch = dst->pitch; /* See if we can do RLE acceleration */ - if (surface->flags & SDL_RLEACCELOK) { + if (surface->map->info.flags & SDL_COPY_RLE_DESIRED) { if (SDL_RLESurface(surface) == 0) { return 0; } } /* Choose a standard blit function */ - src_format = SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask); - dst_format = SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); - if (map->identity && !map->info.flags) { /* Handle overlapping blits on the same surface */ if (surface == dst) { @@ -240,15 +243,32 @@ SDL_CalculateBlit(SDL_Surface * surface) blit = SDL_BlitCopy; } } else if (surface->format->BitsPerPixel < 8) { - blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable0); + blit = SDL_CalculateBlit0(surface); } else if (surface->format->BytesPerPixel == 1) { - blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable1); + blit = SDL_CalculateBlit1(surface); + } else if (map->info.flags & SDL_COPY_BLEND) { + blit = SDL_CalculateBlitA(surface); } else { - blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTableN); + blit = SDL_CalculateBlitN(surface); } if (blit == NULL) { - blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_GeneratedBlitFuncTable); + Uint32 src_format = + SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, + surface->format->Rmask, + surface->format->Gmask, + surface->format->Bmask, + surface->format->Amask); + Uint32 dst_format = + SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, + dst->format->Rmask, dst->format->Gmask, + dst->format->Bmask, + dst->format->Amask); + + blit = + SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, + SDL_GeneratedBlitFuncTable); } + map->data = blit; /* Make sure we have a blit function */ if (blit == NULL) { diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index 28e3b1168..b5c0920e4 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -62,13 +62,16 @@ #define SDL_CPU_ALTIVEC_PREFETCH 0x00000010 #define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020 -typedef struct { +typedef struct +{ Uint8 *src; int src_w, src_h; int src_pitch; + int src_skip; Uint8 *dst; int dst_w, dst_h; int dst_pitch; + int dst_skip; SDL_PixelFormat *src_fmt; SDL_PixelFormat *dst_fmt; Uint8 *table; @@ -77,9 +80,10 @@ typedef struct { Uint8 r, g, b, a; } SDL_BlitInfo; -typedef void (SDLCALL * SDL_BlitFunc)(SDL_BlitInfo *info); +typedef void (SDLCALL * SDL_BlitFunc) (SDL_BlitInfo * info); -typedef struct { +typedef struct +{ Uint32 src_format; Uint32 dst_format; int flags; @@ -104,10 +108,11 @@ typedef struct SDL_BlitMap /* Functions found in SDL_blit.c */ extern int SDL_CalculateBlit(SDL_Surface * surface); -/* Blit function tables in SDL_blit_*.c */ -extern SDL_BlitFuncEntry SDL_BlitFuncTable0[]; -extern SDL_BlitFuncEntry SDL_BlitFuncTable1[]; -extern SDL_BlitFuncEntry SDL_BlitFuncTableN[]; +/* Functions found in SDL_blit_*.c */ +extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface); +extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface); +extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface); +extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface); /* * Useful macros for blitting routines diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index c3f099e41..0b04ee4b2 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -38,9 +38,9 @@ BlitBto1(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; srcskip += width - (width + 7) / 8; @@ -93,9 +93,9 @@ BlitBto2(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = (Uint16 *) info->dst; - dstskip = info->dst_pitch / 2; + dstskip = info->dst_skip / 2; map = (Uint16 *) info->table; srcskip += width - (width + 7) / 8; @@ -128,9 +128,9 @@ BlitBto3(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; srcskip += width - (width + 7) / 8; @@ -167,9 +167,9 @@ BlitBto4(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = (Uint32 *) info->dst; - dstskip = info->dst_pitch / 4; + dstskip = info->dst_skip / 4; map = (Uint32 *) info->table; srcskip += width - (width + 7) / 8; @@ -198,9 +198,9 @@ BlitBto1Key(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; @@ -251,9 +251,9 @@ BlitBto2Key(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint16 *dstp = (Uint16 *) info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; @@ -286,9 +286,9 @@ BlitBto3Key(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; @@ -320,9 +320,9 @@ BlitBto4Key(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint32 *dstp = (Uint32 *) info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; @@ -355,13 +355,13 @@ BlitBtoNAlpha(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - const SDL_Color *srcpal = info->src->palette->colors; - SDL_PixelFormat *dstfmt = info->dst; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + const SDL_Color *srcpal = info->src_fmt->palette->colors; + SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp; int c; - const int A = (info->cmod >> 24); + const int A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; @@ -400,15 +400,15 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info) int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; - int srcskip = info->s_skip; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int srcskip = info->src_skip; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; const SDL_Color *srcpal = srcfmt->palette->colors; int dstbpp; int c; - const int A = (info->cmod >> 24); - Uint32 ckey = info->ckey; + const int A = info->a; + Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; @@ -440,16 +440,16 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info) } } -static SDL_loblit bitmap_blit[] = { +static SDL_BlitFunc bitmap_blit[] = { NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; -static SDL_loblit colorkey_blit[] = { +static SDL_BlitFunc colorkey_blit[] = { NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; -SDL_loblit -SDL_CalculateBlit0(SDL_Surface * surface, int blit_index) +SDL_BlitFunc +SDL_CalculateBlit0(SDL_Surface * surface) { int which; @@ -462,17 +462,17 @@ SDL_CalculateBlit0(SDL_Surface * surface, int blit_index) } else { which = surface->map->dst->format->BytesPerPixel; } - switch (blit_index) { - case 0: /* copy */ + switch (surface->map->info.flags) { + case 0: return bitmap_blit[which]; - case 1: /* colorkey */ + case SDL_COPY_COLORKEY: return colorkey_blit[which]; - case 2: /* alpha */ + case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? BlitBtoNAlpha : NULL; - case 4: /* alpha + colorkey */ + case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? BlitBtoNAlphaKey : NULL; } return NULL; diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 86517ab7a..7319850ab 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -42,9 +42,9 @@ Blit1to1(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; while (height--) { @@ -93,9 +93,9 @@ Blit1to2(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = (Uint16 *) info->table; #ifdef USE_DUFFS_LOOP @@ -199,9 +199,9 @@ Blit1to3(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; while (height--) { @@ -247,9 +247,9 @@ Blit1to4(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = (Uint32 *) info->dst; - dstskip = info->dst_pitch / 4; + dstskip = info->dst_skip / 4; map = (Uint32 *) info->table; while (height--) { @@ -286,11 +286,11 @@ Blit1to1Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint8 *palmap = info->table; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; if (palmap) { while (height--) { @@ -333,11 +333,11 @@ Blit1to2Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint16 *palmap = (Uint16 *) info->table; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstskip /= 2; @@ -365,11 +365,11 @@ Blit1to3Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint8 *palmap = info->table; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; int o; while (height--) { @@ -398,11 +398,11 @@ Blit1to4Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint32 *palmap = (Uint32 *) info->table; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstskip /= 4; @@ -430,13 +430,13 @@ Blit1toNAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *dstfmt = info->dst; - const SDL_Color *srcpal = info->src->palette->colors; + int dstskip = info->dst_skip; + SDL_PixelFormat *dstfmt = info->dst_fmt; + const SDL_Color *srcpal = info->src_fmt->palette->colors; int dstbpp; - const int A = (info->cmod >> 24); + const int A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; @@ -471,15 +471,15 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - const SDL_Color *srcpal = info->src->palette->colors; - Uint32 ckey = info->ckey; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; + const SDL_Color *srcpal = info->src_fmt->palette->colors; + Uint32 ckey = info->colorkey; int dstbpp; - const int A = (info->cmod >> 24); + const int A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; @@ -510,16 +510,16 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) } } -static SDL_loblit one_blit[] = { +static SDL_BlitFunc one_blit[] = { NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; -static SDL_loblit one_blitkey[] = { +static SDL_BlitFunc one_blitkey[] = { NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; -SDL_loblit -SDL_CalculateBlit1(SDL_Surface * surface, int blit_index) +SDL_BlitFunc +SDL_CalculateBlit1(SDL_Surface * surface) { int which; SDL_PixelFormat *dstfmt; @@ -530,22 +530,21 @@ SDL_CalculateBlit1(SDL_Surface * surface, int blit_index) } else { which = dstfmt->BytesPerPixel; } - switch (blit_index) { - case 0: /* copy */ + switch (surface->map->info.flags) { + case 0: return one_blit[which]; - case 1: /* colorkey */ + case SDL_COPY_COLORKEY: return one_blitkey[which]; - case 2: /* alpha */ + case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: /* Supporting 8bpp->8bpp alpha is doable but requires lots of tables which consume space and takes time to precompute, so is better left to the user */ return which >= 2 ? Blit1toNAlpha : NULL; - case 3: /* alpha + colorkey */ + case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? Blit1toNAlphaKey : NULL; - } return NULL; } diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c index dcd502207..ee5638374 100644 --- a/src/video/SDL_blit_A.c +++ b/src/video/SDL_blit_A.c @@ -33,15 +33,15 @@ BlitNto1SurfaceAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; - const unsigned A = (info->cmod >> 24); + const unsigned A = info->a; while (height--) { /* *INDENT-OFF* */ @@ -89,12 +89,12 @@ BlitNto1PixelAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; /* FIXME: fix alpha bit field expansion here too? */ @@ -145,16 +145,16 @@ BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; - const int A = (info->cmod >> 24); + const int A = info->a; while (height--) { /* *INDENT-OFF* */ @@ -206,10 +206,10 @@ BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - Uint32 dalpha = info->dst->Amask; + int dstskip = info->dst_skip >> 2; + Uint32 dalpha = info->dst_fmt->Amask; __m64 src1, src2, dst1, dst2, lmask, hmask, dsta; @@ -259,9 +259,9 @@ BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info) static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info) { - SDL_PixelFormat *df = info->dst; + SDL_PixelFormat *df = info->dst_fmt; Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask; - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { /* only call a128 version when R,G,B occupy lower bits */ @@ -270,9 +270,9 @@ BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; Uint32 dalpha = df->Amask; Uint32 amult; @@ -359,10 +359,10 @@ BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - SDL_PixelFormat *sf = info->src; + int dstskip = info->dst_skip >> 2; + SDL_PixelFormat *sf = info->src_fmt; Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; Uint32 amask = sf->Amask; Uint32 ashift = sf->Ashift; @@ -544,10 +544,10 @@ Blit32to565PixelAlphaAltivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; vector unsigned char v0 = vec_splat_u8(0); vector unsigned short v8_16 = vec_splat_u16(8); @@ -720,15 +720,15 @@ Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - unsigned sA = (info->cmod >> 24); + int dstskip = info->dst_skip >> 2; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; + unsigned sA = info->a; unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; vector unsigned char mergePermute; vector unsigned char vsrcPermute; vector unsigned char vdstPermute; @@ -847,11 +847,11 @@ Blit32to32PixelAlphaAltivec(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip >> 2; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; vector unsigned char mergePermute; vector unsigned char valphaPermute; vector unsigned char vsrcPermute; @@ -945,9 +945,9 @@ BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; vector unsigned char mergePermute; vector unsigned char valphaPermute; vector unsigned char valphamask; @@ -1042,12 +1042,12 @@ Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info) /* XXX : 6 */ int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - unsigned sA = (info->cmod >> 24); + int dstskip = info->dst_skip >> 2; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; + unsigned sA = info->a; unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; vector unsigned char mergePermute; vector unsigned char vsrcPermute; @@ -1136,12 +1136,12 @@ Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info) static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; vector unsigned char mergePermute; vector unsigned char valpha; vector unsigned char valphamask; @@ -1227,9 +1227,9 @@ BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; while (height--) { /* *INDENT-OFF* */ @@ -1249,16 +1249,16 @@ BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info) static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; if (alpha == 128) { BlitRGBtoRGBSurfaceAlpha128(info); } else { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; Uint32 s; Uint32 d; Uint32 s1; @@ -1324,9 +1324,9 @@ BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; + int dstskip = info->dst_skip >> 2; while (height--) { /* *INDENT-OFF* */ @@ -1377,10 +1377,10 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch >> 2; - SDL_PixelFormat *sf = info->src; + int dstskip = info->dst_skip >> 2; + SDL_PixelFormat *sf = info->src_fmt; Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; Uint32 amask = sf->Amask; Uint32 ashift = sf->Ashift; @@ -1459,9 +1459,9 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask) int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip >> 1; + int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; while (height--) { if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) { @@ -1558,16 +1558,16 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask) static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xf7de); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip >> 1; + int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; Uint32 s, d; __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha; @@ -1695,16 +1695,16 @@ Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info) static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xfbde); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip >> 1; + int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; Uint32 s, d; __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha; @@ -1835,16 +1835,16 @@ Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info) static void Blit565to565SurfaceAlpha(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); + unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xf7de); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip >> 1; + int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { @@ -1874,16 +1874,16 @@ Blit565to565SurfaceAlpha(SDL_BlitInfo * info) static void Blit555to555SurfaceAlpha(SDL_BlitInfo * info) { - unsigned alpha = (info->cmod >> 24); /* downscale alpha to 5 bits */ + unsigned alpha = info->a; /* downscale alpha to 5 bits */ if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xfbde); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip >> 1; + int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { @@ -1916,9 +1916,9 @@ BlitARGBto565PixelAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; while (height--) { /* *INDENT-OFF* */ @@ -1962,9 +1962,9 @@ BlitARGBto555PixelAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip >> 2; + int srcskip = info->src_skip >> 2; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch >> 1; + int dstskip = info->dst_skip >> 1; while (height--) { /* *INDENT-OFF* */ @@ -2009,14 +2009,14 @@ BlitNtoNSurfaceAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = (info->cmod >> 24); + unsigned sA = info->a; unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; if (sA) { @@ -2053,15 +2053,15 @@ BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - Uint32 ckey = info->ckey; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; + Uint32 ckey = info->colorkey; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = (info->cmod >> 24); + unsigned sA = info->a; unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; while (height--) { @@ -2099,11 +2099,11 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp; int dstbpp; @@ -2147,25 +2147,80 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info) } -SDL_loblit -SDL_CalculateAlphaBlit(SDL_Surface * surface, int blit_index) +SDL_BlitFunc +SDL_CalculateBlitA(SDL_Surface * surface) { SDL_PixelFormat *sf = surface->format; SDL_PixelFormat *df = surface->map->dst->format; - if (sf->Amask == 0) { - if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { - if (df->BytesPerPixel == 1) - return BlitNto1SurfaceAlphaKey; + switch (surface->map->info.flags) { + case SDL_COPY_BLEND: + /* Per-pixel alpha blits */ + switch (df->BytesPerPixel) { + case 1: + return BlitNto1PixelAlpha; + + case 2: +#if SDL_ALTIVEC_BLITTERS + if (sf->BytesPerPixel == 4 + && df->Gmask == 0x7e0 && df->Bmask == 0x1f + && SDL_HasAltiVec()) + return Blit32to565PixelAlphaAltivec; else +#endif + if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 + && sf->Gmask == 0xff00 + && ((sf->Rmask == 0xff && df->Rmask == 0x1f) + || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { + if (df->Gmask == 0x7e0) + return BlitARGBto565PixelAlpha; + else if (df->Gmask == 0x3e0) + return BlitARGBto555PixelAlpha; + } + return BlitNtoNPixelAlpha; + + case 4: + if (sf->Rmask == df->Rmask + && sf->Gmask == df->Gmask + && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { +#if defined(__MMX__) || defined(__3dNOW__) + if (sf->Rshift % 8 == 0 + && sf->Gshift % 8 == 0 + && sf->Bshift % 8 == 0 + && sf->Ashift % 8 == 0 && sf->Aloss == 0) { +#ifdef __3dNOW__ + if (SDL_Has3DNow()) + return BlitRGBtoRGBPixelAlphaMMX3DNOW; +#endif +#ifdef __MMX__ + if (SDL_HasMMX()) + return BlitRGBtoRGBPixelAlphaMMX; +#endif + } +#endif /* __MMX__ || __3dNOW__ */ + if (sf->Amask == 0xff000000) { #if SDL_ALTIVEC_BLITTERS - if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && - SDL_HasAltiVec()) - return Blit32to32SurfaceAlphaKeyAltivec; + if (SDL_HasAltiVec()) + return BlitRGBtoRGBPixelAlphaAltivec; +#endif + return BlitRGBtoRGBPixelAlpha; + } + } +#if SDL_ALTIVEC_BLITTERS + if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec()) + return Blit32to32PixelAlphaAltivec; else #endif - return BlitNtoNSurfaceAlphaKey; - } else { + return BlitNtoNPixelAlpha; + + case 3: + default: + return BlitNtoNPixelAlpha; + } + break; + + case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: + if (sf->Amask == 0) { /* Per-surface alpha blits */ switch (df->BytesPerPixel) { case 1: @@ -2221,70 +2276,25 @@ SDL_CalculateAlphaBlit(SDL_Surface * surface, int blit_index) return BlitNtoNSurfaceAlpha; } } - } else { - /* Per-pixel alpha blits */ - switch (df->BytesPerPixel) { - case 1: - return BlitNto1PixelAlpha; + break; - case 2: -#if SDL_ALTIVEC_BLITTERS - if (sf->BytesPerPixel == 4 - && df->Gmask == 0x7e0 && df->Bmask == 0x1f - && SDL_HasAltiVec()) - return Blit32to565PixelAlphaAltivec; + case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: + if (sf->Amask == 0) { + if (df->BytesPerPixel == 1) + return BlitNto1SurfaceAlphaKey; else -#endif - if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 - && sf->Gmask == 0xff00 - && ((sf->Rmask == 0xff && df->Rmask == 0x1f) - || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { - if (df->Gmask == 0x7e0) - return BlitARGBto565PixelAlpha; - else if (df->Gmask == 0x3e0) - return BlitARGBto555PixelAlpha; - } - return BlitNtoNPixelAlpha; - - case 4: - if (sf->Rmask == df->Rmask - && sf->Gmask == df->Gmask - && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { -#if defined(__MMX__) || defined(__3dNOW__) - if (sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 - && sf->Ashift % 8 == 0 && sf->Aloss == 0) { -#ifdef __3dNOW__ - if (SDL_Has3DNow()) - return BlitRGBtoRGBPixelAlphaMMX3DNOW; -#endif -#ifdef __MMX__ - if (SDL_HasMMX()) - return BlitRGBtoRGBPixelAlphaMMX; -#endif - } -#endif /* __MMX__ || __3dNOW__ */ - if (sf->Amask == 0xff000000) { -#if SDL_ALTIVEC_BLITTERS - if (SDL_HasAltiVec()) - return BlitRGBtoRGBPixelAlphaAltivec; -#endif - return BlitRGBtoRGBPixelAlpha; - } - } #if SDL_ALTIVEC_BLITTERS - if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec()) - return Blit32to32PixelAlphaAltivec; + if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && + SDL_HasAltiVec()) + return Blit32to32SurfaceAlphaKeyAltivec; else #endif - return BlitNtoNPixelAlpha; - - case 3: - default: - return BlitNtoNPixelAlpha; + return BlitNtoNSurfaceAlphaKey; } + break; } + + return NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 70c3fb7a7..38fba803e 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -160,9 +160,9 @@ Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; vector unsigned char valpha = vec_splat_u8(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); @@ -264,9 +264,9 @@ Blit_RGB565_32Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; unsigned alpha; @@ -322,8 +322,8 @@ Blit_RGB565_32Altivec(SDL_BlitInfo * info) vf800 = (vector unsigned short) vec_splat_u8(-7); vf800 = vec_sl(vf800, vec_splat_u16(8)); - if (dstfmt->Amask && (info->cmod >> 24)) { - ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24); + if (dstfmt->Amask && info->a) { + ((unsigned char *) &valpha)[0] = alpha = info->a; valpha = vec_splat(valpha, 0); } else { alpha = 0; @@ -412,9 +412,9 @@ Blit_RGB555_32Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; unsigned alpha; @@ -470,8 +470,8 @@ Blit_RGB555_32Altivec(SDL_BlitInfo * info) vf800 = (vector unsigned short) vec_splat_u8(-7); vf800 = vec_sl(vf800, vec_splat_u16(8)); - if (dstfmt->Amask && (info->cmod >> 24)) { - ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24); + if (dstfmt->Amask && info->a) { + ((unsigned char *) &valpha)[0] = alpha = info->a; valpha = vec_splat(valpha, 0); } else { alpha = 0; @@ -561,17 +561,17 @@ Blit32to32KeyAltivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst; int dstbpp = dstfmt->BytesPerPixel; int copy_alpha = (srcfmt->Amask && dstfmt->Amask); - unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0; + unsigned alpha = dstfmt->Amask ? info->a : 0; Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; vector unsigned int valpha; vector unsigned char vpermute; vector unsigned char vzero; @@ -679,17 +679,17 @@ ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info) { int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; vector unsigned int vzero = vec_splat_u32(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { - if ((info->cmod >> 24)) { + if (info->a) { vector unsigned char valpha; - ((unsigned char *) &valpha)[0] = (info->cmod >> 24); + ((unsigned char *) &valpha)[0] = info->a; vzero = (vector unsigned int) vec_splat(valpha, 0); } } @@ -758,17 +758,17 @@ ConvertAltivec32to32_prefetch(SDL_BlitInfo * info) int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_pitch; + int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; vector unsigned int vzero = vec_splat_u32(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { - if ((info->cmod >> 24)) { + if (info->a) { vector unsigned char valpha; - ((unsigned char *) &valpha)[0] = (info->cmod >> 24); + ((unsigned char *) &valpha)[0] = info->a; vzero = (vector unsigned int) vec_splat(valpha, 0); } } @@ -901,9 +901,9 @@ Blit_RGB888_index8(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; - srcskip = info->s_skip / 4; + srcskip = info->src_skip / 4; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; if (map == NULL) { @@ -1018,9 +1018,9 @@ Blit_RGB888_RGB555(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; - srcskip = info->s_skip / 4; + srcskip = info->src_skip / 4; dst = (Uint16 *) info->dst; - dstskip = info->dst_pitch / 2; + dstskip = info->dst_skip / 2; #ifdef USE_DUFFS_LOOP while (height--) { @@ -1142,9 +1142,9 @@ Blit_RGB888_RGB565(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; - srcskip = info->s_skip / 4; + srcskip = info->src_skip / 4; dst = (Uint16 *) info->dst; - dstskip = info->dst_pitch / 2; + dstskip = info->dst_skip / 2; #ifdef USE_DUFFS_LOOP while (height--) { @@ -1255,9 +1255,9 @@ Blit_RGB565_32(SDL_BlitInfo * info, const Uint32 * map) width = info->dst_w; height = info->dst_h; src = (Uint8 *) info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = (Uint32 *) info->dst; - dstskip = info->dst_pitch / 4; + dstskip = info->dst_skip / 4; #ifdef USE_DUFFS_LOOP while (height--) { @@ -1877,9 +1877,9 @@ Blit_RGB888_index8_map(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; - srcskip = info->s_skip / 4; + srcskip = info->src_skip / 4; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; #ifdef USE_DUFFS_LOOP @@ -1950,11 +1950,11 @@ BlitNto1(SDL_BlitInfo * info) width = info->dst_w; height = info->dst_h; src = info->src; - srcskip = info->s_skip; + srcskip = info->src_skip; dst = info->dst; - dstskip = info->dst_pitch; + dstskip = info->dst_skip; map = info->table; - srcfmt = info->src; + srcfmt = info->src_fmt; srcbpp = srcfmt->BytesPerPixel; if (map == NULL) { @@ -2031,15 +2031,15 @@ Blit4to4MaskAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; if (dstfmt->Amask) { /* RGB->RGBA, SET_ALPHA */ - Uint32 mask = ((info->cmod >> 24) >> dstfmt->Aloss) << dstfmt->Ashift; + Uint32 mask = (info->a >> dstfmt->Aloss) << dstfmt->Ashift; while (height--) { /* *INDENT-OFF* */ @@ -2080,14 +2080,14 @@ BlitNtoN(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst; + SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0; + unsigned alpha = dstfmt->Amask ? info->a : 0; while (height--) { /* *INDENT-OFF* */ @@ -2115,12 +2115,12 @@ BlitNtoNCopyAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst; + SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; int c; @@ -2145,12 +2145,12 @@ BlitNto1Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - SDL_PixelFormat *srcfmt = info->src; + int dstskip = info->dst_skip; + SDL_PixelFormat *srcfmt = info->src_fmt; const Uint8 *palmap = info->table; - Uint32 ckey = info->ckey; + Uint32 ckey = info->colorkey; Uint32 rgbmask = ~srcfmt->Amask; int srcbpp; Uint32 Pixel; @@ -2211,11 +2211,11 @@ Blit2to2Key(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; - Uint32 rgbmask = ~info->src->Amask; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; + Uint32 rgbmask = ~info->src_fmt->Amask; /* Set up some basic variables */ srcskip /= 2; @@ -2245,15 +2245,15 @@ BlitNtoNKey(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0; + unsigned alpha = dstfmt->Amask ? info->a : 0; Uint32 rgbmask = ~srcfmt->Amask; /* Set up some basic variables */ @@ -2288,12 +2288,12 @@ BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; - int srcskip = info->s_skip; + int srcskip = info->src_skip; Uint8 *dst = info->dst; - int dstskip = info->dst_pitch; - Uint32 ckey = info->ckey; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; + int dstskip = info->dst_skip; + Uint32 ckey = info->colorkey; + SDL_PixelFormat *srcfmt = info->src_fmt; + SDL_PixelFormat *dstfmt = info->dst_fmt; Uint32 rgbmask = ~srcfmt->Amask; Uint8 srcbpp; @@ -2332,7 +2332,7 @@ struct blit_table int dstbpp; Uint32 dstR, dstG, dstB; Uint32 blit_features; - SDL_loblit blitfunc; + SDL_BlitFunc blitfunc; enum { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha; }; @@ -2403,30 +2403,77 @@ static const struct blit_table *normal_blit[] = { /* Mask matches table, or table entry is zero */ #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000)) -SDL_loblit -SDL_CalculateBlitN(SDL_Surface * surface, int blit_index) +SDL_BlitFunc +SDL_CalculateBlitN(SDL_Surface * surface) { SDL_PixelFormat *srcfmt; SDL_PixelFormat *dstfmt; const struct blit_table *table; int which; - SDL_loblit blitfun; + SDL_BlitFunc blitfun; /* Set up data for choosing the blit */ srcfmt = surface->format; dstfmt = surface->map->dst->format; - if (blit_index & 2) { - /* alpha or alpha+colorkey */ - return SDL_CalculateAlphaBlit(surface, blit_index); - } - /* We don't support destinations less than 8-bits */ if (dstfmt->BitsPerPixel < 8) { return (NULL); } - if (blit_index == 1) { + switch (surface->map->info.flags) { + case 0: + blitfun = NULL; + if (dstfmt->BitsPerPixel == 8) { + /* We assume 8-bit destinations are palettized */ + if ((srcfmt->BytesPerPixel == 4) && + (srcfmt->Rmask == 0x00FF0000) && + (srcfmt->Gmask == 0x0000FF00) && + (srcfmt->Bmask == 0x000000FF)) { + if (surface->map->info.table) { + blitfun = Blit_RGB888_index8_map; + } else { + blitfun = Blit_RGB888_index8; + } + } else { + blitfun = BlitNto1; + } + } else { + /* Now the meat, choose the blitter we want */ + int a_need = NO_ALPHA; + if (dstfmt->Amask) + a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; + table = normal_blit[srcfmt->BytesPerPixel - 1]; + for (which = 0; table[which].dstbpp; ++which) { + if (MASKOK(srcfmt->Rmask, table[which].srcR) && + MASKOK(srcfmt->Gmask, table[which].srcG) && + MASKOK(srcfmt->Bmask, table[which].srcB) && + MASKOK(dstfmt->Rmask, table[which].dstR) && + MASKOK(dstfmt->Gmask, table[which].dstG) && + MASKOK(dstfmt->Bmask, table[which].dstB) && + dstfmt->BytesPerPixel == table[which].dstbpp && + (a_need & table[which].alpha) == a_need && + ((table[which].blit_features & GetBlitFeatures()) == + table[which].blit_features)) + break; + } + blitfun = table[which].blitfunc; + + if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ + /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ + if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 + && srcfmt->Rmask == dstfmt->Rmask + && srcfmt->Gmask == dstfmt->Gmask + && srcfmt->Bmask == dstfmt->Bmask) { + blitfun = Blit4to4MaskAlpha; + } else if (a_need == COPY_ALPHA) { + blitfun = BlitNtoNCopyAlpha; + } + } + } + return (blitfun); + + case SDL_COPY_COLORKEY: /* colorkey blit: Here we don't have too many options, mostly because RLE is the preferred fast way to deal with this. If a particular case turns out to be useful we'll add it. */ @@ -2442,70 +2489,15 @@ SDL_CalculateBlitN(SDL_Surface * surface, int blit_index) return Blit32to32KeyAltivec; } else #endif - - if (srcfmt->Amask && dstfmt->Amask) + if (srcfmt->Amask && dstfmt->Amask) { return BlitNtoNKeyCopyAlpha; - else - return BlitNtoNKey; - } - } - - blitfun = NULL; - if (dstfmt->BitsPerPixel == 8) { - /* We assume 8-bit destinations are palettized */ - if ((srcfmt->BytesPerPixel == 4) && - (srcfmt->Rmask == 0x00FF0000) && - (srcfmt->Gmask == 0x0000FF00) && (srcfmt->Bmask == 0x000000FF)) { - if (surface->map->table) { - blitfun = Blit_RGB888_index8_map; } else { - blitfun = Blit_RGB888_index8; - } - } else { - blitfun = BlitNto1; - } - } else { - /* Now the meat, choose the blitter we want */ - int a_need = NO_ALPHA; - if (dstfmt->Amask) - a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; - table = normal_blit[srcfmt->BytesPerPixel - 1]; - for (which = 0; table[which].dstbpp; ++which) { - if (MASKOK(srcfmt->Rmask, table[which].srcR) && - MASKOK(srcfmt->Gmask, table[which].srcG) && - MASKOK(srcfmt->Bmask, table[which].srcB) && - MASKOK(dstfmt->Rmask, table[which].dstR) && - MASKOK(dstfmt->Gmask, table[which].dstG) && - MASKOK(dstfmt->Bmask, table[which].dstB) && - dstfmt->BytesPerPixel == table[which].dstbpp && - (a_need & table[which].alpha) == a_need && - ((table[which].blit_features & GetBlitFeatures()) == - table[which].blit_features)) - break; - } - blitfun = table[which].blitfunc; - - if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ - /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ - if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && - srcfmt->Rmask == dstfmt->Rmask && - srcfmt->Gmask == dstfmt->Gmask && - srcfmt->Bmask == dstfmt->Bmask) { - blitfun = Blit4to4MaskAlpha; - } else if (a_need == COPY_ALPHA) { - blitfun = BlitNtoNCopyAlpha; + return BlitNtoNKey; } } } -#ifdef DEBUG_ASM - if ((blitfun == BlitNtoN) || (blitfun == BlitNto1)) - fprintf(stderr, "Using C blit\n"); - else - fprintf(stderr, "Using optimized C blit\n"); -#endif /* DEBUG_ASM */ - - return (blitfun); + return NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_auto.c b/src/video/SDL_blit_auto.c index ea1ac8e09..2ce5862fc 100644 --- a/src/video/SDL_blit_auto.c +++ b/src/video/SDL_blit_auto.c @@ -5262,7 +5262,7 @@ static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) } } -static SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { +SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Scale }, { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend }, { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend_Scale }, diff --git a/src/video/SDL_blit_copy.c b/src/video/SDL_blit_copy.c index 251e8e2fa..3d816b2cd 100644 --- a/src/video/SDL_blit_copy.c +++ b/src/video/SDL_blit_copy.c @@ -95,12 +95,12 @@ SDL_BlitCopy(SDL_BlitInfo * info) int w, h; int srcskip, dstskip; - w = info->dst_w * info->dst->BytesPerPixel; + w = info->dst_w * info->dst_fmt->BytesPerPixel; h = info->dst_h; src = info->src; dst = info->dst; - srcskip = w + info->s_skip; - dstskip = w + info->dst_pitch; + srcskip = info->src_pitch; + dstskip = info->dst_pitch; #ifdef __SSE__ if (SDL_HasSSE() && !((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) { @@ -139,11 +139,11 @@ SDL_BlitCopyOverlap(SDL_BlitInfo * info) int w, h; int skip; - w = info->dst_w * info->dst->BytesPerPixel; + w = info->dst_w * info->dst_fmt->BytesPerPixel; h = info->dst_h; src = info->src; dst = info->dst; - skip = w + info->s_skip; + skip = info->src_pitch; if ((dst < src) || (dst >= (src + h * skip))) { SDL_BlitCopy(info); } else { diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 93a7b06a4..db4a6486f 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -668,12 +668,12 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) /* Map from Palette to BitField */ static Uint8 * -Map1toN(SDL_PixelFormat * src, Uint32 cmod, SDL_PixelFormat * dst) +Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, + SDL_PixelFormat * dst) { Uint8 *map; int i; int bpp; - unsigned Amod, Rmod, Gmod, Bmod; SDL_Palette *pal = src->palette; bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); @@ -683,17 +683,12 @@ Map1toN(SDL_PixelFormat * src, Uint32 cmod, SDL_PixelFormat * dst) return (NULL); } - Amod = (cmod >> 24) & 0xFF; - Rmod = (cmod >> 16) & 0xFF; - Gmod = (cmod >> 8) & 0xFF; - Bmod = (cmod >> 0) & 0xFF; - /* We memory copy to the pixel map so the endianness is preserved */ for (i = 0; i < pal->ncolors; ++i) { Uint8 A = Amod; - Uint8 R = (pal->colors[i].r * Rmod) / 255; - Uint8 G = (pal->colors[i].g * Gmod) / 255; - Uint8 B = (pal->colors[i].b * Bmod) / 255; + Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); + Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); + Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); } return (map); @@ -725,7 +720,10 @@ SDL_AllocBlitMap(void) SDL_OutOfMemory(); return (NULL); } - map->cmod = 0xFFFFFFFF; + map->info.r = 0xFF; + map->info.g = 0xFF; + map->info.b = 0xFF; + map->info.a = 0xFF; /* It's ready to go */ return (map); @@ -739,9 +737,9 @@ SDL_InvalidateMap(SDL_BlitMap * map) } map->dst = NULL; map->format_version = (unsigned int) -1; - if (map->table) { - SDL_free(map->table); - map->table = NULL; + if (map->info.table) { + SDL_free(map->info.table); + map->info.table = NULL; } } int @@ -767,10 +765,10 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) switch (dstfmt->BytesPerPixel) { case 1: /* Palette --> Palette */ - map->table = + map->info.table = Map1to1(srcfmt->palette, dstfmt->palette, &map->identity); if (!map->identity) { - if (map->table == NULL) { + if (map->info.table == NULL) { return (-1); } } @@ -780,8 +778,10 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) default: /* Palette --> BitField */ - map->table = Map1toN(srcfmt, src->map->cmod, dstfmt); - if (map->table == NULL) { + map->info.table = + Map1toN(srcfmt, src->map->info.r, src->map->info.g, + src->map->info.b, src->map->info.a, dstfmt); + if (map->info.table == NULL) { return (-1); } break; @@ -791,9 +791,9 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) switch (dstfmt->BytesPerPixel) { case 1: /* BitField --> Palette */ - map->table = MapNto1(srcfmt, dstfmt, &map->identity); + map->info.table = MapNto1(srcfmt, dstfmt, &map->identity); if (!map->identity) { - if (map->table == NULL) { + if (map->info.table == NULL) { return (-1); } } diff --git a/src/video/SDL_renderer_sw.c b/src/video/SDL_renderer_sw.c index 63fd4f40c..2c4133078 100644 --- a/src/video/SDL_renderer_sw.c +++ b/src/video/SDL_renderer_sw.c @@ -26,7 +26,6 @@ #include "SDL_pixels_c.h" #include "SDL_rect_c.h" #include "SDL_yuv_sw_c.h" -#include "SDL_rendercopy.h" /* SDL surface based renderer implementation */ @@ -431,81 +430,33 @@ SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, } } -static void -SW_UpdateRenderCopyFunc(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Window *window = SDL_GetWindowFromID(renderer->window); - SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); - SDL_DisplayMode *displayMode = &display->current_mode; - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - - /* We only need a special copy function for advanced features */ - if (texture->modMode - || (texture-> - blendMode & (SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD)) - || texture->scaleMode) { - surface->userdata = - SDL_GetRenderCopyFunc(texture->format, displayMode->format, - texture->modMode, texture->blendMode, - texture->scaleMode); - } else { - surface->userdata = NULL; - } -} - static int SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) { - SW_UpdateRenderCopyFunc(renderer, texture); - return 0; + SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + return SDL_SetSurfaceColorMod(surface, texture->r, texture->g, + texture->b); } static int SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) { - SW_UpdateRenderCopyFunc(renderer, texture); - return 0; + SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + return SDL_SetSurfaceAlphaMod(surface, texture->a); } static int SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) { - switch (texture->blendMode) { - case SDL_TEXTUREBLENDMODE_NONE: - case SDL_TEXTUREBLENDMODE_MASK: - case SDL_TEXTUREBLENDMODE_BLEND: - case SDL_TEXTUREBLENDMODE_ADD: - case SDL_TEXTUREBLENDMODE_MOD: - SW_UpdateRenderCopyFunc(renderer, texture); - return 0; - default: - SDL_Unsupported(); - texture->blendMode = SDL_TEXTUREBLENDMODE_NONE; - SW_UpdateRenderCopyFunc(renderer, texture); - return -1; - } + SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + return SDL_SetSurfaceBlendMode(surface, texture->blendMode); } static int SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) { - switch (texture->scaleMode) { - case SDL_TEXTURESCALEMODE_NONE: - case SDL_TEXTURESCALEMODE_FAST: - SW_UpdateRenderCopyFunc(renderer, texture); - return 0; - case SDL_TEXTURESCALEMODE_SLOW: - case SDL_TEXTURESCALEMODE_BEST: - SDL_Unsupported(); - texture->scaleMode = SDL_TEXTURESCALEMODE_FAST; - SW_UpdateRenderCopyFunc(renderer, texture); - return -1; - default: - SDL_Unsupported(); - texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; - SW_UpdateRenderCopyFunc(renderer, texture); - return -1; - } + SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + return SDL_SetSurfaceBlendMode(surface, texture->scaleMode); } static int @@ -629,60 +580,18 @@ SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, data->surface.pixels, data->surface.pitch); } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - SDL_RenderCopyFunc copyfunc = (SDL_RenderCopyFunc) surface->userdata; - - if (copyfunc) { - SDL_RenderCopyData copydata; - - copydata.src = - (Uint8 *) surface->pixels + srcrect->y * surface->pitch + - srcrect->x * surface->format->BytesPerPixel; - copydata.src_w = srcrect->w; - copydata.src_h = srcrect->h; - copydata.src_pitch = surface->pitch; - copydata.dst = (Uint8 *) data->surface.pixels; - copydata.dst_w = dstrect->w; - copydata.dst_h = dstrect->h; - copydata.dst_pitch = data->surface.pitch; - copydata.flags = 0; - if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { - copydata.flags |= SDL_RENDERCOPY_MODULATE_COLOR; - copydata.r = texture->r; - copydata.g = texture->g; - copydata.b = texture->b; - } - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { - copydata.flags |= SDL_RENDERCOPY_MODULATE_ALPHA; - copydata.a = texture->a; - } - if (texture->blendMode & SDL_TEXTUREBLENDMODE_MASK) { - copydata.flags |= SDL_RENDERCOPY_MASK; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_BLEND) { - copydata.flags |= SDL_RENDERCOPY_BLEND; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_ADD) { - copydata.flags |= SDL_RENDERCOPY_ADD; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_MOD) { - copydata.flags |= SDL_RENDERCOPY_MOD; - } - if (texture->scaleMode) { - copydata.flags |= SDL_RENDERCOPY_NEAREST; - } - copyfunc(©data); - status = 0; - } else { - SDL_Rect real_srcrect = *srcrect; - SDL_Rect real_dstrect; - - data->surface.w = dstrect->w; - data->surface.h = dstrect->h; - data->surface.clip_rect.w = dstrect->w; - data->surface.clip_rect.h = dstrect->h; - real_dstrect = data->surface.clip_rect; - - status = - SDL_LowerBlit(surface, &real_srcrect, &data->surface, - &real_dstrect); - } + SDL_Rect real_srcrect = *srcrect; + SDL_Rect real_dstrect; + + data->surface.w = dstrect->w; + data->surface.h = dstrect->h; + data->surface.clip_rect.w = dstrect->w; + data->surface.clip_rect.h = dstrect->h; + real_dstrect = data->surface.clip_rect; + + status = + SDL_LowerBlit(surface, &real_srcrect, &data->surface, + &real_dstrect); } data->renderer->UnlockTexture(data->renderer, data->texture[data->current_texture]); diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index afe0b4f6e..581d8aaaf 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -53,9 +53,6 @@ SDL_CreateRGBSurface(Uint32 flags, SDL_FreeSurface(surface); return NULL; } - if (Amask) { - surface->flags |= SDL_SRCALPHA; - } surface->w = width; surface->h = height; surface->pitch = SDL_CalculatePitch(surface); @@ -138,6 +135,11 @@ SDL_CreateRGBSurface(Uint32 flags, } SDL_FormatChanged(surface); + /* By default surface with an alpha mask are set up for blending */ + if (Amask) { + SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND); + } + /* The surface is ready to go */ surface->refcount = 1; #ifdef CHECK_LEAKS @@ -212,26 +214,29 @@ SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) return 0; } -int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag) +int +SDL_SetSurfaceRLE(SDL_Surface * surface, int flag) { - Uint32 flags; + int flags; if (!surface) { return -1; } + flags = surface->map->info.flags; if (flag) { - surface->flags |= SDL_RLEACCELOK; + surface->map->info.flags |= SDL_COPY_RLE_DESIRED; } else { - surface->flags &= ~SDL_RLEACCELOK; + surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED; } - if (surface->flags != flags) { + if (surface->map->info.flags != flags) { SDL_InvalidateMap(surface->map); } return 0; } -int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) +int +SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key) { int flags; @@ -253,10 +258,19 @@ int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) if (surface->map->info.flags != flags) { SDL_InvalidateMap(surface->map); } + + /* Compatibility mode */ + if (surface->map->info.flags & SDL_COPY_COLORKEY) { + surface->flags |= SDL_SRCCOLORKEY; + } else { + surface->flags &= ~SDL_SRCCOLORKEY; + } + return 0; } -int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) +int +SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b) { int flags; @@ -281,7 +295,8 @@ int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) } -int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 * r, Uint8 * g, Uint8 * b) +int +SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b) { if (!surface) { return -1; @@ -299,7 +314,8 @@ int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 * r, Uint8 * g, Uint8 * b return 0; } -int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) +int +SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha) { int flags; @@ -321,7 +337,8 @@ int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) return 0; } -int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 * alpha) +int +SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha) { if (!surface) { return -1; @@ -333,7 +350,8 @@ int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 * alpha) return 0; } -int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode) +int +SDL_SetSurfaceBlendMode(SDL_Surface * surface, int blendMode) { int flags, status; @@ -343,7 +361,8 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode) status = 0; flags = surface->map->info.flags; - surface->map->info.flags &= ~(SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD); + surface->map->info.flags &= + ~(SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD); switch (blendMode) { case SDL_TEXTUREBLENDMODE_NONE: break; @@ -368,10 +387,19 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode) if (surface->map->info.flags != flags) { SDL_InvalidateMap(surface->map); } + + /* Compatibility mode */ + if (surface->map->info.flags & SDL_COPY_BLEND) { + surface->flags |= SDL_SRCALPHA; + } else { + surface->flags &= ~SDL_SRCALPHA; + } + return status; } -int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode) +int +SDL_GetSurfaceBlendMode(SDL_Surface * surface, int *blendMode) { if (!surface) { return -1; @@ -381,27 +409,30 @@ int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode) return 0; } - switch(surface->map->info.flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { + switch (surface->map->info. + flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | + SDL_COPY_MOD)) { case SDL_COPY_MASK: - *blendMode = SDL_TEXTUREBLENDMODE_MASK: + *blendMode = SDL_TEXTUREBLENDMODE_MASK; break; case SDL_COPY_BLEND: - *blendMode = SDL_TEXTUREBLENDMODE_BLEND: + *blendMode = SDL_TEXTUREBLENDMODE_BLEND; break; case SDL_COPY_ADD: - *blendMode = SDL_TEXTUREBLENDMODE_ADD: + *blendMode = SDL_TEXTUREBLENDMODE_ADD; break; case SDL_COPY_MOD: - *blendMode = SDL_TEXTUREBLENDMODE_MOD: + *blendMode = SDL_TEXTUREBLENDMODE_MOD; break; default: - *blendMode = SDL_TEXTUREBLENDMODE_NONE: + *blendMode = SDL_TEXTUREBLENDMODE_NONE; break; } return 0; } -int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode) +int +SDL_SetSurfaceScaleMode(SDL_Surface * surface, int scaleMode) { int flags, status; @@ -436,7 +467,8 @@ int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode) return status; } -int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode) +int +SDL_GetSurfaceScaleMode(SDL_Surface * surface, int *scaleMode) { if (!surface) { return -1; @@ -446,12 +478,12 @@ int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode) return 0; } - switch(surface->map->info.flags & (SDL_COPY_LINEAR)) { - case SDL_COPY_LINEAR: - *scaleMode = SDL_TEXTURESCALEMODE_FAST: + switch (surface->map->info.flags & (SDL_COPY_NEAREST)) { + case SDL_COPY_NEAREST: + *scaleMode = SDL_TEXTURESCALEMODE_FAST; break; default: - *scaleMode = SDL_TEXTURESCALEMODE_NONE: + *scaleMode = SDL_TEXTURESCALEMODE_NONE; break; } return 0; @@ -706,7 +738,8 @@ SDL_ConvertSurface(SDL_Surface * surface, if (copy_flags & SDL_COPY_COLORKEY) { Uint8 keyR, keyG, keyB, keyA; - SDL_GetRGBA(colorkey, surface->format, &keyR, &keyG, &keyB, &keyA); + SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, + &keyG, &keyB, &keyA); SDL_SetColorKey(convert, 1, SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); } diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index bbb44315b..7c779b22a 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1552,7 +1552,9 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) return 0; } } else { - if (surface->format->Amask || !(flags & (SDL_COPY_COLORKEY|SDL_COPY_MASK|SDL_COPY_BLEND))) { + if (surface->format->Amask + || !(surface->map->info.flags & + (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { bpp = fmt->BitsPerPixel; Rmask = fmt->Rmask; Gmask = fmt->Gmask; @@ -1602,31 +1604,34 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); if (dst_fmt) { if (SDL_ISPIXELFORMAT_INDEXED(format)) { - dst_fmt->palette = SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); + dst_fmt->palette = + SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); if (dst_fmt->palette) { - if (fmt->palette) { -fixme - } else { - SDL_DitherColors(dst_fmt->palette->colors, SDL_BITSPERPIXEL(format)); - } - } - if (fmt->palette) { - dst_fmt->palette = fmt->palette; - } else { + /* FIXME: Should we try to copy fmt->palette? */ + SDL_DitherColors(dst_fmt->palette->colors, + SDL_BITSPERPIXEL(format)); } } - cvt = SDL_ConvertSurface(surface, fmt, 0); - if (cvt) { - SDL_UpdateTexture(textureID, NULL, cvt->pixels, cvt->pitch); - SDL_FreeSurface(cvt); + dst = SDL_ConvertSurface(surface, dst_fmt, 0); + if (dst) { + SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); + SDL_FreeSurface(dst); } - SDL_FreeFormat(fmt); + if (dst_fmt->palette) { + SDL_FreePalette(dst_fmt->palette); + } + SDL_FreeFormat(dst_fmt); + } + if (!dst) { + SDL_DestroyTexture(textureID); + return 0; } } if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { - SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, fmt->palette->ncolors); + SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, + fmt->palette->ncolors); } return textureID; diff --git a/src/video/dummy/SDL_nullrender.c b/src/video/dummy/SDL_nullrender.c index d3462abdb..9bcad517a 100644 --- a/src/video/dummy/SDL_nullrender.c +++ b/src/video/dummy/SDL_nullrender.c @@ -25,7 +25,6 @@ #include "../SDL_sysvideo.h" #include "../SDL_yuv_sw_c.h" #include "../SDL_renderer_sw.h" -#include "../SDL_rendercopy.h" /* SDL surface based renderer implementation */ @@ -160,55 +159,10 @@ SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; SDL_Surface *target = data->screens[data->current_screen]; - SDL_RenderCopyFunc copyfunc = (SDL_RenderCopyFunc) surface->userdata; + SDL_Rect real_srcrect = *srcrect; + SDL_Rect real_dstrect = *dstrect; - if (copyfunc) { - SDL_RenderCopyData copydata; - - copydata.src = - (Uint8 *) surface->pixels + srcrect->y * surface->pitch + - srcrect->x * surface->format->BytesPerPixel; - copydata.src_w = srcrect->w; - copydata.src_h = srcrect->h; - copydata.src_pitch = surface->pitch; - copydata.dst = - (Uint8 *) target->pixels + dstrect->y * target->pitch + - dstrect->x * target->format->BytesPerPixel; - copydata.dst_w = dstrect->w; - copydata.dst_h = dstrect->h; - copydata.dst_pitch = target->pitch; - copydata.flags = 0; - if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { - copydata.flags |= SDL_RENDERCOPY_MODULATE_COLOR; - copydata.r = texture->r; - copydata.g = texture->g; - copydata.b = texture->b; - } - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { - copydata.flags |= SDL_RENDERCOPY_MODULATE_ALPHA; - copydata.a = texture->a; - } - if (texture->blendMode & SDL_TEXTUREBLENDMODE_MASK) { - copydata.flags |= SDL_RENDERCOPY_MASK; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_BLEND) { - copydata.flags |= SDL_RENDERCOPY_BLEND; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_ADD) { - copydata.flags |= SDL_RENDERCOPY_ADD; - } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_MOD) { - copydata.flags |= SDL_RENDERCOPY_MOD; - } - if (texture->scaleMode) { - copydata.flags |= SDL_RENDERCOPY_NEAREST; - } - copyfunc(©data); - return 0; - } else { - SDL_Rect real_srcrect = *srcrect; - SDL_Rect real_dstrect = *dstrect; - - return SDL_LowerBlit(surface, &real_srcrect, target, - &real_dstrect); - } + return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); } } diff --git a/src/video/sdlgenblit.pl b/src/video/sdlgenblit.pl index 0341785b1..c0c8988d3 100755 --- a/src/video/sdlgenblit.pl +++ b/src/video/sdlgenblit.pl @@ -384,7 +384,7 @@ sub output_copyinc sub output_copyfunctable { print FILE <<__EOF__; -static SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { +SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { __EOF__ for (my $i = 0; $i <= $#src_formats; ++$i) { my $src = $src_formats[$i]; diff --git a/test/testalpha.c b/test/testalpha.c index c08204799..5c6b20674 100644 --- a/test/testalpha.c +++ b/test/testalpha.c @@ -253,7 +253,7 @@ void MoveSprite(SDL_Surface * screen, SDL_Surface * light) { SDL_Rect updates[2]; - int alpha; + Uint8 alpha; /* Erase the sprite if it was visible */ if (sprite_visible) { @@ -290,10 +290,10 @@ MoveSprite(SDL_Surface * screen, SDL_Surface * light) } /* Update transparency (fade in and out) */ - alpha = sprite->format->alpha; - if ((alpha + alpha_vel) < 0) { + SDL_GetSurfaceAlphaMod(sprite, &alpha); + if (((int) alpha + alpha_vel) < 0) { alpha_vel = -alpha_vel; - } else if ((alpha + alpha_vel) > 255) { + } else if (((int) alpha + alpha_vel) > 255) { alpha_vel = -alpha_vel; } SDL_SetAlpha(sprite, SDL_SRCALPHA, (Uint8) (alpha + alpha_vel)); diff --git a/test/testblitspeed.c b/test/testblitspeed.c index 32cc4343e..f3f023e20 100644 --- a/test/testblitspeed.c +++ b/test/testblitspeed.c @@ -91,9 +91,6 @@ output_surface_details(const char *name, SDL_Surface * surface) printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel); printf(" pitch : %d\n", (int) surface->pitch); - printf(" alpha : %d\n", (int) surface->format->alpha); - printf(" colorkey : 0x%X\n", - (unsigned int) surface->format->colorkey); printf(" red bits : 0x%08X mask, %d shift, %d loss\n", (int) surface->format->Rmask, @@ -216,8 +213,10 @@ setup_test(int argc, char **argv) Uint32 origdstalphaflags = 0; Uint32 srcalphaflags = 0; Uint32 dstalphaflags = 0; - int srcalpha = 255; - int dstalpha = 255; + Uint8 origsrcalpha = 255; + Uint8 origdstalpha = 255; + Uint8 srcalpha = 255; + Uint8 dstalpha = 255; int screenSurface = 0; int i = 0; @@ -313,8 +312,10 @@ setup_test(int argc, char **argv) (dest->flags & SDL_SRCALPHA) | (dest->flags & SDL_RLEACCEL); origsrcalphaflags = srcalphaflags; origdstalphaflags = dstalphaflags; - srcalpha = src->format->alpha; - dstalpha = dest->format->alpha; + SDL_GetSurfaceAlphaMod(src, &srcalpha); + SDL_GetSurfaceAlphaMod(dest, &dstalpha); + origsrcalpha = srcalpha; + origdstalpha = dstalpha; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -339,12 +340,10 @@ setup_test(int argc, char **argv) else if (strcmp(arg, "--dstnorleaccel") == 0) dstalphaflags &= ~SDL_RLEACCEL; } - if ((dstalphaflags != origdstalphaflags) - || (dstalpha != dest->format->alpha)) - SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha); - if ((srcalphaflags != origsrcalphaflags) - || (srcalpha != src->format->alpha)) - SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha); + if ((dstalphaflags != origdstalphaflags) || (origdstalpha != dstalpha)) + SDL_SetAlpha(dest, dstalphaflags, dstalpha); + if ((srcalphaflags != origsrcalphaflags) || (origsrcalpha != srcalpha)) + SDL_SetAlpha(src, srcalphaflags, srcalpha); /* set some sane defaults so we can see if the blit code is broken... */ SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); diff --git a/test/testgl.c b/test/testgl.c index 6730b9249..f14afe8b9 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -201,7 +201,7 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord) /* Save the alpha blending attributes */ saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); - saved_alpha = surface->format->alpha; + SDL_GetSurfaceAlphaMod(surface, &saved_alpha); if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { SDL_SetAlpha(surface, 0, 0); } diff --git a/test/testoverlay.c b/test/testoverlay.c index 2abba3f1f..bc0ad4066 100644 --- a/test/testoverlay.c +++ b/test/testoverlay.c @@ -487,8 +487,6 @@ main(int argc, char **argv) format.Gloss = 0; format.Bloss = 0; format.Aloss = 8; - format.colorkey = 0; - format.alpha = 0; newsurf = SDL_ConvertSurface(pic, &format, SDL_SWSURFACE); if (!newsurf) { diff --git a/test/testoverlay2.c b/test/testoverlay2.c index 85fba6445..33b5f1ce6 100644 --- a/test/testoverlay2.c +++ b/test/testoverlay2.c @@ -521,8 +521,6 @@ main(int argc, char **argv) format.Gloss = 0; format.Bloss = 0; format.Aloss = 8; - format.colorkey = 0; - format.alpha = 0; newsurf = SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);