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