Mercurial > sdl-ios-xcode
comparison src/video/SDL_blit.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children | eef792d31de8 |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
36 #include "mmx.h" | 36 #include "mmx.h" |
37 #endif | 37 #endif |
38 | 38 |
39 /* The general purpose software blit routine */ | 39 /* The general purpose software blit routine */ |
40 static int | 40 static int |
41 SDL_SoftBlit (SDL_Surface * src, SDL_Rect * srcrect, | 41 SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect, |
42 SDL_Surface * dst, SDL_Rect * dstrect) | 42 SDL_Surface * dst, SDL_Rect * dstrect) |
43 { | 43 { |
44 int okay; | 44 int okay; |
45 int src_locked; | 45 int src_locked; |
46 int dst_locked; | 46 int dst_locked; |
47 | 47 |
48 /* Everything is okay at the beginning... */ | 48 /* Everything is okay at the beginning... */ |
49 okay = 1; | 49 okay = 1; |
50 | 50 |
51 /* Lock the destination if it's in hardware */ | 51 /* Lock the destination if it's in hardware */ |
52 dst_locked = 0; | 52 dst_locked = 0; |
53 if (SDL_MUSTLOCK (dst)) { | 53 if (SDL_MUSTLOCK(dst)) { |
54 if (SDL_LockSurface (dst) < 0) { | 54 if (SDL_LockSurface(dst) < 0) { |
55 okay = 0; | 55 okay = 0; |
56 } else { | 56 } else { |
57 dst_locked = 1; | 57 dst_locked = 1; |
58 } | 58 } |
59 } | 59 } |
60 /* Lock the source if it's in hardware */ | 60 /* Lock the source if it's in hardware */ |
61 src_locked = 0; | 61 src_locked = 0; |
62 if (SDL_MUSTLOCK (src)) { | 62 if (SDL_MUSTLOCK(src)) { |
63 if (SDL_LockSurface (src) < 0) { | 63 if (SDL_LockSurface(src) < 0) { |
64 okay = 0; | 64 okay = 0; |
65 } else { | 65 } else { |
66 src_locked = 1; | 66 src_locked = 1; |
67 } | 67 } |
68 } | 68 } |
90 info.table = src->map->table; | 90 info.table = src->map->table; |
91 info.dst = dst->format; | 91 info.dst = dst->format; |
92 RunBlit = src->map->sw_data->blit; | 92 RunBlit = src->map->sw_data->blit; |
93 | 93 |
94 /* Run the actual software blit */ | 94 /* Run the actual software blit */ |
95 RunBlit (&info); | 95 RunBlit(&info); |
96 } | 96 } |
97 | 97 |
98 /* We need to unlock the surfaces if they're locked */ | 98 /* We need to unlock the surfaces if they're locked */ |
99 if (dst_locked) { | 99 if (dst_locked) { |
100 SDL_UnlockSurface (dst); | 100 SDL_UnlockSurface(dst); |
101 } | 101 } |
102 if (src_locked) { | 102 if (src_locked) { |
103 SDL_UnlockSurface (src); | 103 SDL_UnlockSurface(src); |
104 } | 104 } |
105 /* Blit is done! */ | 105 /* Blit is done! */ |
106 return (okay ? 0 : -1); | 106 return (okay ? 0 : -1); |
107 } | 107 } |
108 | 108 |
109 #ifdef MMX_ASMBLIT | 109 #ifdef MMX_ASMBLIT |
110 static __inline__ void | 110 static __inline__ void |
111 SDL_memcpyMMX (Uint8 * to, const Uint8 * from, int len) | 111 SDL_memcpyMMX(Uint8 * to, const Uint8 * from, int len) |
112 { | 112 { |
113 int i; | 113 int i; |
114 | 114 |
115 for (i = 0; i < len / 8; i++) { | 115 for (i = 0; i < len / 8; i++) { |
116 __asm__ __volatile__ (" movq (%0), %%mm0\n" | 116 __asm__ __volatile__(" movq (%0), %%mm0\n" |
117 " movq %%mm0, (%1)\n"::"r" (from), | 117 " movq %%mm0, (%1)\n"::"r"(from), |
118 "r" (to):"memory"); | 118 "r"(to):"memory"); |
119 from += 8; | 119 from += 8; |
120 to += 8; | 120 to += 8; |
121 } | 121 } |
122 if (len & 7) | 122 if (len & 7) |
123 SDL_memcpy (to, from, len & 7); | 123 SDL_memcpy(to, from, len & 7); |
124 } | 124 } |
125 | 125 |
126 static __inline__ void | 126 static __inline__ void |
127 SDL_memcpySSE (Uint8 * to, const Uint8 * from, int len) | 127 SDL_memcpySSE(Uint8 * to, const Uint8 * from, int len) |
128 { | 128 { |
129 int i; | 129 int i; |
130 | 130 |
131 __asm__ __volatile__ (" prefetchnta (%0)\n" | 131 __asm__ __volatile__(" prefetchnta (%0)\n" |
132 " prefetchnta 64(%0)\n" | 132 " prefetchnta 64(%0)\n" |
133 " prefetchnta 128(%0)\n" | 133 " prefetchnta 128(%0)\n" |
134 " prefetchnta 192(%0)\n"::"r" (from)); | 134 " prefetchnta 192(%0)\n"::"r"(from)); |
135 | 135 |
136 for (i = 0; i < len / 8; i++) { | 136 for (i = 0; i < len / 8; i++) { |
137 __asm__ __volatile__ (" prefetchnta 256(%0)\n" | 137 __asm__ __volatile__(" prefetchnta 256(%0)\n" |
138 " movq (%0), %%mm0\n" | 138 " movq (%0), %%mm0\n" |
139 " movntq %%mm0, (%1)\n"::"r" (from), | 139 " movntq %%mm0, (%1)\n"::"r"(from), |
140 "r" (to):"memory"); | 140 "r"(to):"memory"); |
141 from += 8; | 141 from += 8; |
142 to += 8; | 142 to += 8; |
143 } | 143 } |
144 if (len & 7) | 144 if (len & 7) |
145 SDL_memcpy (to, from, len & 7); | 145 SDL_memcpy(to, from, len & 7); |
146 } | 146 } |
147 #endif | 147 #endif |
148 | 148 |
149 static void | 149 static void |
150 SDL_BlitCopy (SDL_BlitInfo * info) | 150 SDL_BlitCopy(SDL_BlitInfo * info) |
151 { | 151 { |
152 Uint8 *src, *dst; | 152 Uint8 *src, *dst; |
153 int w, h; | 153 int w, h; |
154 int srcskip, dstskip; | 154 int srcskip, dstskip; |
155 | 155 |
158 src = info->s_pixels; | 158 src = info->s_pixels; |
159 dst = info->d_pixels; | 159 dst = info->d_pixels; |
160 srcskip = w + info->s_skip; | 160 srcskip = w + info->s_skip; |
161 dstskip = w + info->d_skip; | 161 dstskip = w + info->d_skip; |
162 #ifdef MMX_ASMBLIT | 162 #ifdef MMX_ASMBLIT |
163 if (SDL_HasSSE ()) { | 163 if (SDL_HasSSE()) { |
164 while (h--) { | 164 while (h--) { |
165 SDL_memcpySSE (dst, src, w); | 165 SDL_memcpySSE(dst, src, w); |
166 src += srcskip; | 166 src += srcskip; |
167 dst += dstskip; | 167 dst += dstskip; |
168 } | 168 } |
169 __asm__ __volatile__ (" emms\n"::); | 169 __asm__ __volatile__(" emms\n"::); |
170 } else if (SDL_HasMMX ()) { | 170 } else if (SDL_HasMMX()) { |
171 while (h--) { | 171 while (h--) { |
172 SDL_memcpyMMX (dst, src, w); | 172 SDL_memcpyMMX(dst, src, w); |
173 src += srcskip; | 173 src += srcskip; |
174 dst += dstskip; | 174 dst += dstskip; |
175 } | 175 } |
176 __asm__ __volatile__ (" emms\n"::); | 176 __asm__ __volatile__(" emms\n"::); |
177 } else | 177 } else |
178 #endif | 178 #endif |
179 while (h--) { | 179 while (h--) { |
180 SDL_memcpy (dst, src, w); | 180 SDL_memcpy(dst, src, w); |
181 src += srcskip; | 181 src += srcskip; |
182 dst += dstskip; | 182 dst += dstskip; |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 static void | 186 static void |
187 SDL_BlitCopyOverlap (SDL_BlitInfo * info) | 187 SDL_BlitCopyOverlap(SDL_BlitInfo * info) |
188 { | 188 { |
189 Uint8 *src, *dst; | 189 Uint8 *src, *dst; |
190 int w, h; | 190 int w, h; |
191 int srcskip, dstskip; | 191 int srcskip, dstskip; |
192 | 192 |
196 dst = info->d_pixels; | 196 dst = info->d_pixels; |
197 srcskip = w + info->s_skip; | 197 srcskip = w + info->s_skip; |
198 dstskip = w + info->d_skip; | 198 dstskip = w + info->d_skip; |
199 if (dst < src) { | 199 if (dst < src) { |
200 while (h--) { | 200 while (h--) { |
201 SDL_memcpy (dst, src, w); | 201 SDL_memcpy(dst, src, w); |
202 src += srcskip; | 202 src += srcskip; |
203 dst += dstskip; | 203 dst += dstskip; |
204 } | 204 } |
205 } else { | 205 } else { |
206 src += ((h - 1) * srcskip); | 206 src += ((h - 1) * srcskip); |
207 dst += ((h - 1) * dstskip); | 207 dst += ((h - 1) * dstskip); |
208 while (h--) { | 208 while (h--) { |
209 SDL_revcpy (dst, src, w); | 209 SDL_revcpy(dst, src, w); |
210 src -= srcskip; | 210 src -= srcskip; |
211 dst -= dstskip; | 211 dst -= dstskip; |
212 } | 212 } |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 /* Figure out which of many blit routines to set up on a surface */ | 216 /* Figure out which of many blit routines to set up on a surface */ |
217 int | 217 int |
218 SDL_CalculateBlit (SDL_Surface * surface) | 218 SDL_CalculateBlit(SDL_Surface * surface) |
219 { | 219 { |
220 SDL_VideoDevice *_this = SDL_GetVideoDevice (); | 220 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
221 const SDL_VideoInfo *info = SDL_GetVideoInfo (); | 221 const SDL_VideoInfo *info = SDL_GetVideoInfo(); |
222 int blit_index; | 222 int blit_index; |
223 | 223 |
224 /* Clean everything out to start */ | 224 /* Clean everything out to start */ |
225 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { | 225 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { |
226 SDL_UnRLESurface (surface, 1); | 226 SDL_UnRLESurface(surface, 1); |
227 } | 227 } |
228 surface->map->sw_blit = NULL; | 228 surface->map->sw_blit = NULL; |
229 | 229 |
230 /* Figure out if an accelerated hardware blit is possible */ | 230 /* Figure out if an accelerated hardware blit is possible */ |
231 surface->flags &= ~SDL_HWACCEL; | 231 surface->flags &= ~SDL_HWACCEL; |
258 if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) { | 258 if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) { |
259 hw_blit_ok = info->blit_sw_A; | 259 hw_blit_ok = info->blit_sw_A; |
260 } | 260 } |
261 } | 261 } |
262 if (hw_blit_ok) { | 262 if (hw_blit_ok) { |
263 _this->CheckHWBlit (_this, surface, surface->map->dst); | 263 _this->CheckHWBlit(_this, surface, surface->map->dst); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 /* if an alpha pixel format is specified, we can accelerate alpha blits */ | 267 /* if an alpha pixel format is specified, we can accelerate alpha blits */ |
268 if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) | 268 if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) |
269 && (_this->displayformatalphapixel)) { | 269 && (_this->displayformatalphapixel)) { |
270 if ((surface->flags & SDL_SRCALPHA)) | 270 if ((surface->flags & SDL_SRCALPHA)) |
271 if (info->blit_hw_A) { | 271 if (info->blit_hw_A) { |
272 _this->CheckHWBlit (_this, surface, surface->map->dst); | 272 _this->CheckHWBlit(_this, surface, surface->map->dst); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 /* Get the blit function index, based on surface mode */ | 276 /* Get the blit function index, based on surface mode */ |
277 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ | 277 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ |
292 surface->map->sw_data->blit = SDL_BlitCopyOverlap; | 292 surface->map->sw_data->blit = SDL_BlitCopyOverlap; |
293 } | 293 } |
294 } else { | 294 } else { |
295 if (surface->format->BitsPerPixel < 8) { | 295 if (surface->format->BitsPerPixel < 8) { |
296 surface->map->sw_data->blit = | 296 surface->map->sw_data->blit = |
297 SDL_CalculateBlit0 (surface, blit_index); | 297 SDL_CalculateBlit0(surface, blit_index); |
298 } else { | 298 } else { |
299 switch (surface->format->BytesPerPixel) { | 299 switch (surface->format->BytesPerPixel) { |
300 case 1: | 300 case 1: |
301 surface->map->sw_data->blit = | 301 surface->map->sw_data->blit = |
302 SDL_CalculateBlit1 (surface, blit_index); | 302 SDL_CalculateBlit1(surface, blit_index); |
303 break; | 303 break; |
304 case 2: | 304 case 2: |
305 case 3: | 305 case 3: |
306 case 4: | 306 case 4: |
307 surface->map->sw_data->blit = | 307 surface->map->sw_data->blit = |
308 SDL_CalculateBlitN (surface, blit_index); | 308 SDL_CalculateBlitN(surface, blit_index); |
309 break; | 309 break; |
310 default: | 310 default: |
311 surface->map->sw_data->blit = NULL; | 311 surface->map->sw_data->blit = NULL; |
312 break; | 312 break; |
313 } | 313 } |
314 } | 314 } |
315 } | 315 } |
316 /* Make sure we have a blit function */ | 316 /* Make sure we have a blit function */ |
317 if (surface->map->sw_data->blit == NULL) { | 317 if (surface->map->sw_data->blit == NULL) { |
318 SDL_InvalidateMap (surface->map); | 318 SDL_InvalidateMap(surface->map); |
319 SDL_SetError ("Blit combination not supported"); | 319 SDL_SetError("Blit combination not supported"); |
320 return (-1); | 320 return (-1); |
321 } | 321 } |
322 | 322 |
323 /* Choose software blitting function */ | 323 /* Choose software blitting function */ |
324 if (surface->flags & SDL_RLEACCELOK | 324 if (surface->flags & SDL_RLEACCELOK |
325 && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { | 325 && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { |
326 | 326 |
327 if (surface->map->identity | 327 if (surface->map->identity |
328 && (blit_index == 1 | 328 && (blit_index == 1 |
329 || (blit_index == 3 && !surface->format->Amask))) { | 329 || (blit_index == 3 && !surface->format->Amask))) { |
330 if (SDL_RLESurface (surface) == 0) | 330 if (SDL_RLESurface(surface) == 0) |
331 surface->map->sw_blit = SDL_RLEBlit; | 331 surface->map->sw_blit = SDL_RLEBlit; |
332 } else if (blit_index == 2 && surface->format->Amask) { | 332 } else if (blit_index == 2 && surface->format->Amask) { |
333 if (SDL_RLESurface (surface) == 0) | 333 if (SDL_RLESurface(surface) == 0) |
334 surface->map->sw_blit = SDL_RLEAlphaBlit; | 334 surface->map->sw_blit = SDL_RLEAlphaBlit; |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 if (surface->map->sw_blit == NULL) { | 338 if (surface->map->sw_blit == NULL) { |