2 /* Simple program -- figure out what kind of video display we have */
12 #define NUM_UPDATES 500
14 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \
15 SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \
18 void PrintFlags(Uint32 flags)
20 printf("0x%8.8x", (flags & FLAG_MASK));
21 if ( flags & SDL_HWSURFACE ) {
22 printf(" SDL_HWSURFACE");
24 printf(" SDL_SWSURFACE");
26 if ( flags & SDL_FULLSCREEN ) {
27 printf(" | SDL_FULLSCREEN");
29 if ( flags & SDL_DOUBLEBUF ) {
30 printf(" | SDL_DOUBLEBUF");
32 if ( flags & SDL_SRCCOLORKEY ) {
33 printf(" | SDL_SRCCOLORKEY");
35 if ( flags & SDL_SRCALPHA ) {
36 printf(" | SDL_SRCALPHA");
38 if ( flags & SDL_RLEACCEL ) {
39 printf(" | SDL_RLEACCEL");
41 if ( flags & SDL_RLEACCELOK ) {
42 printf(" | SDL_RLEACCELOK");
46 int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
53 maxx = (int)screen->w - bmp->w + 1;
54 maxy = (int)screen->h - bmp->h + 1;
55 for ( i = 0; i < NUM_UPDATES; ++i ) {
56 for ( j = 0; j < blitcount; ++j ) {
58 dst.x = rand() % maxx;
63 dst.y = rand() % maxy;
69 SDL_BlitSurface(bmp, NULL, screen, &dst);
77 int RunModeTests(SDL_Surface *screen)
84 SDL_Surface *bmp, *bmpcc, *tmp;
87 while ( SDL_PollEvent(&event) ) {
88 if ( event.type == SDL_KEYDOWN )
92 /* First test fills and screen update speed */
93 printf("Running color fill and fullscreen update test\n");
94 then = SDL_GetTicks();
96 for ( i = 0; i < 256; ++i ) {
100 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
104 for ( i = 0; i < 256; ++i ) {
108 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
112 for ( i = 0; i < 256; ++i ) {
116 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
120 now = SDL_GetTicks();
121 seconds = (float)(now - then) / 1000.0f;
122 if ( seconds > 0.0f ) {
123 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
125 printf("%d fills and flips in zero seconds!n", frames);
128 /* clear the screen after fill test */
129 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
132 while ( SDL_PollEvent(&event) ) {
133 if ( event.type == SDL_KEYDOWN )
137 /* run the generic blit test */
138 bmp = SDL_LoadBMP("sample.bmp");
140 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
143 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
144 bmp->w, bmp->h, bmp->format->BitsPerPixel);
145 PrintFlags(bmp->flags);
147 then = SDL_GetTicks();
148 frames = RunBlitTests(screen, bmp, NUM_BLITS);
149 now = SDL_GetTicks();
150 seconds = (float)(now - then) / 1000.0f;
151 if ( seconds > 0.0f ) {
152 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
154 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
157 /* clear the screen after blit test */
158 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
161 while ( SDL_PollEvent(&event) ) {
162 if ( event.type == SDL_KEYDOWN )
166 /* run the colorkeyed blit test */
167 bmpcc = SDL_LoadBMP("sample.bmp");
169 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
172 printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ",
173 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
174 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
176 PrintFlags(bmpcc->flags);
178 then = SDL_GetTicks();
179 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
180 now = SDL_GetTicks();
181 seconds = (float)(now - then) / 1000.0f;
182 if ( seconds > 0.0f ) {
183 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
185 printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
188 /* clear the screen after cc blit test */
189 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
192 while ( SDL_PollEvent(&event) ) {
193 if ( event.type == SDL_KEYDOWN )
197 /* run the generic blit test */
199 bmp = SDL_DisplayFormat(bmp);
200 SDL_FreeSurface(tmp);
202 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
205 printf("Running display format blit test: %dx%d at %d bpp, flags: ",
206 bmp->w, bmp->h, bmp->format->BitsPerPixel);
207 PrintFlags(bmp->flags);
209 then = SDL_GetTicks();
210 frames = RunBlitTests(screen, bmp, NUM_BLITS);
211 now = SDL_GetTicks();
212 seconds = (float)(now - then) / 1000.0f;
213 if ( seconds > 0.0f ) {
214 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
216 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
219 /* clear the screen after blit test */
220 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
223 while ( SDL_PollEvent(&event) ) {
224 if ( event.type == SDL_KEYDOWN )
228 /* run the colorkeyed blit test */
230 bmpcc = SDL_DisplayFormat(bmpcc);
231 SDL_FreeSurface(tmp);
233 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
236 printf("Running display format cc blit test: %dx%d at %d bpp, flags: ",
237 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
238 PrintFlags(bmpcc->flags);
240 then = SDL_GetTicks();
241 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
242 now = SDL_GetTicks();
243 seconds = (float)(now - then) / 1000.0f;
244 if ( seconds > 0.0f ) {
245 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
247 printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
250 /* clear the screen after cc blit test */
251 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
254 while ( SDL_PollEvent(&event) ) {
255 if ( event.type == SDL_KEYDOWN )
259 /* run the alpha blit test only if screen bpp>8 */
260 if (bmp->format->BitsPerPixel>8)
262 SDL_FreeSurface(bmp);
263 bmp = SDL_LoadBMP("sample.bmp");
264 SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
266 bmp = SDL_DisplayFormat(bmp);
267 SDL_FreeSurface(tmp);
269 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
272 printf("Running display format alpha blit test: %dx%d at %d bpp, flags: ",
273 bmp->w, bmp->h, bmp->format->BitsPerPixel);
274 PrintFlags(bmp->flags);
276 then = SDL_GetTicks();
277 frames = RunBlitTests(screen, bmp, NUM_BLITS);
278 now = SDL_GetTicks();
279 seconds = (float)(now - then) / 1000.0f;
280 if ( seconds > 0.0f ) {
281 printf("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
283 printf("%d alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
287 /* clear the screen after alpha blit test */
288 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
291 while ( SDL_PollEvent(&event) ) {
292 if ( event.type == SDL_KEYDOWN )
296 /* run the cc+alpha blit test only if screen bpp>8 */
297 if (bmp->format->BitsPerPixel>8)
299 SDL_FreeSurface(bmpcc);
300 bmpcc = SDL_LoadBMP("sample.bmp");
301 SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */
302 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
304 bmpcc = SDL_DisplayFormat(bmpcc);
305 SDL_FreeSurface(tmp);
307 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
310 printf("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ",
311 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
312 PrintFlags(bmpcc->flags);
314 then = SDL_GetTicks();
315 frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
316 now = SDL_GetTicks();
317 seconds = (float)(now - then) / 1000.0f;
318 if ( seconds > 0.0f ) {
319 printf("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
321 printf("%d cc+alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
325 SDL_FreeSurface(bmpcc);
326 SDL_FreeSurface(bmp);
328 while ( SDL_PollEvent(&event) ) {
329 if ( event.type == SDL_KEYDOWN )
337 static const struct {
340 { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 },
341 { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 },
342 { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 }
344 static const Uint32 flags[] = {
346 (SDL_SWSURFACE | SDL_FULLSCREEN),
347 (SDL_HWSURFACE | SDL_FULLSCREEN),
348 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
353 /* Test out several different video mode combinations */
354 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
356 for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
357 for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
358 printf("===================================\n");
359 printf("Setting video mode: %dx%d at %d bpp, flags: ",
363 PrintFlags(flags[j]);
365 screen = SDL_SetVideoMode(mode_list[i].w,
370 printf("Setting video mode failed: %s\n", SDL_GetError());
373 if ( (screen->flags & FLAG_MASK) != flags[j] ) {
374 printf("Flags didn't match: ");
375 PrintFlags(screen->flags);
379 if ( ! RunModeTests(screen) ) {
386 int main(int argc, char *argv[])
388 const SDL_VideoInfo *info;
393 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
395 "Couldn't initialize SDL: %s\n", SDL_GetError());
398 if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
399 printf("Video driver: %s\n", driver);
401 info = SDL_GetVideoInfo();
403 "Current display: %dx%d, %d bits-per-pixel\n",
404 info->current_w, info->current_h, info->vfmt->BitsPerPixel);
405 if ( info->vfmt->palette == NULL ) {
406 printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
407 printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);
408 printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
410 /* Print available fullscreen video modes */
411 modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
412 if ( modes == (SDL_Rect **)0 ) {
413 printf("No available fullscreen video modes\n");
415 if ( modes == (SDL_Rect **)-1 ) {
416 printf("No special fullscreen video modes\n");
418 printf("Fullscreen video modes:\n");
419 for ( i=0; modes[i]; ++i ) {
420 printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
423 if ( info->wm_available ) {
424 printf("A window manager is available\n");
426 if ( info->hw_available ) {
427 printf("Hardware surfaces are available (%dK video memory)\n",
430 if ( info->blit_hw ) {
432 "Copy blits between hardware surfaces are accelerated\n");
434 if ( info->blit_hw_CC ) {
436 "Colorkey blits between hardware surfaces are accelerated\n");
438 if ( info->blit_hw_A ) {
440 "Alpha blits between hardware surfaces are accelerated\n");
442 if ( info->blit_sw ) {
444 "Copy blits from software surfaces to hardware surfaces are accelerated\n");
446 if ( info->blit_sw_CC ) {
448 "Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
450 if ( info->blit_sw_A ) {
452 "Alpha blits from software surfaces to hardware surfaces are accelerated\n");
454 if ( info->blit_fill ) {
456 "Color fills on hardware surfaces are accelerated\n");
459 if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {