comparison test/testvidinfo.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 98a3207ddde8
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
15 SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \ 15 SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \
16 SDL_RLEACCELOK) 16 SDL_RLEACCELOK)
17 17
18 #if 0 18 #if 0
19 void 19 void
20 PrintFlags (Uint32 flags) 20 PrintFlags(Uint32 flags)
21 { 21 {
22 printf ("0x%8.8x", (flags & FLAG_MASK)); 22 printf("0x%8.8x", (flags & FLAG_MASK));
23 if (flags & SDL_HWSURFACE) { 23 if (flags & SDL_HWSURFACE) {
24 printf (" SDL_HWSURFACE"); 24 printf(" SDL_HWSURFACE");
25 } else { 25 } else {
26 printf (" SDL_SWSURFACE"); 26 printf(" SDL_SWSURFACE");
27 } 27 }
28 if (flags & SDL_FULLSCREEN) { 28 if (flags & SDL_FULLSCREEN) {
29 printf (" | SDL_FULLSCREEN"); 29 printf(" | SDL_FULLSCREEN");
30 } 30 }
31 if (flags & SDL_DOUBLEBUF) { 31 if (flags & SDL_DOUBLEBUF) {
32 printf (" | SDL_DOUBLEBUF"); 32 printf(" | SDL_DOUBLEBUF");
33 } 33 }
34 if (flags & SDL_SRCCOLORKEY) { 34 if (flags & SDL_SRCCOLORKEY) {
35 printf (" | SDL_SRCCOLORKEY"); 35 printf(" | SDL_SRCCOLORKEY");
36 } 36 }
37 if (flags & SDL_SRCALPHA) { 37 if (flags & SDL_SRCALPHA) {
38 printf (" | SDL_SRCALPHA"); 38 printf(" | SDL_SRCALPHA");
39 } 39 }
40 if (flags & SDL_RLEACCEL) { 40 if (flags & SDL_RLEACCEL) {
41 printf (" | SDL_RLEACCEL"); 41 printf(" | SDL_RLEACCEL");
42 } 42 }
43 if (flags & SDL_RLEACCELOK) { 43 if (flags & SDL_RLEACCELOK) {
44 printf (" | SDL_RLEACCELOK"); 44 printf(" | SDL_RLEACCELOK");
45 } 45 }
46 } 46 }
47 47
48 int 48 int
49 RunBlitTests (SDL_Surface * screen, SDL_Surface * bmp, int blitcount) 49 RunBlitTests(SDL_Surface * screen, SDL_Surface * bmp, int blitcount)
50 { 50 {
51 int i, j; 51 int i, j;
52 int maxx; 52 int maxx;
53 int maxy; 53 int maxy;
54 SDL_Rect dst; 54 SDL_Rect dst;
56 maxx = (int) screen->w - bmp->w + 1; 56 maxx = (int) screen->w - bmp->w + 1;
57 maxy = (int) screen->h - bmp->h + 1; 57 maxy = (int) screen->h - bmp->h + 1;
58 for (i = 0; i < NUM_UPDATES; ++i) { 58 for (i = 0; i < NUM_UPDATES; ++i) {
59 for (j = 0; j < blitcount; ++j) { 59 for (j = 0; j < blitcount; ++j) {
60 if (maxx) { 60 if (maxx) {
61 dst.x = rand () % maxx; 61 dst.x = rand() % maxx;
62 } else { 62 } else {
63 dst.x = 0; 63 dst.x = 0;
64 } 64 }
65 if (maxy) { 65 if (maxy) {
66 dst.y = rand () % maxy; 66 dst.y = rand() % maxy;
67 } else { 67 } else {
68 dst.y = 0; 68 dst.y = 0;
69 } 69 }
70 dst.w = bmp->w; 70 dst.w = bmp->w;
71 dst.h = bmp->h; 71 dst.h = bmp->h;
72 SDL_BlitSurface (bmp, NULL, screen, &dst); 72 SDL_BlitSurface(bmp, NULL, screen, &dst);
73 } 73 }
74 SDL_Flip (screen); 74 SDL_Flip(screen);
75 } 75 }
76 76
77 return i; 77 return i;
78 } 78 }
79 79
80 int 80 int
81 RunModeTests (SDL_Surface * screen) 81 RunModeTests(SDL_Surface * screen)
82 { 82 {
83 Uint32 then, now; 83 Uint32 then, now;
84 Uint32 frames; 84 Uint32 frames;
85 float seconds; 85 float seconds;
86 int i; 86 int i;
87 Uint8 r, g, b; 87 Uint8 r, g, b;
88 SDL_Surface *bmp, *bmpcc, *tmp; 88 SDL_Surface *bmp, *bmpcc, *tmp;
89 SDL_Event event; 89 SDL_Event event;
90 90
91 while (SDL_PollEvent (&event)) { 91 while (SDL_PollEvent(&event)) {
92 if (event.type == SDL_KEYDOWN) 92 if (event.type == SDL_KEYDOWN)
93 return 0; 93 return 0;
94 } 94 }
95 95
96 /* First test fills and screen update speed */ 96 /* First test fills and screen update speed */
97 printf ("Running color fill and fullscreen update test\n"); 97 printf("Running color fill and fullscreen update test\n");
98 then = SDL_GetTicks (); 98 then = SDL_GetTicks();
99 frames = 0; 99 frames = 0;
100 for (i = 0; i < 256; ++i) { 100 for (i = 0; i < 256; ++i) {
101 r = i; 101 r = i;
102 g = 0; 102 g = 0;
103 b = 0; 103 b = 0;
104 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, r, g, b)); 104 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
105 SDL_Flip (screen); 105 SDL_Flip(screen);
106 ++frames; 106 ++frames;
107 } 107 }
108 for (i = 0; i < 256; ++i) { 108 for (i = 0; i < 256; ++i) {
109 r = 0; 109 r = 0;
110 g = i; 110 g = i;
111 b = 0; 111 b = 0;
112 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, r, g, b)); 112 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
113 SDL_Flip (screen); 113 SDL_Flip(screen);
114 ++frames; 114 ++frames;
115 } 115 }
116 for (i = 0; i < 256; ++i) { 116 for (i = 0; i < 256; ++i) {
117 r = 0; 117 r = 0;
118 g = 0; 118 g = 0;
119 b = i; 119 b = i;
120 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, r, g, b)); 120 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
121 SDL_Flip (screen); 121 SDL_Flip(screen);
122 ++frames; 122 ++frames;
123 } 123 }
124 now = SDL_GetTicks (); 124 now = SDL_GetTicks();
125 seconds = (float) (now - then) / 1000.0f; 125 seconds = (float) (now - then) / 1000.0f;
126 if (seconds > 0.0f) { 126 if (seconds > 0.0f) {
127 printf ("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, 127 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames,
128 seconds, (float) frames / seconds); 128 seconds, (float) frames / seconds);
129 } else { 129 } else {
130 printf ("%d fills and flips in zero seconds!n", frames); 130 printf("%d fills and flips in zero seconds!n", frames);
131 } 131 }
132 132
133 /* clear the screen after fill test */ 133 /* clear the screen after fill test */
134 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 134 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
135 SDL_Flip (screen); 135 SDL_Flip(screen);
136 136
137 while (SDL_PollEvent (&event)) { 137 while (SDL_PollEvent(&event)) {
138 if (event.type == SDL_KEYDOWN) 138 if (event.type == SDL_KEYDOWN)
139 return 0; 139 return 0;
140 } 140 }
141 141
142 /* run the generic blit test */ 142 /* run the generic blit test */
143 bmp = SDL_LoadBMP ("sample.bmp"); 143 bmp = SDL_LoadBMP("sample.bmp");
144 if (!bmp) { 144 if (!bmp) {
145 printf ("Couldn't load sample.bmp: %s\n", SDL_GetError ()); 145 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
146 return 0; 146 return 0;
147 } 147 }
148 printf ("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", 148 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
149 bmp->w, bmp->h, bmp->format->BitsPerPixel); 149 bmp->w, bmp->h, bmp->format->BitsPerPixel);
150 PrintFlags (bmp->flags); 150 PrintFlags(bmp->flags);
151 printf ("\n"); 151 printf("\n");
152 then = SDL_GetTicks (); 152 then = SDL_GetTicks();
153 frames = RunBlitTests (screen, bmp, NUM_BLITS); 153 frames = RunBlitTests(screen, bmp, NUM_BLITS);
154 now = SDL_GetTicks (); 154 now = SDL_GetTicks();
155 seconds = (float) (now - then) / 1000.0f; 155 seconds = (float) (now - then) / 1000.0f;
156 if (seconds > 0.0f) { 156 if (seconds > 0.0f) {
157 printf ("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", 157 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n",
158 NUM_BLITS * frames, frames, seconds, 158 NUM_BLITS * frames, frames, seconds, (float) frames / seconds);
159 (float) frames / seconds); 159 } else {
160 } else { 160 printf("%d blits / %d updates in zero seconds!\n",
161 printf ("%d blits / %d updates in zero seconds!\n", 161 NUM_BLITS * frames, frames);
162 NUM_BLITS * frames, frames);
163 } 162 }
164 163
165 /* clear the screen after blit test */ 164 /* clear the screen after blit test */
166 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 165 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
167 SDL_Flip (screen); 166 SDL_Flip(screen);
168 167
169 while (SDL_PollEvent (&event)) { 168 while (SDL_PollEvent(&event)) {
170 if (event.type == SDL_KEYDOWN) 169 if (event.type == SDL_KEYDOWN)
171 return 0; 170 return 0;
172 } 171 }
173 172
174 /* run the colorkeyed blit test */ 173 /* run the colorkeyed blit test */
175 bmpcc = SDL_LoadBMP ("sample.bmp"); 174 bmpcc = SDL_LoadBMP("sample.bmp");
176 if (!bmpcc) { 175 if (!bmpcc) {
177 printf ("Couldn't load sample.bmp: %s\n", SDL_GetError ()); 176 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
178 return 0; 177 return 0;
179 } 178 }
180 printf ("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", 179 printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ",
181 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); 180 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
182 SDL_SetColorKey (bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, 181 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL,
183 *(Uint8 *) bmpcc->pixels); 182 *(Uint8 *) bmpcc->pixels);
184 183
185 PrintFlags (bmpcc->flags); 184 PrintFlags(bmpcc->flags);
186 printf ("\n"); 185 printf("\n");
187 then = SDL_GetTicks (); 186 then = SDL_GetTicks();
188 frames = RunBlitTests (screen, bmpcc, NUM_BLITS); 187 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
189 now = SDL_GetTicks (); 188 now = SDL_GetTicks();
190 seconds = (float) (now - then) / 1000.0f; 189 seconds = (float) (now - then) / 1000.0f;
191 if (seconds > 0.0f) { 190 if (seconds > 0.0f) {
192 printf ("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", 191 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n",
193 NUM_BLITS * frames, frames, seconds, 192 NUM_BLITS * frames, frames, seconds, (float) frames / seconds);
194 (float) frames / seconds); 193 } else {
195 } else { 194 printf("%d cc blits / %d updates in zero seconds!\n",
196 printf ("%d cc blits / %d updates in zero seconds!\n", 195 NUM_BLITS * frames, frames);
197 NUM_BLITS * frames, frames);
198 } 196 }
199 197
200 /* clear the screen after cc blit test */ 198 /* clear the screen after cc blit test */
201 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 199 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
202 SDL_Flip (screen); 200 SDL_Flip(screen);
203 201
204 while (SDL_PollEvent (&event)) { 202 while (SDL_PollEvent(&event)) {
205 if (event.type == SDL_KEYDOWN) 203 if (event.type == SDL_KEYDOWN)
206 return 0; 204 return 0;
207 } 205 }
208 206
209 /* run the generic blit test */ 207 /* run the generic blit test */
210 tmp = bmp; 208 tmp = bmp;
211 bmp = SDL_DisplayFormat (bmp); 209 bmp = SDL_DisplayFormat(bmp);
212 SDL_FreeSurface (tmp); 210 SDL_FreeSurface(tmp);
213 if (!bmp) { 211 if (!bmp) {
214 printf ("Couldn't convert sample.bmp: %s\n", SDL_GetError ()); 212 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
215 return 0; 213 return 0;
216 } 214 }
217 printf ("Running display format blit test: %dx%d at %d bpp, flags: ", 215 printf("Running display format blit test: %dx%d at %d bpp, flags: ",
218 bmp->w, bmp->h, bmp->format->BitsPerPixel); 216 bmp->w, bmp->h, bmp->format->BitsPerPixel);
219 PrintFlags (bmp->flags); 217 PrintFlags(bmp->flags);
220 printf ("\n"); 218 printf("\n");
221 then = SDL_GetTicks (); 219 then = SDL_GetTicks();
222 frames = RunBlitTests (screen, bmp, NUM_BLITS); 220 frames = RunBlitTests(screen, bmp, NUM_BLITS);
223 now = SDL_GetTicks (); 221 now = SDL_GetTicks();
224 seconds = (float) (now - then) / 1000.0f; 222 seconds = (float) (now - then) / 1000.0f;
225 if (seconds > 0.0f) { 223 if (seconds > 0.0f) {
226 printf ("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", 224 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n",
227 NUM_BLITS * frames, frames, seconds, 225 NUM_BLITS * frames, frames, seconds, (float) frames / seconds);
228 (float) frames / seconds); 226 } else {
229 } else { 227 printf("%d blits / %d updates in zero seconds!\n",
230 printf ("%d blits / %d updates in zero seconds!\n", 228 NUM_BLITS * frames, frames);
231 NUM_BLITS * frames, frames);
232 } 229 }
233 230
234 /* clear the screen after blit test */ 231 /* clear the screen after blit test */
235 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 232 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
236 SDL_Flip (screen); 233 SDL_Flip(screen);
237 234
238 while (SDL_PollEvent (&event)) { 235 while (SDL_PollEvent(&event)) {
239 if (event.type == SDL_KEYDOWN) 236 if (event.type == SDL_KEYDOWN)
240 return 0; 237 return 0;
241 } 238 }
242 239
243 /* run the colorkeyed blit test */ 240 /* run the colorkeyed blit test */
244 tmp = bmpcc; 241 tmp = bmpcc;
245 bmpcc = SDL_DisplayFormat (bmpcc); 242 bmpcc = SDL_DisplayFormat(bmpcc);
246 SDL_FreeSurface (tmp); 243 SDL_FreeSurface(tmp);
247 if (!bmpcc) { 244 if (!bmpcc) {
248 printf ("Couldn't convert sample.bmp: %s\n", SDL_GetError ()); 245 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
249 return 0; 246 return 0;
250 } 247 }
251 printf ("Running display format cc blit test: %dx%d at %d bpp, flags: ", 248 printf("Running display format cc blit test: %dx%d at %d bpp, flags: ",
252 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); 249 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
253 PrintFlags (bmpcc->flags); 250 PrintFlags(bmpcc->flags);
254 printf ("\n"); 251 printf("\n");
255 then = SDL_GetTicks (); 252 then = SDL_GetTicks();
256 frames = RunBlitTests (screen, bmpcc, NUM_BLITS); 253 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
257 now = SDL_GetTicks (); 254 now = SDL_GetTicks();
258 seconds = (float) (now - then) / 1000.0f; 255 seconds = (float) (now - then) / 1000.0f;
259 if (seconds > 0.0f) { 256 if (seconds > 0.0f) {
260 printf ("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", 257 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n",
261 NUM_BLITS * frames, frames, seconds, 258 NUM_BLITS * frames, frames, seconds, (float) frames / seconds);
262 (float) frames / seconds); 259 } else {
263 } else { 260 printf("%d cc blits / %d updates in zero seconds!\n",
264 printf ("%d cc blits / %d updates in zero seconds!\n", 261 NUM_BLITS * frames, frames);
265 NUM_BLITS * frames, frames);
266 } 262 }
267 263
268 /* clear the screen after cc blit test */ 264 /* clear the screen after cc blit test */
269 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 265 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
270 SDL_Flip (screen); 266 SDL_Flip(screen);
271 267
272 while (SDL_PollEvent (&event)) { 268 while (SDL_PollEvent(&event)) {
273 if (event.type == SDL_KEYDOWN) 269 if (event.type == SDL_KEYDOWN)
274 return 0; 270 return 0;
275 } 271 }
276 272
277 /* run the alpha blit test only if screen bpp>8 */ 273 /* run the alpha blit test only if screen bpp>8 */
278 if (bmp->format->BitsPerPixel > 8) { 274 if (bmp->format->BitsPerPixel > 8) {
279 SDL_FreeSurface (bmp); 275 SDL_FreeSurface(bmp);
280 bmp = SDL_LoadBMP ("sample.bmp"); 276 bmp = SDL_LoadBMP("sample.bmp");
281 SDL_SetAlpha (bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ 277 SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
282 tmp = bmp; 278 tmp = bmp;
283 bmp = SDL_DisplayFormat (bmp); 279 bmp = SDL_DisplayFormat(bmp);
284 SDL_FreeSurface (tmp); 280 SDL_FreeSurface(tmp);
285 if (!bmp) { 281 if (!bmp) {
286 printf ("Couldn't convert sample.bmp: %s\n", SDL_GetError ()); 282 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
287 return 0; 283 return 0;
288 } 284 }
289 printf 285 printf
290 ("Running display format alpha blit test: %dx%d at %d bpp, flags: ", 286 ("Running display format alpha blit test: %dx%d at %d bpp, flags: ",
291 bmp->w, bmp->h, bmp->format->BitsPerPixel); 287 bmp->w, bmp->h, bmp->format->BitsPerPixel);
292 PrintFlags (bmp->flags); 288 PrintFlags(bmp->flags);
293 printf ("\n"); 289 printf("\n");
294 then = SDL_GetTicks (); 290 then = SDL_GetTicks();
295 frames = RunBlitTests (screen, bmp, NUM_BLITS); 291 frames = RunBlitTests(screen, bmp, NUM_BLITS);
296 now = SDL_GetTicks (); 292 now = SDL_GetTicks();
297 seconds = (float) (now - then) / 1000.0f; 293 seconds = (float) (now - then) / 1000.0f;
298 if (seconds > 0.0f) { 294 if (seconds > 0.0f) {
299 printf 295 printf
300 ("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", 296 ("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n",
301 NUM_BLITS * frames, frames, seconds, 297 NUM_BLITS * frames, frames, seconds,
302 (float) frames / seconds); 298 (float) frames / seconds);
303 } else { 299 } else {
304 printf ("%d alpha blits / %d updates in zero seconds!\n", 300 printf("%d alpha blits / %d updates in zero seconds!\n",
305 NUM_BLITS * frames, frames); 301 NUM_BLITS * frames, frames);
306 } 302 }
307 } 303 }
308 304
309 /* clear the screen after alpha blit test */ 305 /* clear the screen after alpha blit test */
310 SDL_FillRect (screen, NULL, SDL_MapRGB (screen->format, 0, 0, 0)); 306 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
311 SDL_Flip (screen); 307 SDL_Flip(screen);
312 308
313 while (SDL_PollEvent (&event)) { 309 while (SDL_PollEvent(&event)) {
314 if (event.type == SDL_KEYDOWN) 310 if (event.type == SDL_KEYDOWN)
315 return 0; 311 return 0;
316 } 312 }
317 313
318 /* run the cc+alpha blit test only if screen bpp>8 */ 314 /* run the cc+alpha blit test only if screen bpp>8 */
319 if (bmp->format->BitsPerPixel > 8) { 315 if (bmp->format->BitsPerPixel > 8) {
320 SDL_FreeSurface (bmpcc); 316 SDL_FreeSurface(bmpcc);
321 bmpcc = SDL_LoadBMP ("sample.bmp"); 317 bmpcc = SDL_LoadBMP("sample.bmp");
322 SDL_SetAlpha (bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ 318 SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
323 SDL_SetColorKey (bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, 319 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL,
324 *(Uint8 *) bmpcc->pixels); 320 *(Uint8 *) bmpcc->pixels);
325 tmp = bmpcc; 321 tmp = bmpcc;
326 bmpcc = SDL_DisplayFormat (bmpcc); 322 bmpcc = SDL_DisplayFormat(bmpcc);
327 SDL_FreeSurface (tmp); 323 SDL_FreeSurface(tmp);
328 if (!bmpcc) { 324 if (!bmpcc) {
329 printf ("Couldn't convert sample.bmp: %s\n", SDL_GetError ()); 325 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
330 return 0; 326 return 0;
331 } 327 }
332 printf 328 printf
333 ("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ", 329 ("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ",
334 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); 330 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
335 PrintFlags (bmpcc->flags); 331 PrintFlags(bmpcc->flags);
336 printf ("\n"); 332 printf("\n");
337 then = SDL_GetTicks (); 333 then = SDL_GetTicks();
338 frames = RunBlitTests (screen, bmpcc, NUM_BLITS); 334 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
339 now = SDL_GetTicks (); 335 now = SDL_GetTicks();
340 seconds = (float) (now - then) / 1000.0f; 336 seconds = (float) (now - then) / 1000.0f;
341 if (seconds > 0.0f) { 337 if (seconds > 0.0f) {
342 printf 338 printf
343 ("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", 339 ("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n",
344 NUM_BLITS * frames, frames, seconds, 340 NUM_BLITS * frames, frames, seconds,
345 (float) frames / seconds); 341 (float) frames / seconds);
346 } else { 342 } else {
347 printf ("%d cc+alpha blits / %d updates in zero seconds!\n", 343 printf("%d cc+alpha blits / %d updates in zero seconds!\n",
348 NUM_BLITS * frames, frames); 344 NUM_BLITS * frames, frames);
349 } 345 }
350 } 346 }
351 347
352 SDL_FreeSurface (bmpcc); 348 SDL_FreeSurface(bmpcc);
353 SDL_FreeSurface (bmp); 349 SDL_FreeSurface(bmp);
354 350
355 while (SDL_PollEvent (&event)) { 351 while (SDL_PollEvent(&event)) {
356 if (event.type == SDL_KEYDOWN) 352 if (event.type == SDL_KEYDOWN)
357 return 0; 353 return 0;
358 } 354 }
359 return 1; 355 return 1;
360 } 356 }
361 357
362 void 358 void
363 RunVideoTests () 359 RunVideoTests()
364 { 360 {
365 static const struct 361 static const struct
366 { 362 {
367 int w, h, bpp; 363 int w, h, bpp;
368 } mode_list[] = { 364 } mode_list[] = {
385 }; 381 };
386 int i, j; 382 int i, j;
387 SDL_Surface *screen; 383 SDL_Surface *screen;
388 384
389 /* Test out several different video mode combinations */ 385 /* Test out several different video mode combinations */
390 SDL_WM_SetCaption ("SDL Video Benchmark", "vidtest"); 386 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
391 SDL_ShowCursor (0); 387 SDL_ShowCursor(0);
392 for (i = 0; i < SDL_TABLESIZE (mode_list); ++i) { 388 for (i = 0; i < SDL_TABLESIZE(mode_list); ++i) {
393 for (j = 0; j < SDL_TABLESIZE (flags); ++j) { 389 for (j = 0; j < SDL_TABLESIZE(flags); ++j) {
394 printf ("===================================\n"); 390 printf("===================================\n");
395 printf ("Setting video mode: %dx%d at %d bpp, flags: ", 391 printf("Setting video mode: %dx%d at %d bpp, flags: ",
396 mode_list[i].w, mode_list[i].h, mode_list[i].bpp); 392 mode_list[i].w, mode_list[i].h, mode_list[i].bpp);
397 PrintFlags (flags[j]); 393 PrintFlags(flags[j]);
398 printf ("\n"); 394 printf("\n");
399 screen = SDL_SetVideoMode (mode_list[i].w, 395 screen = SDL_SetVideoMode(mode_list[i].w,
400 mode_list[i].h, 396 mode_list[i].h,
401 mode_list[i].bpp, flags[j]); 397 mode_list[i].bpp, flags[j]);
402 if (!screen) { 398 if (!screen) {
403 printf ("Setting video mode failed: %s\n", SDL_GetError ()); 399 printf("Setting video mode failed: %s\n", SDL_GetError());
404 continue; 400 continue;
405 } 401 }
406 if ((screen->flags & FLAG_MASK) != flags[j]) { 402 if ((screen->flags & FLAG_MASK) != flags[j]) {
407 printf ("Flags didn't match: "); 403 printf("Flags didn't match: ");
408 PrintFlags (screen->flags); 404 PrintFlags(screen->flags);
409 printf ("\n"); 405 printf("\n");
410 continue; 406 continue;
411 } 407 }
412 if (!RunModeTests (screen)) { 408 if (!RunModeTests(screen)) {
413 return; 409 return;
414 } 410 }
415 } 411 }
416 } 412 }
417 } 413 }
418 #endif 414 #endif
419 415
420 int 416 int
421 main (int argc, char *argv[]) 417 main(int argc, char *argv[])
422 { 418 {
423 const SDL_VideoInfo *info; 419 const SDL_VideoInfo *info;
424 int i, n; 420 int i, n;
425 const char *driver; 421 const char *driver;
426 const SDL_DisplayMode *mode; 422 const SDL_DisplayMode *mode;
427 int bpp; 423 int bpp;
428 Uint32 Rmask, Gmask, Bmask, Amask; 424 Uint32 Rmask, Gmask, Bmask, Amask;
429 int nmodes; 425 int nmodes;
430 426
431 /* Print available video drivers */ 427 /* Print available video drivers */
432 n = SDL_GetNumVideoDrivers (); 428 n = SDL_GetNumVideoDrivers();
433 if (n == 0) { 429 if (n == 0) {
434 printf ("No built-in video drivers\n"); 430 printf("No built-in video drivers\n");
435 } else { 431 } else {
436 printf ("Built-in video drivers:"); 432 printf("Built-in video drivers:");
437 for (i = 0; i < n; ++i) { 433 for (i = 0; i < n; ++i) {
438 if (i > 0) { 434 if (i > 0) {
439 printf (","); 435 printf(",");
440 } 436 }
441 printf (" %s", SDL_GetVideoDriver (i)); 437 printf(" %s", SDL_GetVideoDriver(i));
442 } 438 }
443 printf ("\n"); 439 printf("\n");
444 } 440 }
445 441
446 if (SDL_Init (SDL_INIT_VIDEO) < 0) { 442 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
447 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 443 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
448 exit (1); 444 exit(1);
449 } 445 }
450 driver = SDL_GetCurrentVideoDriver (); 446 driver = SDL_GetCurrentVideoDriver();
451 if (driver) { 447 if (driver) {
452 printf ("Video driver: %s\n", driver); 448 printf("Video driver: %s\n", driver);
453 } 449 }
454 printf ("Number of displays: %d\n", SDL_GetNumVideoDisplays ()); 450 printf("Number of displays: %d\n", SDL_GetNumVideoDisplays());
455 mode = SDL_GetDesktopDisplayMode (); 451 mode = SDL_GetDesktopDisplayMode();
456 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask, 452 SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
457 &Amask); 453 &Amask);
458 printf ("Current display: %dx%d@%dHz, %d bits-per-pixel\n", mode->w, 454 printf("Current display: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
459 mode->h, mode->refresh_rate, bpp); 455 mode->h, mode->refresh_rate, bpp);
460 if (Rmask || Gmask || Bmask) { 456 if (Rmask || Gmask || Bmask) {
461 printf (" Red Mask = 0x%.8x\n", Rmask); 457 printf(" Red Mask = 0x%.8x\n", Rmask);
462 printf (" Green Mask = 0x%.8x\n", Gmask); 458 printf(" Green Mask = 0x%.8x\n", Gmask);
463 printf (" Blue Mask = 0x%.8x\n", Bmask); 459 printf(" Blue Mask = 0x%.8x\n", Bmask);
464 if (Amask) 460 if (Amask)
465 printf (" Alpha Mask = 0x%.8x\n", Amask); 461 printf(" Alpha Mask = 0x%.8x\n", Amask);
466 } 462 }
467 /* Print available fullscreen video modes */ 463 /* Print available fullscreen video modes */
468 nmodes = SDL_GetNumDisplayModes (); 464 nmodes = SDL_GetNumDisplayModes();
469 if (nmodes == 0) { 465 if (nmodes == 0) {
470 printf ("No available fullscreen video modes\n"); 466 printf("No available fullscreen video modes\n");
471 } else { 467 } else {
472 printf ("Fullscreen video modes:\n"); 468 printf("Fullscreen video modes:\n");
473 for (i = 0; i < nmodes; ++i) { 469 for (i = 0; i < nmodes; ++i) {
474 mode = SDL_GetDisplayMode (i); 470 mode = SDL_GetDisplayMode(i);
475 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, 471 SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
476 &Gmask, &Bmask, &Amask); 472 &Gmask, &Bmask, &Amask);
477 printf ("Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i, 473 printf("Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
478 mode->w, mode->h, mode->refresh_rate, bpp); 474 mode->w, mode->h, mode->refresh_rate, bpp);
479 if (Rmask || Gmask || Bmask) { 475 if (Rmask || Gmask || Bmask) {
480 printf (" Red Mask = 0x%.8x\n", Rmask); 476 printf(" Red Mask = 0x%.8x\n", Rmask);
481 printf (" Green Mask = 0x%.8x\n", Gmask); 477 printf(" Green Mask = 0x%.8x\n", Gmask);
482 printf (" Blue Mask = 0x%.8x\n", Bmask); 478 printf(" Blue Mask = 0x%.8x\n", Bmask);
483 if (Amask) 479 if (Amask)
484 printf (" Alpha Mask = 0x%.8x\n", Amask); 480 printf(" Alpha Mask = 0x%.8x\n", Amask);
485 } 481 }
486 } 482 }
487 } 483 }
488 info = SDL_GetVideoInfo (); 484 info = SDL_GetVideoInfo();
489 if (info->wm_available) { 485 if (info->wm_available) {
490 printf ("A window manager is available\n"); 486 printf("A window manager is available\n");
491 } 487 }
492 if (info->hw_available) { 488 if (info->hw_available) {
493 printf ("Hardware surfaces are available (%dK video memory)\n", 489 printf("Hardware surfaces are available (%dK video memory)\n",
494 info->video_mem); 490 info->video_mem);
495 } 491 }
496 if (info->blit_hw) { 492 if (info->blit_hw) {
497 printf ("Copy blits between hardware surfaces are accelerated\n"); 493 printf("Copy blits between hardware surfaces are accelerated\n");
498 } 494 }
499 if (info->blit_hw_CC) { 495 if (info->blit_hw_CC) {
500 printf ("Colorkey blits between hardware surfaces are accelerated\n"); 496 printf("Colorkey blits between hardware surfaces are accelerated\n");
501 } 497 }
502 if (info->blit_hw_A) { 498 if (info->blit_hw_A) {
503 printf ("Alpha blits between hardware surfaces are accelerated\n"); 499 printf("Alpha blits between hardware surfaces are accelerated\n");
504 } 500 }
505 if (info->blit_sw) { 501 if (info->blit_sw) {
506 printf 502 printf
507 ("Copy blits from software surfaces to hardware surfaces are accelerated\n"); 503 ("Copy blits from software surfaces to hardware surfaces are accelerated\n");
508 } 504 }
513 if (info->blit_sw_A) { 509 if (info->blit_sw_A) {
514 printf 510 printf
515 ("Alpha blits from software surfaces to hardware surfaces are accelerated\n"); 511 ("Alpha blits from software surfaces to hardware surfaces are accelerated\n");
516 } 512 }
517 if (info->blit_fill) { 513 if (info->blit_fill) {
518 printf ("Color fills on hardware surfaces are accelerated\n"); 514 printf("Color fills on hardware surfaces are accelerated\n");
519 } 515 }
520 #if 0 516 #if 0
521 if (argv[1] && (strcmp (argv[1], "-benchmark") == 0)) { 517 if (argv[1] && (strcmp(argv[1], "-benchmark") == 0)) {
522 RunVideoTests (); 518 RunVideoTests();
523 } 519 }
524 #endif 520 #endif
525 521
526 SDL_Quit (); 522 SDL_Quit();
527 return (0); 523 return (0);
528 } 524 }