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