src/video/SDL_blit_N.c
changeset 7373 5e6efd29b461
parent 7372 f90f720b9e56
child 8093 b43765095a6f
     1.1 --- a/src/video/SDL_blit_N.c	Sun Jul 07 10:31:01 2013 -0700
     1.2 +++ b/src/video/SDL_blit_N.c	Sun Jul 07 12:34:21 2013 -0700
     1.3 @@ -2363,6 +2363,70 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +/* Special optimized blit for ARGB 2-10-10-10 --> RGBA */
     1.8 +static void
     1.9 +Blit2101010toN(SDL_BlitInfo * info)
    1.10 +{
    1.11 +    int width = info->dst_w;
    1.12 +    int height = info->dst_h;
    1.13 +    Uint8 *src = info->src;
    1.14 +    int srcskip = info->src_skip;
    1.15 +    Uint8 *dst = info->dst;
    1.16 +    int dstskip = info->dst_skip;
    1.17 +    SDL_PixelFormat *dstfmt = info->dst_fmt;
    1.18 +    int dstbpp = dstfmt->BytesPerPixel;
    1.19 +    Uint32 Pixel;
    1.20 +    unsigned sR, sG, sB, sA;
    1.21 +
    1.22 +    while (height--) {
    1.23 +        /* *INDENT-OFF* */
    1.24 +        DUFFS_LOOP(
    1.25 +        {
    1.26 +            Pixel = *(Uint32 *)src;
    1.27 +            RGBA_FROM_ARGB2101010(Pixel, sR, sG, sB, sA);
    1.28 +            ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
    1.29 +            dst += dstbpp;
    1.30 +            src += 4;
    1.31 +        },
    1.32 +        width);
    1.33 +        /* *INDENT-ON* */
    1.34 +        src += srcskip;
    1.35 +        dst += dstskip;
    1.36 +    }
    1.37 +}
    1.38 +
    1.39 +/* Special optimized blit for RGBA --> ARGB 2-10-10-10 */
    1.40 +static void
    1.41 +BlitNto2101010(SDL_BlitInfo * info)
    1.42 +{
    1.43 +    int width = info->dst_w;
    1.44 +    int height = info->dst_h;
    1.45 +    Uint8 *src = info->src;
    1.46 +    int srcskip = info->src_skip;
    1.47 +    Uint8 *dst = info->dst;
    1.48 +    int dstskip = info->dst_skip;
    1.49 +    SDL_PixelFormat *srcfmt = info->src_fmt;
    1.50 +    int srcbpp = srcfmt->BytesPerPixel;
    1.51 +    Uint32 Pixel;
    1.52 +    unsigned sR, sG, sB, sA;
    1.53 +
    1.54 +    while (height--) {
    1.55 +        /* *INDENT-OFF* */
    1.56 +        DUFFS_LOOP(
    1.57 +        {
    1.58 +            DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
    1.59 +            ARGB2101010_FROM_RGBA(Pixel, sR, sG, sB, sA);
    1.60 +            *(Uint32 *)dst = Pixel;
    1.61 +            dst += 4;
    1.62 +            src += srcbpp;
    1.63 +        },
    1.64 +        width);
    1.65 +        /* *INDENT-ON* */
    1.66 +        src += srcskip;
    1.67 +        dst += dstskip;
    1.68 +    }
    1.69 +}
    1.70 +
    1.71  /* Normal N to N optimized blitters */
    1.72  struct blit_table
    1.73  {
    1.74 @@ -2382,24 +2446,18 @@
    1.75  static const struct blit_table normal_blit_2[] = {
    1.76  #if SDL_ALTIVEC_BLITTERS
    1.77      /* has-altivec */
    1.78 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000,
    1.79 -     0x00000000,
    1.80 +    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
    1.81       2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.82 -    {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000,
    1.83 -     0x00000000,
    1.84 +    {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
    1.85       2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.86  #endif
    1.87 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00,
    1.88 -     0x000000FF,
    1.89 +    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
    1.90       0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.91 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00,
    1.92 -     0x00FF0000,
    1.93 +    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
    1.94       0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.95 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000,
    1.96 -     0x0000FF00,
    1.97 +    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, 0x0000FF00,
    1.98       0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
    1.99 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000,
   1.100 -     0xFF000000,
   1.101 +    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, 0xFF000000,
   1.102       0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.103  
   1.104      /* Default for 16-bit RGB source, used if no other blitter matches */
   1.105 @@ -2414,25 +2472,18 @@
   1.106  static const struct blit_table normal_blit_4[] = {
   1.107  #if SDL_ALTIVEC_BLITTERS
   1.108      /* has-altivec | dont-use-prefetch */
   1.109 -    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   1.110 -     0x00000000,
   1.111 -     6, ConvertAltivec32to32_noprefetch,
   1.112 -     NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.113 +    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
   1.114 +     6, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.115      /* has-altivec */
   1.116 -    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   1.117 -     0x00000000,
   1.118 -     2, ConvertAltivec32to32_prefetch,
   1.119 -     NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.120 +    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
   1.121 +     2, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.122      /* has-altivec */
   1.123 -    {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0,
   1.124 -     0x0000001F,
   1.125 +    {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
   1.126       2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
   1.127  #endif
   1.128 -    {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0,
   1.129 -     0x0000001F,
   1.130 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
   1.131       0, Blit_RGB888_RGB565, NO_ALPHA},
   1.132 -    {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0,
   1.133 -     0x0000001F,
   1.134 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
   1.135       0, Blit_RGB888_RGB555, NO_ALPHA},
   1.136      /* Default for 32-bit RGB source, used if no other blitter matches */
   1.137      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   1.138 @@ -2502,11 +2553,16 @@
   1.139              blitfun = table[which].blitfunc;
   1.140  
   1.141              if (blitfun == BlitNtoN) {  /* default C fallback catch-all. Slow! */
   1.142 -                /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
   1.143 -                if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4
   1.144 -                    && srcfmt->Rmask == dstfmt->Rmask
   1.145 -                    && srcfmt->Gmask == dstfmt->Gmask
   1.146 -                    && srcfmt->Bmask == dstfmt->Bmask) {
   1.147 +                if (srcfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
   1.148 +                    blitfun = Blit2101010toN;
   1.149 +                } else if (dstfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
   1.150 +                    blitfun = BlitNto2101010;
   1.151 +                } else if (srcfmt->BytesPerPixel == 4 &&
   1.152 +                            dstfmt->BytesPerPixel == 4 &&
   1.153 +                            srcfmt->Rmask == dstfmt->Rmask &&
   1.154 +                            srcfmt->Gmask == dstfmt->Gmask &&
   1.155 +                            srcfmt->Bmask == dstfmt->Bmask) {
   1.156 +                    /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
   1.157                      blitfun = Blit4to4MaskAlpha;
   1.158                  } else if (a_need == COPY_ALPHA) {
   1.159                      blitfun = BlitNtoNCopyAlpha;