blit-auto optimizations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
diff --git a/src/video/sdlgenblit.pl b/src/video/sdlgenblit.pl
index bb70ceb..c2a22b0 100755
--- a/src/video/sdlgenblit.pl
+++ b/src/video/sdlgenblit.pl
@@ -220,16 +220,82 @@ sub output_copycore
my $A_is_const_FF = shift;
my $s = "";
my $d = "";
+ my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
+ my $src_has_alpha = ($src =~ /A/) ? 1 : 0;
+ my $sa = "";
+ my $da = "";
- # Nice and easy...
- if ( $src eq $dst && !$modulate && !$blend ) {
- print FILE <<__EOF__;
+ if (!$modulate && !$blend) {
+ # Nice and easy...
+ if ( $src eq $dst ) {
+ print FILE <<__EOF__;
*dst = *src;
__EOF__
- return;
+ return;
+ }
+
+ # Matching color-order
+ $sa = $src;
+ $sa =~ s/[A8]//g;
+ $da = $dst;
+ $da =~ s/[A8]//g;
+ if ($sa eq $da) {
+ if ($dst_has_alpha && $src_has_alpha) {
+ $da = substr $dst, 0, 1;
+ if ($da eq "A") {
+ # RGBA -> ARGB
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel = (pixel >> 8) | (pixel << 24);
+ *dst = pixel;
+__EOF__
+ } else {
+ # ARGB -> RGBA -- unused
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel = (pixel << 8) | A;
+ *dst = pixel;
+__EOF__
+ }
+ } elsif ($dst_has_alpha) {
+ $da = substr $dst, 0, 1;
+ if ($da eq "A") {
+ # RGB -> ARGB
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel |= (A << 24);
+ *dst = pixel;
+__EOF__
+ } else {
+ # RGB -> RGBA -- unused
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel = (pixel << 8) | A;
+ *dst = pixel;
+__EOF__
+ }
+ } else {
+ $sa = substr $src, 0, 1;
+ if ($sa eq "A") {
+ # ARGB -> RGB
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel &= 0xFFFFFF;
+ *dst = pixel;
+__EOF__
+ } else {
+ # RGBA -> RGB
+ print FILE <<__EOF__;
+ pixel = *src;
+ pixel >>= 8;
+ *dst = pixel;
+__EOF__
+ }
+ }
+ return;
+ }
}
- my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
if ( $blend ) {
@@ -366,6 +432,14 @@ sub output_copyfunc
my $is_modulateA_done = 0;
my $A_is_const_FF = 0;
+ my $sa = $src;
+ my $da = $dst;
+ my $matching_colors = 0;
+
+ $sa =~ s/[A8]//g;
+ $da =~ s/[A8]//g;
+ $matching_colors = (!$modulate && !$blend && ($sa eq $da)) ? 1 : 0;
+
output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
print FILE <<__EOF__;
{
@@ -424,8 +498,8 @@ __EOF__
print FILE <<__EOF__;
Uint32 pixel;
__EOF__
- if (!$ignore_dst_alpha && !$src_has_alpha) {
- if ($modulate){
+ if ( !$ignore_dst_alpha && !$src_has_alpha ) {
+ if ( $modulate ) {
$is_modulateA_done = 1;
print FILE <<__EOF__;
const Uint32 A = (flags & SDL_COPY_MODULATE_ALPHA) ? modulateA : 0xFF;
@@ -436,14 +510,18 @@ __EOF__
const Uint32 A = 0xFF;
__EOF__
}
- print FILE <<__EOF__;
+ if ( !$matching_colors ) {
+ print FILE <<__EOF__;
Uint32 R, G, B;
__EOF__
- } elsif (!$ignore_dst_alpha) {
- print FILE <<__EOF__;
+ }
+ } elsif ( !$ignore_dst_alpha ) {
+ if ( !$matching_colors ) {
+ print FILE <<__EOF__;
Uint32 R, G, B, A;
__EOF__
- } else {
+ }
+ } elsif ( !$matching_colors ) {
print FILE <<__EOF__;
Uint32 R, G, B;
__EOF__