SDL2: SDL_BLENDMODE_NONE blits

Hello.

I can’t understand the logic behind blit function selection when blend mode
is set to SDL_BLENDMODE_NONE and the surfaces are both 32 bit.

The relevant code is (in SDL_CalculateBlitN()) :

        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;
}
}

blitfun is always BlitNtoN for 32bpp-source blits on Intel and everything
else that lacks Altivec extenstions - see const struct blit_table
normal_blit_4[] just above the SDL_CalculateBlitN()

So, what this code does is to select masking blitter (that is, one that
discards the alpha value) if component masks match, disregarding the
a_need value at all.

The code makes much more sense this way:

        if (blitfun == BlitNtoN) {  /* default C fallback catch-all.

Slow! /
if (a_need == COPY_ALPHA)
blitfun = BlitNtoNCopyAlpha;
/
Fastpath C fallback: 32bit RGB<->RGBA blit with matching
RGB */
else if (srcfmt->BytesPerPixel == 4 &&
dstfmt->BytesPerPixel == 4
&& srcfmt->Rmask == dstfmt->Rmask
&& srcfmt->Gmask == dstfmt->Gmask
&& srcfmt->Bmask == dstfmt->Bmask)
blitfun = Blit4to4MaskAlpha;
}