Mercurial > sdl-ios-xcode
annotate src/video/SDL_stretch.c @ 4541:abb56f7699ea SDL-1.2
Fixed bug 936
Make sure that eip doesn't overflow the copy buffer beforehand. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 18 Jul 2010 10:08:06 -0700 |
parents | ab2dfac9d5c1 |
children | d7cdc25af9a2 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 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:
1234
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:
1234
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:
1234
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:
1234
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:
1234
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:
1234
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 /* This a stretch blit implementation based on ideas given to me by | |
25 Tomasz Cejner - thanks! :) | |
26 | |
27 April 27, 2000 - Sam Lantinga | |
28 */ | |
29 | |
30 #include "SDL_video.h" | |
31 #include "SDL_blit.h" | |
32 | |
33 /* This isn't ready for general consumption yet - it should be folded | |
34 into the general blitting mechanism. | |
35 */ | |
36 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
37 #if ((defined(_MFC_VER) && defined(_M_IX86)/* && !defined(_WIN32_WCE) still needed? */) || \ |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
38 defined(__WATCOMC__) || \ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
39 (defined(__GNUC__) && defined(__i386__))) && SDL_ASSEMBLY_ROUTINES |
4356
ab2dfac9d5c1
There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct value after the first scanline. Ugh.
Sam Lantinga <slouken@libsdl.org>
parents:
4355
diff
changeset
|
40 /* There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct |
ab2dfac9d5c1
There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct value after the first scanline. Ugh.
Sam Lantinga <slouken@libsdl.org>
parents:
4355
diff
changeset
|
41 * value after the first scanline. FIXME? */ |
ab2dfac9d5c1
There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct value after the first scanline. Ugh.
Sam Lantinga <slouken@libsdl.org>
parents:
4355
diff
changeset
|
42 /*#define USE_ASM_STRETCH*/ |
0 | 43 #endif |
44 | |
45 #ifdef USE_ASM_STRETCH | |
46 | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
47 #ifdef HAVE_MPROTECT |
4108 | 48 #include <sys/types.h> |
49 #include <sys/mman.h> | |
50 #endif | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
51 #ifdef __GNUC__ |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
52 #define PAGE_ALIGNED __attribute__((__aligned__(4096))) |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
53 #else |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
54 #define PAGE_ALIGNED |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
55 #endif |
4108 | 56 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
57 #if defined(_M_IX86) || defined(i386) |
0 | 58 #define PREFIX16 0x66 |
59 #define STORE_BYTE 0xAA | |
60 #define STORE_WORD 0xAB | |
61 #define LOAD_BYTE 0xAC | |
62 #define LOAD_WORD 0xAD | |
63 #define RETURN 0xC3 | |
64 #else | |
65 #error Need assembly opcodes for this architecture | |
66 #endif | |
67 | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
68 static unsigned char copy_row[4096] PAGE_ALIGNED; |
0 | 69 |
70 static int generate_rowbytes(int src_w, int dst_w, int bpp) | |
71 { | |
72 static struct { | |
73 int bpp; | |
74 int src_w; | |
75 int dst_w; | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
76 int status; |
0 | 77 } last; |
78 | |
79 int i; | |
80 int pos, inc; | |
4541 | 81 unsigned char *eip, *end; |
0 | 82 unsigned char load, store; |
83 | |
84 /* See if we need to regenerate the copy buffer */ | |
85 if ( (src_w == last.src_w) && | |
1164
10b3fb28c86b
Date: Mon, 31 Oct 2005 14:23:34 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
894
diff
changeset
|
86 (dst_w == last.dst_w) && (bpp == last.bpp) ) { |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
87 return(last.status); |
0 | 88 } |
89 last.bpp = bpp; | |
90 last.src_w = src_w; | |
91 last.dst_w = dst_w; | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
92 last.status = -1; |
0 | 93 |
94 switch (bpp) { | |
95 case 1: | |
96 load = LOAD_BYTE; | |
97 store = STORE_BYTE; | |
98 break; | |
99 case 2: | |
100 case 4: | |
101 load = LOAD_WORD; | |
102 store = STORE_WORD; | |
103 break; | |
104 default: | |
105 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); | |
106 return(-1); | |
107 } | |
4355 | 108 #ifdef HAVE_MPROTECT |
109 /* Make the code writeable */ | |
110 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE) < 0 ) { | |
111 SDL_SetError("Couldn't make copy buffer writeable"); | |
112 return(-1); | |
113 } | |
114 #endif | |
0 | 115 pos = 0x10000; |
116 inc = (src_w << 16) / dst_w; | |
117 eip = copy_row; | |
4541 | 118 end = copy_row+sizeof(copy_row); |
119 for ( i=0; i<dst_w && eip < end; ++i ) { | |
0 | 120 while ( pos >= 0x10000L ) { |
121 if ( bpp == 2 ) { | |
122 *eip++ = PREFIX16; | |
123 } | |
124 *eip++ = load; | |
125 pos -= 0x10000L; | |
126 } | |
127 if ( bpp == 2 ) { | |
128 *eip++ = PREFIX16; | |
129 } | |
130 *eip++ = store; | |
131 pos += inc; | |
132 } | |
133 *eip++ = RETURN; | |
134 | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
135 /* Verify that we didn't overflow (too late!!!) */ |
4541 | 136 if ( i < dst_w ) { |
137 SDL_SetError("Copy buffer too small"); | |
0 | 138 return(-1); |
139 } | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
140 #ifdef HAVE_MPROTECT |
4355 | 141 /* Make the code executable but not writeable */ |
142 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) { | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
143 SDL_SetError("Couldn't make copy buffer executable"); |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
144 return(-1); |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
145 } |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
146 #endif |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
147 last.status = 0; |
0 | 148 return(0); |
149 } | |
150 | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
151 #endif /* USE_ASM_STRETCH */ |
0 | 152 |
153 #define DEFINE_COPY_ROW(name, type) \ | |
154 void name(type *src, int src_w, type *dst, int dst_w) \ | |
155 { \ | |
156 int i; \ | |
157 int pos, inc; \ | |
158 type pixel = 0; \ | |
159 \ | |
160 pos = 0x10000; \ | |
161 inc = (src_w << 16) / dst_w; \ | |
162 for ( i=dst_w; i>0; --i ) { \ | |
163 while ( pos >= 0x10000L ) { \ | |
164 pixel = *src++; \ | |
165 pos -= 0x10000L; \ | |
166 } \ | |
167 *dst++ = pixel; \ | |
168 pos += inc; \ | |
169 } \ | |
170 } | |
171 DEFINE_COPY_ROW(copy_row1, Uint8) | |
172 DEFINE_COPY_ROW(copy_row2, Uint16) | |
173 DEFINE_COPY_ROW(copy_row4, Uint32) | |
174 | |
175 /* The ASM code doesn't handle 24-bpp stretch blits */ | |
176 void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w) | |
177 { | |
178 int i; | |
179 int pos, inc; | |
1849
b5a4ac87b98c
Fixed uninitialized variable warnings
Sam Lantinga <slouken@libsdl.org>
parents:
1442
diff
changeset
|
180 Uint8 pixel[3] = { 0, 0, 0 }; |
0 | 181 |
182 pos = 0x10000; | |
183 inc = (src_w << 16) / dst_w; | |
184 for ( i=dst_w; i>0; --i ) { | |
185 while ( pos >= 0x10000L ) { | |
186 pixel[0] = *src++; | |
187 pixel[1] = *src++; | |
188 pixel[2] = *src++; | |
189 pos -= 0x10000L; | |
190 } | |
191 *dst++ = pixel[0]; | |
192 *dst++ = pixel[1]; | |
193 *dst++ = pixel[2]; | |
194 pos += inc; | |
195 } | |
196 } | |
197 | |
198 /* Perform a stretch blit between two surfaces of the same format. | |
199 NOTE: This function is not safe to call from multiple threads! | |
200 */ | |
201 int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, | |
202 SDL_Surface *dst, SDL_Rect *dstrect) | |
203 { | |
894
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
204 int src_locked; |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
205 int dst_locked; |
0 | 206 int pos, inc; |
207 int dst_width; | |
208 int dst_maxrow; | |
209 int src_row, dst_row; | |
210 Uint8 *srcp = NULL; | |
211 Uint8 *dstp; | |
212 SDL_Rect full_src; | |
213 SDL_Rect full_dst; | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
214 #ifdef USE_ASM_STRETCH |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
215 SDL_bool use_asm = SDL_TRUE; |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
216 #ifdef __GNUC__ |
0 | 217 int u1, u2; |
218 #endif | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
219 #endif /* USE_ASM_STRETCH */ |
0 | 220 const int bpp = dst->format->BytesPerPixel; |
221 | |
222 if ( src->format->BitsPerPixel != dst->format->BitsPerPixel ) { | |
223 SDL_SetError("Only works with same format surfaces"); | |
224 return(-1); | |
225 } | |
226 | |
227 /* Verify the blit rectangles */ | |
228 if ( srcrect ) { | |
229 if ( (srcrect->x < 0) || (srcrect->y < 0) || | |
230 ((srcrect->x+srcrect->w) > src->w) || | |
231 ((srcrect->y+srcrect->h) > src->h) ) { | |
232 SDL_SetError("Invalid source blit rectangle"); | |
233 return(-1); | |
234 } | |
235 } else { | |
236 full_src.x = 0; | |
237 full_src.y = 0; | |
238 full_src.w = src->w; | |
239 full_src.h = src->h; | |
240 srcrect = &full_src; | |
241 } | |
242 if ( dstrect ) { | |
243 if ( (dstrect->x < 0) || (dstrect->y < 0) || | |
244 ((dstrect->x+dstrect->w) > dst->w) || | |
245 ((dstrect->y+dstrect->h) > dst->h) ) { | |
246 SDL_SetError("Invalid destination blit rectangle"); | |
247 return(-1); | |
248 } | |
249 } else { | |
250 full_dst.x = 0; | |
251 full_dst.y = 0; | |
252 full_dst.w = dst->w; | |
253 full_dst.h = dst->h; | |
254 dstrect = &full_dst; | |
255 } | |
256 | |
894
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
257 /* Lock the destination if it's in hardware */ |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
258 dst_locked = 0; |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
259 if ( SDL_MUSTLOCK(dst) ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
260 if ( SDL_LockSurface(dst) < 0 ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
261 SDL_SetError("Unable to lock destination surface"); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
262 return(-1); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
263 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
264 dst_locked = 1; |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
265 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
266 /* Lock the source if it's in hardware */ |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
267 src_locked = 0; |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
268 if ( SDL_MUSTLOCK(src) ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
269 if ( SDL_LockSurface(src) < 0 ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
270 if ( dst_locked ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
271 SDL_UnlockSurface(dst); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
272 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
273 SDL_SetError("Unable to lock source surface"); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
274 return(-1); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
275 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
276 src_locked = 1; |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
277 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
278 |
0 | 279 /* Set up the data... */ |
280 pos = 0x10000; | |
281 inc = (srcrect->h << 16) / dstrect->h; | |
282 src_row = srcrect->y; | |
283 dst_row = dstrect->y; | |
284 dst_width = dstrect->w*bpp; | |
285 | |
286 #ifdef USE_ASM_STRETCH | |
287 /* Write the opcodes for this stretch */ | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
288 if ( (bpp == 3) || |
0 | 289 (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0) ) { |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
290 use_asm = SDL_FALSE; |
0 | 291 } |
292 #endif | |
293 | |
294 /* Perform the stretch blit */ | |
295 for ( dst_maxrow = dst_row+dstrect->h; dst_row<dst_maxrow; ++dst_row ) { | |
296 dstp = (Uint8 *)dst->pixels + (dst_row*dst->pitch) | |
297 + (dstrect->x*bpp); | |
298 while ( pos >= 0x10000L ) { | |
299 srcp = (Uint8 *)src->pixels + (src_row*src->pitch) | |
300 + (srcrect->x*bpp); | |
301 ++src_row; | |
302 pos -= 0x10000L; | |
303 } | |
304 #ifdef USE_ASM_STRETCH | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
305 if (use_asm) { |
0 | 306 #ifdef __GNUC__ |
627
8b9ac38381d0
Fixed compile problem in SDL_stretch.c with gcc 3.3
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
307 __asm__ __volatile__ ( |
1228
f4a3a4129d04
From Mike Frysinger and/or Gentoo:
Ryan C. Gordon <icculus@icculus.org>
parents:
1164
diff
changeset
|
308 "call *%4" |
0 | 309 : "=&D" (u1), "=&S" (u2) |
1234
73676c1f56ee
For sanity's sake, removed the '&' when passing copy_row array to asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
1233
diff
changeset
|
310 : "0" (dstp), "1" (srcp), "r" (copy_row) |
0 | 311 : "memory" ); |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
312 #elif defined(_MSC_VER) || defined(__WATCOMC__) |
1234
73676c1f56ee
For sanity's sake, removed the '&' when passing copy_row array to asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
1233
diff
changeset
|
313 { void *code = copy_row; |
0 | 314 __asm { |
315 push edi | |
316 push esi | |
317 | |
318 mov edi, dstp | |
319 mov esi, srcp | |
320 call dword ptr code | |
321 | |
322 pop esi | |
323 pop edi | |
324 } | |
325 } | |
326 #else | |
327 #error Need inline assembly for this compiler | |
328 #endif | |
4109
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
329 } else |
cd2ab40f1219
Made the mprotect() fix for SDL_SoftStretch() more general for hardened linux, etc.
Sam Lantinga <slouken@libsdl.org>
parents:
4108
diff
changeset
|
330 #endif |
0 | 331 switch (bpp) { |
332 case 1: | |
333 copy_row1(srcp, srcrect->w, dstp, dstrect->w); | |
334 break; | |
335 case 2: | |
336 copy_row2((Uint16 *)srcp, srcrect->w, | |
337 (Uint16 *)dstp, dstrect->w); | |
338 break; | |
339 case 3: | |
340 copy_row3(srcp, srcrect->w, dstp, dstrect->w); | |
341 break; | |
342 case 4: | |
343 copy_row4((Uint32 *)srcp, srcrect->w, | |
344 (Uint32 *)dstp, dstrect->w); | |
345 break; | |
346 } | |
347 pos += inc; | |
348 } | |
894
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
349 |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
350 /* We need to unlock the surfaces if they're locked */ |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
351 if ( dst_locked ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
352 SDL_UnlockSurface(dst); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
353 } |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
354 if ( src_locked ) { |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
355 SDL_UnlockSurface(src); |
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
356 } |
0 | 357 return(0); |
358 } | |
359 |