Fixed some bugs and added some features to the -benchmark facility
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40481
This commit is contained in:
parent
5b393a92a4
commit
9e8960992e
1 changed files with 61 additions and 30 deletions
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
#define NUM_BLITS 10
|
||||||
|
#define NUM_UPDATES 500
|
||||||
|
|
||||||
#define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
|
#define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
|
||||||
|
|
||||||
void PrintFlags(Uint32 flags)
|
void PrintFlags(Uint32 flags)
|
||||||
|
@ -30,49 +33,47 @@ int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
|
||||||
int i, j;
|
int i, j;
|
||||||
int maxx;
|
int maxx;
|
||||||
int maxy;
|
int maxy;
|
||||||
SDL_Rect *rects;
|
SDL_Rect dst;
|
||||||
|
|
||||||
rects = (SDL_Rect *)malloc(blitcount * sizeof(*rects));
|
maxx = (int)screen->w - bmp->w + 1;
|
||||||
if ( ! rects ) {
|
maxy = (int)screen->h - bmp->h + 1;
|
||||||
return 0;
|
for ( i = 0; i < NUM_UPDATES; ++i ) {
|
||||||
}
|
|
||||||
maxx = (int)screen->w - bmp->w;
|
|
||||||
maxy = (int)screen->h - bmp->h;
|
|
||||||
for ( i = 0; i < 100; ++i ) {
|
|
||||||
for ( j = 0; j < blitcount; ++j ) {
|
for ( j = 0; j < blitcount; ++j ) {
|
||||||
if ( maxx ) {
|
if ( maxx ) {
|
||||||
rects[j].x = rand() % maxx;
|
dst.x = rand() % maxx;
|
||||||
} else {
|
} else {
|
||||||
rects[j].x = 0;
|
dst.x = 0;
|
||||||
}
|
}
|
||||||
if ( maxy ) {
|
if ( maxy ) {
|
||||||
rects[j].y = rand() % maxy;
|
dst.y = rand() % maxy;
|
||||||
} else {
|
} else {
|
||||||
rects[j].y = 0;
|
dst.y = 0;
|
||||||
}
|
}
|
||||||
rects[j].w = bmp->w;
|
dst.w = bmp->w;
|
||||||
rects[j].h = bmp->h;
|
dst.h = bmp->h;
|
||||||
SDL_BlitSurface(bmp, NULL, screen, &rects[j]);
|
SDL_BlitSurface(bmp, NULL, screen, &dst);
|
||||||
}
|
|
||||||
if ( screen->flags & SDL_DOUBLEBUF ) {
|
|
||||||
SDL_Flip(screen);
|
|
||||||
} else {
|
|
||||||
SDL_UpdateRects(screen, blitcount, rects);
|
|
||||||
}
|
}
|
||||||
|
SDL_Flip(screen);
|
||||||
}
|
}
|
||||||
free(rects);
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunModeTests(SDL_Surface *screen)
|
int RunModeTests(SDL_Surface *screen)
|
||||||
{
|
{
|
||||||
Uint32 then, now;
|
Uint32 then, now;
|
||||||
Uint32 frames;
|
Uint32 frames;
|
||||||
|
float seconds;
|
||||||
int i;
|
int i;
|
||||||
Uint8 r, g, b;
|
Uint8 r, g, b;
|
||||||
Uint32 pixel;
|
Uint32 pixel;
|
||||||
SDL_Surface *bmp, *tmp;
|
SDL_Surface *bmp, *tmp;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
while ( SDL_PollEvent(&event) ) {
|
||||||
|
if ( event.type == SDL_KEYDOWN )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* First test fills and screen update speed */
|
/* First test fills and screen update speed */
|
||||||
printf("Running color fill and fullscreen update test\n");
|
printf("Running color fill and fullscreen update test\n");
|
||||||
|
@ -103,7 +104,17 @@ void RunModeTests(SDL_Surface *screen)
|
||||||
++frames;
|
++frames;
|
||||||
}
|
}
|
||||||
now = SDL_GetTicks();
|
now = SDL_GetTicks();
|
||||||
printf("%d fills and flips, %f FPS\n", frames, (float)(now - then) / frames);
|
seconds = (float)(now - then) / 1000.0f;
|
||||||
|
if ( seconds > 0.0f ) {
|
||||||
|
printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
|
||||||
|
} else {
|
||||||
|
printf("%d fills and flips in zero seconds!n", frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( SDL_PollEvent(&event) ) {
|
||||||
|
if ( event.type == SDL_KEYDOWN )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bmp = SDL_LoadBMP("sample.bmp");
|
bmp = SDL_LoadBMP("sample.bmp");
|
||||||
if ( ! bmp ) {
|
if ( ! bmp ) {
|
||||||
|
@ -115,10 +126,13 @@ void RunModeTests(SDL_Surface *screen)
|
||||||
PrintFlags(bmp->flags);
|
PrintFlags(bmp->flags);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
then = SDL_GetTicks();
|
then = SDL_GetTicks();
|
||||||
frames = RunBlitTests(screen, bmp, 10);
|
frames = RunBlitTests(screen, bmp, NUM_BLITS);
|
||||||
now = SDL_GetTicks();
|
now = SDL_GetTicks();
|
||||||
if ( frames ) {
|
seconds = (float)(now - then) / 1000.0f;
|
||||||
printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
|
if ( seconds > 0.0f ) {
|
||||||
|
printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
|
||||||
|
} else {
|
||||||
|
printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = bmp;
|
tmp = bmp;
|
||||||
|
@ -133,12 +147,21 @@ void RunModeTests(SDL_Surface *screen)
|
||||||
PrintFlags(bmp->flags);
|
PrintFlags(bmp->flags);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
then = SDL_GetTicks();
|
then = SDL_GetTicks();
|
||||||
frames = RunBlitTests(screen, bmp, 10);
|
frames = RunBlitTests(screen, bmp, NUM_BLITS);
|
||||||
now = SDL_GetTicks();
|
now = SDL_GetTicks();
|
||||||
if ( frames ) {
|
seconds = (float)(now - then) / 1000.0f;
|
||||||
printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
|
if ( seconds > 0.0f ) {
|
||||||
|
printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
|
||||||
|
} else {
|
||||||
|
printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
|
||||||
}
|
}
|
||||||
SDL_FreeSurface(bmp);
|
SDL_FreeSurface(bmp);
|
||||||
|
|
||||||
|
while ( SDL_PollEvent(&event) ) {
|
||||||
|
if ( event.type == SDL_KEYDOWN )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunVideoTests()
|
void RunVideoTests()
|
||||||
|
@ -160,6 +183,8 @@ void RunVideoTests()
|
||||||
SDL_Surface *screen;
|
SDL_Surface *screen;
|
||||||
|
|
||||||
/* Test out several different video mode combinations */
|
/* Test out several different video mode combinations */
|
||||||
|
SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
|
||||||
|
SDL_ShowCursor(0);
|
||||||
for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
|
for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
|
||||||
for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
|
for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
|
||||||
printf("===================================\n");
|
printf("===================================\n");
|
||||||
|
@ -183,7 +208,9 @@ void RunVideoTests()
|
||||||
printf("\n");
|
printf("\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RunModeTests(screen);
|
if ( ! RunModeTests(screen) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,12 +220,16 @@ int main(int argc, char *argv[])
|
||||||
const SDL_VideoInfo *info;
|
const SDL_VideoInfo *info;
|
||||||
int i;
|
int i;
|
||||||
SDL_Rect **modes;
|
SDL_Rect **modes;
|
||||||
|
char driver[128];
|
||||||
|
|
||||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Couldn't initialize SDL: %s\n", SDL_GetError());
|
"Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
|
||||||
|
printf("Video driver: %s\n", driver);
|
||||||
|
}
|
||||||
info = SDL_GetVideoInfo();
|
info = SDL_GetVideoInfo();
|
||||||
printf(
|
printf(
|
||||||
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
|
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue