src/video/sdlgenblit.pl
changeset 2262 bee005ace1bf
parent 1992 7387e0514595
child 2263 900c35d8e8fd
     1.1 --- a/src/video/sdlgenblit.pl	Fri Aug 17 03:22:03 2007 +0000
     1.2 +++ b/src/video/sdlgenblit.pl	Fri Aug 17 06:21:58 2007 +0000
     1.3 @@ -123,30 +123,7 @@
     1.4  sub output_copydefs
     1.5  {
     1.6      print FILE <<__EOF__;
     1.7 -#define SDL_RENDERCOPY_MODULATE_COLOR   0x0001
     1.8 -#define SDL_RENDERCOPY_MODULATE_ALPHA   0x0002
     1.9 -#define SDL_RENDERCOPY_MASK             0x0010
    1.10 -#define SDL_RENDERCOPY_BLEND            0x0020
    1.11 -#define SDL_RENDERCOPY_ADD              0x0040
    1.12 -#define SDL_RENDERCOPY_MOD              0x0080
    1.13 -#define SDL_RENDERCOPY_NEAREST          0x0100
    1.14 -
    1.15 -typedef struct {
    1.16 -    void *src;
    1.17 -    int src_w, src_h;
    1.18 -    int src_pitch;
    1.19 -    void *dst;
    1.20 -    int dst_w, dst_h;
    1.21 -    int dst_pitch;
    1.22 -    void *aux_data;
    1.23 -    int flags;
    1.24 -    Uint8 r, g, b, a;
    1.25 -} SDL_RenderCopyData;
    1.26 -
    1.27 -typedef int (*SDL_RenderCopyFunc)(SDL_RenderCopyData *data);
    1.28 -
    1.29 -extern SDL_RenderCopyFunc SDLCALL SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode);
    1.30 -
    1.31 +extern SDL_BlitFuncEntry *SDL_GeneratedBlitFuncTable;
    1.32  __EOF__
    1.33  }
    1.34  
    1.35 @@ -161,7 +138,7 @@
    1.36      my $args = shift;
    1.37      my $suffix = shift;
    1.38  
    1.39 -    print FILE "$prefix SDL_RenderCopy_${src}_${dst}";
    1.40 +    print FILE "$prefix SDL_Blit_${src}_${dst}";
    1.41      if ( $modulate ) {
    1.42          print FILE "_Modulate";
    1.43      }
    1.44 @@ -172,7 +149,7 @@
    1.45          print FILE "_Scale";
    1.46      }
    1.47      if ( $args ) {
    1.48 -        print FILE "(SDL_RenderCopyData *data)";
    1.49 +        print FILE "(SDL_BlitInfo *info)";
    1.50      }
    1.51      print FILE "$suffix";
    1.52  }
    1.53 @@ -225,7 +202,7 @@
    1.54  __EOF__
    1.55          return;
    1.56      }
    1.57 -        
    1.58 +
    1.59      if ( $blend ) {
    1.60          get_rgba("src", $src);
    1.61          get_rgba("dst", $dst);
    1.62 @@ -237,19 +214,19 @@
    1.63  
    1.64      if ( $modulate ) {
    1.65          print FILE <<__EOF__;
    1.66 -            if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
    1.67 +            if (flags & SDL_COPY_MODULATE_COLOR) {
    1.68                  ${s}R = (${s}R * modulateR) / 255;
    1.69                  ${s}G = (${s}G * modulateG) / 255;
    1.70                  ${s}B = (${s}B * modulateB) / 255;
    1.71              }
    1.72 -            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
    1.73 +            if (flags & SDL_COPY_MODULATE_ALPHA) {
    1.74                  ${s}A = (${s}A * modulateA) / 255;
    1.75              }
    1.76  __EOF__
    1.77      }
    1.78      if ( $blend ) {
    1.79          print FILE <<__EOF__;
    1.80 -            if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
    1.81 +            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
    1.82                  /* This goes away if we ever use premultiplied alpha */
    1.83                  if (${s}A < 255) {
    1.84                      ${s}R = (${s}R * ${s}A) / 255;
    1.85 @@ -257,25 +234,25 @@
    1.86                      ${s}B = (${s}B * ${s}A) / 255;
    1.87                  }
    1.88              }
    1.89 -            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.90 -            case SDL_RENDERCOPY_MASK:
    1.91 +            switch (flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
    1.92 +            case SDL_COPY_MASK:
    1.93                  if (${s}A) {
    1.94                      ${d}R = ${s}R;
    1.95                      ${d}G = ${s}G;
    1.96                      ${d}B = ${s}B;
    1.97                  }
    1.98                  break;
    1.99 -            case SDL_RENDERCOPY_BLEND:
   1.100 +            case SDL_COPY_BLEND:
   1.101                  ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
   1.102                  ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
   1.103                  ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
   1.104                  break;
   1.105 -            case SDL_RENDERCOPY_ADD:
   1.106 +            case SDL_COPY_ADD:
   1.107                  ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
   1.108                  ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
   1.109                  ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
   1.110                  break;
   1.111 -            case SDL_RENDERCOPY_MOD:
   1.112 +            case SDL_COPY_MOD:
   1.113                  ${d}R = (${s}R * ${d}R) / 255;
   1.114                  ${d}G = (${s}G * ${d}G) / 255;
   1.115                  ${d}B = (${s}B * ${d}B) / 255;
   1.116 @@ -298,17 +275,17 @@
   1.117      my $blend = shift;
   1.118      my $scale = shift;
   1.119  
   1.120 -    output_copyfuncname("int", $src, $dst, $modulate, $blend, $scale, 1, "\n");
   1.121 +    output_copyfuncname("void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
   1.122      print FILE <<__EOF__;
   1.123  {
   1.124 -    const int flags = data->flags;
   1.125 +    const int flags = info->flags;
   1.126  __EOF__
   1.127      if ( $modulate ) {
   1.128          print FILE <<__EOF__;
   1.129 -    const Uint32 modulateR = data->r;
   1.130 -    const Uint32 modulateG = data->g;
   1.131 -    const Uint32 modulateB = data->b;
   1.132 -    const Uint32 modulateA = data->a;
   1.133 +    const Uint32 modulateR = info->r;
   1.134 +    const Uint32 modulateG = info->g;
   1.135 +    const Uint32 modulateB = info->b;
   1.136 +    const Uint32 modulateA = info->a;
   1.137  __EOF__
   1.138      }
   1.139      if ( $blend ) {
   1.140 @@ -332,13 +309,13 @@
   1.141  
   1.142      srcy = 0;
   1.143      posy = 0;
   1.144 -    incy = (data->src_h << 16) / data->dst_h;
   1.145 -    incx = (data->src_w << 16) / data->dst_w;
   1.146 +    incy = (info->src_h << 16) / info->dst_h;
   1.147 +    incx = (info->src_w << 16) / info->dst_w;
   1.148  
   1.149 -    while (data->dst_h--) {
   1.150 +    while (info->dst_h--) {
   1.151          $format_type{$src} *src;
   1.152 -        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
   1.153 -        int n = data->dst_w;
   1.154 +        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
   1.155 +        int n = info->dst_w;
   1.156          srcx = -1;
   1.157          posx = 0x10000L;
   1.158          while (posy >= 0x10000L) {
   1.159 @@ -351,7 +328,7 @@
   1.160                      ++srcx;
   1.161                      posx -= 0x10000L;
   1.162                  }
   1.163 -                src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src}));
   1.164 +                src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
   1.165  __EOF__
   1.166          print FILE <<__EOF__;
   1.167              }
   1.168 @@ -362,16 +339,16 @@
   1.169              ++dst;
   1.170          }
   1.171          posy += incy;
   1.172 -        data->dst += data->dst_pitch;
   1.173 +        info->dst += info->dst_pitch;
   1.174      }
   1.175  __EOF__
   1.176      } else {
   1.177          print FILE <<__EOF__;
   1.178  
   1.179 -    while (data->dst_h--) {
   1.180 -        $format_type{$src} *src = ($format_type{$src} *)data->src;
   1.181 -        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
   1.182 -        int n = data->dst_w;
   1.183 +    while (info->dst_h--) {
   1.184 +        $format_type{$src} *src = ($format_type{$src} *)info->src;
   1.185 +        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
   1.186 +        int n = info->dst_w;
   1.187          while (n--) {
   1.188  __EOF__
   1.189          output_copycore($src, $dst, $modulate, $blend);
   1.190 @@ -379,13 +356,12 @@
   1.191              ++src;
   1.192              ++dst;
   1.193          }
   1.194 -        data->src += data->src_pitch;
   1.195 -        data->dst += data->dst_pitch;
   1.196 +        info->src += info->src_pitch;
   1.197 +        info->dst += info->dst_pitch;
   1.198      }
   1.199  __EOF__
   1.200      }
   1.201      print FILE <<__EOF__;
   1.202 -    return 0;
   1.203  }
   1.204  
   1.205  __EOF__
   1.206 @@ -393,24 +369,14 @@
   1.207  
   1.208  sub output_copyfunc_h
   1.209  {
   1.210 -    my $src = shift;
   1.211 -    my $dst = shift;
   1.212 -    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
   1.213 -        for (my $blend = 0; $blend <= 1; ++$blend) {
   1.214 -            for (my $scale = 0; $scale <= 1; ++$scale) {
   1.215 -                if ( $modulate || $blend || $scale ) {
   1.216 -                    output_copyfuncname("extern int SDLCALL", $src, $dst, $modulate, $blend, $scale, 1, ";\n");
   1.217 -                }
   1.218 -            }
   1.219 -        }
   1.220 -    }
   1.221  }
   1.222  
   1.223  sub output_copyinc
   1.224  {
   1.225      print FILE <<__EOF__;
   1.226  #include "SDL_video.h"
   1.227 -#include "SDL_rendercopy.h"
   1.228 +#include "SDL_blit.h"
   1.229 +#include "SDL_blit_auto.h"
   1.230  
   1.231  __EOF__
   1.232  }
   1.233 @@ -418,14 +384,7 @@
   1.234  sub output_copyfunctable
   1.235  {
   1.236      print FILE <<__EOF__;
   1.237 -static struct {
   1.238 -    Uint32 src_format;
   1.239 -    Uint32 dst_format;
   1.240 -    int modMode;
   1.241 -    int blendMode;
   1.242 -    int scaleMode;
   1.243 -    SDL_RenderCopyFunc func;
   1.244 -} SDL_RenderCopyFuncTable[] = {
   1.245 +static SDL_BlitFuncEntry _SDL_GeneratedBlitFuncTable[] = {
   1.246  __EOF__
   1.247      for (my $i = 0; $i <= $#src_formats; ++$i) {
   1.248          my $src = $src_formats[$i];
   1.249 @@ -436,21 +395,36 @@
   1.250                      for (my $scale = 0; $scale <= 1; ++$scale) {
   1.251                          if ( $modulate || $blend || $scale ) {
   1.252                              print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
   1.253 +                            my $flags = "";
   1.254 +                            my $flag = "";
   1.255                              if ( $modulate ) {
   1.256 -                                print FILE "(SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), ";
   1.257 -                            } else {
   1.258 -                                print FILE "0, ";
   1.259 +                                $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA";
   1.260 +                                if ( $flags eq "" ) {
   1.261 +                                    $flags = $flag;
   1.262 +                                } else {
   1.263 +                                    $flags = "$flags | $flag";
   1.264 +                                }
   1.265                              }
   1.266                              if ( $blend ) {
   1.267 -                                print FILE "(SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), ";
   1.268 -                            } else {
   1.269 -                                print FILE "0, ";
   1.270 +                                $flag = "SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD";
   1.271 +                                if ( $flags eq "" ) {
   1.272 +                                    $flags = $flag;
   1.273 +                                } else {
   1.274 +                                    $flags = "$flags | $flag";
   1.275 +                                }
   1.276                              }
   1.277                              if ( $scale ) {
   1.278 -                                print FILE "SDL_TEXTURESCALEMODE_FAST, ";
   1.279 -                            } else {
   1.280 -                                print FILE "0, ";
   1.281 +                                $flag = "SDL_COPY_NEAREST";
   1.282 +                                if ( $flags eq "" ) {
   1.283 +                                    $flags = $flag;
   1.284 +                                } else {
   1.285 +                                    $flags = "$flags | $flag";
   1.286 +                                }
   1.287                              }
   1.288 +                            if ( $flags eq "" ) {
   1.289 +                                $flags = "0";
   1.290 +                            }
   1.291 +                            print FILE "($flags), SDL_CPU_ANY,";
   1.292                              output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
   1.293                          }
   1.294                      }
   1.295 @@ -459,32 +433,10 @@
   1.296          }
   1.297      }
   1.298      print FILE <<__EOF__;
   1.299 +    { 0, 0, 0, 0, NULL }
   1.300  };
   1.301  
   1.302 -SDL_RenderCopyFunc SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode)
   1.303 -{
   1.304 -    int i;
   1.305 -
   1.306 -    for (i = 0; i < SDL_arraysize(SDL_RenderCopyFuncTable); ++i) {
   1.307 -        if (src_format != SDL_RenderCopyFuncTable[i].src_format) {
   1.308 -            continue;
   1.309 -        }
   1.310 -        if (dst_format != SDL_RenderCopyFuncTable[i].dst_format) {
   1.311 -            continue;
   1.312 -        }
   1.313 -        if ((modMode & SDL_RenderCopyFuncTable[i].modMode) != modMode) {
   1.314 -            continue;
   1.315 -        }
   1.316 -        if ((blendMode & SDL_RenderCopyFuncTable[i].blendMode) != blendMode) {
   1.317 -            continue;
   1.318 -        }
   1.319 -        if ((scaleMode & SDL_RenderCopyFuncTable[i].scaleMode) != scaleMode) {
   1.320 -            continue;
   1.321 -        }
   1.322 -        return SDL_RenderCopyFuncTable[i].func;
   1.323 -    }
   1.324 -    return NULL;
   1.325 -}
   1.326 +SDL_BlitFuncEntry *SDL_GeneratedBlitFuncTable = _SDL_GeneratedBlitFuncTable;
   1.327  
   1.328  __EOF__
   1.329  }
   1.330 @@ -505,7 +457,7 @@
   1.331      }
   1.332  }
   1.333  
   1.334 -open_file("SDL_rendercopy.h");
   1.335 +open_file("SDL_blit_auto.h");
   1.336  output_copydefs();
   1.337  for (my $i = 0; $i <= $#src_formats; ++$i) {
   1.338      for (my $j = 0; $j <= $#dst_formats; ++$j) {
   1.339 @@ -513,9 +465,9 @@
   1.340      }
   1.341  }
   1.342  print FILE "\n";
   1.343 -close_file("SDL_rendercopy.h");
   1.344 +close_file("SDL_blit_auto.h");
   1.345  
   1.346 -open_file("SDL_rendercopy.c");
   1.347 +open_file("SDL_blit_auto.c");
   1.348  output_copyinc();
   1.349  output_copyfunctable();
   1.350  for (my $i = 0; $i <= $#src_formats; ++$i) {
   1.351 @@ -523,4 +475,4 @@
   1.352          output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
   1.353      }
   1.354  }
   1.355 -close_file("SDL_rendercopy.c");
   1.356 +close_file("SDL_blit_auto.c");