Mercurial > sdl-ios-xcode
annotate src/video/SDL_blit.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | b81f54c3963f |
children | 450721ad5436 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 | |
27 #include "SDL_error.h" | |
28 #include "SDL_video.h" | |
29 #include "SDL_sysvideo.h" | |
30 #include "SDL_blit.h" | |
31 #include "SDL_RLEaccel_c.h" | |
32 #include "SDL_pixels_c.h" | |
33 #include "SDL_memops.h" | |
34 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
35 #if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT) |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
36 #define MMX_ASMBLIT |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
37 #endif |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
38 |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
39 #if defined(MMX_ASMBLIT) |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
40 #include "SDL_cpuinfo.h" |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
41 #include "mmx.h" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
42 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
43 |
0 | 44 /* The general purpose software blit routine */ |
45 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
46 SDL_Surface *dst, SDL_Rect *dstrect) | |
47 { | |
48 int okay; | |
49 int src_locked; | |
50 int dst_locked; | |
51 | |
52 /* Everything is okay at the beginning... */ | |
53 okay = 1; | |
54 | |
55 /* Lock the destination if it's in hardware */ | |
56 dst_locked = 0; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
57 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
58 if ( SDL_LockSurface(dst) < 0 ) { |
0 | 59 okay = 0; |
60 } else { | |
61 dst_locked = 1; | |
62 } | |
63 } | |
64 /* Lock the source if it's in hardware */ | |
65 src_locked = 0; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
66 if ( SDL_MUSTLOCK(src) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
67 if ( SDL_LockSurface(src) < 0 ) { |
0 | 68 okay = 0; |
69 } else { | |
70 src_locked = 1; | |
71 } | |
72 } | |
73 | |
74 /* Set up source and destination buffer pointers, and BLIT! */ | |
75 if ( okay && srcrect->w && srcrect->h ) { | |
76 SDL_BlitInfo info; | |
77 SDL_loblit RunBlit; | |
78 | |
79 /* Set up the blit information */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
80 info.s_pixels = (Uint8 *)src->pixels + |
0 | 81 (Uint16)srcrect->y*src->pitch + |
82 (Uint16)srcrect->x*src->format->BytesPerPixel; | |
83 info.s_width = srcrect->w; | |
84 info.s_height = srcrect->h; | |
85 info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
86 info.d_pixels = (Uint8 *)dst->pixels + |
0 | 87 (Uint16)dstrect->y*dst->pitch + |
88 (Uint16)dstrect->x*dst->format->BytesPerPixel; | |
89 info.d_width = dstrect->w; | |
90 info.d_height = dstrect->h; | |
91 info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel; | |
92 info.aux_data = src->map->sw_data->aux_data; | |
93 info.src = src->format; | |
94 info.table = src->map->table; | |
95 info.dst = dst->format; | |
96 RunBlit = src->map->sw_data->blit; | |
97 | |
98 /* Run the actual software blit */ | |
99 RunBlit(&info); | |
100 } | |
101 | |
102 /* We need to unlock the surfaces if they're locked */ | |
103 if ( dst_locked ) { | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
104 SDL_UnlockSurface(dst); |
310
c97c1d3b3b5c
Blit bug fix from John Popplewell
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
105 } |
0 | 106 if ( src_locked ) { |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
107 SDL_UnlockSurface(src); |
0 | 108 } |
109 /* Blit is done! */ | |
110 return(okay ? 0 : -1); | |
111 } | |
112 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
113 #ifdef MMX_ASMBLIT |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1052
diff
changeset
|
114 static __inline__ void SDL_memcpyMMX(Uint8 *to, const Uint8 *from, int len) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
115 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
116 int i; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
117 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
118 for(i=0; i<len/8; i++) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
119 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
120 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
121 " movq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
122 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
123 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
124 to+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
125 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
126 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
127 SDL_memcpy(to, from, len&7); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
128 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
129 |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1052
diff
changeset
|
130 static __inline__ void SDL_memcpySSE(Uint8 *to, const Uint8 *from, int len) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
131 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
132 int i; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
133 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
134 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
135 " prefetchnta (%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
136 " prefetchnta 64(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
137 " prefetchnta 128(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
138 " prefetchnta 192(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
139 : : "r" (from) ); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
140 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
141 for(i=0; i<len/8; i++) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
142 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
143 " prefetchnta 256(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
144 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
145 " movntq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
146 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
147 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
148 to+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
149 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
150 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
151 SDL_memcpy(to, from, len&7); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
152 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
153 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
154 |
0 | 155 static void SDL_BlitCopy(SDL_BlitInfo *info) |
156 { | |
157 Uint8 *src, *dst; | |
158 int w, h; | |
159 int srcskip, dstskip; | |
160 | |
161 w = info->d_width*info->dst->BytesPerPixel; | |
162 h = info->d_height; | |
163 src = info->s_pixels; | |
164 dst = info->d_pixels; | |
165 srcskip = w+info->s_skip; | |
166 dstskip = w+info->d_skip; | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
167 #ifdef MMX_ASMBLIT |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
168 if(SDL_HasSSE()) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
169 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
170 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
171 SDL_memcpySSE(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
172 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
173 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
174 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
175 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
176 " emms\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
177 ::); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
178 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
179 else |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
180 if(SDL_HasMMX()) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
181 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
182 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
183 SDL_memcpyMMX(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
184 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
185 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
186 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
187 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
188 " emms\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
189 ::); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
190 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
191 else |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
192 #endif |
0 | 193 while ( h-- ) { |
194 SDL_memcpy(dst, src, w); | |
195 src += srcskip; | |
196 dst += dstskip; | |
197 } | |
198 } | |
199 | |
200 static void SDL_BlitCopyOverlap(SDL_BlitInfo *info) | |
201 { | |
202 Uint8 *src, *dst; | |
203 int w, h; | |
204 int srcskip, dstskip; | |
205 | |
206 w = info->d_width*info->dst->BytesPerPixel; | |
207 h = info->d_height; | |
208 src = info->s_pixels; | |
209 dst = info->d_pixels; | |
210 srcskip = w+info->s_skip; | |
211 dstskip = w+info->d_skip; | |
212 if ( dst < src ) { | |
213 while ( h-- ) { | |
214 SDL_memcpy(dst, src, w); | |
215 src += srcskip; | |
216 dst += dstskip; | |
217 } | |
218 } else { | |
219 src += ((h-1) * srcskip); | |
220 dst += ((h-1) * dstskip); | |
221 while ( h-- ) { | |
222 SDL_revcpy(dst, src, w); | |
223 src -= srcskip; | |
224 dst -= dstskip; | |
225 } | |
226 } | |
227 } | |
228 | |
229 /* Figure out which of many blit routines to set up on a surface */ | |
230 int SDL_CalculateBlit(SDL_Surface *surface) | |
231 { | |
232 int blit_index; | |
233 | |
234 /* Clean everything out to start */ | |
235 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { | |
236 SDL_UnRLESurface(surface, 1); | |
237 } | |
238 surface->map->sw_blit = NULL; | |
239 | |
240 /* Figure out if an accelerated hardware blit is possible */ | |
241 surface->flags &= ~SDL_HWACCEL; | |
242 if ( surface->map->identity ) { | |
243 int hw_blit_ok; | |
244 | |
245 if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { | |
246 /* We only support accelerated blitting to hardware */ | |
247 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
248 hw_blit_ok = current_video->info.blit_hw; | |
249 } else { | |
250 hw_blit_ok = 0; | |
251 } | |
252 if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { | |
253 hw_blit_ok = current_video->info.blit_hw_CC; | |
254 } | |
255 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
256 hw_blit_ok = current_video->info.blit_hw_A; | |
257 } | |
258 } else { | |
259 /* We only support accelerated blitting to hardware */ | |
260 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
261 hw_blit_ok = current_video->info.blit_sw; | |
262 } else { | |
263 hw_blit_ok = 0; | |
264 } | |
265 if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { | |
266 hw_blit_ok = current_video->info.blit_sw_CC; | |
267 } | |
268 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
269 hw_blit_ok = current_video->info.blit_sw_A; | |
270 } | |
271 } | |
272 if ( hw_blit_ok ) { | |
273 SDL_VideoDevice *video = current_video; | |
274 SDL_VideoDevice *this = current_video; | |
275 video->CheckHWBlit(this, surface, surface->map->dst); | |
276 } | |
277 } | |
1052
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
278 |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
279 /* if an alpha pixel format is specified, we can accelerate alpha blits */ |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
280 if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )&&(current_video->displayformatalphapixel)) |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
281 { |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
282 if ( (surface->flags & SDL_SRCALPHA) ) |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
283 if ( current_video->info.blit_hw_A ) { |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
284 SDL_VideoDevice *video = current_video; |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
285 SDL_VideoDevice *this = current_video; |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
286 video->CheckHWBlit(this, surface, surface->map->dst); |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
287 } |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
288 } |
0 | 289 |
290 /* Get the blit function index, based on surface mode */ | |
291 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ | |
292 blit_index = 0; | |
293 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; | |
294 if ( surface->flags & SDL_SRCALPHA | |
295 && (surface->format->alpha != SDL_ALPHA_OPAQUE | |
296 || surface->format->Amask) ) { | |
297 blit_index |= 2; | |
298 } | |
299 | |
300 /* Check for special "identity" case -- copy blit */ | |
301 if ( surface->map->identity && blit_index == 0 ) { | |
302 surface->map->sw_data->blit = SDL_BlitCopy; | |
303 | |
304 /* Handle overlapping blits on the same surface */ | |
305 if ( surface == surface->map->dst ) { | |
306 surface->map->sw_data->blit = SDL_BlitCopyOverlap; | |
307 } | |
308 } else { | |
309 if ( surface->format->BitsPerPixel < 8 ) { | |
310 surface->map->sw_data->blit = | |
311 SDL_CalculateBlit0(surface, blit_index); | |
312 } else { | |
313 switch ( surface->format->BytesPerPixel ) { | |
314 case 1: | |
315 surface->map->sw_data->blit = | |
316 SDL_CalculateBlit1(surface, blit_index); | |
317 break; | |
318 case 2: | |
319 case 3: | |
320 case 4: | |
321 surface->map->sw_data->blit = | |
322 SDL_CalculateBlitN(surface, blit_index); | |
323 break; | |
324 default: | |
325 surface->map->sw_data->blit = NULL; | |
326 break; | |
327 } | |
328 } | |
329 } | |
330 /* Make sure we have a blit function */ | |
331 if ( surface->map->sw_data->blit == NULL ) { | |
332 SDL_InvalidateMap(surface->map); | |
333 SDL_SetError("Blit combination not supported"); | |
334 return(-1); | |
335 } | |
336 | |
337 /* Choose software blitting function */ | |
338 if(surface->flags & SDL_RLEACCELOK | |
339 && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { | |
340 | |
341 if(surface->map->identity | |
342 && (blit_index == 1 | |
343 || (blit_index == 3 && !surface->format->Amask))) { | |
344 if ( SDL_RLESurface(surface) == 0 ) | |
345 surface->map->sw_blit = SDL_RLEBlit; | |
346 } else if(blit_index == 2 && surface->format->Amask) { | |
347 if ( SDL_RLESurface(surface) == 0 ) | |
348 surface->map->sw_blit = SDL_RLEAlphaBlit; | |
349 } | |
350 } | |
351 | |
352 if ( surface->map->sw_blit == NULL ) { | |
353 surface->map->sw_blit = SDL_SoftBlit; | |
354 } | |
355 return(0); | |
356 } | |
357 |