Mercurial > sdl-ios-xcode
annotate src/video/SDL_blit.c @ 720:f90d80d68071
N Sep 17 8791 Sam Lantinga Re: tks source released
Date: Sun, 07 Sep 2003 02:51:58 +0200
From: Stephane Marchesin
Subject: [SDL] Two little patches
Compiling SDL with a recent gcc (gcc 3.3.1, 3.3 doesn't have this
behaviour) gives some nasty warnings :
SDL_blit_A.c: In function `BlitRGBtoRGBSurfaceAlpha128MMX':
SDL_blit_A.c:223: warning: integer constant is too large for "long" type
SDL_blit_A.c:225: warning: integer constant is too large for "long" type
SDL_blit_A.c:227: warning: integer constant is too large for "long" type
[...]
The first attached patch (longlongfix.patch) tells gcc to really treat
those constants as unsigned long long and not long.
The second patch (nasinclude.patch) fixes an include problem I had while
compiling nas audio : when the <audio/audiolib.h> file lies in
/usr/X11R6/include, a -I/usr/X11R6/include option is needed or the file
isn't found.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 21 Sep 2003 18:32:04 +0000 |
parents | 8468fc0504f3 |
children | 22dbf364c017 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
40 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT) |
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 /* Function to check the CPU flags */ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
43 #define MMX_CPU 0x800000 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
44 #define SSE_CPU 0x2000000 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
45 #define CPU_Flags() Hermes_X86_CPU() |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
46 #define X86_ASSEMBLER |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
47 #define HermesConverterInterface void |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
48 #define HermesClearInterface void |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
49 #define STACKCALL |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
50 #include "HeadX86.h" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
51 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
52 |
0 | 53 /* The general purpose software blit routine */ |
54 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
55 SDL_Surface *dst, SDL_Rect *dstrect) | |
56 { | |
57 int okay; | |
58 int src_locked; | |
59 int dst_locked; | |
60 | |
61 /* Everything is okay at the beginning... */ | |
62 okay = 1; | |
63 | |
64 /* Lock the destination if it's in hardware */ | |
65 dst_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(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
67 if ( SDL_LockSurface(dst) < 0 ) { |
0 | 68 okay = 0; |
69 } else { | |
70 dst_locked = 1; | |
71 } | |
72 } | |
73 /* Lock the source if it's in hardware */ | |
74 src_locked = 0; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
75 if ( SDL_MUSTLOCK(src) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
76 if ( SDL_LockSurface(src) < 0 ) { |
0 | 77 okay = 0; |
78 } else { | |
79 src_locked = 1; | |
80 } | |
81 } | |
82 | |
83 /* Set up source and destination buffer pointers, and BLIT! */ | |
84 if ( okay && srcrect->w && srcrect->h ) { | |
85 SDL_BlitInfo info; | |
86 SDL_loblit RunBlit; | |
87 | |
88 /* 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
|
89 info.s_pixels = (Uint8 *)src->pixels + |
0 | 90 (Uint16)srcrect->y*src->pitch + |
91 (Uint16)srcrect->x*src->format->BytesPerPixel; | |
92 info.s_width = srcrect->w; | |
93 info.s_height = srcrect->h; | |
94 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
|
95 info.d_pixels = (Uint8 *)dst->pixels + |
0 | 96 (Uint16)dstrect->y*dst->pitch + |
97 (Uint16)dstrect->x*dst->format->BytesPerPixel; | |
98 info.d_width = dstrect->w; | |
99 info.d_height = dstrect->h; | |
100 info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel; | |
101 info.aux_data = src->map->sw_data->aux_data; | |
102 info.src = src->format; | |
103 info.table = src->map->table; | |
104 info.dst = dst->format; | |
105 RunBlit = src->map->sw_data->blit; | |
106 | |
107 /* Run the actual software blit */ | |
108 RunBlit(&info); | |
109 } | |
110 | |
111 /* We need to unlock the surfaces if they're locked */ | |
112 if ( dst_locked ) { | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
113 SDL_UnlockSurface(dst); |
310
c97c1d3b3b5c
Blit bug fix from John Popplewell
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
114 } |
0 | 115 if ( src_locked ) { |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
116 SDL_UnlockSurface(src); |
0 | 117 } |
118 /* Blit is done! */ | |
119 return(okay ? 0 : -1); | |
120 } | |
121 | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
122 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
123 void SDL_memcpyMMX(char* to,char* from,int len) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
124 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
125 int i; |
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 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
|
128 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
129 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
130 " movq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
131 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
132 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
133 to+=8; |
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 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
136 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
|
137 } |
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 void SDL_memcpySSE(char* to,char* from,int len) |
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 int i; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
142 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
143 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
144 " prefetchnta (%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
145 " prefetchnta 64(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
146 " prefetchnta 128(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
147 " prefetchnta 192(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
148 : : "r" (from) ); |
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 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
|
151 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
152 " prefetchnta 256(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
153 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
154 " movntq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
155 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
156 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
157 to+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
158 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
159 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
160 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
|
161 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
162 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
163 |
0 | 164 static void SDL_BlitCopy(SDL_BlitInfo *info) |
165 { | |
166 Uint8 *src, *dst; | |
167 int w, h; | |
168 int srcskip, dstskip; | |
697
8468fc0504f3
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
169 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
170 Uint32 f; |
697
8468fc0504f3
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
171 #endif |
0 | 172 |
173 w = info->d_width*info->dst->BytesPerPixel; | |
174 h = info->d_height; | |
175 src = info->s_pixels; | |
176 dst = info->d_pixels; | |
177 srcskip = w+info->s_skip; | |
178 dstskip = w+info->d_skip; | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
179 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
180 f=CPU_Flags(); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
181 if((f&(MMX_CPU|SSE_CPU))==(MMX_CPU|SSE_CPU)) |
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 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
184 SDL_memcpySSE(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
185 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
186 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
187 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
188 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
189 " emms\n" |
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 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
192 else |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
193 if((f&(MMX_CPU))!=0) |
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 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
196 SDL_memcpyMMX(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
197 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
198 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
199 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
200 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
201 " emms\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
202 ::); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
203 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
204 else |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
205 #endif |
0 | 206 while ( h-- ) { |
207 SDL_memcpy(dst, src, w); | |
208 src += srcskip; | |
209 dst += dstskip; | |
210 } | |
211 } | |
212 | |
213 static void SDL_BlitCopyOverlap(SDL_BlitInfo *info) | |
214 { | |
215 Uint8 *src, *dst; | |
216 int w, h; | |
217 int srcskip, dstskip; | |
218 | |
219 w = info->d_width*info->dst->BytesPerPixel; | |
220 h = info->d_height; | |
221 src = info->s_pixels; | |
222 dst = info->d_pixels; | |
223 srcskip = w+info->s_skip; | |
224 dstskip = w+info->d_skip; | |
225 if ( dst < src ) { | |
226 while ( h-- ) { | |
227 SDL_memcpy(dst, src, w); | |
228 src += srcskip; | |
229 dst += dstskip; | |
230 } | |
231 } else { | |
232 src += ((h-1) * srcskip); | |
233 dst += ((h-1) * dstskip); | |
234 while ( h-- ) { | |
235 SDL_revcpy(dst, src, w); | |
236 src -= srcskip; | |
237 dst -= dstskip; | |
238 } | |
239 } | |
240 } | |
241 | |
242 /* Figure out which of many blit routines to set up on a surface */ | |
243 int SDL_CalculateBlit(SDL_Surface *surface) | |
244 { | |
245 int blit_index; | |
246 | |
247 /* Clean everything out to start */ | |
248 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { | |
249 SDL_UnRLESurface(surface, 1); | |
250 } | |
251 surface->map->sw_blit = NULL; | |
252 | |
253 /* Figure out if an accelerated hardware blit is possible */ | |
254 surface->flags &= ~SDL_HWACCEL; | |
255 if ( surface->map->identity ) { | |
256 int hw_blit_ok; | |
257 | |
258 if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { | |
259 /* We only support accelerated blitting to hardware */ | |
260 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
261 hw_blit_ok = current_video->info.blit_hw; | |
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_hw_CC; | |
267 } | |
268 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
269 hw_blit_ok = current_video->info.blit_hw_A; | |
270 } | |
271 } else { | |
272 /* We only support accelerated blitting to hardware */ | |
273 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
274 hw_blit_ok = current_video->info.blit_sw; | |
275 } else { | |
276 hw_blit_ok = 0; | |
277 } | |
278 if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { | |
279 hw_blit_ok = current_video->info.blit_sw_CC; | |
280 } | |
281 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
282 hw_blit_ok = current_video->info.blit_sw_A; | |
283 } | |
284 } | |
285 if ( hw_blit_ok ) { | |
286 SDL_VideoDevice *video = current_video; | |
287 SDL_VideoDevice *this = current_video; | |
288 video->CheckHWBlit(this, surface, surface->map->dst); | |
289 } | |
290 } | |
291 | |
292 /* Get the blit function index, based on surface mode */ | |
293 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ | |
294 blit_index = 0; | |
295 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; | |
296 if ( surface->flags & SDL_SRCALPHA | |
297 && (surface->format->alpha != SDL_ALPHA_OPAQUE | |
298 || surface->format->Amask) ) { | |
299 blit_index |= 2; | |
300 } | |
301 | |
302 /* Check for special "identity" case -- copy blit */ | |
303 if ( surface->map->identity && blit_index == 0 ) { | |
304 surface->map->sw_data->blit = SDL_BlitCopy; | |
305 | |
306 /* Handle overlapping blits on the same surface */ | |
307 if ( surface == surface->map->dst ) { | |
308 surface->map->sw_data->blit = SDL_BlitCopyOverlap; | |
309 } | |
310 } else { | |
311 if ( surface->format->BitsPerPixel < 8 ) { | |
312 surface->map->sw_data->blit = | |
313 SDL_CalculateBlit0(surface, blit_index); | |
314 } else { | |
315 switch ( surface->format->BytesPerPixel ) { | |
316 case 1: | |
317 surface->map->sw_data->blit = | |
318 SDL_CalculateBlit1(surface, blit_index); | |
319 break; | |
320 case 2: | |
321 case 3: | |
322 case 4: | |
323 surface->map->sw_data->blit = | |
324 SDL_CalculateBlitN(surface, blit_index); | |
325 break; | |
326 default: | |
327 surface->map->sw_data->blit = NULL; | |
328 break; | |
329 } | |
330 } | |
331 } | |
332 /* Make sure we have a blit function */ | |
333 if ( surface->map->sw_data->blit == NULL ) { | |
334 SDL_InvalidateMap(surface->map); | |
335 SDL_SetError("Blit combination not supported"); | |
336 return(-1); | |
337 } | |
338 | |
339 /* Choose software blitting function */ | |
340 if(surface->flags & SDL_RLEACCELOK | |
341 && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { | |
342 | |
343 if(surface->map->identity | |
344 && (blit_index == 1 | |
345 || (blit_index == 3 && !surface->format->Amask))) { | |
346 if ( SDL_RLESurface(surface) == 0 ) | |
347 surface->map->sw_blit = SDL_RLEBlit; | |
348 } else if(blit_index == 2 && surface->format->Amask) { | |
349 if ( SDL_RLESurface(surface) == 0 ) | |
350 surface->map->sw_blit = SDL_RLEAlphaBlit; | |
351 } | |
352 } | |
353 | |
354 if ( surface->map->sw_blit == NULL ) { | |
355 surface->map->sw_blit = SDL_SoftBlit; | |
356 } | |
357 return(0); | |
358 } | |
359 |