test/testvidinfo.c
changeset 480 92596bfe8446
parent 479 c0a1744bc2cf
child 482 6417071ba2e5
     1.1 --- a/test/testvidinfo.c	Sat Aug 31 19:48:11 2002 +0000
     1.2 +++ b/test/testvidinfo.c	Sat Aug 31 21:00:28 2002 +0000
     1.3 @@ -7,6 +7,9 @@
     1.4  
     1.5  #include "SDL.h"
     1.6  
     1.7 +#define NUM_BLITS	10
     1.8 +#define NUM_UPDATES	500
     1.9 +
    1.10  #define FLAG_MASK	(SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
    1.11  
    1.12  void PrintFlags(Uint32 flags)
    1.13 @@ -30,49 +33,47 @@
    1.14  	int i, j;
    1.15  	int maxx;
    1.16  	int maxy;
    1.17 -	SDL_Rect *rects;
    1.18 +	SDL_Rect dst;
    1.19  
    1.20 -	rects = (SDL_Rect *)malloc(blitcount * sizeof(*rects));
    1.21 -	if ( ! rects ) {
    1.22 -		return 0;
    1.23 -	}
    1.24 -	maxx = (int)screen->w - bmp->w;
    1.25 -	maxy = (int)screen->h - bmp->h;
    1.26 -	for ( i = 0; i < 100; ++i ) {
    1.27 +	maxx = (int)screen->w - bmp->w + 1;
    1.28 +	maxy = (int)screen->h - bmp->h + 1;
    1.29 +	for ( i = 0; i < NUM_UPDATES; ++i ) {
    1.30  		for ( j = 0; j < blitcount; ++j ) {
    1.31  			if ( maxx ) {
    1.32 -				rects[j].x = rand() % maxx;
    1.33 +				dst.x = rand() % maxx;
    1.34  			} else {
    1.35 -				rects[j].x = 0;
    1.36 +				dst.x = 0;
    1.37  			}
    1.38  			if ( maxy ) {
    1.39 -				rects[j].y = rand() % maxy;
    1.40 +				dst.y = rand() % maxy;
    1.41  			} else {
    1.42 -				rects[j].y = 0;
    1.43 +				dst.y = 0;
    1.44  			}
    1.45 -			rects[j].w = bmp->w;
    1.46 -			rects[j].h = bmp->h;
    1.47 -			SDL_BlitSurface(bmp, NULL, screen, &rects[j]);
    1.48 +			dst.w = bmp->w;
    1.49 +			dst.h = bmp->h;
    1.50 +			SDL_BlitSurface(bmp, NULL, screen, &dst);
    1.51  		}
    1.52 -		if ( screen->flags & SDL_DOUBLEBUF ) {
    1.53 -			SDL_Flip(screen);
    1.54 -		} else {
    1.55 -			SDL_UpdateRects(screen, blitcount, rects);
    1.56 -		}
    1.57 +		SDL_Flip(screen);
    1.58  	}
    1.59 -	free(rects);
    1.60  
    1.61  	return i;
    1.62  }
    1.63  
    1.64 -void RunModeTests(SDL_Surface *screen)
    1.65 +int RunModeTests(SDL_Surface *screen)
    1.66  {
    1.67  	Uint32 then, now;
    1.68  	Uint32 frames;
    1.69 +	float seconds;
    1.70  	int i;
    1.71  	Uint8 r, g, b;
    1.72  	Uint32 pixel;
    1.73  	SDL_Surface *bmp, *tmp;
    1.74 +	SDL_Event event;
    1.75 +
    1.76 +	while ( SDL_PollEvent(&event) ) {
    1.77 +		if ( event.type == SDL_KEYDOWN )
    1.78 +			return 0;
    1.79 +	}
    1.80  
    1.81  	/* First test fills and screen update speed */
    1.82  	printf("Running color fill and fullscreen update test\n");
    1.83 @@ -103,7 +104,17 @@
    1.84  		++frames;
    1.85  	}
    1.86  	now = SDL_GetTicks();
    1.87 -	printf("%d fills and flips, %f FPS\n", frames, (float)(now - then) / frames);
    1.88 +	seconds = (float)(now - then) / 1000.0f;
    1.89 +	if ( seconds > 0.0f ) {
    1.90 +		printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
    1.91 +	} else {
    1.92 +		printf("%d fills and flips in zero seconds!n", frames);
    1.93 +	}
    1.94 +
    1.95 +	while ( SDL_PollEvent(&event) ) {
    1.96 +		if ( event.type == SDL_KEYDOWN )
    1.97 +			return 0;
    1.98 +	}
    1.99  
   1.100  	bmp = SDL_LoadBMP("sample.bmp");
   1.101  	if ( ! bmp ) {
   1.102 @@ -115,10 +126,13 @@
   1.103  	PrintFlags(bmp->flags);
   1.104  	printf("\n");
   1.105  	then = SDL_GetTicks();
   1.106 -	frames = RunBlitTests(screen, bmp, 10);
   1.107 +	frames = RunBlitTests(screen, bmp, NUM_BLITS);
   1.108  	now = SDL_GetTicks();
   1.109 -	if ( frames ) {
   1.110 -		printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
   1.111 +	seconds = (float)(now - then) / 1000.0f;
   1.112 +	if ( seconds > 0.0f ) {
   1.113 +		printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
   1.114 +	} else {
   1.115 +		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
   1.116  	}
   1.117  
   1.118  	tmp = bmp;
   1.119 @@ -133,12 +147,21 @@
   1.120  	PrintFlags(bmp->flags);
   1.121  	printf("\n");
   1.122  	then = SDL_GetTicks();
   1.123 -	frames = RunBlitTests(screen, bmp, 10);
   1.124 +	frames = RunBlitTests(screen, bmp, NUM_BLITS);
   1.125  	now = SDL_GetTicks();
   1.126 -	if ( frames ) {
   1.127 -		printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
   1.128 +	seconds = (float)(now - then) / 1000.0f;
   1.129 +	if ( seconds > 0.0f ) {
   1.130 +		printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
   1.131 +	} else {
   1.132 +		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
   1.133  	}
   1.134  	SDL_FreeSurface(bmp);
   1.135 +
   1.136 +	while ( SDL_PollEvent(&event) ) {
   1.137 +		if ( event.type == SDL_KEYDOWN )
   1.138 +			return 0;
   1.139 +	}
   1.140 +	return 1;
   1.141  }
   1.142  
   1.143  void RunVideoTests()
   1.144 @@ -160,6 +183,8 @@
   1.145  	SDL_Surface *screen;
   1.146  
   1.147  	/* Test out several different video mode combinations */
   1.148 +	SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
   1.149 +	SDL_ShowCursor(0);
   1.150  	for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
   1.151  		for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
   1.152  			printf("===================================\n");
   1.153 @@ -183,7 +208,9 @@
   1.154  				printf("\n");
   1.155  				continue;
   1.156  			}
   1.157 -			RunModeTests(screen);
   1.158 +			if ( ! RunModeTests(screen) ) {
   1.159 +				return;
   1.160 +			}
   1.161  		}
   1.162  	}
   1.163  }
   1.164 @@ -193,12 +220,16 @@
   1.165  	const SDL_VideoInfo *info;
   1.166  	int i;
   1.167  	SDL_Rect **modes;
   1.168 +	char driver[128];
   1.169  
   1.170  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.171  		fprintf(stderr,
   1.172  			"Couldn't initialize SDL: %s\n", SDL_GetError());
   1.173  		exit(1);
   1.174  	}
   1.175 +	if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
   1.176 +		printf("Video driver: %s\n", driver);
   1.177 +	}
   1.178  	info = SDL_GetVideoInfo();
   1.179  	printf(
   1.180  "Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);