Use fast path for RGB 565 -> 32-bit XRGB 8888
authorSam Lantinga <slouken@libsdl.org>
Sun, 02 Sep 2012 16:03:56 -0700
changeset 6410f6c0a9462662
parent 6409 b85e863a507e
child 6412 628702b5d490
Use fast path for RGB 565 -> 32-bit XRGB 8888

Hello Sam,
while profiling ScummVM I noticed it was making use of the generic
BlitNToN blitter, which struck me as odd because it should be a very
classical codepath.
After investigating, I saw that in the blit op chooser:

{ 0x0000F800,0x000007E0,0x0000001F, 4, 0x00FF0000,0x0000FF00,0x000000FF,
0, NULL, Blit_RGB565_ARGB8888, SET_ALPHA },
{ 0x0000F800,0x000007E0,0x0000001F, 4, 0x000000FF,0x0000FF00,0x00FF0000,
0, NULL, Blit_RGB565_ABGR8888, SET_ALPHA },
{ 0x0000F800,0x000007E0,0x0000001F, 4, 0xFF000000,0x00FF0000,0x0000FF00,
0, NULL, Blit_RGB565_RGBA8888, SET_ALPHA },
{ 0x0000F800,0x000007E0,0x0000001F, 4, 0x0000FF00,0x00FF0000,0xFF000000,
0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA },

Couldn't the optimized versions be used for NO_ALPHA too? I take it
that the resulting alpha component can be undefined as it should never
be used.
I tried this (see attached patch) and it worked perfectly (and
therefore faster) on ScummVM but there might be a trick (I'm not
expert at the semantics of SDL, ie NO_ALPHA, SET_ALPHA and COPY_ALPHA
there).
What do you think?

Cheers,
Bertrand
src/video/SDL_blit_N.c
     1.1 --- a/src/video/SDL_blit_N.c	Thu Aug 30 12:58:58 2012 -0700
     1.2 +++ b/src/video/SDL_blit_N.c	Sun Sep 02 16:03:56 2012 -0700
     1.3 @@ -2360,16 +2360,16 @@
     1.4  #endif
     1.5      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00,
     1.6       0x000000FF,
     1.7 -     0, Blit_RGB565_ARGB8888, SET_ALPHA},
     1.8 +     0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
     1.9      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00,
    1.10       0x00FF0000,
    1.11 -     0, Blit_RGB565_ABGR8888, SET_ALPHA},
    1.12 +     0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.13      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000,
    1.14       0x0000FF00,
    1.15 -     0, Blit_RGB565_RGBA8888, SET_ALPHA},
    1.16 +     0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.17      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000,
    1.18       0xFF000000,
    1.19 -     0, Blit_RGB565_BGRA8888, SET_ALPHA},
    1.20 +     0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.21  
    1.22      /* Default for 16-bit RGB source, used if no other blitter matches */
    1.23      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}