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