From Bug #36:
authorRyan C. Gordon <icculus@icculus.org>
Sun, 08 Jan 2006 21:18:15 +0000
changeset 12403b8a43c428bb
parent 1239 cbdb2c156aca
child 1241 4b2146866b82
From Bug #36:

There are a couple of issues with the selection of Altivec alpha-blitting
routines in CalculateAlphaBlit() in src/video/SDL_Blit_A.c.

1) There's no check for the presence of Altivec when checking if the
Blit32to565PixelAlphaAltivec() routine can be selected.

2) Altivec cannot be used in video memory, and there's no check if the
destination surface is a hardware surface. (Alpha-blitting to a hardware
surface with GPU support is a bad idea, but somebody's bound to do it anyway.)

Patch to fix these attached.
src/video/SDL_blit_A.c
     1.1 --- a/src/video/SDL_blit_A.c	Sun Jan 08 17:29:19 2006 +0000
     1.2 +++ b/src/video/SDL_blit_A.c	Sun Jan 08 21:18:15 2006 +0000
     1.3 @@ -2145,7 +2145,8 @@
     1.4  		return BlitNto1SurfaceAlphaKey;
     1.5  	    else
     1.6  #ifdef USE_ALTIVEC_BLITTERS
     1.7 -        if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && SDL_HasAltiVec())
     1.8 +	if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 &&
     1.9 +	    !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
    1.10              return Blit32to32SurfaceAlphaKeyAltivec;
    1.11          else
    1.12  #endif
    1.13 @@ -2192,7 +2193,7 @@
    1.14  		else
    1.15  #endif
    1.16  #ifdef USE_ALTIVEC_BLITTERS
    1.17 -        if(SDL_HasAltiVec())
    1.18 +	if(!(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
    1.19              return BlitRGBtoRGBSurfaceAlphaAltivec;
    1.20          else
    1.21  #endif
    1.22 @@ -2200,7 +2201,8 @@
    1.23  		}
    1.24  		else
    1.25  #ifdef USE_ALTIVEC_BLITTERS
    1.26 -        if((sf->BytesPerPixel == 4) && SDL_HasAltiVec())
    1.27 +        if((sf->BytesPerPixel == 4) &&
    1.28 +	   !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
    1.29              return Blit32to32SurfaceAlphaAltivec;
    1.30          else
    1.31  #endif
    1.32 @@ -2219,9 +2221,9 @@
    1.33  
    1.34  	case 2:
    1.35  #ifdef USE_ALTIVEC_BLITTERS
    1.36 -        if(sf->BytesPerPixel == 4 && 
    1.37 +	if(sf->BytesPerPixel == 4 && !(surface->map->dst->flags & SDL_HWSURFACE) &&
    1.38             df->Gmask == 0x7e0 &&
    1.39 -           df->Bmask == 0x1f)
    1.40 +	   df->Bmask == 0x1f && SDL_HasAltiVec())
    1.41              return Blit32to565PixelAlphaAltivec;
    1.42          else
    1.43  #endif
    1.44 @@ -2252,14 +2254,15 @@
    1.45  		else
    1.46  #endif
    1.47  #ifdef USE_ALTIVEC_BLITTERS
    1.48 -        if(SDL_HasAltiVec())
    1.49 +	if(!(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
    1.50              return BlitRGBtoRGBPixelAlphaAltivec;
    1.51          else
    1.52  #endif
    1.53  		    return BlitRGBtoRGBPixelAlpha;
    1.54  	    }
    1.55  #ifdef USE_ALTIVEC_BLITTERS
    1.56 -        if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec())
    1.57 +        if (sf->Amask && sf->BytesPerPixel == 4 &&
    1.58 +	    !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
    1.59              return Blit32to32PixelAlphaAltivec;
    1.60          else
    1.61  #endif