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