comparison test/testblitspeed.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
13 static SDL_Surface *dest = NULL; 13 static SDL_Surface *dest = NULL;
14 static SDL_Surface *src = NULL; 14 static SDL_Surface *src = NULL;
15 static int testSeconds = 10; 15 static int testSeconds = 10;
16 16
17 17
18 static int percent(int val, int total) 18 static int
19 { 19 percent (int val, int total)
20 return((int) ((((float) val) / ((float) total)) * 100.0f)); 20 {
21 } 21 return ((int) ((((float) val) / ((float) total)) * 100.0f));
22 22 }
23 static int randRange(int lo, int hi) 23
24 { 24 static int
25 return(lo + (int) (((double) hi)*rand()/(RAND_MAX+1.0))); 25 randRange (int lo, int hi)
26 } 26 {
27 27 return (lo + (int) (((double) hi) * rand () / (RAND_MAX + 1.0)));
28 static void copy_trunc_str(char *str, size_t strsize, const char *flagstr) 28 }
29 { 29
30 if ( (strlen(str) + strlen(flagstr)) >= (strsize - 1) ) 30 static void
31 strcpy(str + (strsize - 5), " ..."); 31 copy_trunc_str (char *str, size_t strsize, const char *flagstr)
32 {
33 if ((strlen (str) + strlen (flagstr)) >= (strsize - 1))
34 strcpy (str + (strsize - 5), " ...");
32 else 35 else
33 strcat(str, flagstr); 36 strcat (str, flagstr);
34 } 37 }
35 38
36 static void __append_sdl_surface_flag(SDL_Surface *_surface, char *str, 39 static void
37 size_t strsize, Uint32 flag, 40 __append_sdl_surface_flag (SDL_Surface * _surface, char *str,
38 const char *flagstr) 41 size_t strsize, Uint32 flag, const char *flagstr)
39 { 42 {
40 if (_surface->flags & flag) 43 if (_surface->flags & flag)
41 copy_trunc_str(str, strsize, flagstr); 44 copy_trunc_str (str, strsize, flagstr);
42 } 45 }
43 46
44 47
45 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl) 48 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl)
46 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" ) 49 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" )
47 50
48 static void output_videoinfo_details(void) 51 static void
49 { 52 output_videoinfo_details (void)
50 const SDL_VideoInfo *info = SDL_GetVideoInfo(); 53 {
51 printf("SDL_GetVideoInfo():\n"); 54 const SDL_VideoInfo *info = SDL_GetVideoInfo ();
55 printf ("SDL_GetVideoInfo():\n");
52 if (info == NULL) 56 if (info == NULL)
53 printf(" (null.)\n"); 57 printf (" (null.)\n");
54 else 58 else {
55 { 59 print_tf_state (" hardware surface available", info->hw_available);
56 print_tf_state(" hardware surface available", info->hw_available); 60 print_tf_state (" window manager available", info->wm_available);
57 print_tf_state(" window manager available", info->wm_available); 61 print_tf_state (" accelerated hardware->hardware blits",
58 print_tf_state(" accelerated hardware->hardware blits", info->blit_hw); 62 info->blit_hw);
59 print_tf_state(" accelerated hardware->hardware colorkey blits", info->blit_hw_CC); 63 print_tf_state (" accelerated hardware->hardware colorkey blits",
60 print_tf_state(" accelerated hardware->hardware alpha blits", info->blit_hw_A); 64 info->blit_hw_CC);
61 print_tf_state(" accelerated software->hardware blits", info->blit_sw); 65 print_tf_state (" accelerated hardware->hardware alpha blits",
62 print_tf_state(" accelerated software->hardware colorkey blits", info->blit_sw_CC); 66 info->blit_hw_A);
63 print_tf_state(" accelerated software->hardware alpha blits", info->blit_sw_A); 67 print_tf_state (" accelerated software->hardware blits",
64 print_tf_state(" accelerated color fills", info->blit_fill); 68 info->blit_sw);
65 printf(" video memory: (%d)\n", info->video_mem); 69 print_tf_state (" accelerated software->hardware colorkey blits",
66 } 70 info->blit_sw_CC);
67 71 print_tf_state (" accelerated software->hardware alpha blits",
68 printf("\n"); 72 info->blit_sw_A);
69 } 73 print_tf_state (" accelerated color fills", info->blit_fill);
70 74 printf (" video memory: (%d)\n", info->video_mem);
71 static void output_surface_details(const char *name, SDL_Surface *surface) 75 }
72 { 76
73 printf("Details for %s:\n", name); 77 printf ("\n");
74 78 }
75 if (surface == NULL) 79
76 { 80 static void
77 printf("-WARNING- You've got a NULL surface!"); 81 output_surface_details (const char *name, SDL_Surface * surface)
78 } 82 {
79 else 83 printf ("Details for %s:\n", name);
80 { 84
85 if (surface == NULL) {
86 printf ("-WARNING- You've got a NULL surface!");
87 } else {
81 char f[256]; 88 char f[256];
82 printf(" width : %d\n", surface->w); 89 printf (" width : %d\n", surface->w);
83 printf(" height : %d\n", surface->h); 90 printf (" height : %d\n", surface->h);
84 printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel); 91 printf (" depth : %d bits per pixel\n",
85 printf(" pitch : %d\n", (int) surface->pitch); 92 surface->format->BitsPerPixel);
86 printf(" alpha : %d\n", (int) surface->format->alpha); 93 printf (" pitch : %d\n", (int) surface->pitch);
87 printf(" colorkey : 0x%X\n", (unsigned int) surface->format->colorkey); 94 printf (" alpha : %d\n", (int) surface->format->alpha);
88 95 printf (" colorkey : 0x%X\n",
89 printf(" red bits : 0x%08X mask, %d shift, %d loss\n", 96 (unsigned int) surface->format->colorkey);
90 (int) surface->format->Rmask, 97
91 (int) surface->format->Rshift, 98 printf (" red bits : 0x%08X mask, %d shift, %d loss\n",
92 (int) surface->format->Rloss); 99 (int) surface->format->Rmask,
93 printf(" green bits : 0x%08X mask, %d shift, %d loss\n", 100 (int) surface->format->Rshift, (int) surface->format->Rloss);
94 (int) surface->format->Gmask, 101 printf (" green bits : 0x%08X mask, %d shift, %d loss\n",
95 (int) surface->format->Gshift, 102 (int) surface->format->Gmask,
96 (int) surface->format->Gloss); 103 (int) surface->format->Gshift, (int) surface->format->Gloss);
97 printf(" blue bits : 0x%08X mask, %d shift, %d loss\n", 104 printf (" blue bits : 0x%08X mask, %d shift, %d loss\n",
98 (int) surface->format->Bmask, 105 (int) surface->format->Bmask,
99 (int) surface->format->Bshift, 106 (int) surface->format->Bshift, (int) surface->format->Bloss);
100 (int) surface->format->Bloss); 107 printf (" alpha bits : 0x%08X mask, %d shift, %d loss\n",
101 printf(" alpha bits : 0x%08X mask, %d shift, %d loss\n", 108 (int) surface->format->Amask,
102 (int) surface->format->Amask, 109 (int) surface->format->Ashift, (int) surface->format->Aloss);
103 (int) surface->format->Ashift,
104 (int) surface->format->Aloss);
105 110
106 f[0] = '\0'; 111 f[0] = '\0';
107 112
108 /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE);*/ 113 /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE); */
109 if ((surface->flags & SDL_HWSURFACE) == 0) 114 if ((surface->flags & SDL_HWSURFACE) == 0)
110 copy_trunc_str(f, sizeof (f), " SDL_SWSURFACE"); 115 copy_trunc_str (f, sizeof (f), " SDL_SWSURFACE");
111 116
112 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWSURFACE); 117 append_sdl_surface_flag (surface, f, sizeof (f), SDL_HWSURFACE);
113 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ASYNCBLIT); 118 append_sdl_surface_flag (surface, f, sizeof (f), SDL_ASYNCBLIT);
114 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ANYFORMAT); 119 append_sdl_surface_flag (surface, f, sizeof (f), SDL_ANYFORMAT);
115 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWPALETTE); 120 append_sdl_surface_flag (surface, f, sizeof (f), SDL_HWPALETTE);
116 append_sdl_surface_flag(surface, f, sizeof (f), SDL_DOUBLEBUF); 121 append_sdl_surface_flag (surface, f, sizeof (f), SDL_DOUBLEBUF);
117 append_sdl_surface_flag(surface, f, sizeof (f), SDL_FULLSCREEN); 122 append_sdl_surface_flag (surface, f, sizeof (f), SDL_FULLSCREEN);
118 append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGL); 123 append_sdl_surface_flag (surface, f, sizeof (f), SDL_OPENGL);
119 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RESIZABLE); 124 append_sdl_surface_flag (surface, f, sizeof (f), SDL_RESIZABLE);
120 append_sdl_surface_flag(surface, f, sizeof (f), SDL_NOFRAME); 125 append_sdl_surface_flag (surface, f, sizeof (f), SDL_NOFRAME);
121 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWACCEL); 126 append_sdl_surface_flag (surface, f, sizeof (f), SDL_HWACCEL);
122 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCCOLORKEY); 127 append_sdl_surface_flag (surface, f, sizeof (f), SDL_SRCCOLORKEY);
123 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCELOK); 128 append_sdl_surface_flag (surface, f, sizeof (f), SDL_RLEACCELOK);
124 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCEL); 129 append_sdl_surface_flag (surface, f, sizeof (f), SDL_RLEACCEL);
125 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCALPHA); 130 append_sdl_surface_flag (surface, f, sizeof (f), SDL_SRCALPHA);
126 append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC); 131 append_sdl_surface_flag (surface, f, sizeof (f), SDL_PREALLOC);
127 132
128 if (f[0] == '\0') 133 if (f[0] == '\0')
129 strcpy(f, " (none)"); 134 strcpy (f, " (none)");
130 135
131 printf(" flags :%s\n", f); 136 printf (" flags :%s\n", f);
132 } 137 }
133 138
134 printf("\n"); 139 printf ("\n");
135 } 140 }
136 141
137 static void output_details(void) 142 static void
138 { 143 output_details (void)
139 output_videoinfo_details(); 144 {
140 output_surface_details("Source Surface", src); 145 output_videoinfo_details ();
141 output_surface_details("Destination Surface", dest); 146 output_surface_details ("Source Surface", src);
142 } 147 output_surface_details ("Destination Surface", dest);
143 148 }
144 static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y) 149
150 static Uint32
151 blit (SDL_Surface * dst, SDL_Surface * src, int x, int y)
145 { 152 {
146 Uint32 start = 0; 153 Uint32 start = 0;
147 SDL_Rect srcRect; 154 SDL_Rect srcRect;
148 SDL_Rect dstRect; 155 SDL_Rect dstRect;
149 156
150 srcRect.x = 0; 157 srcRect.x = 0;
151 srcRect.y = 0; 158 srcRect.y = 0;
152 dstRect.x = x; 159 dstRect.x = x;
153 dstRect.y = y; 160 dstRect.y = y;
154 dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */ 161 dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */
155 dstRect.h = srcRect.h = src->h; 162 dstRect.h = srcRect.h = src->h;
156 163
157 start = SDL_GetTicks(); 164 start = SDL_GetTicks ();
158 SDL_BlitSurface(src, &srcRect, dst, &dstRect); 165 SDL_BlitSurface (src, &srcRect, dst, &dstRect);
159 return(SDL_GetTicks() - start); 166 return (SDL_GetTicks () - start);
160 } 167 }
161 168
162 static void blitCentered(SDL_Surface *dst, SDL_Surface *src) 169 static void
170 blitCentered (SDL_Surface * dst, SDL_Surface * src)
163 { 171 {
164 int x = (dst->w - src->w) / 2; 172 int x = (dst->w - src->w) / 2;
165 int y = (dst->h - src->h) / 2; 173 int y = (dst->h - src->h) / 2;
166 blit(dst, src, x, y); 174 blit (dst, src, x, y);
167 } 175 }
168 176
169 static int atoi_hex(const char *str) 177 static int
178 atoi_hex (const char *str)
170 { 179 {
171 if (str == NULL) 180 if (str == NULL)
172 return 0; 181 return 0;
173 182
174 if (strlen(str) > 2) 183 if (strlen (str) > 2) {
175 {
176 int retval = 0; 184 int retval = 0;
177 if ((str[0] == '0') && (str[1] == 'x')) 185 if ((str[0] == '0') && (str[1] == 'x'))
178 sscanf(str + 2, "%X", &retval); 186 sscanf (str + 2, "%X", &retval);
179 return(retval); 187 return (retval);
180 } 188 }
181 189
182 return(atoi(str)); 190 return (atoi (str));
183 } 191 }
184 192
185 193
186 static int setup_test(int argc, char **argv) 194 static int
195 setup_test (int argc, char **argv)
187 { 196 {
188 const char *dumpfile = NULL; 197 const char *dumpfile = NULL;
189 SDL_Surface *bmp = NULL; 198 SDL_Surface *bmp = NULL;
190 Uint32 dstbpp = 32; 199 Uint32 dstbpp = 32;
191 Uint32 dstrmask = 0x00FF0000; 200 Uint32 dstrmask = 0x00FF0000;
210 int srcalpha = 255; 219 int srcalpha = 255;
211 int dstalpha = 255; 220 int dstalpha = 255;
212 int screenSurface = 0; 221 int screenSurface = 0;
213 int i = 0; 222 int i = 0;
214 223
215 for (i = 1; i < argc; i++) 224 for (i = 1; i < argc; i++) {
216 {
217 const char *arg = argv[i]; 225 const char *arg = argv[i];
218 226
219 if (strcmp(arg, "--dstbpp") == 0) 227 if (strcmp (arg, "--dstbpp") == 0)
220 dstbpp = atoi(argv[++i]); 228 dstbpp = atoi (argv[++i]);
221 else if (strcmp(arg, "--dstrmask") == 0) 229 else if (strcmp (arg, "--dstrmask") == 0)
222 dstrmask = atoi_hex(argv[++i]); 230 dstrmask = atoi_hex (argv[++i]);
223 else if (strcmp(arg, "--dstgmask") == 0) 231 else if (strcmp (arg, "--dstgmask") == 0)
224 dstgmask = atoi_hex(argv[++i]); 232 dstgmask = atoi_hex (argv[++i]);
225 else if (strcmp(arg, "--dstbmask") == 0) 233 else if (strcmp (arg, "--dstbmask") == 0)
226 dstbmask = atoi_hex(argv[++i]); 234 dstbmask = atoi_hex (argv[++i]);
227 else if (strcmp(arg, "--dstamask") == 0) 235 else if (strcmp (arg, "--dstamask") == 0)
228 dstamask = atoi_hex(argv[++i]); 236 dstamask = atoi_hex (argv[++i]);
229 else if (strcmp(arg, "--dstwidth") == 0) 237 else if (strcmp (arg, "--dstwidth") == 0)
230 dstw = atoi(argv[++i]); 238 dstw = atoi (argv[++i]);
231 else if (strcmp(arg, "--dstheight") == 0) 239 else if (strcmp (arg, "--dstheight") == 0)
232 dsth = atoi(argv[++i]); 240 dsth = atoi (argv[++i]);
233 else if (strcmp(arg, "--dsthwsurface") == 0) 241 else if (strcmp (arg, "--dsthwsurface") == 0)
234 dstflags |= SDL_HWSURFACE; 242 dstflags |= SDL_HWSURFACE;
235 else if (strcmp(arg, "--srcbpp") == 0) 243 else if (strcmp (arg, "--srcbpp") == 0)
236 srcbpp = atoi(argv[++i]); 244 srcbpp = atoi (argv[++i]);
237 else if (strcmp(arg, "--srcrmask") == 0) 245 else if (strcmp (arg, "--srcrmask") == 0)
238 srcrmask = atoi_hex(argv[++i]); 246 srcrmask = atoi_hex (argv[++i]);
239 else if (strcmp(arg, "--srcgmask") == 0) 247 else if (strcmp (arg, "--srcgmask") == 0)
240 srcgmask = atoi_hex(argv[++i]); 248 srcgmask = atoi_hex (argv[++i]);
241 else if (strcmp(arg, "--srcbmask") == 0) 249 else if (strcmp (arg, "--srcbmask") == 0)
242 srcbmask = atoi_hex(argv[++i]); 250 srcbmask = atoi_hex (argv[++i]);
243 else if (strcmp(arg, "--srcamask") == 0) 251 else if (strcmp (arg, "--srcamask") == 0)
244 srcamask = atoi_hex(argv[++i]); 252 srcamask = atoi_hex (argv[++i]);
245 else if (strcmp(arg, "--srcwidth") == 0) 253 else if (strcmp (arg, "--srcwidth") == 0)
246 srcw = atoi(argv[++i]); 254 srcw = atoi (argv[++i]);
247 else if (strcmp(arg, "--srcheight") == 0) 255 else if (strcmp (arg, "--srcheight") == 0)
248 srch = atoi(argv[++i]); 256 srch = atoi (argv[++i]);
249 else if (strcmp(arg, "--srchwsurface") == 0) 257 else if (strcmp (arg, "--srchwsurface") == 0)
250 srcflags |= SDL_HWSURFACE; 258 srcflags |= SDL_HWSURFACE;
251 else if (strcmp(arg, "--seconds") == 0) 259 else if (strcmp (arg, "--seconds") == 0)
252 testSeconds = atoi(argv[++i]); 260 testSeconds = atoi (argv[++i]);
253 else if (strcmp(arg, "--screen") == 0) 261 else if (strcmp (arg, "--screen") == 0)
254 screenSurface = 1; 262 screenSurface = 1;
255 else if (strcmp(arg, "--dumpfile") == 0) 263 else if (strcmp (arg, "--dumpfile") == 0)
256 dumpfile = argv[++i]; 264 dumpfile = argv[++i];
257 /* !!! FIXME: set colorkey. */ 265 /* !!! FIXME: set colorkey. */
258 else if (0) /* !!! FIXME: we handle some commandlines elsewhere now */ 266 else if (0) { /* !!! FIXME: we handle some commandlines elsewhere now */
259 { 267 fprintf (stderr, "Unknown commandline option: %s\n", arg);
260 fprintf(stderr, "Unknown commandline option: %s\n", arg); 268 return (0);
261 return(0);
262 } 269 }
263 } 270 }
264 271
265 if (SDL_Init(SDL_INIT_VIDEO) == -1) 272 if (SDL_Init (SDL_INIT_VIDEO) == -1) {
266 { 273 fprintf (stderr, "SDL_Init failed: %s\n", SDL_GetError ());
267 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); 274 return (0);
268 return(0); 275 }
269 } 276
270 277 bmp = SDL_LoadBMP ("sample.bmp");
271 bmp = SDL_LoadBMP("sample.bmp"); 278 if (bmp == NULL) {
272 if (bmp == NULL) 279 fprintf (stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError ());
273 { 280 SDL_Quit ();
274 fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError()); 281 return (0);
275 SDL_Quit(); 282 }
276 return(0); 283
277 } 284 if ((dstflags & SDL_HWSURFACE) == 0)
278 285 dstflags |= SDL_SWSURFACE;
279 if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE; 286 if ((srcflags & SDL_HWSURFACE) == 0)
280 if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE; 287 srcflags |= SDL_SWSURFACE;
281 288
282 if (screenSurface) 289 if (screenSurface)
283 dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags); 290 dest = SDL_SetVideoMode (dstw, dsth, dstbpp, dstflags);
284 else 291 else {
285 { 292 dest = SDL_CreateRGBSurface (dstflags, dstw, dsth, dstbpp,
286 dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp, 293 dstrmask, dstgmask, dstbmask, dstamask);
287 dstrmask, dstgmask, dstbmask, dstamask); 294 }
288 } 295
289 296 if (dest == NULL) {
290 if (dest == NULL) 297 fprintf (stderr, "dest surface creation failed: %s\n",
291 { 298 SDL_GetError ());
292 fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError()); 299 SDL_Quit ();
293 SDL_Quit(); 300 return (0);
294 return(0); 301 }
295 } 302
296 303 src = SDL_CreateRGBSurface (srcflags, srcw, srch, srcbpp,
297 src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp, 304 srcrmask, srcgmask, srcbmask, srcamask);
298 srcrmask, srcgmask, srcbmask, srcamask); 305 if (src == NULL) {
299 if (src == NULL) 306 fprintf (stderr, "src surface creation failed: %s\n",
300 { 307 SDL_GetError ());
301 fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError()); 308 SDL_Quit ();
302 SDL_Quit(); 309 return (0);
303 return(0);
304 } 310 }
305 311
306 /* handle alpha settings... */ 312 /* handle alpha settings... */
307 srcalphaflags = (src->flags&SDL_SRCALPHA) | (src->flags&SDL_RLEACCEL); 313 srcalphaflags = (src->flags & SDL_SRCALPHA) | (src->flags & SDL_RLEACCEL);
308 dstalphaflags = (dest->flags&SDL_SRCALPHA) | (dest->flags&SDL_RLEACCEL); 314 dstalphaflags =
315 (dest->flags & SDL_SRCALPHA) | (dest->flags & SDL_RLEACCEL);
309 origsrcalphaflags = srcalphaflags; 316 origsrcalphaflags = srcalphaflags;
310 origdstalphaflags = dstalphaflags; 317 origdstalphaflags = dstalphaflags;
311 srcalpha = src->format->alpha; 318 srcalpha = src->format->alpha;
312 dstalpha = dest->format->alpha; 319 dstalpha = dest->format->alpha;
313 for (i = 1; i < argc; i++) 320 for (i = 1; i < argc; i++) {
314 {
315 const char *arg = argv[i]; 321 const char *arg = argv[i];
316 322
317 if (strcmp(arg, "--srcalpha") == 0) 323 if (strcmp (arg, "--srcalpha") == 0)
318 srcalpha = atoi(argv[++i]); 324 srcalpha = atoi (argv[++i]);
319 else if (strcmp(arg, "--dstalpha") == 0) 325 else if (strcmp (arg, "--dstalpha") == 0)
320 dstalpha = atoi(argv[++i]); 326 dstalpha = atoi (argv[++i]);
321 else if (strcmp(arg, "--srcsrcalpha") == 0) 327 else if (strcmp (arg, "--srcsrcalpha") == 0)
322 srcalphaflags |= SDL_SRCALPHA; 328 srcalphaflags |= SDL_SRCALPHA;
323 else if (strcmp(arg, "--srcnosrcalpha") == 0) 329 else if (strcmp (arg, "--srcnosrcalpha") == 0)
324 srcalphaflags &= ~SDL_SRCALPHA; 330 srcalphaflags &= ~SDL_SRCALPHA;
325 else if (strcmp(arg, "--srcrleaccel") == 0) 331 else if (strcmp (arg, "--srcrleaccel") == 0)
326 srcalphaflags |= SDL_RLEACCEL; 332 srcalphaflags |= SDL_RLEACCEL;
327 else if (strcmp(arg, "--srcnorleaccel") == 0) 333 else if (strcmp (arg, "--srcnorleaccel") == 0)
328 srcalphaflags &= ~SDL_RLEACCEL; 334 srcalphaflags &= ~SDL_RLEACCEL;
329 else if (strcmp(arg, "--dstsrcalpha") == 0) 335 else if (strcmp (arg, "--dstsrcalpha") == 0)
330 dstalphaflags |= SDL_SRCALPHA; 336 dstalphaflags |= SDL_SRCALPHA;
331 else if (strcmp(arg, "--dstnosrcalpha") == 0) 337 else if (strcmp (arg, "--dstnosrcalpha") == 0)
332 dstalphaflags &= ~SDL_SRCALPHA; 338 dstalphaflags &= ~SDL_SRCALPHA;
333 else if (strcmp(arg, "--dstrleaccel") == 0) 339 else if (strcmp (arg, "--dstrleaccel") == 0)
334 dstalphaflags |= SDL_RLEACCEL; 340 dstalphaflags |= SDL_RLEACCEL;
335 else if (strcmp(arg, "--dstnorleaccel") == 0) 341 else if (strcmp (arg, "--dstnorleaccel") == 0)
336 dstalphaflags &= ~SDL_RLEACCEL; 342 dstalphaflags &= ~SDL_RLEACCEL;
337 } 343 }
338 if ((dstalphaflags != origdstalphaflags) || (dstalpha != dest->format->alpha)) 344 if ((dstalphaflags != origdstalphaflags)
339 SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha); 345 || (dstalpha != dest->format->alpha))
340 if ((srcalphaflags != origsrcalphaflags) || (srcalpha != src->format->alpha)) 346 SDL_SetAlpha (dest, dstalphaflags, (Uint8) dstalpha);
341 SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha); 347 if ((srcalphaflags != origsrcalphaflags)
348 || (srcalpha != src->format->alpha))
349 SDL_SetAlpha (src, srcalphaflags, (Uint8) srcalpha);
342 350
343 /* set some sane defaults so we can see if the blit code is broken... */ 351 /* set some sane defaults so we can see if the blit code is broken... */
344 SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); 352 SDL_FillRect (dest, NULL, SDL_MapRGB (dest->format, 0, 0, 0));
345 SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0)); 353 SDL_FillRect (src, NULL, SDL_MapRGB (src->format, 0, 0, 0));
346 354
347 blitCentered(src, bmp); 355 blitCentered (src, bmp);
348 SDL_FreeSurface(bmp); 356 SDL_FreeSurface (bmp);
349 357
350 if (dumpfile) 358 if (dumpfile)
351 SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */ 359 SDL_SaveBMP (src, dumpfile); /* make sure initial convert is sane. */
352 360
353 output_details(); 361 output_details ();
354 362
355 return(1); 363 return (1);
356 } 364 }
357 365
358 366
359 static void test_blit_speed(void) 367 static void
360 { 368 test_blit_speed (void)
361 Uint32 clearColor = SDL_MapRGB(dest->format, 0, 0, 0); 369 {
370 Uint32 clearColor = SDL_MapRGB (dest->format, 0, 0, 0);
362 Uint32 iterations = 0; 371 Uint32 iterations = 0;
363 Uint32 elasped = 0; 372 Uint32 elasped = 0;
364 Uint32 end = 0; 373 Uint32 end = 0;
365 Uint32 now = 0; 374 Uint32 now = 0;
366 Uint32 last = 0; 375 Uint32 last = 0;
367 int testms = testSeconds * 1000; 376 int testms = testSeconds * 1000;
368 int wmax = (dest->w - src->w); 377 int wmax = (dest->w - src->w);
369 int hmax = (dest->h - src->h); 378 int hmax = (dest->h - src->h);
370 int isScreen = (SDL_GetVideoSurface() == dest); 379 int isScreen = (SDL_GetVideoSurface () == dest);
371 SDL_Event event; 380 SDL_Event event;
372 381
373 printf("Testing blit speed for %d seconds...\n", testSeconds); 382 printf ("Testing blit speed for %d seconds...\n", testSeconds);
374 383
375 now = SDL_GetTicks(); 384 now = SDL_GetTicks ();
376 end = now + testms; 385 end = now + testms;
377 386
378 do 387 do {
379 {
380 /* pump the event queue occasionally to keep OS happy... */ 388 /* pump the event queue occasionally to keep OS happy... */
381 if (now - last > 1000) 389 if (now - last > 1000) {
382 {
383 last = now; 390 last = now;
384 while (SDL_PollEvent(&event)) { /* no-op. */ } 391 while (SDL_PollEvent (&event)) { /* no-op. */
392 }
385 } 393 }
386 394
387 iterations++; 395 iterations++;
388 elasped += blit(dest, src, randRange(0, wmax), randRange(0, hmax)); 396 elasped += blit (dest, src, randRange (0, wmax), randRange (0, hmax));
389 if (isScreen) 397 if (isScreen) {
390 { 398 SDL_Flip (dest); /* show it! */
391 SDL_Flip(dest); /* show it! */ 399 SDL_FillRect (dest, NULL, clearColor); /* blank it for next time! */
392 SDL_FillRect(dest, NULL, clearColor); /* blank it for next time! */
393 } 400 }
394 401
395 now = SDL_GetTicks(); 402 now = SDL_GetTicks ();
396 } while (now < end); 403 }
397 404 while (now < end);
398 printf("Non-blitting crap accounted for %d percent of this run.\n", 405
399 percent(testms - elasped, testms)); 406 printf ("Non-blitting crap accounted for %d percent of this run.\n",
400 407 percent (testms - elasped, testms));
401 printf("%d blits took %d ms (%d fps).\n", 408
409 printf ("%d blits took %d ms (%d fps).\n",
402 (int) iterations, 410 (int) iterations,
403 (int) elasped, 411 (int) elasped,
404 (int) (((float)iterations) / (((float)elasped) / 1000.0f))); 412 (int) (((float) iterations) / (((float) elasped) / 1000.0f)));
405 } 413 }
406 414
407 int main(int argc, char **argv) 415 int
408 { 416 main (int argc, char **argv)
409 int initialized = setup_test(argc, argv); 417 {
410 if (initialized) 418 int initialized = setup_test (argc, argv);
411 { 419 if (initialized) {
412 test_blit_speed(); 420 test_blit_speed ();
413 SDL_Quit(); 421 SDL_Quit ();
414 } 422 }
415 return(!initialized); 423 return (!initialized);
416 } 424 }
417 425
418 /* end of testblitspeed.c ... */ 426 /* end of testblitspeed.c ... */
419